mm: vmscan: only update per-cpu thresholds for online CPU
[linux/fpc-iii.git] / kernel / sysctl.c
blobc1b26e176aa6f690773d7857b69163f09a4f0248
1 /*
2 * sysctl.c: General linux system control interface
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
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/kmemleak.h>
34 #include <linux/fs.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/kexec.h>
67 #include <asm/uaccess.h>
68 #include <asm/processor.h>
70 #ifdef CONFIG_X86
71 #include <asm/nmi.h>
72 #include <asm/stacktrace.h>
73 #include <asm/io.h>
74 #endif
75 #ifdef CONFIG_SPARC
76 #include <asm/setup.h>
77 #endif
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 #include <linux/acct.h>
80 #endif
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
83 #endif
84 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85 #include <linux/lockdep.h>
86 #endif
87 #ifdef CONFIG_CHR_DEV_SG
88 #include <scsi/sg.h>
89 #endif
91 #ifdef CONFIG_LOCKUP_DETECTOR
92 #include <linux/nmi.h>
93 #endif
96 #if defined(CONFIG_SYSCTL)
98 /* External variables not in a header file. */
99 extern int max_threads;
100 extern int suid_dumpable;
101 #ifdef CONFIG_COREDUMP
102 extern int core_uses_pid;
103 extern char core_pattern[];
104 extern unsigned int core_pipe_limit;
105 #endif
106 extern int pid_max;
107 extern int pid_max_min, pid_max_max;
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
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
122 #endif
124 static int __maybe_unused neg_one = -1;
126 static int zero;
127 static int __maybe_unused one = 1;
128 static int __maybe_unused two = 2;
129 static int __maybe_unused three = 3;
130 static unsigned long one_ul = 1;
131 static int one_hundred = 100;
132 #ifdef CONFIG_PRINTK
133 static int ten_thousand = 10000;
134 #endif
136 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140 static int maxolduid = 65535;
141 static int minolduid;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
147 #ifdef CONFIG_DETECT_HUNG_TASK
148 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
149 #endif
151 #ifdef CONFIG_INOTIFY_USER
152 #include <linux/inotify.h>
153 #endif
154 #ifdef CONFIG_SPARC
155 #endif
157 #ifdef CONFIG_SPARC64
158 extern int sysctl_tsb_ratio;
159 #endif
161 #ifdef __hppa__
162 extern int pwrsw_enabled;
163 #endif
165 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
166 extern int unaligned_enabled;
167 #endif
169 #ifdef CONFIG_IA64
170 extern int unaligned_dump_stack;
171 #endif
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
174 extern int no_unaligned_warning;
175 #endif
177 #ifdef CONFIG_PROC_SYSCTL
178 static int proc_do_cad_pid(struct ctl_table *table, int write,
179 void __user *buffer, size_t *lenp, loff_t *ppos);
180 static int proc_taint(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos);
182 #endif
184 #ifdef CONFIG_PRINTK
185 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
187 #endif
189 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
191 #ifdef CONFIG_COREDUMP
192 static int proc_dostring_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
194 #endif
196 #ifdef CONFIG_MAGIC_SYSRQ
197 /* Note: sysrq code uses it's own private copy */
198 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
200 static int sysrq_sysctl_handler(ctl_table *table, int write,
201 void __user *buffer, size_t *lenp,
202 loff_t *ppos)
204 int error;
206 error = proc_dointvec(table, write, buffer, lenp, ppos);
207 if (error)
208 return error;
210 if (write)
211 sysrq_toggle_support(__sysrq_enabled);
213 return 0;
216 #endif
218 static struct ctl_table kern_table[];
219 static struct ctl_table vm_table[];
220 static struct ctl_table fs_table[];
221 static struct ctl_table debug_table[];
222 static struct ctl_table dev_table[];
223 extern struct ctl_table random_table[];
224 #ifdef CONFIG_EPOLL
225 extern struct ctl_table epoll_table[];
226 #endif
228 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229 int sysctl_legacy_va_layout;
230 #endif
232 /* The default sysctl tables: */
234 static struct ctl_table sysctl_base_table[] = {
236 .procname = "kernel",
237 .mode = 0555,
238 .child = kern_table,
241 .procname = "vm",
242 .mode = 0555,
243 .child = vm_table,
246 .procname = "fs",
247 .mode = 0555,
248 .child = fs_table,
251 .procname = "debug",
252 .mode = 0555,
253 .child = debug_table,
256 .procname = "dev",
257 .mode = 0555,
258 .child = dev_table,
263 #ifdef CONFIG_SCHED_DEBUG
264 static int min_sched_granularity_ns = 100000; /* 100 usecs */
265 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
266 static int min_wakeup_granularity_ns; /* 0 usecs */
267 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
268 #ifdef CONFIG_SMP
269 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
270 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
271 #endif /* CONFIG_SMP */
272 #endif /* CONFIG_SCHED_DEBUG */
274 #ifdef CONFIG_COMPACTION
275 static int min_extfrag_threshold;
276 static int max_extfrag_threshold = 1000;
277 #endif
279 static struct ctl_table kern_table[] = {
281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = proc_dointvec,
287 #ifdef CONFIG_SCHED_DEBUG
289 .procname = "sched_min_granularity_ns",
290 .data = &sysctl_sched_min_granularity,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = sched_proc_update_handler,
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
298 .procname = "sched_latency_ns",
299 .data = &sysctl_sched_latency,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_sched_granularity_ns,
304 .extra2 = &max_sched_granularity_ns,
307 .procname = "sched_wakeup_granularity_ns",
308 .data = &sysctl_sched_wakeup_granularity,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = sched_proc_update_handler,
312 .extra1 = &min_wakeup_granularity_ns,
313 .extra2 = &max_wakeup_granularity_ns,
315 #ifdef CONFIG_SMP
317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
320 .mode = 0644,
321 .proc_handler = sched_proc_update_handler,
322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
326 .procname = "sched_migration_cost_ns",
327 .data = &sysctl_sched_migration_cost,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = proc_dointvec,
333 .procname = "sched_nr_migrate",
334 .data = &sysctl_sched_nr_migrate,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec,
340 .procname = "sched_time_avg_ms",
341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec,
347 .procname = "sched_shares_window_ns",
348 .data = &sysctl_sched_shares_window,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = proc_dointvec,
354 .procname = "timer_migration",
355 .data = &sysctl_timer_migration,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
358 .proc_handler = proc_dointvec_minmax,
359 .extra1 = &zero,
360 .extra2 = &one,
362 #endif /* CONFIG_SMP */
363 #ifdef CONFIG_NUMA_BALANCING
365 .procname = "numa_balancing_scan_delay_ms",
366 .data = &sysctl_numa_balancing_scan_delay,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
369 .proc_handler = proc_dointvec,
372 .procname = "numa_balancing_scan_period_min_ms",
373 .data = &sysctl_numa_balancing_scan_period_min,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
376 .proc_handler = proc_dointvec,
379 .procname = "numa_balancing_scan_period_max_ms",
380 .data = &sysctl_numa_balancing_scan_period_max,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = proc_dointvec,
386 .procname = "numa_balancing_scan_size_mb",
387 .data = &sysctl_numa_balancing_scan_size,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = proc_dointvec,
393 .procname = "numa_balancing_migrate_deferred",
394 .data = &sysctl_numa_balancing_migrate_deferred,
395 .maxlen = sizeof(unsigned int),
396 .mode = 0644,
397 .proc_handler = proc_dointvec,
400 .procname = "numa_balancing",
401 .data = NULL, /* filled in by handler */
402 .maxlen = sizeof(unsigned int),
403 .mode = 0644,
404 .proc_handler = sysctl_numa_balancing,
405 .extra1 = &zero,
406 .extra2 = &one,
408 #endif /* CONFIG_NUMA_BALANCING */
409 #endif /* CONFIG_SCHED_DEBUG */
411 .procname = "sched_rt_period_us",
412 .data = &sysctl_sched_rt_period,
413 .maxlen = sizeof(unsigned int),
414 .mode = 0644,
415 .proc_handler = sched_rt_handler,
418 .procname = "sched_rt_runtime_us",
419 .data = &sysctl_sched_rt_runtime,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = sched_rt_handler,
425 .procname = "sched_rr_timeslice_ms",
426 .data = &sched_rr_timeslice,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = sched_rr_handler,
431 #ifdef CONFIG_SCHED_AUTOGROUP
433 .procname = "sched_autogroup_enabled",
434 .data = &sysctl_sched_autogroup_enabled,
435 .maxlen = sizeof(unsigned int),
436 .mode = 0644,
437 .proc_handler = proc_dointvec_minmax,
438 .extra1 = &zero,
439 .extra2 = &one,
441 #endif
442 #ifdef CONFIG_CFS_BANDWIDTH
444 .procname = "sched_cfs_bandwidth_slice_us",
445 .data = &sysctl_sched_cfs_bandwidth_slice,
446 .maxlen = sizeof(unsigned int),
447 .mode = 0644,
448 .proc_handler = proc_dointvec_minmax,
449 .extra1 = &one,
451 #endif
452 #ifdef CONFIG_PROVE_LOCKING
454 .procname = "prove_locking",
455 .data = &prove_locking,
456 .maxlen = sizeof(int),
457 .mode = 0644,
458 .proc_handler = proc_dointvec,
460 #endif
461 #ifdef CONFIG_LOCK_STAT
463 .procname = "lock_stat",
464 .data = &lock_stat,
465 .maxlen = sizeof(int),
466 .mode = 0644,
467 .proc_handler = proc_dointvec,
469 #endif
471 .procname = "panic",
472 .data = &panic_timeout,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec,
477 #ifdef CONFIG_COREDUMP
479 .procname = "core_uses_pid",
480 .data = &core_uses_pid,
481 .maxlen = sizeof(int),
482 .mode = 0644,
483 .proc_handler = proc_dointvec,
486 .procname = "core_pattern",
487 .data = core_pattern,
488 .maxlen = CORENAME_MAX_SIZE,
489 .mode = 0644,
490 .proc_handler = proc_dostring_coredump,
493 .procname = "core_pipe_limit",
494 .data = &core_pipe_limit,
495 .maxlen = sizeof(unsigned int),
496 .mode = 0644,
497 .proc_handler = proc_dointvec,
499 #endif
500 #ifdef CONFIG_PROC_SYSCTL
502 .procname = "tainted",
503 .maxlen = sizeof(long),
504 .mode = 0644,
505 .proc_handler = proc_taint,
507 #endif
508 #ifdef CONFIG_LATENCYTOP
510 .procname = "latencytop",
511 .data = &latencytop_enabled,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = proc_dointvec,
516 #endif
517 #ifdef CONFIG_BLK_DEV_INITRD
519 .procname = "real-root-dev",
520 .data = &real_root_dev,
521 .maxlen = sizeof(int),
522 .mode = 0644,
523 .proc_handler = proc_dointvec,
525 #endif
527 .procname = "print-fatal-signals",
528 .data = &print_fatal_signals,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = proc_dointvec,
533 #ifdef CONFIG_SPARC
535 .procname = "reboot-cmd",
536 .data = reboot_command,
537 .maxlen = 256,
538 .mode = 0644,
539 .proc_handler = proc_dostring,
542 .procname = "stop-a",
543 .data = &stop_a_enabled,
544 .maxlen = sizeof (int),
545 .mode = 0644,
546 .proc_handler = proc_dointvec,
549 .procname = "scons-poweroff",
550 .data = &scons_pwroff,
551 .maxlen = sizeof (int),
552 .mode = 0644,
553 .proc_handler = proc_dointvec,
555 #endif
556 #ifdef CONFIG_SPARC64
558 .procname = "tsb-ratio",
559 .data = &sysctl_tsb_ratio,
560 .maxlen = sizeof (int),
561 .mode = 0644,
562 .proc_handler = proc_dointvec,
564 #endif
565 #ifdef __hppa__
567 .procname = "soft-power",
568 .data = &pwrsw_enabled,
569 .maxlen = sizeof (int),
570 .mode = 0644,
571 .proc_handler = proc_dointvec,
573 #endif
574 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
576 .procname = "unaligned-trap",
577 .data = &unaligned_enabled,
578 .maxlen = sizeof (int),
579 .mode = 0644,
580 .proc_handler = proc_dointvec,
582 #endif
584 .procname = "ctrl-alt-del",
585 .data = &C_A_D,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = proc_dointvec,
590 #ifdef CONFIG_FUNCTION_TRACER
592 .procname = "ftrace_enabled",
593 .data = &ftrace_enabled,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = ftrace_enable_sysctl,
598 #endif
599 #ifdef CONFIG_STACK_TRACER
601 .procname = "stack_tracer_enabled",
602 .data = &stack_tracer_enabled,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = stack_trace_sysctl,
607 #endif
608 #ifdef CONFIG_TRACING
610 .procname = "ftrace_dump_on_oops",
611 .data = &ftrace_dump_on_oops,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = proc_dointvec,
617 .procname = "traceoff_on_warning",
618 .data = &__disable_trace_on_warning,
619 .maxlen = sizeof(__disable_trace_on_warning),
620 .mode = 0644,
621 .proc_handler = proc_dointvec,
623 #endif
624 #ifdef CONFIG_KEXEC
626 .procname = "kexec_load_disabled",
627 .data = &kexec_load_disabled,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 /* only handle a transition from default "0" to "1" */
631 .proc_handler = proc_dointvec_minmax,
632 .extra1 = &one,
633 .extra2 = &one,
635 #endif
636 #ifdef CONFIG_MODULES
638 .procname = "modprobe",
639 .data = &modprobe_path,
640 .maxlen = KMOD_PATH_LEN,
641 .mode = 0644,
642 .proc_handler = proc_dostring,
645 .procname = "modules_disabled",
646 .data = &modules_disabled,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 /* only handle a transition from default "0" to "1" */
650 .proc_handler = proc_dointvec_minmax,
651 .extra1 = &one,
652 .extra2 = &one,
654 #endif
657 .procname = "hotplug",
658 .data = &uevent_helper,
659 .maxlen = UEVENT_HELPER_PATH_LEN,
660 .mode = 0644,
661 .proc_handler = proc_dostring,
664 #ifdef CONFIG_CHR_DEV_SG
666 .procname = "sg-big-buff",
667 .data = &sg_big_buff,
668 .maxlen = sizeof (int),
669 .mode = 0444,
670 .proc_handler = proc_dointvec,
672 #endif
673 #ifdef CONFIG_BSD_PROCESS_ACCT
675 .procname = "acct",
676 .data = &acct_parm,
677 .maxlen = 3*sizeof(int),
678 .mode = 0644,
679 .proc_handler = proc_dointvec,
681 #endif
682 #ifdef CONFIG_MAGIC_SYSRQ
684 .procname = "sysrq",
685 .data = &__sysrq_enabled,
686 .maxlen = sizeof (int),
687 .mode = 0644,
688 .proc_handler = sysrq_sysctl_handler,
690 #endif
691 #ifdef CONFIG_PROC_SYSCTL
693 .procname = "cad_pid",
694 .data = NULL,
695 .maxlen = sizeof (int),
696 .mode = 0600,
697 .proc_handler = proc_do_cad_pid,
699 #endif
701 .procname = "threads-max",
702 .data = &max_threads,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = proc_dointvec,
708 .procname = "random",
709 .mode = 0555,
710 .child = random_table,
713 .procname = "usermodehelper",
714 .mode = 0555,
715 .child = usermodehelper_table,
718 .procname = "overflowuid",
719 .data = &overflowuid,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = proc_dointvec_minmax,
723 .extra1 = &minolduid,
724 .extra2 = &maxolduid,
727 .procname = "overflowgid",
728 .data = &overflowgid,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = proc_dointvec_minmax,
732 .extra1 = &minolduid,
733 .extra2 = &maxolduid,
735 #ifdef CONFIG_S390
736 #ifdef CONFIG_MATHEMU
738 .procname = "ieee_emulation_warnings",
739 .data = &sysctl_ieee_emulation_warnings,
740 .maxlen = sizeof(int),
741 .mode = 0644,
742 .proc_handler = proc_dointvec,
744 #endif
746 .procname = "userprocess_debug",
747 .data = &show_unhandled_signals,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = proc_dointvec,
752 #endif
754 .procname = "pid_max",
755 .data = &pid_max,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec_minmax,
759 .extra1 = &pid_max_min,
760 .extra2 = &pid_max_max,
763 .procname = "panic_on_oops",
764 .data = &panic_on_oops,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = proc_dointvec,
769 #if defined CONFIG_PRINTK
771 .procname = "printk",
772 .data = &console_loglevel,
773 .maxlen = 4*sizeof(int),
774 .mode = 0644,
775 .proc_handler = proc_dointvec,
778 .procname = "printk_ratelimit",
779 .data = &printk_ratelimit_state.interval,
780 .maxlen = sizeof(int),
781 .mode = 0644,
782 .proc_handler = proc_dointvec_jiffies,
785 .procname = "printk_ratelimit_burst",
786 .data = &printk_ratelimit_state.burst,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = proc_dointvec,
792 .procname = "printk_delay",
793 .data = &printk_delay_msec,
794 .maxlen = sizeof(int),
795 .mode = 0644,
796 .proc_handler = proc_dointvec_minmax,
797 .extra1 = &zero,
798 .extra2 = &ten_thousand,
801 .procname = "dmesg_restrict",
802 .data = &dmesg_restrict,
803 .maxlen = sizeof(int),
804 .mode = 0644,
805 .proc_handler = proc_dointvec_minmax_sysadmin,
806 .extra1 = &zero,
807 .extra2 = &one,
810 .procname = "kptr_restrict",
811 .data = &kptr_restrict,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = proc_dointvec_minmax_sysadmin,
815 .extra1 = &zero,
816 .extra2 = &two,
818 #endif
820 .procname = "ngroups_max",
821 .data = &ngroups_max,
822 .maxlen = sizeof (int),
823 .mode = 0444,
824 .proc_handler = proc_dointvec,
827 .procname = "cap_last_cap",
828 .data = (void *)&cap_last_cap,
829 .maxlen = sizeof(int),
830 .mode = 0444,
831 .proc_handler = proc_dointvec,
833 #if defined(CONFIG_LOCKUP_DETECTOR)
835 .procname = "watchdog",
836 .data = &watchdog_user_enabled,
837 .maxlen = sizeof (int),
838 .mode = 0644,
839 .proc_handler = proc_dowatchdog,
840 .extra1 = &zero,
841 .extra2 = &one,
844 .procname = "watchdog_thresh",
845 .data = &watchdog_thresh,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = proc_dowatchdog,
849 .extra1 = &zero,
850 .extra2 = &sixty,
853 .procname = "softlockup_panic",
854 .data = &softlockup_panic,
855 .maxlen = sizeof(int),
856 .mode = 0644,
857 .proc_handler = proc_dointvec_minmax,
858 .extra1 = &zero,
859 .extra2 = &one,
862 .procname = "nmi_watchdog",
863 .data = &watchdog_user_enabled,
864 .maxlen = sizeof (int),
865 .mode = 0644,
866 .proc_handler = proc_dowatchdog,
867 .extra1 = &zero,
868 .extra2 = &one,
870 #endif
871 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
873 .procname = "unknown_nmi_panic",
874 .data = &unknown_nmi_panic,
875 .maxlen = sizeof (int),
876 .mode = 0644,
877 .proc_handler = proc_dointvec,
879 #endif
880 #if defined(CONFIG_X86)
882 .procname = "panic_on_unrecovered_nmi",
883 .data = &panic_on_unrecovered_nmi,
884 .maxlen = sizeof(int),
885 .mode = 0644,
886 .proc_handler = proc_dointvec,
889 .procname = "panic_on_io_nmi",
890 .data = &panic_on_io_nmi,
891 .maxlen = sizeof(int),
892 .mode = 0644,
893 .proc_handler = proc_dointvec,
895 #ifdef CONFIG_DEBUG_STACKOVERFLOW
897 .procname = "panic_on_stackoverflow",
898 .data = &sysctl_panic_on_stackoverflow,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = proc_dointvec,
903 #endif
905 .procname = "bootloader_type",
906 .data = &bootloader_type,
907 .maxlen = sizeof (int),
908 .mode = 0444,
909 .proc_handler = proc_dointvec,
912 .procname = "bootloader_version",
913 .data = &bootloader_version,
914 .maxlen = sizeof (int),
915 .mode = 0444,
916 .proc_handler = proc_dointvec,
919 .procname = "kstack_depth_to_print",
920 .data = &kstack_depth_to_print,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = proc_dointvec,
926 .procname = "io_delay_type",
927 .data = &io_delay_type,
928 .maxlen = sizeof(int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
932 #endif
933 #if defined(CONFIG_MMU)
935 .procname = "randomize_va_space",
936 .data = &randomize_va_space,
937 .maxlen = sizeof(int),
938 .mode = 0644,
939 .proc_handler = proc_dointvec,
941 #endif
942 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
944 .procname = "spin_retry",
945 .data = &spin_retry,
946 .maxlen = sizeof (int),
947 .mode = 0644,
948 .proc_handler = proc_dointvec,
950 #endif
951 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
953 .procname = "acpi_video_flags",
954 .data = &acpi_realmode_flags,
955 .maxlen = sizeof (unsigned long),
956 .mode = 0644,
957 .proc_handler = proc_doulongvec_minmax,
959 #endif
960 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
962 .procname = "ignore-unaligned-usertrap",
963 .data = &no_unaligned_warning,
964 .maxlen = sizeof (int),
965 .mode = 0644,
966 .proc_handler = proc_dointvec,
968 #endif
969 #ifdef CONFIG_IA64
971 .procname = "unaligned-dump-stack",
972 .data = &unaligned_dump_stack,
973 .maxlen = sizeof (int),
974 .mode = 0644,
975 .proc_handler = proc_dointvec,
977 #endif
978 #ifdef CONFIG_DETECT_HUNG_TASK
980 .procname = "hung_task_panic",
981 .data = &sysctl_hung_task_panic,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = proc_dointvec_minmax,
985 .extra1 = &zero,
986 .extra2 = &one,
989 .procname = "hung_task_check_count",
990 .data = &sysctl_hung_task_check_count,
991 .maxlen = sizeof(int),
992 .mode = 0644,
993 .proc_handler = proc_dointvec_minmax,
994 .extra1 = &zero,
997 .procname = "hung_task_timeout_secs",
998 .data = &sysctl_hung_task_timeout_secs,
999 .maxlen = sizeof(unsigned long),
1000 .mode = 0644,
1001 .proc_handler = proc_dohung_task_timeout_secs,
1002 .extra2 = &hung_task_timeout_max,
1005 .procname = "hung_task_warnings",
1006 .data = &sysctl_hung_task_warnings,
1007 .maxlen = sizeof(int),
1008 .mode = 0644,
1009 .proc_handler = proc_dointvec_minmax,
1010 .extra1 = &neg_one,
1012 #endif
1013 #ifdef CONFIG_COMPAT
1015 .procname = "compat-log",
1016 .data = &compat_log,
1017 .maxlen = sizeof (int),
1018 .mode = 0644,
1019 .proc_handler = proc_dointvec,
1021 #endif
1022 #ifdef CONFIG_RT_MUTEXES
1024 .procname = "max_lock_depth",
1025 .data = &max_lock_depth,
1026 .maxlen = sizeof(int),
1027 .mode = 0644,
1028 .proc_handler = proc_dointvec,
1030 #endif
1032 .procname = "poweroff_cmd",
1033 .data = &poweroff_cmd,
1034 .maxlen = POWEROFF_CMD_PATH_LEN,
1035 .mode = 0644,
1036 .proc_handler = proc_dostring,
1038 #ifdef CONFIG_KEYS
1040 .procname = "keys",
1041 .mode = 0555,
1042 .child = key_sysctls,
1044 #endif
1045 #ifdef CONFIG_RCU_TORTURE_TEST
1047 .procname = "rcutorture_runnable",
1048 .data = &rcutorture_runnable,
1049 .maxlen = sizeof(int),
1050 .mode = 0644,
1051 .proc_handler = proc_dointvec,
1053 #endif
1054 #ifdef CONFIG_PERF_EVENTS
1056 * User-space scripts rely on the existence of this file
1057 * as a feature check for perf_events being enabled.
1059 * So it's an ABI, do not remove!
1062 .procname = "perf_event_paranoid",
1063 .data = &sysctl_perf_event_paranoid,
1064 .maxlen = sizeof(sysctl_perf_event_paranoid),
1065 .mode = 0644,
1066 .proc_handler = proc_dointvec,
1069 .procname = "perf_event_mlock_kb",
1070 .data = &sysctl_perf_event_mlock,
1071 .maxlen = sizeof(sysctl_perf_event_mlock),
1072 .mode = 0644,
1073 .proc_handler = proc_dointvec,
1076 .procname = "perf_event_max_sample_rate",
1077 .data = &sysctl_perf_event_sample_rate,
1078 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1079 .mode = 0644,
1080 .proc_handler = perf_proc_update_handler,
1081 .extra1 = &one,
1084 .procname = "perf_cpu_time_max_percent",
1085 .data = &sysctl_perf_cpu_time_max_percent,
1086 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1087 .mode = 0644,
1088 .proc_handler = perf_cpu_time_max_percent_handler,
1089 .extra1 = &zero,
1090 .extra2 = &one_hundred,
1092 #endif
1093 #ifdef CONFIG_KMEMCHECK
1095 .procname = "kmemcheck",
1096 .data = &kmemcheck_enabled,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
1099 .proc_handler = proc_dointvec,
1101 #endif
1102 #ifdef CONFIG_BLOCK
1104 .procname = "blk_iopoll",
1105 .data = &blk_iopoll_enabled,
1106 .maxlen = sizeof(int),
1107 .mode = 0644,
1108 .proc_handler = proc_dointvec,
1110 #endif
1114 static struct ctl_table vm_table[] = {
1116 .procname = "overcommit_memory",
1117 .data = &sysctl_overcommit_memory,
1118 .maxlen = sizeof(sysctl_overcommit_memory),
1119 .mode = 0644,
1120 .proc_handler = proc_dointvec_minmax,
1121 .extra1 = &zero,
1122 .extra2 = &two,
1125 .procname = "panic_on_oom",
1126 .data = &sysctl_panic_on_oom,
1127 .maxlen = sizeof(sysctl_panic_on_oom),
1128 .mode = 0644,
1129 .proc_handler = proc_dointvec_minmax,
1130 .extra1 = &zero,
1131 .extra2 = &two,
1134 .procname = "oom_kill_allocating_task",
1135 .data = &sysctl_oom_kill_allocating_task,
1136 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1137 .mode = 0644,
1138 .proc_handler = proc_dointvec,
1141 .procname = "oom_dump_tasks",
1142 .data = &sysctl_oom_dump_tasks,
1143 .maxlen = sizeof(sysctl_oom_dump_tasks),
1144 .mode = 0644,
1145 .proc_handler = proc_dointvec,
1148 .procname = "overcommit_ratio",
1149 .data = &sysctl_overcommit_ratio,
1150 .maxlen = sizeof(sysctl_overcommit_ratio),
1151 .mode = 0644,
1152 .proc_handler = overcommit_ratio_handler,
1155 .procname = "overcommit_kbytes",
1156 .data = &sysctl_overcommit_kbytes,
1157 .maxlen = sizeof(sysctl_overcommit_kbytes),
1158 .mode = 0644,
1159 .proc_handler = overcommit_kbytes_handler,
1162 .procname = "page-cluster",
1163 .data = &page_cluster,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
1166 .proc_handler = proc_dointvec_minmax,
1167 .extra1 = &zero,
1170 .procname = "dirty_background_ratio",
1171 .data = &dirty_background_ratio,
1172 .maxlen = sizeof(dirty_background_ratio),
1173 .mode = 0644,
1174 .proc_handler = dirty_background_ratio_handler,
1175 .extra1 = &zero,
1176 .extra2 = &one_hundred,
1179 .procname = "dirty_background_bytes",
1180 .data = &dirty_background_bytes,
1181 .maxlen = sizeof(dirty_background_bytes),
1182 .mode = 0644,
1183 .proc_handler = dirty_background_bytes_handler,
1184 .extra1 = &one_ul,
1187 .procname = "dirty_ratio",
1188 .data = &vm_dirty_ratio,
1189 .maxlen = sizeof(vm_dirty_ratio),
1190 .mode = 0644,
1191 .proc_handler = dirty_ratio_handler,
1192 .extra1 = &zero,
1193 .extra2 = &one_hundred,
1196 .procname = "dirty_bytes",
1197 .data = &vm_dirty_bytes,
1198 .maxlen = sizeof(vm_dirty_bytes),
1199 .mode = 0644,
1200 .proc_handler = dirty_bytes_handler,
1201 .extra1 = &dirty_bytes_min,
1204 .procname = "dirty_writeback_centisecs",
1205 .data = &dirty_writeback_interval,
1206 .maxlen = sizeof(dirty_writeback_interval),
1207 .mode = 0644,
1208 .proc_handler = dirty_writeback_centisecs_handler,
1211 .procname = "dirty_expire_centisecs",
1212 .data = &dirty_expire_interval,
1213 .maxlen = sizeof(dirty_expire_interval),
1214 .mode = 0644,
1215 .proc_handler = proc_dointvec_minmax,
1216 .extra1 = &zero,
1219 .procname = "nr_pdflush_threads",
1220 .mode = 0444 /* read-only */,
1221 .proc_handler = pdflush_proc_obsolete,
1224 .procname = "swappiness",
1225 .data = &vm_swappiness,
1226 .maxlen = sizeof(vm_swappiness),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec_minmax,
1229 .extra1 = &zero,
1230 .extra2 = &one_hundred,
1232 #ifdef CONFIG_HUGETLB_PAGE
1234 .procname = "nr_hugepages",
1235 .data = NULL,
1236 .maxlen = sizeof(unsigned long),
1237 .mode = 0644,
1238 .proc_handler = hugetlb_sysctl_handler,
1239 .extra1 = (void *)&hugetlb_zero,
1240 .extra2 = (void *)&hugetlb_infinity,
1242 #ifdef CONFIG_NUMA
1244 .procname = "nr_hugepages_mempolicy",
1245 .data = NULL,
1246 .maxlen = sizeof(unsigned long),
1247 .mode = 0644,
1248 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1249 .extra1 = (void *)&hugetlb_zero,
1250 .extra2 = (void *)&hugetlb_infinity,
1252 #endif
1254 .procname = "hugetlb_shm_group",
1255 .data = &sysctl_hugetlb_shm_group,
1256 .maxlen = sizeof(gid_t),
1257 .mode = 0644,
1258 .proc_handler = proc_dointvec,
1261 .procname = "hugepages_treat_as_movable",
1262 .data = &hugepages_treat_as_movable,
1263 .maxlen = sizeof(int),
1264 .mode = 0644,
1265 .proc_handler = proc_dointvec,
1268 .procname = "nr_overcommit_hugepages",
1269 .data = NULL,
1270 .maxlen = sizeof(unsigned long),
1271 .mode = 0644,
1272 .proc_handler = hugetlb_overcommit_handler,
1273 .extra1 = (void *)&hugetlb_zero,
1274 .extra2 = (void *)&hugetlb_infinity,
1276 #endif
1278 .procname = "lowmem_reserve_ratio",
1279 .data = &sysctl_lowmem_reserve_ratio,
1280 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1281 .mode = 0644,
1282 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1285 .procname = "drop_caches",
1286 .data = &sysctl_drop_caches,
1287 .maxlen = sizeof(int),
1288 .mode = 0644,
1289 .proc_handler = drop_caches_sysctl_handler,
1290 .extra1 = &one,
1291 .extra2 = &three,
1293 #ifdef CONFIG_COMPACTION
1295 .procname = "compact_memory",
1296 .data = &sysctl_compact_memory,
1297 .maxlen = sizeof(int),
1298 .mode = 0200,
1299 .proc_handler = sysctl_compaction_handler,
1302 .procname = "extfrag_threshold",
1303 .data = &sysctl_extfrag_threshold,
1304 .maxlen = sizeof(int),
1305 .mode = 0644,
1306 .proc_handler = sysctl_extfrag_handler,
1307 .extra1 = &min_extfrag_threshold,
1308 .extra2 = &max_extfrag_threshold,
1311 #endif /* CONFIG_COMPACTION */
1313 .procname = "min_free_kbytes",
1314 .data = &min_free_kbytes,
1315 .maxlen = sizeof(min_free_kbytes),
1316 .mode = 0644,
1317 .proc_handler = min_free_kbytes_sysctl_handler,
1318 .extra1 = &zero,
1321 .procname = "percpu_pagelist_fraction",
1322 .data = &percpu_pagelist_fraction,
1323 .maxlen = sizeof(percpu_pagelist_fraction),
1324 .mode = 0644,
1325 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1326 .extra1 = &zero,
1328 #ifdef CONFIG_MMU
1330 .procname = "max_map_count",
1331 .data = &sysctl_max_map_count,
1332 .maxlen = sizeof(sysctl_max_map_count),
1333 .mode = 0644,
1334 .proc_handler = proc_dointvec_minmax,
1335 .extra1 = &zero,
1337 #else
1339 .procname = "nr_trim_pages",
1340 .data = &sysctl_nr_trim_pages,
1341 .maxlen = sizeof(sysctl_nr_trim_pages),
1342 .mode = 0644,
1343 .proc_handler = proc_dointvec_minmax,
1344 .extra1 = &zero,
1346 #endif
1348 .procname = "laptop_mode",
1349 .data = &laptop_mode,
1350 .maxlen = sizeof(laptop_mode),
1351 .mode = 0644,
1352 .proc_handler = proc_dointvec_jiffies,
1355 .procname = "block_dump",
1356 .data = &block_dump,
1357 .maxlen = sizeof(block_dump),
1358 .mode = 0644,
1359 .proc_handler = proc_dointvec,
1360 .extra1 = &zero,
1363 .procname = "vfs_cache_pressure",
1364 .data = &sysctl_vfs_cache_pressure,
1365 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1366 .mode = 0644,
1367 .proc_handler = proc_dointvec,
1368 .extra1 = &zero,
1370 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1372 .procname = "legacy_va_layout",
1373 .data = &sysctl_legacy_va_layout,
1374 .maxlen = sizeof(sysctl_legacy_va_layout),
1375 .mode = 0644,
1376 .proc_handler = proc_dointvec,
1377 .extra1 = &zero,
1379 #endif
1380 #ifdef CONFIG_NUMA
1382 .procname = "zone_reclaim_mode",
1383 .data = &zone_reclaim_mode,
1384 .maxlen = sizeof(zone_reclaim_mode),
1385 .mode = 0644,
1386 .proc_handler = proc_dointvec,
1387 .extra1 = &zero,
1390 .procname = "min_unmapped_ratio",
1391 .data = &sysctl_min_unmapped_ratio,
1392 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1393 .mode = 0644,
1394 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1395 .extra1 = &zero,
1396 .extra2 = &one_hundred,
1399 .procname = "min_slab_ratio",
1400 .data = &sysctl_min_slab_ratio,
1401 .maxlen = sizeof(sysctl_min_slab_ratio),
1402 .mode = 0644,
1403 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1404 .extra1 = &zero,
1405 .extra2 = &one_hundred,
1407 #endif
1408 #ifdef CONFIG_SMP
1410 .procname = "stat_interval",
1411 .data = &sysctl_stat_interval,
1412 .maxlen = sizeof(sysctl_stat_interval),
1413 .mode = 0644,
1414 .proc_handler = proc_dointvec_jiffies,
1416 #endif
1417 #ifdef CONFIG_MMU
1419 .procname = "mmap_min_addr",
1420 .data = &dac_mmap_min_addr,
1421 .maxlen = sizeof(unsigned long),
1422 .mode = 0644,
1423 .proc_handler = mmap_min_addr_handler,
1425 #endif
1426 #ifdef CONFIG_NUMA
1428 .procname = "numa_zonelist_order",
1429 .data = &numa_zonelist_order,
1430 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1431 .mode = 0644,
1432 .proc_handler = numa_zonelist_order_handler,
1434 #endif
1435 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1436 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1438 .procname = "vdso_enabled",
1439 .data = &vdso_enabled,
1440 .maxlen = sizeof(vdso_enabled),
1441 .mode = 0644,
1442 .proc_handler = proc_dointvec,
1443 .extra1 = &zero,
1445 #endif
1446 #ifdef CONFIG_HIGHMEM
1448 .procname = "highmem_is_dirtyable",
1449 .data = &vm_highmem_is_dirtyable,
1450 .maxlen = sizeof(vm_highmem_is_dirtyable),
1451 .mode = 0644,
1452 .proc_handler = proc_dointvec_minmax,
1453 .extra1 = &zero,
1454 .extra2 = &one,
1456 #endif
1458 .procname = "scan_unevictable_pages",
1459 .data = &scan_unevictable_pages,
1460 .maxlen = sizeof(scan_unevictable_pages),
1461 .mode = 0644,
1462 .proc_handler = scan_unevictable_handler,
1464 #ifdef CONFIG_MEMORY_FAILURE
1466 .procname = "memory_failure_early_kill",
1467 .data = &sysctl_memory_failure_early_kill,
1468 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1469 .mode = 0644,
1470 .proc_handler = proc_dointvec_minmax,
1471 .extra1 = &zero,
1472 .extra2 = &one,
1475 .procname = "memory_failure_recovery",
1476 .data = &sysctl_memory_failure_recovery,
1477 .maxlen = sizeof(sysctl_memory_failure_recovery),
1478 .mode = 0644,
1479 .proc_handler = proc_dointvec_minmax,
1480 .extra1 = &zero,
1481 .extra2 = &one,
1483 #endif
1485 .procname = "user_reserve_kbytes",
1486 .data = &sysctl_user_reserve_kbytes,
1487 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1488 .mode = 0644,
1489 .proc_handler = proc_doulongvec_minmax,
1492 .procname = "admin_reserve_kbytes",
1493 .data = &sysctl_admin_reserve_kbytes,
1494 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1495 .mode = 0644,
1496 .proc_handler = proc_doulongvec_minmax,
1501 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1502 static struct ctl_table binfmt_misc_table[] = {
1505 #endif
1507 static struct ctl_table fs_table[] = {
1509 .procname = "inode-nr",
1510 .data = &inodes_stat,
1511 .maxlen = 2*sizeof(long),
1512 .mode = 0444,
1513 .proc_handler = proc_nr_inodes,
1516 .procname = "inode-state",
1517 .data = &inodes_stat,
1518 .maxlen = 7*sizeof(long),
1519 .mode = 0444,
1520 .proc_handler = proc_nr_inodes,
1523 .procname = "file-nr",
1524 .data = &files_stat,
1525 .maxlen = sizeof(files_stat),
1526 .mode = 0444,
1527 .proc_handler = proc_nr_files,
1530 .procname = "file-max",
1531 .data = &files_stat.max_files,
1532 .maxlen = sizeof(files_stat.max_files),
1533 .mode = 0644,
1534 .proc_handler = proc_doulongvec_minmax,
1537 .procname = "nr_open",
1538 .data = &sysctl_nr_open,
1539 .maxlen = sizeof(int),
1540 .mode = 0644,
1541 .proc_handler = proc_dointvec_minmax,
1542 .extra1 = &sysctl_nr_open_min,
1543 .extra2 = &sysctl_nr_open_max,
1546 .procname = "dentry-state",
1547 .data = &dentry_stat,
1548 .maxlen = 6*sizeof(long),
1549 .mode = 0444,
1550 .proc_handler = proc_nr_dentry,
1553 .procname = "overflowuid",
1554 .data = &fs_overflowuid,
1555 .maxlen = sizeof(int),
1556 .mode = 0644,
1557 .proc_handler = proc_dointvec_minmax,
1558 .extra1 = &minolduid,
1559 .extra2 = &maxolduid,
1562 .procname = "overflowgid",
1563 .data = &fs_overflowgid,
1564 .maxlen = sizeof(int),
1565 .mode = 0644,
1566 .proc_handler = proc_dointvec_minmax,
1567 .extra1 = &minolduid,
1568 .extra2 = &maxolduid,
1570 #ifdef CONFIG_FILE_LOCKING
1572 .procname = "leases-enable",
1573 .data = &leases_enable,
1574 .maxlen = sizeof(int),
1575 .mode = 0644,
1576 .proc_handler = proc_dointvec,
1578 #endif
1579 #ifdef CONFIG_DNOTIFY
1581 .procname = "dir-notify-enable",
1582 .data = &dir_notify_enable,
1583 .maxlen = sizeof(int),
1584 .mode = 0644,
1585 .proc_handler = proc_dointvec,
1587 #endif
1588 #ifdef CONFIG_MMU
1589 #ifdef CONFIG_FILE_LOCKING
1591 .procname = "lease-break-time",
1592 .data = &lease_break_time,
1593 .maxlen = sizeof(int),
1594 .mode = 0644,
1595 .proc_handler = proc_dointvec,
1597 #endif
1598 #ifdef CONFIG_AIO
1600 .procname = "aio-nr",
1601 .data = &aio_nr,
1602 .maxlen = sizeof(aio_nr),
1603 .mode = 0444,
1604 .proc_handler = proc_doulongvec_minmax,
1607 .procname = "aio-max-nr",
1608 .data = &aio_max_nr,
1609 .maxlen = sizeof(aio_max_nr),
1610 .mode = 0644,
1611 .proc_handler = proc_doulongvec_minmax,
1613 #endif /* CONFIG_AIO */
1614 #ifdef CONFIG_INOTIFY_USER
1616 .procname = "inotify",
1617 .mode = 0555,
1618 .child = inotify_table,
1620 #endif
1621 #ifdef CONFIG_EPOLL
1623 .procname = "epoll",
1624 .mode = 0555,
1625 .child = epoll_table,
1627 #endif
1628 #endif
1630 .procname = "protected_symlinks",
1631 .data = &sysctl_protected_symlinks,
1632 .maxlen = sizeof(int),
1633 .mode = 0600,
1634 .proc_handler = proc_dointvec_minmax,
1635 .extra1 = &zero,
1636 .extra2 = &one,
1639 .procname = "protected_hardlinks",
1640 .data = &sysctl_protected_hardlinks,
1641 .maxlen = sizeof(int),
1642 .mode = 0600,
1643 .proc_handler = proc_dointvec_minmax,
1644 .extra1 = &zero,
1645 .extra2 = &one,
1648 .procname = "suid_dumpable",
1649 .data = &suid_dumpable,
1650 .maxlen = sizeof(int),
1651 .mode = 0644,
1652 .proc_handler = proc_dointvec_minmax_coredump,
1653 .extra1 = &zero,
1654 .extra2 = &two,
1656 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1658 .procname = "binfmt_misc",
1659 .mode = 0555,
1660 .child = binfmt_misc_table,
1662 #endif
1664 .procname = "pipe-max-size",
1665 .data = &pipe_max_size,
1666 .maxlen = sizeof(int),
1667 .mode = 0644,
1668 .proc_handler = &pipe_proc_fn,
1669 .extra1 = &pipe_min_size,
1674 static struct ctl_table debug_table[] = {
1675 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1677 .procname = "exception-trace",
1678 .data = &show_unhandled_signals,
1679 .maxlen = sizeof(int),
1680 .mode = 0644,
1681 .proc_handler = proc_dointvec
1683 #endif
1684 #if defined(CONFIG_OPTPROBES)
1686 .procname = "kprobes-optimization",
1687 .data = &sysctl_kprobes_optimization,
1688 .maxlen = sizeof(int),
1689 .mode = 0644,
1690 .proc_handler = proc_kprobes_optimization_handler,
1691 .extra1 = &zero,
1692 .extra2 = &one,
1694 #endif
1698 static struct ctl_table dev_table[] = {
1702 int __init sysctl_init(void)
1704 struct ctl_table_header *hdr;
1706 hdr = register_sysctl_table(sysctl_base_table);
1707 kmemleak_not_leak(hdr);
1708 return 0;
1711 #endif /* CONFIG_SYSCTL */
1714 * /proc/sys support
1717 #ifdef CONFIG_PROC_SYSCTL
1719 static int _proc_do_string(void* data, int maxlen, int write,
1720 void __user *buffer,
1721 size_t *lenp, loff_t *ppos)
1723 size_t len;
1724 char __user *p;
1725 char c;
1727 if (!data || !maxlen || !*lenp) {
1728 *lenp = 0;
1729 return 0;
1732 if (write) {
1733 len = 0;
1734 p = buffer;
1735 while (len < *lenp) {
1736 if (get_user(c, p++))
1737 return -EFAULT;
1738 if (c == 0 || c == '\n')
1739 break;
1740 len++;
1742 if (len >= maxlen)
1743 len = maxlen-1;
1744 if(copy_from_user(data, buffer, len))
1745 return -EFAULT;
1746 ((char *) data)[len] = 0;
1747 *ppos += *lenp;
1748 } else {
1749 len = strlen(data);
1750 if (len > maxlen)
1751 len = maxlen;
1753 if (*ppos > len) {
1754 *lenp = 0;
1755 return 0;
1758 data += *ppos;
1759 len -= *ppos;
1761 if (len > *lenp)
1762 len = *lenp;
1763 if (len)
1764 if(copy_to_user(buffer, data, len))
1765 return -EFAULT;
1766 if (len < *lenp) {
1767 if(put_user('\n', ((char __user *) buffer) + len))
1768 return -EFAULT;
1769 len++;
1771 *lenp = len;
1772 *ppos += len;
1774 return 0;
1778 * proc_dostring - read a string sysctl
1779 * @table: the sysctl table
1780 * @write: %TRUE if this is a write to the sysctl file
1781 * @buffer: the user buffer
1782 * @lenp: the size of the user buffer
1783 * @ppos: file position
1785 * Reads/writes a string from/to the user buffer. If the kernel
1786 * buffer provided is not large enough to hold the string, the
1787 * string is truncated. The copied string is %NULL-terminated.
1788 * If the string is being read by the user process, it is copied
1789 * and a newline '\n' is added. It is truncated if the buffer is
1790 * not large enough.
1792 * Returns 0 on success.
1794 int proc_dostring(struct ctl_table *table, int write,
1795 void __user *buffer, size_t *lenp, loff_t *ppos)
1797 return _proc_do_string(table->data, table->maxlen, write,
1798 buffer, lenp, ppos);
1801 static size_t proc_skip_spaces(char **buf)
1803 size_t ret;
1804 char *tmp = skip_spaces(*buf);
1805 ret = tmp - *buf;
1806 *buf = tmp;
1807 return ret;
1810 static void proc_skip_char(char **buf, size_t *size, const char v)
1812 while (*size) {
1813 if (**buf != v)
1814 break;
1815 (*size)--;
1816 (*buf)++;
1820 #define TMPBUFLEN 22
1822 * proc_get_long - reads an ASCII formatted integer from a user buffer
1824 * @buf: a kernel buffer
1825 * @size: size of the kernel buffer
1826 * @val: this is where the number will be stored
1827 * @neg: set to %TRUE if number is negative
1828 * @perm_tr: a vector which contains the allowed trailers
1829 * @perm_tr_len: size of the perm_tr vector
1830 * @tr: pointer to store the trailer character
1832 * In case of success %0 is returned and @buf and @size are updated with
1833 * the amount of bytes read. If @tr is non-NULL and a trailing
1834 * character exists (size is non-zero after returning from this
1835 * function), @tr is updated with the trailing character.
1837 static int proc_get_long(char **buf, size_t *size,
1838 unsigned long *val, bool *neg,
1839 const char *perm_tr, unsigned perm_tr_len, char *tr)
1841 int len;
1842 char *p, tmp[TMPBUFLEN];
1844 if (!*size)
1845 return -EINVAL;
1847 len = *size;
1848 if (len > TMPBUFLEN - 1)
1849 len = TMPBUFLEN - 1;
1851 memcpy(tmp, *buf, len);
1853 tmp[len] = 0;
1854 p = tmp;
1855 if (*p == '-' && *size > 1) {
1856 *neg = true;
1857 p++;
1858 } else
1859 *neg = false;
1860 if (!isdigit(*p))
1861 return -EINVAL;
1863 *val = simple_strtoul(p, &p, 0);
1865 len = p - tmp;
1867 /* We don't know if the next char is whitespace thus we may accept
1868 * invalid integers (e.g. 1234...a) or two integers instead of one
1869 * (e.g. 123...1). So lets not allow such large numbers. */
1870 if (len == TMPBUFLEN - 1)
1871 return -EINVAL;
1873 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1874 return -EINVAL;
1876 if (tr && (len < *size))
1877 *tr = *p;
1879 *buf += len;
1880 *size -= len;
1882 return 0;
1886 * proc_put_long - converts an integer to a decimal ASCII formatted string
1888 * @buf: the user buffer
1889 * @size: the size of the user buffer
1890 * @val: the integer to be converted
1891 * @neg: sign of the number, %TRUE for negative
1893 * In case of success %0 is returned and @buf and @size are updated with
1894 * the amount of bytes written.
1896 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1897 bool neg)
1899 int len;
1900 char tmp[TMPBUFLEN], *p = tmp;
1902 sprintf(p, "%s%lu", neg ? "-" : "", val);
1903 len = strlen(tmp);
1904 if (len > *size)
1905 len = *size;
1906 if (copy_to_user(*buf, tmp, len))
1907 return -EFAULT;
1908 *size -= len;
1909 *buf += len;
1910 return 0;
1912 #undef TMPBUFLEN
1914 static int proc_put_char(void __user **buf, size_t *size, char c)
1916 if (*size) {
1917 char __user **buffer = (char __user **)buf;
1918 if (put_user(c, *buffer))
1919 return -EFAULT;
1920 (*size)--, (*buffer)++;
1921 *buf = *buffer;
1923 return 0;
1926 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1927 int *valp,
1928 int write, void *data)
1930 if (write) {
1931 *valp = *negp ? -*lvalp : *lvalp;
1932 } else {
1933 int val = *valp;
1934 if (val < 0) {
1935 *negp = true;
1936 *lvalp = (unsigned long)-val;
1937 } else {
1938 *negp = false;
1939 *lvalp = (unsigned long)val;
1942 return 0;
1945 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1947 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1948 int write, void __user *buffer,
1949 size_t *lenp, loff_t *ppos,
1950 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1951 int write, void *data),
1952 void *data)
1954 int *i, vleft, first = 1, err = 0;
1955 unsigned long page = 0;
1956 size_t left;
1957 char *kbuf;
1959 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1960 *lenp = 0;
1961 return 0;
1964 i = (int *) tbl_data;
1965 vleft = table->maxlen / sizeof(*i);
1966 left = *lenp;
1968 if (!conv)
1969 conv = do_proc_dointvec_conv;
1971 if (write) {
1972 if (left > PAGE_SIZE - 1)
1973 left = PAGE_SIZE - 1;
1974 page = __get_free_page(GFP_TEMPORARY);
1975 kbuf = (char *) page;
1976 if (!kbuf)
1977 return -ENOMEM;
1978 if (copy_from_user(kbuf, buffer, left)) {
1979 err = -EFAULT;
1980 goto free;
1982 kbuf[left] = 0;
1985 for (; left && vleft--; i++, first=0) {
1986 unsigned long lval;
1987 bool neg;
1989 if (write) {
1990 left -= proc_skip_spaces(&kbuf);
1992 if (!left)
1993 break;
1994 err = proc_get_long(&kbuf, &left, &lval, &neg,
1995 proc_wspace_sep,
1996 sizeof(proc_wspace_sep), NULL);
1997 if (err)
1998 break;
1999 if (conv(&neg, &lval, i, 1, data)) {
2000 err = -EINVAL;
2001 break;
2003 } else {
2004 if (conv(&neg, &lval, i, 0, data)) {
2005 err = -EINVAL;
2006 break;
2008 if (!first)
2009 err = proc_put_char(&buffer, &left, '\t');
2010 if (err)
2011 break;
2012 err = proc_put_long(&buffer, &left, lval, neg);
2013 if (err)
2014 break;
2018 if (!write && !first && left && !err)
2019 err = proc_put_char(&buffer, &left, '\n');
2020 if (write && !err && left)
2021 left -= proc_skip_spaces(&kbuf);
2022 free:
2023 if (write) {
2024 free_page(page);
2025 if (first)
2026 return err ? : -EINVAL;
2028 *lenp -= left;
2029 *ppos += *lenp;
2030 return err;
2033 static int do_proc_dointvec(struct ctl_table *table, int write,
2034 void __user *buffer, size_t *lenp, loff_t *ppos,
2035 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2036 int write, void *data),
2037 void *data)
2039 return __do_proc_dointvec(table->data, table, write,
2040 buffer, lenp, ppos, conv, data);
2044 * proc_dointvec - read a vector of integers
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @buffer: the user buffer
2048 * @lenp: the size of the user buffer
2049 * @ppos: file position
2051 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2052 * values from/to the user buffer, treated as an ASCII string.
2054 * Returns 0 on success.
2056 int proc_dointvec(struct ctl_table *table, int write,
2057 void __user *buffer, size_t *lenp, loff_t *ppos)
2059 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2060 NULL,NULL);
2064 * Taint values can only be increased
2065 * This means we can safely use a temporary.
2067 static int proc_taint(struct ctl_table *table, int write,
2068 void __user *buffer, size_t *lenp, loff_t *ppos)
2070 struct ctl_table t;
2071 unsigned long tmptaint = get_taint();
2072 int err;
2074 if (write && !capable(CAP_SYS_ADMIN))
2075 return -EPERM;
2077 t = *table;
2078 t.data = &tmptaint;
2079 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2080 if (err < 0)
2081 return err;
2083 if (write) {
2085 * Poor man's atomic or. Not worth adding a primitive
2086 * to everyone's atomic.h for this
2088 int i;
2089 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2090 if ((tmptaint >> i) & 1)
2091 add_taint(i, LOCKDEP_STILL_OK);
2095 return err;
2098 #ifdef CONFIG_PRINTK
2099 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2100 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 if (write && !capable(CAP_SYS_ADMIN))
2103 return -EPERM;
2105 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2107 #endif
2109 struct do_proc_dointvec_minmax_conv_param {
2110 int *min;
2111 int *max;
2114 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2115 int *valp,
2116 int write, void *data)
2118 struct do_proc_dointvec_minmax_conv_param *param = data;
2119 if (write) {
2120 int val = *negp ? -*lvalp : *lvalp;
2121 if ((param->min && *param->min > val) ||
2122 (param->max && *param->max < val))
2123 return -EINVAL;
2124 *valp = val;
2125 } else {
2126 int val = *valp;
2127 if (val < 0) {
2128 *negp = true;
2129 *lvalp = (unsigned long)-val;
2130 } else {
2131 *negp = false;
2132 *lvalp = (unsigned long)val;
2135 return 0;
2139 * proc_dointvec_minmax - read a vector of integers with min/max values
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @buffer: the user buffer
2143 * @lenp: the size of the user buffer
2144 * @ppos: file position
2146 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2147 * values from/to the user buffer, treated as an ASCII string.
2149 * This routine will ensure the values are within the range specified by
2150 * table->extra1 (min) and table->extra2 (max).
2152 * Returns 0 on success.
2154 int proc_dointvec_minmax(struct ctl_table *table, int write,
2155 void __user *buffer, size_t *lenp, loff_t *ppos)
2157 struct do_proc_dointvec_minmax_conv_param param = {
2158 .min = (int *) table->extra1,
2159 .max = (int *) table->extra2,
2161 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2162 do_proc_dointvec_minmax_conv, &param);
2165 static void validate_coredump_safety(void)
2167 #ifdef CONFIG_COREDUMP
2168 if (suid_dumpable == SUID_DUMP_ROOT &&
2169 core_pattern[0] != '/' && core_pattern[0] != '|') {
2170 printk(KERN_WARNING "Unsafe core_pattern used with "\
2171 "suid_dumpable=2. Pipe handler or fully qualified "\
2172 "core dump path required.\n");
2174 #endif
2177 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2178 void __user *buffer, size_t *lenp, loff_t *ppos)
2180 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2181 if (!error)
2182 validate_coredump_safety();
2183 return error;
2186 #ifdef CONFIG_COREDUMP
2187 static int proc_dostring_coredump(struct ctl_table *table, int write,
2188 void __user *buffer, size_t *lenp, loff_t *ppos)
2190 int error = proc_dostring(table, write, buffer, lenp, ppos);
2191 if (!error)
2192 validate_coredump_safety();
2193 return error;
2195 #endif
2197 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2198 void __user *buffer,
2199 size_t *lenp, loff_t *ppos,
2200 unsigned long convmul,
2201 unsigned long convdiv)
2203 unsigned long *i, *min, *max;
2204 int vleft, first = 1, err = 0;
2205 unsigned long page = 0;
2206 size_t left;
2207 char *kbuf;
2209 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2210 *lenp = 0;
2211 return 0;
2214 i = (unsigned long *) data;
2215 min = (unsigned long *) table->extra1;
2216 max = (unsigned long *) table->extra2;
2217 vleft = table->maxlen / sizeof(unsigned long);
2218 left = *lenp;
2220 if (write) {
2221 if (left > PAGE_SIZE - 1)
2222 left = PAGE_SIZE - 1;
2223 page = __get_free_page(GFP_TEMPORARY);
2224 kbuf = (char *) page;
2225 if (!kbuf)
2226 return -ENOMEM;
2227 if (copy_from_user(kbuf, buffer, left)) {
2228 err = -EFAULT;
2229 goto free;
2231 kbuf[left] = 0;
2234 for (; left && vleft--; i++, first = 0) {
2235 unsigned long val;
2237 if (write) {
2238 bool neg;
2240 left -= proc_skip_spaces(&kbuf);
2242 err = proc_get_long(&kbuf, &left, &val, &neg,
2243 proc_wspace_sep,
2244 sizeof(proc_wspace_sep), NULL);
2245 if (err)
2246 break;
2247 if (neg)
2248 continue;
2249 if ((min && val < *min) || (max && val > *max))
2250 continue;
2251 *i = val;
2252 } else {
2253 val = convdiv * (*i) / convmul;
2254 if (!first) {
2255 err = proc_put_char(&buffer, &left, '\t');
2256 if (err)
2257 break;
2259 err = proc_put_long(&buffer, &left, val, false);
2260 if (err)
2261 break;
2265 if (!write && !first && left && !err)
2266 err = proc_put_char(&buffer, &left, '\n');
2267 if (write && !err)
2268 left -= proc_skip_spaces(&kbuf);
2269 free:
2270 if (write) {
2271 free_page(page);
2272 if (first)
2273 return err ? : -EINVAL;
2275 *lenp -= left;
2276 *ppos += *lenp;
2277 return err;
2280 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2281 void __user *buffer,
2282 size_t *lenp, loff_t *ppos,
2283 unsigned long convmul,
2284 unsigned long convdiv)
2286 return __do_proc_doulongvec_minmax(table->data, table, write,
2287 buffer, lenp, ppos, convmul, convdiv);
2291 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2292 * @table: the sysctl table
2293 * @write: %TRUE if this is a write to the sysctl file
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2299 * values from/to the user buffer, treated as an ASCII string.
2301 * This routine will ensure the values are within the range specified by
2302 * table->extra1 (min) and table->extra2 (max).
2304 * Returns 0 on success.
2306 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2307 void __user *buffer, size_t *lenp, loff_t *ppos)
2309 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2313 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2314 * @table: the sysctl table
2315 * @write: %TRUE if this is a write to the sysctl file
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2320 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2321 * values from/to the user buffer, treated as an ASCII string. The values
2322 * are treated as milliseconds, and converted to jiffies when they are stored.
2324 * This routine will ensure the values are within the range specified by
2325 * table->extra1 (min) and table->extra2 (max).
2327 * Returns 0 on success.
2329 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2330 void __user *buffer,
2331 size_t *lenp, loff_t *ppos)
2333 return do_proc_doulongvec_minmax(table, write, buffer,
2334 lenp, ppos, HZ, 1000l);
2338 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2339 int *valp,
2340 int write, void *data)
2342 if (write) {
2343 if (*lvalp > LONG_MAX / HZ)
2344 return 1;
2345 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2346 } else {
2347 int val = *valp;
2348 unsigned long lval;
2349 if (val < 0) {
2350 *negp = true;
2351 lval = (unsigned long)-val;
2352 } else {
2353 *negp = false;
2354 lval = (unsigned long)val;
2356 *lvalp = lval / HZ;
2358 return 0;
2361 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2362 int *valp,
2363 int write, void *data)
2365 if (write) {
2366 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2367 return 1;
2368 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2369 } else {
2370 int val = *valp;
2371 unsigned long lval;
2372 if (val < 0) {
2373 *negp = true;
2374 lval = (unsigned long)-val;
2375 } else {
2376 *negp = false;
2377 lval = (unsigned long)val;
2379 *lvalp = jiffies_to_clock_t(lval);
2381 return 0;
2384 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2385 int *valp,
2386 int write, void *data)
2388 if (write) {
2389 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2391 if (jif > INT_MAX)
2392 return 1;
2393 *valp = (int)jif;
2394 } else {
2395 int val = *valp;
2396 unsigned long lval;
2397 if (val < 0) {
2398 *negp = true;
2399 lval = (unsigned long)-val;
2400 } else {
2401 *negp = false;
2402 lval = (unsigned long)val;
2404 *lvalp = jiffies_to_msecs(lval);
2406 return 0;
2410 * proc_dointvec_jiffies - read a vector of integers as seconds
2411 * @table: the sysctl table
2412 * @write: %TRUE if this is a write to the sysctl file
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2417 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2418 * values from/to the user buffer, treated as an ASCII string.
2419 * The values read are assumed to be in seconds, and are converted into
2420 * jiffies.
2422 * Returns 0 on success.
2424 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2427 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2428 do_proc_dointvec_jiffies_conv,NULL);
2432 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2433 * @table: the sysctl table
2434 * @write: %TRUE if this is a write to the sysctl file
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: pointer to the file position
2439 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2440 * values from/to the user buffer, treated as an ASCII string.
2441 * The values read are assumed to be in 1/USER_HZ seconds, and
2442 * are converted into jiffies.
2444 * Returns 0 on success.
2446 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2447 void __user *buffer, size_t *lenp, loff_t *ppos)
2449 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2450 do_proc_dointvec_userhz_jiffies_conv,NULL);
2454 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2455 * @table: the sysctl table
2456 * @write: %TRUE if this is a write to the sysctl file
2457 * @buffer: the user buffer
2458 * @lenp: the size of the user buffer
2459 * @ppos: file position
2460 * @ppos: the current position in the file
2462 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2463 * values from/to the user buffer, treated as an ASCII string.
2464 * The values read are assumed to be in 1/1000 seconds, and
2465 * are converted into jiffies.
2467 * Returns 0 on success.
2469 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2470 void __user *buffer, size_t *lenp, loff_t *ppos)
2472 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2473 do_proc_dointvec_ms_jiffies_conv, NULL);
2476 static int proc_do_cad_pid(struct ctl_table *table, int write,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2479 struct pid *new_pid;
2480 pid_t tmp;
2481 int r;
2483 tmp = pid_vnr(cad_pid);
2485 r = __do_proc_dointvec(&tmp, table, write, buffer,
2486 lenp, ppos, NULL, NULL);
2487 if (r || !write)
2488 return r;
2490 new_pid = find_get_pid(tmp);
2491 if (!new_pid)
2492 return -ESRCH;
2494 put_pid(xchg(&cad_pid, new_pid));
2495 return 0;
2499 * proc_do_large_bitmap - read/write from/to a large bitmap
2500 * @table: the sysctl table
2501 * @write: %TRUE if this is a write to the sysctl file
2502 * @buffer: the user buffer
2503 * @lenp: the size of the user buffer
2504 * @ppos: file position
2506 * The bitmap is stored at table->data and the bitmap length (in bits)
2507 * in table->maxlen.
2509 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2510 * large bitmaps may be represented in a compact manner. Writing into
2511 * the file will clear the bitmap then update it with the given input.
2513 * Returns 0 on success.
2515 int proc_do_large_bitmap(struct ctl_table *table, int write,
2516 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 int err = 0;
2519 bool first = 1;
2520 size_t left = *lenp;
2521 unsigned long bitmap_len = table->maxlen;
2522 unsigned long *bitmap = (unsigned long *) table->data;
2523 unsigned long *tmp_bitmap = NULL;
2524 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2526 if (!bitmap_len || !left || (*ppos && !write)) {
2527 *lenp = 0;
2528 return 0;
2531 if (write) {
2532 unsigned long page = 0;
2533 char *kbuf;
2535 if (left > PAGE_SIZE - 1)
2536 left = PAGE_SIZE - 1;
2538 page = __get_free_page(GFP_TEMPORARY);
2539 kbuf = (char *) page;
2540 if (!kbuf)
2541 return -ENOMEM;
2542 if (copy_from_user(kbuf, buffer, left)) {
2543 free_page(page);
2544 return -EFAULT;
2546 kbuf[left] = 0;
2548 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2549 GFP_KERNEL);
2550 if (!tmp_bitmap) {
2551 free_page(page);
2552 return -ENOMEM;
2554 proc_skip_char(&kbuf, &left, '\n');
2555 while (!err && left) {
2556 unsigned long val_a, val_b;
2557 bool neg;
2559 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2560 sizeof(tr_a), &c);
2561 if (err)
2562 break;
2563 if (val_a >= bitmap_len || neg) {
2564 err = -EINVAL;
2565 break;
2568 val_b = val_a;
2569 if (left) {
2570 kbuf++;
2571 left--;
2574 if (c == '-') {
2575 err = proc_get_long(&kbuf, &left, &val_b,
2576 &neg, tr_b, sizeof(tr_b),
2577 &c);
2578 if (err)
2579 break;
2580 if (val_b >= bitmap_len || neg ||
2581 val_a > val_b) {
2582 err = -EINVAL;
2583 break;
2585 if (left) {
2586 kbuf++;
2587 left--;
2591 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2592 first = 0;
2593 proc_skip_char(&kbuf, &left, '\n');
2595 free_page(page);
2596 } else {
2597 unsigned long bit_a, bit_b = 0;
2599 while (left) {
2600 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2601 if (bit_a >= bitmap_len)
2602 break;
2603 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2604 bit_a + 1) - 1;
2606 if (!first) {
2607 err = proc_put_char(&buffer, &left, ',');
2608 if (err)
2609 break;
2611 err = proc_put_long(&buffer, &left, bit_a, false);
2612 if (err)
2613 break;
2614 if (bit_a != bit_b) {
2615 err = proc_put_char(&buffer, &left, '-');
2616 if (err)
2617 break;
2618 err = proc_put_long(&buffer, &left, bit_b, false);
2619 if (err)
2620 break;
2623 first = 0; bit_b++;
2625 if (!err)
2626 err = proc_put_char(&buffer, &left, '\n');
2629 if (!err) {
2630 if (write) {
2631 if (*ppos)
2632 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2633 else
2634 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2636 kfree(tmp_bitmap);
2637 *lenp -= left;
2638 *ppos += *lenp;
2639 return 0;
2640 } else {
2641 kfree(tmp_bitmap);
2642 return err;
2646 #else /* CONFIG_PROC_SYSCTL */
2648 int proc_dostring(struct ctl_table *table, int write,
2649 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 return -ENOSYS;
2654 int proc_dointvec(struct ctl_table *table, int write,
2655 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 return -ENOSYS;
2660 int proc_dointvec_minmax(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 return -ENOSYS;
2666 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2667 void __user *buffer, size_t *lenp, loff_t *ppos)
2669 return -ENOSYS;
2672 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2673 void __user *buffer, size_t *lenp, loff_t *ppos)
2675 return -ENOSYS;
2678 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2679 void __user *buffer, size_t *lenp, loff_t *ppos)
2681 return -ENOSYS;
2684 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2685 void __user *buffer, size_t *lenp, loff_t *ppos)
2687 return -ENOSYS;
2690 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2691 void __user *buffer,
2692 size_t *lenp, loff_t *ppos)
2694 return -ENOSYS;
2698 #endif /* CONFIG_PROC_SYSCTL */
2701 * No sense putting this after each symbol definition, twice,
2702 * exception granted :-)
2704 EXPORT_SYMBOL(proc_dointvec);
2705 EXPORT_SYMBOL(proc_dointvec_jiffies);
2706 EXPORT_SYMBOL(proc_dointvec_minmax);
2707 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2708 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2709 EXPORT_SYMBOL(proc_dostring);
2710 EXPORT_SYMBOL(proc_doulongvec_minmax);
2711 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);