d48ff4fd44c328eb3458390b79facac08734b7b9
[~shefty/rdma-dev.git] / kernel / sysctl.c
1 /*
2  * sysctl.c: General linux system control interface
3  *
4  * Begun 24 March 1995, Stephen Tweedie
5  * Added /proc support, Dec 1995
6  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9  * Dynamic registration fixes, Stephen Tweedie.
10  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12  *  Horn.
13  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16  *  Wendling.
17  * The list_for_each() macro wasn't appropriate for the sysctl loop.
18  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
19  */
20
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
32 #include <linux/fs.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
59 #include <linux/kmod.h>
60 #include <linux/capability.h>
61 #include <linux/binfmts.h>
62
63 #include <asm/uaccess.h>
64 #include <asm/processor.h>
65
66 #ifdef CONFIG_X86
67 #include <asm/nmi.h>
68 #include <asm/stacktrace.h>
69 #include <asm/io.h>
70 #endif
71 #ifdef CONFIG_BSD_PROCESS_ACCT
72 #include <linux/acct.h>
73 #endif
74 #ifdef CONFIG_RT_MUTEXES
75 #include <linux/rtmutex.h>
76 #endif
77 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
78 #include <linux/lockdep.h>
79 #endif
80 #ifdef CONFIG_CHR_DEV_SG
81 #include <scsi/sg.h>
82 #endif
83
84 #ifdef CONFIG_LOCKUP_DETECTOR
85 #include <linux/nmi.h>
86 #endif
87
88
89 #if defined(CONFIG_SYSCTL)
90
91 /* External variables not in a header file. */
92 extern int sysctl_overcommit_memory;
93 extern int sysctl_overcommit_ratio;
94 extern int max_threads;
95 extern int core_uses_pid;
96 extern int suid_dumpable;
97 extern char core_pattern[];
98 extern unsigned int core_pipe_limit;
99 extern int pid_max;
100 extern int min_free_kbytes;
101 extern int pid_max_min, pid_max_max;
102 extern int sysctl_drop_caches;
103 extern int percpu_pagelist_fraction;
104 extern int compat_log;
105 extern int latencytop_enabled;
106 extern int sysctl_nr_open_min, sysctl_nr_open_max;
107 #ifndef CONFIG_MMU
108 extern int sysctl_nr_trim_pages;
109 #endif
110 #ifdef CONFIG_BLOCK
111 extern int blk_iopoll_enabled;
112 #endif
113
114 /* Constants used for minimum and  maximum */
115 #ifdef CONFIG_LOCKUP_DETECTOR
116 static int sixty = 60;
117 static int neg_one = -1;
118 #endif
119
120 static int zero;
121 static int __maybe_unused one = 1;
122 static int __maybe_unused two = 2;
123 static int __maybe_unused three = 3;
124 static unsigned long one_ul = 1;
125 static int one_hundred = 100;
126 #ifdef CONFIG_PRINTK
127 static int ten_thousand = 10000;
128 #endif
129
130 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132
133 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134 static int maxolduid = 65535;
135 static int minolduid;
136 static int min_percpu_pagelist_fract = 8;
137
138 static int ngroups_max = NGROUPS_MAX;
139 static const int cap_last_cap = CAP_LAST_CAP;
140
141 #ifdef CONFIG_INOTIFY_USER
142 #include <linux/inotify.h>
143 #endif
144 #ifdef CONFIG_SPARC
145 #include <asm/system.h>
146 #endif
147
148 #ifdef CONFIG_SPARC64
149 extern int sysctl_tsb_ratio;
150 #endif
151
152 #ifdef __hppa__
153 extern int pwrsw_enabled;
154 extern int unaligned_enabled;
155 #endif
156
157 #ifdef CONFIG_IA64
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
160 #endif
161
162 #ifdef CONFIG_PROC_SYSCTL
163 static int proc_do_cad_pid(struct ctl_table *table, int write,
164                   void __user *buffer, size_t *lenp, loff_t *ppos);
165 static int proc_taint(struct ctl_table *table, int write,
166                                void __user *buffer, size_t *lenp, loff_t *ppos);
167 #endif
168
169 #ifdef CONFIG_PRINTK
170 static int proc_dmesg_restrict(struct ctl_table *table, int write,
171                                 void __user *buffer, size_t *lenp, loff_t *ppos);
172 #endif
173
174 #ifdef CONFIG_MAGIC_SYSRQ
175 /* Note: sysrq code uses it's own private copy */
176 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
177
178 static int sysrq_sysctl_handler(ctl_table *table, int write,
179                                 void __user *buffer, size_t *lenp,
180                                 loff_t *ppos)
181 {
182         int error;
183
184         error = proc_dointvec(table, write, buffer, lenp, ppos);
185         if (error)
186                 return error;
187
188         if (write)
189                 sysrq_toggle_support(__sysrq_enabled);
190
191         return 0;
192 }
193
194 #endif
195
196 static struct ctl_table kern_table[];
197 static struct ctl_table vm_table[];
198 static struct ctl_table fs_table[];
199 static struct ctl_table debug_table[];
200 static struct ctl_table dev_table[];
201 extern struct ctl_table random_table[];
202 #ifdef CONFIG_EPOLL
203 extern struct ctl_table epoll_table[];
204 #endif
205
206 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
207 int sysctl_legacy_va_layout;
208 #endif
209
210 /* The default sysctl tables: */
211
212 static struct ctl_table sysctl_base_table[] = {
213         {
214                 .procname       = "kernel",
215                 .mode           = 0555,
216                 .child          = kern_table,
217         },
218         {
219                 .procname       = "vm",
220                 .mode           = 0555,
221                 .child          = vm_table,
222         },
223         {
224                 .procname       = "fs",
225                 .mode           = 0555,
226                 .child          = fs_table,
227         },
228         {
229                 .procname       = "debug",
230                 .mode           = 0555,
231                 .child          = debug_table,
232         },
233         {
234                 .procname       = "dev",
235                 .mode           = 0555,
236                 .child          = dev_table,
237         },
238         { }
239 };
240
241 #ifdef CONFIG_SCHED_DEBUG
242 static int min_sched_granularity_ns = 100000;           /* 100 usecs */
243 static int max_sched_granularity_ns = NSEC_PER_SEC;     /* 1 second */
244 static int min_wakeup_granularity_ns;                   /* 0 usecs */
245 static int max_wakeup_granularity_ns = NSEC_PER_SEC;    /* 1 second */
246 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
247 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
248 #endif
249
250 #ifdef CONFIG_COMPACTION
251 static int min_extfrag_threshold;
252 static int max_extfrag_threshold = 1000;
253 #endif
254
255 static struct ctl_table kern_table[] = {
256         {
257                 .procname       = "sched_child_runs_first",
258                 .data           = &sysctl_sched_child_runs_first,
259                 .maxlen         = sizeof(unsigned int),
260                 .mode           = 0644,
261                 .proc_handler   = proc_dointvec,
262         },
263 #ifdef CONFIG_SCHED_DEBUG
264         {
265                 .procname       = "sched_min_granularity_ns",
266                 .data           = &sysctl_sched_min_granularity,
267                 .maxlen         = sizeof(unsigned int),
268                 .mode           = 0644,
269                 .proc_handler   = sched_proc_update_handler,
270                 .extra1         = &min_sched_granularity_ns,
271                 .extra2         = &max_sched_granularity_ns,
272         },
273         {
274                 .procname       = "sched_latency_ns",
275                 .data           = &sysctl_sched_latency,
276                 .maxlen         = sizeof(unsigned int),
277                 .mode           = 0644,
278                 .proc_handler   = sched_proc_update_handler,
279                 .extra1         = &min_sched_granularity_ns,
280                 .extra2         = &max_sched_granularity_ns,
281         },
282         {
283                 .procname       = "sched_wakeup_granularity_ns",
284                 .data           = &sysctl_sched_wakeup_granularity,
285                 .maxlen         = sizeof(unsigned int),
286                 .mode           = 0644,
287                 .proc_handler   = sched_proc_update_handler,
288                 .extra1         = &min_wakeup_granularity_ns,
289                 .extra2         = &max_wakeup_granularity_ns,
290         },
291         {
292                 .procname       = "sched_tunable_scaling",
293                 .data           = &sysctl_sched_tunable_scaling,
294                 .maxlen         = sizeof(enum sched_tunable_scaling),
295                 .mode           = 0644,
296                 .proc_handler   = sched_proc_update_handler,
297                 .extra1         = &min_sched_tunable_scaling,
298                 .extra2         = &max_sched_tunable_scaling,
299         },
300         {
301                 .procname       = "sched_migration_cost",
302                 .data           = &sysctl_sched_migration_cost,
303                 .maxlen         = sizeof(unsigned int),
304                 .mode           = 0644,
305                 .proc_handler   = proc_dointvec,
306         },
307         {
308                 .procname       = "sched_nr_migrate",
309                 .data           = &sysctl_sched_nr_migrate,
310                 .maxlen         = sizeof(unsigned int),
311                 .mode           = 0644,
312                 .proc_handler   = proc_dointvec,
313         },
314         {
315                 .procname       = "sched_time_avg",
316                 .data           = &sysctl_sched_time_avg,
317                 .maxlen         = sizeof(unsigned int),
318                 .mode           = 0644,
319                 .proc_handler   = proc_dointvec,
320         },
321         {
322                 .procname       = "sched_shares_window",
323                 .data           = &sysctl_sched_shares_window,
324                 .maxlen         = sizeof(unsigned int),
325                 .mode           = 0644,
326                 .proc_handler   = proc_dointvec,
327         },
328         {
329                 .procname       = "timer_migration",
330                 .data           = &sysctl_timer_migration,
331                 .maxlen         = sizeof(unsigned int),
332                 .mode           = 0644,
333                 .proc_handler   = proc_dointvec_minmax,
334                 .extra1         = &zero,
335                 .extra2         = &one,
336         },
337 #endif
338         {
339                 .procname       = "sched_rt_period_us",
340                 .data           = &sysctl_sched_rt_period,
341                 .maxlen         = sizeof(unsigned int),
342                 .mode           = 0644,
343                 .proc_handler   = sched_rt_handler,
344         },
345         {
346                 .procname       = "sched_rt_runtime_us",
347                 .data           = &sysctl_sched_rt_runtime,
348                 .maxlen         = sizeof(int),
349                 .mode           = 0644,
350                 .proc_handler   = sched_rt_handler,
351         },
352 #ifdef CONFIG_SCHED_AUTOGROUP
353         {
354                 .procname       = "sched_autogroup_enabled",
355                 .data           = &sysctl_sched_autogroup_enabled,
356                 .maxlen         = sizeof(unsigned int),
357                 .mode           = 0644,
358                 .proc_handler   = proc_dointvec_minmax,
359                 .extra1         = &zero,
360                 .extra2         = &one,
361         },
362 #endif
363 #ifdef CONFIG_CFS_BANDWIDTH
364         {
365                 .procname       = "sched_cfs_bandwidth_slice_us",
366                 .data           = &sysctl_sched_cfs_bandwidth_slice,
367                 .maxlen         = sizeof(unsigned int),
368                 .mode           = 0644,
369                 .proc_handler   = proc_dointvec_minmax,
370                 .extra1         = &one,
371         },
372 #endif
373 #ifdef CONFIG_PROVE_LOCKING
374         {
375                 .procname       = "prove_locking",
376                 .data           = &prove_locking,
377                 .maxlen         = sizeof(int),
378                 .mode           = 0644,
379                 .proc_handler   = proc_dointvec,
380         },
381 #endif
382 #ifdef CONFIG_LOCK_STAT
383         {
384                 .procname       = "lock_stat",
385                 .data           = &lock_stat,
386                 .maxlen         = sizeof(int),
387                 .mode           = 0644,
388                 .proc_handler   = proc_dointvec,
389         },
390 #endif
391         {
392                 .procname       = "panic",
393                 .data           = &panic_timeout,
394                 .maxlen         = sizeof(int),
395                 .mode           = 0644,
396                 .proc_handler   = proc_dointvec,
397         },
398         {
399                 .procname       = "core_uses_pid",
400                 .data           = &core_uses_pid,
401                 .maxlen         = sizeof(int),
402                 .mode           = 0644,
403                 .proc_handler   = proc_dointvec,
404         },
405         {
406                 .procname       = "core_pattern",
407                 .data           = core_pattern,
408                 .maxlen         = CORENAME_MAX_SIZE,
409                 .mode           = 0644,
410                 .proc_handler   = proc_dostring,
411         },
412         {
413                 .procname       = "core_pipe_limit",
414                 .data           = &core_pipe_limit,
415                 .maxlen         = sizeof(unsigned int),
416                 .mode           = 0644,
417                 .proc_handler   = proc_dointvec,
418         },
419 #ifdef CONFIG_PROC_SYSCTL
420         {
421                 .procname       = "tainted",
422                 .maxlen         = sizeof(long),
423                 .mode           = 0644,
424                 .proc_handler   = proc_taint,
425         },
426 #endif
427 #ifdef CONFIG_LATENCYTOP
428         {
429                 .procname       = "latencytop",
430                 .data           = &latencytop_enabled,
431                 .maxlen         = sizeof(int),
432                 .mode           = 0644,
433                 .proc_handler   = proc_dointvec,
434         },
435 #endif
436 #ifdef CONFIG_BLK_DEV_INITRD
437         {
438                 .procname       = "real-root-dev",
439                 .data           = &real_root_dev,
440                 .maxlen         = sizeof(int),
441                 .mode           = 0644,
442                 .proc_handler   = proc_dointvec,
443         },
444 #endif
445         {
446                 .procname       = "print-fatal-signals",
447                 .data           = &print_fatal_signals,
448                 .maxlen         = sizeof(int),
449                 .mode           = 0644,
450                 .proc_handler   = proc_dointvec,
451         },
452 #ifdef CONFIG_SPARC
453         {
454                 .procname       = "reboot-cmd",
455                 .data           = reboot_command,
456                 .maxlen         = 256,
457                 .mode           = 0644,
458                 .proc_handler   = proc_dostring,
459         },
460         {
461                 .procname       = "stop-a",
462                 .data           = &stop_a_enabled,
463                 .maxlen         = sizeof (int),
464                 .mode           = 0644,
465                 .proc_handler   = proc_dointvec,
466         },
467         {
468                 .procname       = "scons-poweroff",
469                 .data           = &scons_pwroff,
470                 .maxlen         = sizeof (int),
471                 .mode           = 0644,
472                 .proc_handler   = proc_dointvec,
473         },
474 #endif
475 #ifdef CONFIG_SPARC64
476         {
477                 .procname       = "tsb-ratio",
478                 .data           = &sysctl_tsb_ratio,
479                 .maxlen         = sizeof (int),
480                 .mode           = 0644,
481                 .proc_handler   = proc_dointvec,
482         },
483 #endif
484 #ifdef __hppa__
485         {
486                 .procname       = "soft-power",
487                 .data           = &pwrsw_enabled,
488                 .maxlen         = sizeof (int),
489                 .mode           = 0644,
490                 .proc_handler   = proc_dointvec,
491         },
492         {
493                 .procname       = "unaligned-trap",
494                 .data           = &unaligned_enabled,
495                 .maxlen         = sizeof (int),
496                 .mode           = 0644,
497                 .proc_handler   = proc_dointvec,
498         },
499 #endif
500         {
501                 .procname       = "ctrl-alt-del",
502                 .data           = &C_A_D,
503                 .maxlen         = sizeof(int),
504                 .mode           = 0644,
505                 .proc_handler   = proc_dointvec,
506         },
507 #ifdef CONFIG_FUNCTION_TRACER
508         {
509                 .procname       = "ftrace_enabled",
510                 .data           = &ftrace_enabled,
511                 .maxlen         = sizeof(int),
512                 .mode           = 0644,
513                 .proc_handler   = ftrace_enable_sysctl,
514         },
515 #endif
516 #ifdef CONFIG_STACK_TRACER
517         {
518                 .procname       = "stack_tracer_enabled",
519                 .data           = &stack_tracer_enabled,
520                 .maxlen         = sizeof(int),
521                 .mode           = 0644,
522                 .proc_handler   = stack_trace_sysctl,
523         },
524 #endif
525 #ifdef CONFIG_TRACING
526         {
527                 .procname       = "ftrace_dump_on_oops",
528                 .data           = &ftrace_dump_on_oops,
529                 .maxlen         = sizeof(int),
530                 .mode           = 0644,
531                 .proc_handler   = proc_dointvec,
532         },
533 #endif
534 #ifdef CONFIG_MODULES
535         {
536                 .procname       = "modprobe",
537                 .data           = &modprobe_path,
538                 .maxlen         = KMOD_PATH_LEN,
539                 .mode           = 0644,
540                 .proc_handler   = proc_dostring,
541         },
542         {
543                 .procname       = "modules_disabled",
544                 .data           = &modules_disabled,
545                 .maxlen         = sizeof(int),
546                 .mode           = 0644,
547                 /* only handle a transition from default "0" to "1" */
548                 .proc_handler   = proc_dointvec_minmax,
549                 .extra1         = &one,
550                 .extra2         = &one,
551         },
552 #endif
553 #ifdef CONFIG_HOTPLUG
554         {
555                 .procname       = "hotplug",
556                 .data           = &uevent_helper,
557                 .maxlen         = UEVENT_HELPER_PATH_LEN,
558                 .mode           = 0644,
559                 .proc_handler   = proc_dostring,
560         },
561 #endif
562 #ifdef CONFIG_CHR_DEV_SG
563         {
564                 .procname       = "sg-big-buff",
565                 .data           = &sg_big_buff,
566                 .maxlen         = sizeof (int),
567                 .mode           = 0444,
568                 .proc_handler   = proc_dointvec,
569         },
570 #endif
571 #ifdef CONFIG_BSD_PROCESS_ACCT
572         {
573                 .procname       = "acct",
574                 .data           = &acct_parm,
575                 .maxlen         = 3*sizeof(int),
576                 .mode           = 0644,
577                 .proc_handler   = proc_dointvec,
578         },
579 #endif
580 #ifdef CONFIG_MAGIC_SYSRQ
581         {
582                 .procname       = "sysrq",
583                 .data           = &__sysrq_enabled,
584                 .maxlen         = sizeof (int),
585                 .mode           = 0644,
586                 .proc_handler   = sysrq_sysctl_handler,
587         },
588 #endif
589 #ifdef CONFIG_PROC_SYSCTL
590         {
591                 .procname       = "cad_pid",
592                 .data           = NULL,
593                 .maxlen         = sizeof (int),
594                 .mode           = 0600,
595                 .proc_handler   = proc_do_cad_pid,
596         },
597 #endif
598         {
599                 .procname       = "threads-max",
600                 .data           = &max_threads,
601                 .maxlen         = sizeof(int),
602                 .mode           = 0644,
603                 .proc_handler   = proc_dointvec,
604         },
605         {
606                 .procname       = "random",
607                 .mode           = 0555,
608                 .child          = random_table,
609         },
610         {
611                 .procname       = "usermodehelper",
612                 .mode           = 0555,
613                 .child          = usermodehelper_table,
614         },
615         {
616                 .procname       = "overflowuid",
617                 .data           = &overflowuid,
618                 .maxlen         = sizeof(int),
619                 .mode           = 0644,
620                 .proc_handler   = proc_dointvec_minmax,
621                 .extra1         = &minolduid,
622                 .extra2         = &maxolduid,
623         },
624         {
625                 .procname       = "overflowgid",
626                 .data           = &overflowgid,
627                 .maxlen         = sizeof(int),
628                 .mode           = 0644,
629                 .proc_handler   = proc_dointvec_minmax,
630                 .extra1         = &minolduid,
631                 .extra2         = &maxolduid,
632         },
633 #ifdef CONFIG_S390
634 #ifdef CONFIG_MATHEMU
635         {
636                 .procname       = "ieee_emulation_warnings",
637                 .data           = &sysctl_ieee_emulation_warnings,
638                 .maxlen         = sizeof(int),
639                 .mode           = 0644,
640                 .proc_handler   = proc_dointvec,
641         },
642 #endif
643         {
644                 .procname       = "userprocess_debug",
645                 .data           = &show_unhandled_signals,
646                 .maxlen         = sizeof(int),
647                 .mode           = 0644,
648                 .proc_handler   = proc_dointvec,
649         },
650 #endif
651         {
652                 .procname       = "pid_max",
653                 .data           = &pid_max,
654                 .maxlen         = sizeof (int),
655                 .mode           = 0644,
656                 .proc_handler   = proc_dointvec_minmax,
657                 .extra1         = &pid_max_min,
658                 .extra2         = &pid_max_max,
659         },
660         {
661                 .procname       = "panic_on_oops",
662                 .data           = &panic_on_oops,
663                 .maxlen         = sizeof(int),
664                 .mode           = 0644,
665                 .proc_handler   = proc_dointvec,
666         },
667 #if defined CONFIG_PRINTK
668         {
669                 .procname       = "printk",
670                 .data           = &console_loglevel,
671                 .maxlen         = 4*sizeof(int),
672                 .mode           = 0644,
673                 .proc_handler   = proc_dointvec,
674         },
675         {
676                 .procname       = "printk_ratelimit",
677                 .data           = &printk_ratelimit_state.interval,
678                 .maxlen         = sizeof(int),
679                 .mode           = 0644,
680                 .proc_handler   = proc_dointvec_jiffies,
681         },
682         {
683                 .procname       = "printk_ratelimit_burst",
684                 .data           = &printk_ratelimit_state.burst,
685                 .maxlen         = sizeof(int),
686                 .mode           = 0644,
687                 .proc_handler   = proc_dointvec,
688         },
689         {
690                 .procname       = "printk_delay",
691                 .data           = &printk_delay_msec,
692                 .maxlen         = sizeof(int),
693                 .mode           = 0644,
694                 .proc_handler   = proc_dointvec_minmax,
695                 .extra1         = &zero,
696                 .extra2         = &ten_thousand,
697         },
698         {
699                 .procname       = "dmesg_restrict",
700                 .data           = &dmesg_restrict,
701                 .maxlen         = sizeof(int),
702                 .mode           = 0644,
703                 .proc_handler   = proc_dointvec_minmax,
704                 .extra1         = &zero,
705                 .extra2         = &one,
706         },
707         {
708                 .procname       = "kptr_restrict",
709                 .data           = &kptr_restrict,
710                 .maxlen         = sizeof(int),
711                 .mode           = 0644,
712                 .proc_handler   = proc_dmesg_restrict,
713                 .extra1         = &zero,
714                 .extra2         = &two,
715         },
716 #endif
717         {
718                 .procname       = "ngroups_max",
719                 .data           = &ngroups_max,
720                 .maxlen         = sizeof (int),
721                 .mode           = 0444,
722                 .proc_handler   = proc_dointvec,
723         },
724         {
725                 .procname       = "cap_last_cap",
726                 .data           = (void *)&cap_last_cap,
727                 .maxlen         = sizeof(int),
728                 .mode           = 0444,
729                 .proc_handler   = proc_dointvec,
730         },
731 #if defined(CONFIG_LOCKUP_DETECTOR)
732         {
733                 .procname       = "watchdog",
734                 .data           = &watchdog_enabled,
735                 .maxlen         = sizeof (int),
736                 .mode           = 0644,
737                 .proc_handler   = proc_dowatchdog,
738                 .extra1         = &zero,
739                 .extra2         = &one,
740         },
741         {
742                 .procname       = "watchdog_thresh",
743                 .data           = &watchdog_thresh,
744                 .maxlen         = sizeof(int),
745                 .mode           = 0644,
746                 .proc_handler   = proc_dowatchdog,
747                 .extra1         = &neg_one,
748                 .extra2         = &sixty,
749         },
750         {
751                 .procname       = "softlockup_panic",
752                 .data           = &softlockup_panic,
753                 .maxlen         = sizeof(int),
754                 .mode           = 0644,
755                 .proc_handler   = proc_dointvec_minmax,
756                 .extra1         = &zero,
757                 .extra2         = &one,
758         },
759         {
760                 .procname       = "nmi_watchdog",
761                 .data           = &watchdog_enabled,
762                 .maxlen         = sizeof (int),
763                 .mode           = 0644,
764                 .proc_handler   = proc_dowatchdog,
765                 .extra1         = &zero,
766                 .extra2         = &one,
767         },
768 #endif
769 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
770         {
771                 .procname       = "unknown_nmi_panic",
772                 .data           = &unknown_nmi_panic,
773                 .maxlen         = sizeof (int),
774                 .mode           = 0644,
775                 .proc_handler   = proc_dointvec,
776         },
777 #endif
778 #if defined(CONFIG_X86)
779         {
780                 .procname       = "panic_on_unrecovered_nmi",
781                 .data           = &panic_on_unrecovered_nmi,
782                 .maxlen         = sizeof(int),
783                 .mode           = 0644,
784                 .proc_handler   = proc_dointvec,
785         },
786         {
787                 .procname       = "panic_on_io_nmi",
788                 .data           = &panic_on_io_nmi,
789                 .maxlen         = sizeof(int),
790                 .mode           = 0644,
791                 .proc_handler   = proc_dointvec,
792         },
793 #ifdef CONFIG_DEBUG_STACKOVERFLOW
794         {
795                 .procname       = "panic_on_stackoverflow",
796                 .data           = &sysctl_panic_on_stackoverflow,
797                 .maxlen         = sizeof(int),
798                 .mode           = 0644,
799                 .proc_handler   = proc_dointvec,
800         },
801 #endif
802         {
803                 .procname       = "bootloader_type",
804                 .data           = &bootloader_type,
805                 .maxlen         = sizeof (int),
806                 .mode           = 0444,
807                 .proc_handler   = proc_dointvec,
808         },
809         {
810                 .procname       = "bootloader_version",
811                 .data           = &bootloader_version,
812                 .maxlen         = sizeof (int),
813                 .mode           = 0444,
814                 .proc_handler   = proc_dointvec,
815         },
816         {
817                 .procname       = "kstack_depth_to_print",
818                 .data           = &kstack_depth_to_print,
819                 .maxlen         = sizeof(int),
820                 .mode           = 0644,
821                 .proc_handler   = proc_dointvec,
822         },
823         {
824                 .procname       = "io_delay_type",
825                 .data           = &io_delay_type,
826                 .maxlen         = sizeof(int),
827                 .mode           = 0644,
828                 .proc_handler   = proc_dointvec,
829         },
830 #endif
831 #if defined(CONFIG_MMU)
832         {
833                 .procname       = "randomize_va_space",
834                 .data           = &randomize_va_space,
835                 .maxlen         = sizeof(int),
836                 .mode           = 0644,
837                 .proc_handler   = proc_dointvec,
838         },
839 #endif
840 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
841         {
842                 .procname       = "spin_retry",
843                 .data           = &spin_retry,
844                 .maxlen         = sizeof (int),
845                 .mode           = 0644,
846                 .proc_handler   = proc_dointvec,
847         },
848 #endif
849 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
850         {
851                 .procname       = "acpi_video_flags",
852                 .data           = &acpi_realmode_flags,
853                 .maxlen         = sizeof (unsigned long),
854                 .mode           = 0644,
855                 .proc_handler   = proc_doulongvec_minmax,
856         },
857 #endif
858 #ifdef CONFIG_IA64
859         {
860                 .procname       = "ignore-unaligned-usertrap",
861                 .data           = &no_unaligned_warning,
862                 .maxlen         = sizeof (int),
863                 .mode           = 0644,
864                 .proc_handler   = proc_dointvec,
865         },
866         {
867                 .procname       = "unaligned-dump-stack",
868                 .data           = &unaligned_dump_stack,
869                 .maxlen         = sizeof (int),
870                 .mode           = 0644,
871                 .proc_handler   = proc_dointvec,
872         },
873 #endif
874 #ifdef CONFIG_DETECT_HUNG_TASK
875         {
876                 .procname       = "hung_task_panic",
877                 .data           = &sysctl_hung_task_panic,
878                 .maxlen         = sizeof(int),
879                 .mode           = 0644,
880                 .proc_handler   = proc_dointvec_minmax,
881                 .extra1         = &zero,
882                 .extra2         = &one,
883         },
884         {
885                 .procname       = "hung_task_check_count",
886                 .data           = &sysctl_hung_task_check_count,
887                 .maxlen         = sizeof(unsigned long),
888                 .mode           = 0644,
889                 .proc_handler   = proc_doulongvec_minmax,
890         },
891         {
892                 .procname       = "hung_task_timeout_secs",
893                 .data           = &sysctl_hung_task_timeout_secs,
894                 .maxlen         = sizeof(unsigned long),
895                 .mode           = 0644,
896                 .proc_handler   = proc_dohung_task_timeout_secs,
897         },
898         {
899                 .procname       = "hung_task_warnings",
900                 .data           = &sysctl_hung_task_warnings,
901                 .maxlen         = sizeof(unsigned long),
902                 .mode           = 0644,
903                 .proc_handler   = proc_doulongvec_minmax,
904         },
905 #endif
906 #ifdef CONFIG_COMPAT
907         {
908                 .procname       = "compat-log",
909                 .data           = &compat_log,
910                 .maxlen         = sizeof (int),
911                 .mode           = 0644,
912                 .proc_handler   = proc_dointvec,
913         },
914 #endif
915 #ifdef CONFIG_RT_MUTEXES
916         {
917                 .procname       = "max_lock_depth",
918                 .data           = &max_lock_depth,
919                 .maxlen         = sizeof(int),
920                 .mode           = 0644,
921                 .proc_handler   = proc_dointvec,
922         },
923 #endif
924         {
925                 .procname       = "poweroff_cmd",
926                 .data           = &poweroff_cmd,
927                 .maxlen         = POWEROFF_CMD_PATH_LEN,
928                 .mode           = 0644,
929                 .proc_handler   = proc_dostring,
930         },
931 #ifdef CONFIG_KEYS
932         {
933                 .procname       = "keys",
934                 .mode           = 0555,
935                 .child          = key_sysctls,
936         },
937 #endif
938 #ifdef CONFIG_RCU_TORTURE_TEST
939         {
940                 .procname       = "rcutorture_runnable",
941                 .data           = &rcutorture_runnable,
942                 .maxlen         = sizeof(int),
943                 .mode           = 0644,
944                 .proc_handler   = proc_dointvec,
945         },
946 #endif
947 #ifdef CONFIG_PERF_EVENTS
948         /*
949          * User-space scripts rely on the existence of this file
950          * as a feature check for perf_events being enabled.
951          *
952          * So it's an ABI, do not remove!
953          */
954         {
955                 .procname       = "perf_event_paranoid",
956                 .data           = &sysctl_perf_event_paranoid,
957                 .maxlen         = sizeof(sysctl_perf_event_paranoid),
958                 .mode           = 0644,
959                 .proc_handler   = proc_dointvec,
960         },
961         {
962                 .procname       = "perf_event_mlock_kb",
963                 .data           = &sysctl_perf_event_mlock,
964                 .maxlen         = sizeof(sysctl_perf_event_mlock),
965                 .mode           = 0644,
966                 .proc_handler   = proc_dointvec,
967         },
968         {
969                 .procname       = "perf_event_max_sample_rate",
970                 .data           = &sysctl_perf_event_sample_rate,
971                 .maxlen         = sizeof(sysctl_perf_event_sample_rate),
972                 .mode           = 0644,
973                 .proc_handler   = perf_proc_update_handler,
974         },
975 #endif
976 #ifdef CONFIG_KMEMCHECK
977         {
978                 .procname       = "kmemcheck",
979                 .data           = &kmemcheck_enabled,
980                 .maxlen         = sizeof(int),
981                 .mode           = 0644,
982                 .proc_handler   = proc_dointvec,
983         },
984 #endif
985 #ifdef CONFIG_BLOCK
986         {
987                 .procname       = "blk_iopoll",
988                 .data           = &blk_iopoll_enabled,
989                 .maxlen         = sizeof(int),
990                 .mode           = 0644,
991                 .proc_handler   = proc_dointvec,
992         },
993 #endif
994         { }
995 };
996
997 static struct ctl_table vm_table[] = {
998         {
999                 .procname       = "overcommit_memory",
1000                 .data           = &sysctl_overcommit_memory,
1001                 .maxlen         = sizeof(sysctl_overcommit_memory),
1002                 .mode           = 0644,
1003                 .proc_handler   = proc_dointvec_minmax,
1004                 .extra1         = &zero,
1005                 .extra2         = &two,
1006         },
1007         {
1008                 .procname       = "panic_on_oom",
1009                 .data           = &sysctl_panic_on_oom,
1010                 .maxlen         = sizeof(sysctl_panic_on_oom),
1011                 .mode           = 0644,
1012                 .proc_handler   = proc_dointvec_minmax,
1013                 .extra1         = &zero,
1014                 .extra2         = &two,
1015         },
1016         {
1017                 .procname       = "oom_kill_allocating_task",
1018                 .data           = &sysctl_oom_kill_allocating_task,
1019                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
1020                 .mode           = 0644,
1021                 .proc_handler   = proc_dointvec,
1022         },
1023         {
1024                 .procname       = "oom_dump_tasks",
1025                 .data           = &sysctl_oom_dump_tasks,
1026                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
1027                 .mode           = 0644,
1028                 .proc_handler   = proc_dointvec,
1029         },
1030         {
1031                 .procname       = "overcommit_ratio",
1032                 .data           = &sysctl_overcommit_ratio,
1033                 .maxlen         = sizeof(sysctl_overcommit_ratio),
1034                 .mode           = 0644,
1035                 .proc_handler   = proc_dointvec,
1036         },
1037         {
1038                 .procname       = "page-cluster", 
1039                 .data           = &page_cluster,
1040                 .maxlen         = sizeof(int),
1041                 .mode           = 0644,
1042                 .proc_handler   = proc_dointvec_minmax,
1043                 .extra1         = &zero,
1044         },
1045         {
1046                 .procname       = "dirty_background_ratio",
1047                 .data           = &dirty_background_ratio,
1048                 .maxlen         = sizeof(dirty_background_ratio),
1049                 .mode           = 0644,
1050                 .proc_handler   = dirty_background_ratio_handler,
1051                 .extra1         = &zero,
1052                 .extra2         = &one_hundred,
1053         },
1054         {
1055                 .procname       = "dirty_background_bytes",
1056                 .data           = &dirty_background_bytes,
1057                 .maxlen         = sizeof(dirty_background_bytes),
1058                 .mode           = 0644,
1059                 .proc_handler   = dirty_background_bytes_handler,
1060                 .extra1         = &one_ul,
1061         },
1062         {
1063                 .procname       = "dirty_ratio",
1064                 .data           = &vm_dirty_ratio,
1065                 .maxlen         = sizeof(vm_dirty_ratio),
1066                 .mode           = 0644,
1067                 .proc_handler   = dirty_ratio_handler,
1068                 .extra1         = &zero,
1069                 .extra2         = &one_hundred,
1070         },
1071         {
1072                 .procname       = "dirty_bytes",
1073                 .data           = &vm_dirty_bytes,
1074                 .maxlen         = sizeof(vm_dirty_bytes),
1075                 .mode           = 0644,
1076                 .proc_handler   = dirty_bytes_handler,
1077                 .extra1         = &dirty_bytes_min,
1078         },
1079         {
1080                 .procname       = "dirty_writeback_centisecs",
1081                 .data           = &dirty_writeback_interval,
1082                 .maxlen         = sizeof(dirty_writeback_interval),
1083                 .mode           = 0644,
1084                 .proc_handler   = dirty_writeback_centisecs_handler,
1085         },
1086         {
1087                 .procname       = "dirty_expire_centisecs",
1088                 .data           = &dirty_expire_interval,
1089                 .maxlen         = sizeof(dirty_expire_interval),
1090                 .mode           = 0644,
1091                 .proc_handler   = proc_dointvec_minmax,
1092                 .extra1         = &zero,
1093         },
1094         {
1095                 .procname       = "nr_pdflush_threads",
1096                 .data           = &nr_pdflush_threads,
1097                 .maxlen         = sizeof nr_pdflush_threads,
1098                 .mode           = 0444 /* read-only*/,
1099                 .proc_handler   = proc_dointvec,
1100         },
1101         {
1102                 .procname       = "swappiness",
1103                 .data           = &vm_swappiness,
1104                 .maxlen         = sizeof(vm_swappiness),
1105                 .mode           = 0644,
1106                 .proc_handler   = proc_dointvec_minmax,
1107                 .extra1         = &zero,
1108                 .extra2         = &one_hundred,
1109         },
1110 #ifdef CONFIG_HUGETLB_PAGE
1111         {
1112                 .procname       = "nr_hugepages",
1113                 .data           = NULL,
1114                 .maxlen         = sizeof(unsigned long),
1115                 .mode           = 0644,
1116                 .proc_handler   = hugetlb_sysctl_handler,
1117                 .extra1         = (void *)&hugetlb_zero,
1118                 .extra2         = (void *)&hugetlb_infinity,
1119         },
1120 #ifdef CONFIG_NUMA
1121         {
1122                 .procname       = "nr_hugepages_mempolicy",
1123                 .data           = NULL,
1124                 .maxlen         = sizeof(unsigned long),
1125                 .mode           = 0644,
1126                 .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
1127                 .extra1         = (void *)&hugetlb_zero,
1128                 .extra2         = (void *)&hugetlb_infinity,
1129         },
1130 #endif
1131          {
1132                 .procname       = "hugetlb_shm_group",
1133                 .data           = &sysctl_hugetlb_shm_group,
1134                 .maxlen         = sizeof(gid_t),
1135                 .mode           = 0644,
1136                 .proc_handler   = proc_dointvec,
1137          },
1138          {
1139                 .procname       = "hugepages_treat_as_movable",
1140                 .data           = &hugepages_treat_as_movable,
1141                 .maxlen         = sizeof(int),
1142                 .mode           = 0644,
1143                 .proc_handler   = hugetlb_treat_movable_handler,
1144         },
1145         {
1146                 .procname       = "nr_overcommit_hugepages",
1147                 .data           = NULL,
1148                 .maxlen         = sizeof(unsigned long),
1149                 .mode           = 0644,
1150                 .proc_handler   = hugetlb_overcommit_handler,
1151                 .extra1         = (void *)&hugetlb_zero,
1152                 .extra2         = (void *)&hugetlb_infinity,
1153         },
1154 #endif
1155         {
1156                 .procname       = "lowmem_reserve_ratio",
1157                 .data           = &sysctl_lowmem_reserve_ratio,
1158                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
1159                 .mode           = 0644,
1160                 .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
1161         },
1162         {
1163                 .procname       = "drop_caches",
1164                 .data           = &sysctl_drop_caches,
1165                 .maxlen         = sizeof(int),
1166                 .mode           = 0644,
1167                 .proc_handler   = drop_caches_sysctl_handler,
1168                 .extra1         = &one,
1169                 .extra2         = &three,
1170         },
1171 #ifdef CONFIG_COMPACTION
1172         {
1173                 .procname       = "compact_memory",
1174                 .data           = &sysctl_compact_memory,
1175                 .maxlen         = sizeof(int),
1176                 .mode           = 0200,
1177                 .proc_handler   = sysctl_compaction_handler,
1178         },
1179         {
1180                 .procname       = "extfrag_threshold",
1181                 .data           = &sysctl_extfrag_threshold,
1182                 .maxlen         = sizeof(int),
1183                 .mode           = 0644,
1184                 .proc_handler   = sysctl_extfrag_handler,
1185                 .extra1         = &min_extfrag_threshold,
1186                 .extra2         = &max_extfrag_threshold,
1187         },
1188
1189 #endif /* CONFIG_COMPACTION */
1190         {
1191                 .procname       = "min_free_kbytes",
1192                 .data           = &min_free_kbytes,
1193                 .maxlen         = sizeof(min_free_kbytes),
1194                 .mode           = 0644,
1195                 .proc_handler   = min_free_kbytes_sysctl_handler,
1196                 .extra1         = &zero,
1197         },
1198         {
1199                 .procname       = "percpu_pagelist_fraction",
1200                 .data           = &percpu_pagelist_fraction,
1201                 .maxlen         = sizeof(percpu_pagelist_fraction),
1202                 .mode           = 0644,
1203                 .proc_handler   = percpu_pagelist_fraction_sysctl_handler,
1204                 .extra1         = &min_percpu_pagelist_fract,
1205         },
1206 #ifdef CONFIG_MMU
1207         {
1208                 .procname       = "max_map_count",
1209                 .data           = &sysctl_max_map_count,
1210                 .maxlen         = sizeof(sysctl_max_map_count),
1211                 .mode           = 0644,
1212                 .proc_handler   = proc_dointvec_minmax,
1213                 .extra1         = &zero,
1214         },
1215 #else
1216         {
1217                 .procname       = "nr_trim_pages",
1218                 .data           = &sysctl_nr_trim_pages,
1219                 .maxlen         = sizeof(sysctl_nr_trim_pages),
1220                 .mode           = 0644,
1221                 .proc_handler   = proc_dointvec_minmax,
1222                 .extra1         = &zero,
1223         },
1224 #endif
1225         {
1226                 .procname       = "laptop_mode",
1227                 .data           = &laptop_mode,
1228                 .maxlen         = sizeof(laptop_mode),
1229                 .mode           = 0644,
1230                 .proc_handler   = proc_dointvec_jiffies,
1231         },
1232         {
1233                 .procname       = "block_dump",
1234                 .data           = &block_dump,
1235                 .maxlen         = sizeof(block_dump),
1236                 .mode           = 0644,
1237                 .proc_handler   = proc_dointvec,
1238                 .extra1         = &zero,
1239         },
1240         {
1241                 .procname       = "vfs_cache_pressure",
1242                 .data           = &sysctl_vfs_cache_pressure,
1243                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1244                 .mode           = 0644,
1245                 .proc_handler   = proc_dointvec,
1246                 .extra1         = &zero,
1247         },
1248 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1249         {
1250                 .procname       = "legacy_va_layout",
1251                 .data           = &sysctl_legacy_va_layout,
1252                 .maxlen         = sizeof(sysctl_legacy_va_layout),
1253                 .mode           = 0644,
1254                 .proc_handler   = proc_dointvec,
1255                 .extra1         = &zero,
1256         },
1257 #endif
1258 #ifdef CONFIG_NUMA
1259         {
1260                 .procname       = "zone_reclaim_mode",
1261                 .data           = &zone_reclaim_mode,
1262                 .maxlen         = sizeof(zone_reclaim_mode),
1263                 .mode           = 0644,
1264                 .proc_handler   = proc_dointvec,
1265                 .extra1         = &zero,
1266         },
1267         {
1268                 .procname       = "min_unmapped_ratio",
1269                 .data           = &sysctl_min_unmapped_ratio,
1270                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1271                 .mode           = 0644,
1272                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
1273                 .extra1         = &zero,
1274                 .extra2         = &one_hundred,
1275         },
1276         {
1277                 .procname       = "min_slab_ratio",
1278                 .data           = &sysctl_min_slab_ratio,
1279                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1280                 .mode           = 0644,
1281                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
1282                 .extra1         = &zero,
1283                 .extra2         = &one_hundred,
1284         },
1285 #endif
1286 #ifdef CONFIG_SMP
1287         {
1288                 .procname       = "stat_interval",
1289                 .data           = &sysctl_stat_interval,
1290                 .maxlen         = sizeof(sysctl_stat_interval),
1291                 .mode           = 0644,
1292                 .proc_handler   = proc_dointvec_jiffies,
1293         },
1294 #endif
1295 #ifdef CONFIG_MMU
1296         {
1297                 .procname       = "mmap_min_addr",
1298                 .data           = &dac_mmap_min_addr,
1299                 .maxlen         = sizeof(unsigned long),
1300                 .mode           = 0644,
1301                 .proc_handler   = mmap_min_addr_handler,
1302         },
1303 #endif
1304 #ifdef CONFIG_NUMA
1305         {
1306                 .procname       = "numa_zonelist_order",
1307                 .data           = &numa_zonelist_order,
1308                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1309                 .mode           = 0644,
1310                 .proc_handler   = numa_zonelist_order_handler,
1311         },
1312 #endif
1313 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1314    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1315         {
1316                 .procname       = "vdso_enabled",
1317                 .data           = &vdso_enabled,
1318                 .maxlen         = sizeof(vdso_enabled),
1319                 .mode           = 0644,
1320                 .proc_handler   = proc_dointvec,
1321                 .extra1         = &zero,
1322         },
1323 #endif
1324 #ifdef CONFIG_HIGHMEM
1325         {
1326                 .procname       = "highmem_is_dirtyable",
1327                 .data           = &vm_highmem_is_dirtyable,
1328                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
1329                 .mode           = 0644,
1330                 .proc_handler   = proc_dointvec_minmax,
1331                 .extra1         = &zero,
1332                 .extra2         = &one,
1333         },
1334 #endif
1335         {
1336                 .procname       = "scan_unevictable_pages",
1337                 .data           = &scan_unevictable_pages,
1338                 .maxlen         = sizeof(scan_unevictable_pages),
1339                 .mode           = 0644,
1340                 .proc_handler   = scan_unevictable_handler,
1341         },
1342 #ifdef CONFIG_MEMORY_FAILURE
1343         {
1344                 .procname       = "memory_failure_early_kill",
1345                 .data           = &sysctl_memory_failure_early_kill,
1346                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
1347                 .mode           = 0644,
1348                 .proc_handler   = proc_dointvec_minmax,
1349                 .extra1         = &zero,
1350                 .extra2         = &one,
1351         },
1352         {
1353                 .procname       = "memory_failure_recovery",
1354                 .data           = &sysctl_memory_failure_recovery,
1355                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
1356                 .mode           = 0644,
1357                 .proc_handler   = proc_dointvec_minmax,
1358                 .extra1         = &zero,
1359                 .extra2         = &one,
1360         },
1361 #endif
1362         { }
1363 };
1364
1365 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1366 static struct ctl_table binfmt_misc_table[] = {
1367         { }
1368 };
1369 #endif
1370
1371 static struct ctl_table fs_table[] = {
1372         {
1373                 .procname       = "inode-nr",
1374                 .data           = &inodes_stat,
1375                 .maxlen         = 2*sizeof(int),
1376                 .mode           = 0444,
1377                 .proc_handler   = proc_nr_inodes,
1378         },
1379         {
1380                 .procname       = "inode-state",
1381                 .data           = &inodes_stat,
1382                 .maxlen         = 7*sizeof(int),
1383                 .mode           = 0444,
1384                 .proc_handler   = proc_nr_inodes,
1385         },
1386         {
1387                 .procname       = "file-nr",
1388                 .data           = &files_stat,
1389                 .maxlen         = sizeof(files_stat),
1390                 .mode           = 0444,
1391                 .proc_handler   = proc_nr_files,
1392         },
1393         {
1394                 .procname       = "file-max",
1395                 .data           = &files_stat.max_files,
1396                 .maxlen         = sizeof(files_stat.max_files),
1397                 .mode           = 0644,
1398                 .proc_handler   = proc_doulongvec_minmax,
1399         },
1400         {
1401                 .procname       = "nr_open",
1402                 .data           = &sysctl_nr_open,
1403                 .maxlen         = sizeof(int),
1404                 .mode           = 0644,
1405                 .proc_handler   = proc_dointvec_minmax,
1406                 .extra1         = &sysctl_nr_open_min,
1407                 .extra2         = &sysctl_nr_open_max,
1408         },
1409         {
1410                 .procname       = "dentry-state",
1411                 .data           = &dentry_stat,
1412                 .maxlen         = 6*sizeof(int),
1413                 .mode           = 0444,
1414                 .proc_handler   = proc_nr_dentry,
1415         },
1416         {
1417                 .procname       = "overflowuid",
1418                 .data           = &fs_overflowuid,
1419                 .maxlen         = sizeof(int),
1420                 .mode           = 0644,
1421                 .proc_handler   = proc_dointvec_minmax,
1422                 .extra1         = &minolduid,
1423                 .extra2         = &maxolduid,
1424         },
1425         {
1426                 .procname       = "overflowgid",
1427                 .data           = &fs_overflowgid,
1428                 .maxlen         = sizeof(int),
1429                 .mode           = 0644,
1430                 .proc_handler   = proc_dointvec_minmax,
1431                 .extra1         = &minolduid,
1432                 .extra2         = &maxolduid,
1433         },
1434 #ifdef CONFIG_FILE_LOCKING
1435         {
1436                 .procname       = "leases-enable",
1437                 .data           = &leases_enable,
1438                 .maxlen         = sizeof(int),
1439                 .mode           = 0644,
1440                 .proc_handler   = proc_dointvec,
1441         },
1442 #endif
1443 #ifdef CONFIG_DNOTIFY
1444         {
1445                 .procname       = "dir-notify-enable",
1446                 .data           = &dir_notify_enable,
1447                 .maxlen         = sizeof(int),
1448                 .mode           = 0644,
1449                 .proc_handler   = proc_dointvec,
1450         },
1451 #endif
1452 #ifdef CONFIG_MMU
1453 #ifdef CONFIG_FILE_LOCKING
1454         {
1455                 .procname       = "lease-break-time",
1456                 .data           = &lease_break_time,
1457                 .maxlen         = sizeof(int),
1458                 .mode           = 0644,
1459                 .proc_handler   = proc_dointvec,
1460         },
1461 #endif
1462 #ifdef CONFIG_AIO
1463         {
1464                 .procname       = "aio-nr",
1465                 .data           = &aio_nr,
1466                 .maxlen         = sizeof(aio_nr),
1467                 .mode           = 0444,
1468                 .proc_handler   = proc_doulongvec_minmax,
1469         },
1470         {
1471                 .procname       = "aio-max-nr",
1472                 .data           = &aio_max_nr,
1473                 .maxlen         = sizeof(aio_max_nr),
1474                 .mode           = 0644,
1475                 .proc_handler   = proc_doulongvec_minmax,
1476         },
1477 #endif /* CONFIG_AIO */
1478 #ifdef CONFIG_INOTIFY_USER
1479         {
1480                 .procname       = "inotify",
1481                 .mode           = 0555,
1482                 .child          = inotify_table,
1483         },
1484 #endif  
1485 #ifdef CONFIG_EPOLL
1486         {
1487                 .procname       = "epoll",
1488                 .mode           = 0555,
1489                 .child          = epoll_table,
1490         },
1491 #endif
1492 #endif
1493         {
1494                 .procname       = "suid_dumpable",
1495                 .data           = &suid_dumpable,
1496                 .maxlen         = sizeof(int),
1497                 .mode           = 0644,
1498                 .proc_handler   = proc_dointvec_minmax,
1499                 .extra1         = &zero,
1500                 .extra2         = &two,
1501         },
1502 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1503         {
1504                 .procname       = "binfmt_misc",
1505                 .mode           = 0555,
1506                 .child          = binfmt_misc_table,
1507         },
1508 #endif
1509         {
1510                 .procname       = "pipe-max-size",
1511                 .data           = &pipe_max_size,
1512                 .maxlen         = sizeof(int),
1513                 .mode           = 0644,
1514                 .proc_handler   = &pipe_proc_fn,
1515                 .extra1         = &pipe_min_size,
1516         },
1517         { }
1518 };
1519
1520 static struct ctl_table debug_table[] = {
1521 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1522     defined(CONFIG_S390) || defined(CONFIG_TILE)
1523         {
1524                 .procname       = "exception-trace",
1525                 .data           = &show_unhandled_signals,
1526                 .maxlen         = sizeof(int),
1527                 .mode           = 0644,
1528                 .proc_handler   = proc_dointvec
1529         },
1530 #endif
1531 #if defined(CONFIG_OPTPROBES)
1532         {
1533                 .procname       = "kprobes-optimization",
1534                 .data           = &sysctl_kprobes_optimization,
1535                 .maxlen         = sizeof(int),
1536                 .mode           = 0644,
1537                 .proc_handler   = proc_kprobes_optimization_handler,
1538                 .extra1         = &zero,
1539                 .extra2         = &one,
1540         },
1541 #endif
1542         { }
1543 };
1544
1545 static struct ctl_table dev_table[] = {
1546         { }
1547 };
1548
1549 int __init sysctl_init(void)
1550 {
1551         register_sysctl_table(sysctl_base_table);
1552         return 0;
1553 }
1554
1555 #endif /* CONFIG_SYSCTL */
1556
1557 /*
1558  * /proc/sys support
1559  */
1560
1561 #ifdef CONFIG_PROC_SYSCTL
1562
1563 static int _proc_do_string(void* data, int maxlen, int write,
1564                            void __user *buffer,
1565                            size_t *lenp, loff_t *ppos)
1566 {
1567         size_t len;
1568         char __user *p;
1569         char c;
1570
1571         if (!data || !maxlen || !*lenp) {
1572                 *lenp = 0;
1573                 return 0;
1574         }
1575
1576         if (write) {
1577                 len = 0;
1578                 p = buffer;
1579                 while (len < *lenp) {
1580                         if (get_user(c, p++))
1581                                 return -EFAULT;
1582                         if (c == 0 || c == '\n')
1583                                 break;
1584                         len++;
1585                 }
1586                 if (len >= maxlen)
1587                         len = maxlen-1;
1588                 if(copy_from_user(data, buffer, len))
1589                         return -EFAULT;
1590                 ((char *) data)[len] = 0;
1591                 *ppos += *lenp;
1592         } else {
1593                 len = strlen(data);
1594                 if (len > maxlen)
1595                         len = maxlen;
1596
1597                 if (*ppos > len) {
1598                         *lenp = 0;
1599                         return 0;
1600                 }
1601
1602                 data += *ppos;
1603                 len  -= *ppos;
1604
1605                 if (len > *lenp)
1606                         len = *lenp;
1607                 if (len)
1608                         if(copy_to_user(buffer, data, len))
1609                                 return -EFAULT;
1610                 if (len < *lenp) {
1611                         if(put_user('\n', ((char __user *) buffer) + len))
1612                                 return -EFAULT;
1613                         len++;
1614                 }
1615                 *lenp = len;
1616                 *ppos += len;
1617         }
1618         return 0;
1619 }
1620
1621 /**
1622  * proc_dostring - read a string sysctl
1623  * @table: the sysctl table
1624  * @write: %TRUE if this is a write to the sysctl file
1625  * @buffer: the user buffer
1626  * @lenp: the size of the user buffer
1627  * @ppos: file position
1628  *
1629  * Reads/writes a string from/to the user buffer. If the kernel
1630  * buffer provided is not large enough to hold the string, the
1631  * string is truncated. The copied string is %NULL-terminated.
1632  * If the string is being read by the user process, it is copied
1633  * and a newline '\n' is added. It is truncated if the buffer is
1634  * not large enough.
1635  *
1636  * Returns 0 on success.
1637  */
1638 int proc_dostring(struct ctl_table *table, int write,
1639                   void __user *buffer, size_t *lenp, loff_t *ppos)
1640 {
1641         return _proc_do_string(table->data, table->maxlen, write,
1642                                buffer, lenp, ppos);
1643 }
1644
1645 static size_t proc_skip_spaces(char **buf)
1646 {
1647         size_t ret;
1648         char *tmp = skip_spaces(*buf);
1649         ret = tmp - *buf;
1650         *buf = tmp;
1651         return ret;
1652 }
1653
1654 static void proc_skip_char(char **buf, size_t *size, const char v)
1655 {
1656         while (*size) {
1657                 if (**buf != v)
1658                         break;
1659                 (*size)--;
1660                 (*buf)++;
1661         }
1662 }
1663
1664 #define TMPBUFLEN 22
1665 /**
1666  * proc_get_long - reads an ASCII formatted integer from a user buffer
1667  *
1668  * @buf: a kernel buffer
1669  * @size: size of the kernel buffer
1670  * @val: this is where the number will be stored
1671  * @neg: set to %TRUE if number is negative
1672  * @perm_tr: a vector which contains the allowed trailers
1673  * @perm_tr_len: size of the perm_tr vector
1674  * @tr: pointer to store the trailer character
1675  *
1676  * In case of success %0 is returned and @buf and @size are updated with
1677  * the amount of bytes read. If @tr is non-NULL and a trailing
1678  * character exists (size is non-zero after returning from this
1679  * function), @tr is updated with the trailing character.
1680  */
1681 static int proc_get_long(char **buf, size_t *size,
1682                           unsigned long *val, bool *neg,
1683                           const char *perm_tr, unsigned perm_tr_len, char *tr)
1684 {
1685         int len;
1686         char *p, tmp[TMPBUFLEN];
1687
1688         if (!*size)
1689                 return -EINVAL;
1690
1691         len = *size;
1692         if (len > TMPBUFLEN - 1)
1693                 len = TMPBUFLEN - 1;
1694
1695         memcpy(tmp, *buf, len);
1696
1697         tmp[len] = 0;
1698         p = tmp;
1699         if (*p == '-' && *size > 1) {
1700                 *neg = true;
1701                 p++;
1702         } else
1703                 *neg = false;
1704         if (!isdigit(*p))
1705                 return -EINVAL;
1706
1707         *val = simple_strtoul(p, &p, 0);
1708
1709         len = p - tmp;
1710
1711         /* We don't know if the next char is whitespace thus we may accept
1712          * invalid integers (e.g. 1234...a) or two integers instead of one
1713          * (e.g. 123...1). So lets not allow such large numbers. */
1714         if (len == TMPBUFLEN - 1)
1715                 return -EINVAL;
1716
1717         if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1718                 return -EINVAL;
1719
1720         if (tr && (len < *size))
1721                 *tr = *p;
1722
1723         *buf += len;
1724         *size -= len;
1725
1726         return 0;
1727 }
1728
1729 /**
1730  * proc_put_long - converts an integer to a decimal ASCII formatted string
1731  *
1732  * @buf: the user buffer
1733  * @size: the size of the user buffer
1734  * @val: the integer to be converted
1735  * @neg: sign of the number, %TRUE for negative
1736  *
1737  * In case of success %0 is returned and @buf and @size are updated with
1738  * the amount of bytes written.
1739  */
1740 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1741                           bool neg)
1742 {
1743         int len;
1744         char tmp[TMPBUFLEN], *p = tmp;
1745
1746         sprintf(p, "%s%lu", neg ? "-" : "", val);
1747         len = strlen(tmp);
1748         if (len > *size)
1749                 len = *size;
1750         if (copy_to_user(*buf, tmp, len))
1751                 return -EFAULT;
1752         *size -= len;
1753         *buf += len;
1754         return 0;
1755 }
1756 #undef TMPBUFLEN
1757
1758 static int proc_put_char(void __user **buf, size_t *size, char c)
1759 {
1760         if (*size) {
1761                 char __user **buffer = (char __user **)buf;
1762                 if (put_user(c, *buffer))
1763                         return -EFAULT;
1764                 (*size)--, (*buffer)++;
1765                 *buf = *buffer;
1766         }
1767         return 0;
1768 }
1769
1770 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1771                                  int *valp,
1772                                  int write, void *data)
1773 {
1774         if (write) {
1775                 *valp = *negp ? -*lvalp : *lvalp;
1776         } else {
1777                 int val = *valp;
1778                 if (val < 0) {
1779                         *negp = true;
1780                         *lvalp = (unsigned long)-val;
1781                 } else {
1782                         *negp = false;
1783                         *lvalp = (unsigned long)val;
1784                 }
1785         }
1786         return 0;
1787 }
1788
1789 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1790
1791 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1792                   int write, void __user *buffer,
1793                   size_t *lenp, loff_t *ppos,
1794                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1795                               int write, void *data),
1796                   void *data)
1797 {
1798         int *i, vleft, first = 1, err = 0;
1799         unsigned long page = 0;
1800         size_t left;
1801         char *kbuf;
1802         
1803         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1804                 *lenp = 0;
1805                 return 0;
1806         }
1807         
1808         i = (int *) tbl_data;
1809         vleft = table->maxlen / sizeof(*i);
1810         left = *lenp;
1811
1812         if (!conv)
1813                 conv = do_proc_dointvec_conv;
1814
1815         if (write) {
1816                 if (left > PAGE_SIZE - 1)
1817                         left = PAGE_SIZE - 1;
1818                 page = __get_free_page(GFP_TEMPORARY);
1819                 kbuf = (char *) page;
1820                 if (!kbuf)
1821                         return -ENOMEM;
1822                 if (copy_from_user(kbuf, buffer, left)) {
1823                         err = -EFAULT;
1824                         goto free;
1825                 }
1826                 kbuf[left] = 0;
1827         }
1828
1829         for (; left && vleft--; i++, first=0) {
1830                 unsigned long lval;
1831                 bool neg;
1832
1833                 if (write) {
1834                         left -= proc_skip_spaces(&kbuf);
1835
1836                         if (!left)
1837                                 break;
1838                         err = proc_get_long(&kbuf, &left, &lval, &neg,
1839                                              proc_wspace_sep,
1840                                              sizeof(proc_wspace_sep), NULL);
1841                         if (err)
1842                                 break;
1843                         if (conv(&neg, &lval, i, 1, data)) {
1844                                 err = -EINVAL;
1845                                 break;
1846                         }
1847                 } else {
1848                         if (conv(&neg, &lval, i, 0, data)) {
1849                                 err = -EINVAL;
1850                                 break;
1851                         }
1852                         if (!first)
1853                                 err = proc_put_char(&buffer, &left, '\t');
1854                         if (err)
1855                                 break;
1856                         err = proc_put_long(&buffer, &left, lval, neg);
1857                         if (err)
1858                                 break;
1859                 }
1860         }
1861
1862         if (!write && !first && left && !err)
1863                 err = proc_put_char(&buffer, &left, '\n');
1864         if (write && !err && left)
1865                 left -= proc_skip_spaces(&kbuf);
1866 free:
1867         if (write) {
1868                 free_page(page);
1869                 if (first)
1870                         return err ? : -EINVAL;
1871         }
1872         *lenp -= left;
1873         *ppos += *lenp;
1874         return err;
1875 }
1876
1877 static int do_proc_dointvec(struct ctl_table *table, int write,
1878                   void __user *buffer, size_t *lenp, loff_t *ppos,
1879                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1880                               int write, void *data),
1881                   void *data)
1882 {
1883         return __do_proc_dointvec(table->data, table, write,
1884                         buffer, lenp, ppos, conv, data);
1885 }
1886
1887 /**
1888  * proc_dointvec - read a vector of integers
1889  * @table: the sysctl table
1890  * @write: %TRUE if this is a write to the sysctl file
1891  * @buffer: the user buffer
1892  * @lenp: the size of the user buffer
1893  * @ppos: file position
1894  *
1895  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1896  * values from/to the user buffer, treated as an ASCII string. 
1897  *
1898  * Returns 0 on success.
1899  */
1900 int proc_dointvec(struct ctl_table *table, int write,
1901                      void __user *buffer, size_t *lenp, loff_t *ppos)
1902 {
1903     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1904                             NULL,NULL);
1905 }
1906
1907 /*
1908  * Taint values can only be increased
1909  * This means we can safely use a temporary.
1910  */
1911 static int proc_taint(struct ctl_table *table, int write,
1912                                void __user *buffer, size_t *lenp, loff_t *ppos)
1913 {
1914         struct ctl_table t;
1915         unsigned long tmptaint = get_taint();
1916         int err;
1917
1918         if (write && !capable(CAP_SYS_ADMIN))
1919                 return -EPERM;
1920
1921         t = *table;
1922         t.data = &tmptaint;
1923         err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1924         if (err < 0)
1925                 return err;
1926
1927         if (write) {
1928                 /*
1929                  * Poor man's atomic or. Not worth adding a primitive
1930                  * to everyone's atomic.h for this
1931                  */
1932                 int i;
1933                 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1934                         if ((tmptaint >> i) & 1)
1935                                 add_taint(i);
1936                 }
1937         }
1938
1939         return err;
1940 }
1941
1942 #ifdef CONFIG_PRINTK
1943 static int proc_dmesg_restrict(struct ctl_table *table, int write,
1944                                 void __user *buffer, size_t *lenp, loff_t *ppos)
1945 {
1946         if (write && !capable(CAP_SYS_ADMIN))
1947                 return -EPERM;
1948
1949         return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1950 }
1951 #endif
1952
1953 struct do_proc_dointvec_minmax_conv_param {
1954         int *min;
1955         int *max;
1956 };
1957
1958 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1959                                         int *valp,
1960                                         int write, void *data)
1961 {
1962         struct do_proc_dointvec_minmax_conv_param *param = data;
1963         if (write) {
1964                 int val = *negp ? -*lvalp : *lvalp;
1965                 if ((param->min && *param->min > val) ||
1966                     (param->max && *param->max < val))
1967                         return -EINVAL;
1968                 *valp = val;
1969         } else {
1970                 int val = *valp;
1971                 if (val < 0) {
1972                         *negp = true;
1973                         *lvalp = (unsigned long)-val;
1974                 } else {
1975                         *negp = false;
1976                         *lvalp = (unsigned long)val;
1977                 }
1978         }
1979         return 0;
1980 }
1981
1982 /**
1983  * proc_dointvec_minmax - read a vector of integers with min/max values
1984  * @table: the sysctl table
1985  * @write: %TRUE if this is a write to the sysctl file
1986  * @buffer: the user buffer
1987  * @lenp: the size of the user buffer
1988  * @ppos: file position
1989  *
1990  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1991  * values from/to the user buffer, treated as an ASCII string.
1992  *
1993  * This routine will ensure the values are within the range specified by
1994  * table->extra1 (min) and table->extra2 (max).
1995  *
1996  * Returns 0 on success.
1997  */
1998 int proc_dointvec_minmax(struct ctl_table *table, int write,
1999                   void __user *buffer, size_t *lenp, loff_t *ppos)
2000 {
2001         struct do_proc_dointvec_minmax_conv_param param = {
2002                 .min = (int *) table->extra1,
2003                 .max = (int *) table->extra2,
2004         };
2005         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2006                                 do_proc_dointvec_minmax_conv, &param);
2007 }
2008
2009 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2010                                      void __user *buffer,
2011                                      size_t *lenp, loff_t *ppos,
2012                                      unsigned long convmul,
2013                                      unsigned long convdiv)
2014 {
2015         unsigned long *i, *min, *max;
2016         int vleft, first = 1, err = 0;
2017         unsigned long page = 0;
2018         size_t left;
2019         char *kbuf;
2020
2021         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2022                 *lenp = 0;
2023                 return 0;
2024         }
2025
2026         i = (unsigned long *) data;
2027         min = (unsigned long *) table->extra1;
2028         max = (unsigned long *) table->extra2;
2029         vleft = table->maxlen / sizeof(unsigned long);
2030         left = *lenp;
2031
2032         if (write) {
2033                 if (left > PAGE_SIZE - 1)
2034                         left = PAGE_SIZE - 1;
2035                 page = __get_free_page(GFP_TEMPORARY);
2036                 kbuf = (char *) page;
2037                 if (!kbuf)
2038                         return -ENOMEM;
2039                 if (copy_from_user(kbuf, buffer, left)) {
2040                         err = -EFAULT;
2041                         goto free;
2042                 }
2043                 kbuf[left] = 0;
2044         }
2045
2046         for (; left && vleft--; i++, first = 0) {
2047                 unsigned long val;
2048
2049                 if (write) {
2050                         bool neg;
2051
2052                         left -= proc_skip_spaces(&kbuf);
2053
2054                         err = proc_get_long(&kbuf, &left, &val, &neg,
2055                                              proc_wspace_sep,
2056                                              sizeof(proc_wspace_sep), NULL);
2057                         if (err)
2058                                 break;
2059                         if (neg)
2060                                 continue;
2061                         if ((min && val < *min) || (max && val > *max))
2062                                 continue;
2063                         *i = val;
2064                 } else {
2065                         val = convdiv * (*i) / convmul;
2066                         if (!first)
2067                                 err = proc_put_char(&buffer, &left, '\t');
2068                         err = proc_put_long(&buffer, &left, val, false);
2069                         if (err)
2070                                 break;
2071                 }
2072         }
2073
2074         if (!write && !first && left && !err)
2075                 err = proc_put_char(&buffer, &left, '\n');
2076         if (write && !err)
2077                 left -= proc_skip_spaces(&kbuf);
2078 free:
2079         if (write) {
2080                 free_page(page);
2081                 if (first)
2082                         return err ? : -EINVAL;
2083         }
2084         *lenp -= left;
2085         *ppos += *lenp;
2086         return err;
2087 }
2088
2089 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2090                                      void __user *buffer,
2091                                      size_t *lenp, loff_t *ppos,
2092                                      unsigned long convmul,
2093                                      unsigned long convdiv)
2094 {
2095         return __do_proc_doulongvec_minmax(table->data, table, write,
2096                         buffer, lenp, ppos, convmul, convdiv);
2097 }
2098
2099 /**
2100  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2101  * @table: the sysctl table
2102  * @write: %TRUE if this is a write to the sysctl file
2103  * @buffer: the user buffer
2104  * @lenp: the size of the user buffer
2105  * @ppos: file position
2106  *
2107  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2108  * values from/to the user buffer, treated as an ASCII string.
2109  *
2110  * This routine will ensure the values are within the range specified by
2111  * table->extra1 (min) and table->extra2 (max).
2112  *
2113  * Returns 0 on success.
2114  */
2115 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2116                            void __user *buffer, size_t *lenp, loff_t *ppos)
2117 {
2118     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2119 }
2120
2121 /**
2122  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2123  * @table: the sysctl table
2124  * @write: %TRUE if this is a write to the sysctl file
2125  * @buffer: the user buffer
2126  * @lenp: the size of the user buffer
2127  * @ppos: file position
2128  *
2129  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2130  * values from/to the user buffer, treated as an ASCII string. The values
2131  * are treated as milliseconds, and converted to jiffies when they are stored.
2132  *
2133  * This routine will ensure the values are within the range specified by
2134  * table->extra1 (min) and table->extra2 (max).
2135  *
2136  * Returns 0 on success.
2137  */
2138 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2139                                       void __user *buffer,
2140                                       size_t *lenp, loff_t *ppos)
2141 {
2142     return do_proc_doulongvec_minmax(table, write, buffer,
2143                                      lenp, ppos, HZ, 1000l);
2144 }
2145
2146
2147 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2148                                          int *valp,
2149                                          int write, void *data)
2150 {
2151         if (write) {
2152                 if (*lvalp > LONG_MAX / HZ)
2153                         return 1;
2154                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2155         } else {
2156                 int val = *valp;
2157                 unsigned long lval;
2158                 if (val < 0) {
2159                         *negp = true;
2160                         lval = (unsigned long)-val;
2161                 } else {
2162                         *negp = false;
2163                         lval = (unsigned long)val;
2164                 }
2165                 *lvalp = lval / HZ;
2166         }
2167         return 0;
2168 }
2169
2170 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2171                                                 int *valp,
2172                                                 int write, void *data)
2173 {
2174         if (write) {
2175                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2176                         return 1;
2177                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2178         } else {
2179                 int val = *valp;
2180                 unsigned long lval;
2181                 if (val < 0) {
2182                         *negp = true;
2183                         lval = (unsigned long)-val;
2184                 } else {
2185                         *negp = false;
2186                         lval = (unsigned long)val;
2187                 }
2188                 *lvalp = jiffies_to_clock_t(lval);
2189         }
2190         return 0;
2191 }
2192
2193 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2194                                             int *valp,
2195                                             int write, void *data)
2196 {
2197         if (write) {
2198                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2199         } else {
2200                 int val = *valp;
2201                 unsigned long lval;
2202                 if (val < 0) {
2203                         *negp = true;
2204                         lval = (unsigned long)-val;
2205                 } else {
2206                         *negp = false;
2207                         lval = (unsigned long)val;
2208                 }
2209                 *lvalp = jiffies_to_msecs(lval);
2210         }
2211         return 0;
2212 }
2213
2214 /**
2215  * proc_dointvec_jiffies - read a vector of integers as seconds
2216  * @table: the sysctl table
2217  * @write: %TRUE if this is a write to the sysctl file
2218  * @buffer: the user buffer
2219  * @lenp: the size of the user buffer
2220  * @ppos: file position
2221  *
2222  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2223  * values from/to the user buffer, treated as an ASCII string. 
2224  * The values read are assumed to be in seconds, and are converted into
2225  * jiffies.
2226  *
2227  * Returns 0 on success.
2228  */
2229 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2230                           void __user *buffer, size_t *lenp, loff_t *ppos)
2231 {
2232     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2233                             do_proc_dointvec_jiffies_conv,NULL);
2234 }
2235
2236 /**
2237  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2238  * @table: the sysctl table
2239  * @write: %TRUE if this is a write to the sysctl file
2240  * @buffer: the user buffer
2241  * @lenp: the size of the user buffer
2242  * @ppos: pointer to the file position
2243  *
2244  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2245  * values from/to the user buffer, treated as an ASCII string. 
2246  * The values read are assumed to be in 1/USER_HZ seconds, and 
2247  * are converted into jiffies.
2248  *
2249  * Returns 0 on success.
2250  */
2251 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2252                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2253 {
2254     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2255                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2256 }
2257
2258 /**
2259  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2260  * @table: the sysctl table
2261  * @write: %TRUE if this is a write to the sysctl file
2262  * @buffer: the user buffer
2263  * @lenp: the size of the user buffer
2264  * @ppos: file position
2265  * @ppos: the current position in the file
2266  *
2267  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2268  * values from/to the user buffer, treated as an ASCII string. 
2269  * The values read are assumed to be in 1/1000 seconds, and 
2270  * are converted into jiffies.
2271  *
2272  * Returns 0 on success.
2273  */
2274 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2275                              void __user *buffer, size_t *lenp, loff_t *ppos)
2276 {
2277         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2278                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2279 }
2280
2281 static int proc_do_cad_pid(struct ctl_table *table, int write,
2282                            void __user *buffer, size_t *lenp, loff_t *ppos)
2283 {
2284         struct pid *new_pid;
2285         pid_t tmp;
2286         int r;
2287
2288         tmp = pid_vnr(cad_pid);
2289
2290         r = __do_proc_dointvec(&tmp, table, write, buffer,
2291                                lenp, ppos, NULL, NULL);
2292         if (r || !write)
2293                 return r;
2294
2295         new_pid = find_get_pid(tmp);
2296         if (!new_pid)
2297                 return -ESRCH;
2298
2299         put_pid(xchg(&cad_pid, new_pid));
2300         return 0;
2301 }
2302
2303 /**
2304  * proc_do_large_bitmap - read/write from/to a large bitmap
2305  * @table: the sysctl table
2306  * @write: %TRUE if this is a write to the sysctl file
2307  * @buffer: the user buffer
2308  * @lenp: the size of the user buffer
2309  * @ppos: file position
2310  *
2311  * The bitmap is stored at table->data and the bitmap length (in bits)
2312  * in table->maxlen.
2313  *
2314  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2315  * large bitmaps may be represented in a compact manner. Writing into
2316  * the file will clear the bitmap then update it with the given input.
2317  *
2318  * Returns 0 on success.
2319  */
2320 int proc_do_large_bitmap(struct ctl_table *table, int write,
2321                          void __user *buffer, size_t *lenp, loff_t *ppos)
2322 {
2323         int err = 0;
2324         bool first = 1;
2325         size_t left = *lenp;
2326         unsigned long bitmap_len = table->maxlen;
2327         unsigned long *bitmap = (unsigned long *) table->data;
2328         unsigned long *tmp_bitmap = NULL;
2329         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2330
2331         if (!bitmap_len || !left || (*ppos && !write)) {
2332                 *lenp = 0;
2333                 return 0;
2334         }
2335
2336         if (write) {
2337                 unsigned long page = 0;
2338                 char *kbuf;
2339
2340                 if (left > PAGE_SIZE - 1)
2341                         left = PAGE_SIZE - 1;
2342
2343                 page = __get_free_page(GFP_TEMPORARY);
2344                 kbuf = (char *) page;
2345                 if (!kbuf)
2346                         return -ENOMEM;
2347                 if (copy_from_user(kbuf, buffer, left)) {
2348                         free_page(page);
2349                         return -EFAULT;
2350                 }
2351                 kbuf[left] = 0;
2352
2353                 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2354                                      GFP_KERNEL);
2355                 if (!tmp_bitmap) {
2356                         free_page(page);
2357                         return -ENOMEM;
2358                 }
2359                 proc_skip_char(&kbuf, &left, '\n');
2360                 while (!err && left) {
2361                         unsigned long val_a, val_b;
2362                         bool neg;
2363
2364                         err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2365                                              sizeof(tr_a), &c);
2366                         if (err)
2367                                 break;
2368                         if (val_a >= bitmap_len || neg) {
2369                                 err = -EINVAL;
2370                                 break;
2371                         }
2372
2373                         val_b = val_a;
2374                         if (left) {
2375                                 kbuf++;
2376                                 left--;
2377                         }
2378
2379                         if (c == '-') {
2380                                 err = proc_get_long(&kbuf, &left, &val_b,
2381                                                      &neg, tr_b, sizeof(tr_b),
2382                                                      &c);
2383                                 if (err)
2384                                         break;
2385                                 if (val_b >= bitmap_len || neg ||
2386                                     val_a > val_b) {
2387                                         err = -EINVAL;
2388                                         break;
2389                                 }
2390                                 if (left) {
2391                                         kbuf++;
2392                                         left--;
2393                                 }
2394                         }
2395
2396                         while (val_a <= val_b)
2397                                 set_bit(val_a++, tmp_bitmap);
2398
2399                         first = 0;
2400                         proc_skip_char(&kbuf, &left, '\n');
2401                 }
2402                 free_page(page);
2403         } else {
2404                 unsigned long bit_a, bit_b = 0;
2405
2406                 while (left) {
2407                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2408                         if (bit_a >= bitmap_len)
2409                                 break;
2410                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
2411                                                    bit_a + 1) - 1;
2412
2413                         if (!first) {
2414                                 err = proc_put_char(&buffer, &left, ',');
2415                                 if (err)
2416                                         break;
2417                         }
2418                         err = proc_put_long(&buffer, &left, bit_a, false);
2419                         if (err)
2420                                 break;
2421                         if (bit_a != bit_b) {
2422                                 err = proc_put_char(&buffer, &left, '-');
2423                                 if (err)
2424                                         break;
2425                                 err = proc_put_long(&buffer, &left, bit_b, false);
2426                                 if (err)
2427                                         break;
2428                         }
2429
2430                         first = 0; bit_b++;
2431                 }
2432                 if (!err)
2433                         err = proc_put_char(&buffer, &left, '\n');
2434         }
2435
2436         if (!err) {
2437                 if (write) {
2438                         if (*ppos)
2439                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2440                         else
2441                                 memcpy(bitmap, tmp_bitmap,
2442                                         BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2443                 }
2444                 kfree(tmp_bitmap);
2445                 *lenp -= left;
2446                 *ppos += *lenp;
2447                 return 0;
2448         } else {
2449                 kfree(tmp_bitmap);
2450                 return err;
2451         }
2452 }
2453
2454 #else /* CONFIG_PROC_SYSCTL */
2455
2456 int proc_dostring(struct ctl_table *table, int write,
2457                   void __user *buffer, size_t *lenp, loff_t *ppos)
2458 {
2459         return -ENOSYS;
2460 }
2461
2462 int proc_dointvec(struct ctl_table *table, int write,
2463                   void __user *buffer, size_t *lenp, loff_t *ppos)
2464 {
2465         return -ENOSYS;
2466 }
2467
2468 int proc_dointvec_minmax(struct ctl_table *table, int write,
2469                     void __user *buffer, size_t *lenp, loff_t *ppos)
2470 {
2471         return -ENOSYS;
2472 }
2473
2474 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2475                     void __user *buffer, size_t *lenp, loff_t *ppos)
2476 {
2477         return -ENOSYS;
2478 }
2479
2480 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2481                     void __user *buffer, size_t *lenp, loff_t *ppos)
2482 {
2483         return -ENOSYS;
2484 }
2485
2486 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2487                              void __user *buffer, size_t *lenp, loff_t *ppos)
2488 {
2489         return -ENOSYS;
2490 }
2491
2492 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2493                     void __user *buffer, size_t *lenp, loff_t *ppos)
2494 {
2495         return -ENOSYS;
2496 }
2497
2498 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2499                                       void __user *buffer,
2500                                       size_t *lenp, loff_t *ppos)
2501 {
2502     return -ENOSYS;
2503 }
2504
2505
2506 #endif /* CONFIG_PROC_SYSCTL */
2507
2508 /*
2509  * No sense putting this after each symbol definition, twice,
2510  * exception granted :-)
2511  */
2512 EXPORT_SYMBOL(proc_dointvec);
2513 EXPORT_SYMBOL(proc_dointvec_jiffies);
2514 EXPORT_SYMBOL(proc_dointvec_minmax);
2515 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2516 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2517 EXPORT_SYMBOL(proc_dostring);
2518 EXPORT_SYMBOL(proc_doulongvec_minmax);
2519 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);