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