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