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
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
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>
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>
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>
64 #include <asm/uaccess.h>
65 #include <asm/processor.h>
69 #include <asm/stacktrace.h>
73 #include <asm/setup.h>
75 #ifdef CONFIG_BSD_PROCESS_ACCT
76 #include <linux/acct.h>
78 #ifdef CONFIG_RT_MUTEXES
79 #include <linux/rtmutex.h>
81 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
82 #include <linux/lockdep.h>
84 #ifdef CONFIG_CHR_DEV_SG
88 #ifdef CONFIG_LOCKUP_DETECTOR
89 #include <linux/nmi.h>
93 #if defined(CONFIG_SYSCTL)
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;
104 extern int min_free_kbytes;
105 extern int pid_max_min, pid_max_max;
106 extern int sysctl_drop_caches;
107 extern int percpu_pagelist_fraction;
108 extern int compat_log;
109 extern int latencytop_enabled;
110 extern int sysctl_nr_open_min, sysctl_nr_open_max;
112 extern int sysctl_nr_trim_pages;
115 extern int blk_iopoll_enabled;
118 /* Constants used for minimum and maximum */
119 #ifdef CONFIG_LOCKUP_DETECTOR
120 static int sixty = 60;
121 static int neg_one = -1;
125 static int __maybe_unused one = 1;
126 static int __maybe_unused two = 2;
127 static int __maybe_unused three = 3;
128 static unsigned long one_ul = 1;
129 static int one_hundred = 100;
131 static int ten_thousand = 10000;
134 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
137 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138 static int maxolduid = 65535;
139 static int minolduid;
140 static int min_percpu_pagelist_fract = 8;
142 static int ngroups_max = NGROUPS_MAX;
143 static const int cap_last_cap = CAP_LAST_CAP;
145 #ifdef CONFIG_INOTIFY_USER
146 #include <linux/inotify.h>
151 #ifdef CONFIG_SPARC64
152 extern int sysctl_tsb_ratio;
156 extern int pwrsw_enabled;
157 extern int unaligned_enabled;
161 extern int no_unaligned_warning;
162 extern int unaligned_dump_stack;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
168 static int proc_taint(struct ctl_table *table, int write,
169 void __user *buffer, size_t *lenp, loff_t *ppos);
173 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
177 #ifdef CONFIG_MAGIC_SYSRQ
178 /* Note: sysrq code uses it's own private copy */
179 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
181 static int sysrq_sysctl_handler(ctl_table *table, int write,
182 void __user *buffer, size_t *lenp,
187 error = proc_dointvec(table, write, buffer, lenp, ppos);
192 sysrq_toggle_support(__sysrq_enabled);
199 static struct ctl_table kern_table[];
200 static struct ctl_table vm_table[];
201 static struct ctl_table fs_table[];
202 static struct ctl_table debug_table[];
203 static struct ctl_table dev_table[];
204 extern struct ctl_table random_table[];
206 extern struct ctl_table epoll_table[];
209 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
210 int sysctl_legacy_va_layout;
213 /* The default sysctl tables: */
215 static struct ctl_table sysctl_base_table[] = {
217 .procname = "kernel",
234 .child = debug_table,
244 #ifdef CONFIG_SCHED_DEBUG
245 static int min_sched_granularity_ns = 100000; /* 100 usecs */
246 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
247 static int min_wakeup_granularity_ns; /* 0 usecs */
248 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
249 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
250 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
253 #ifdef CONFIG_COMPACTION
254 static int min_extfrag_threshold;
255 static int max_extfrag_threshold = 1000;
258 static struct ctl_table kern_table[] = {
260 .procname = "sched_child_runs_first",
261 .data = &sysctl_sched_child_runs_first,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = proc_dointvec,
266 #ifdef CONFIG_SCHED_DEBUG
268 .procname = "sched_min_granularity_ns",
269 .data = &sysctl_sched_min_granularity,
270 .maxlen = sizeof(unsigned int),
272 .proc_handler = sched_proc_update_handler,
273 .extra1 = &min_sched_granularity_ns,
274 .extra2 = &max_sched_granularity_ns,
277 .procname = "sched_latency_ns",
278 .data = &sysctl_sched_latency,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = sched_proc_update_handler,
282 .extra1 = &min_sched_granularity_ns,
283 .extra2 = &max_sched_granularity_ns,
286 .procname = "sched_wakeup_granularity_ns",
287 .data = &sysctl_sched_wakeup_granularity,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = sched_proc_update_handler,
291 .extra1 = &min_wakeup_granularity_ns,
292 .extra2 = &max_wakeup_granularity_ns,
295 .procname = "sched_tunable_scaling",
296 .data = &sysctl_sched_tunable_scaling,
297 .maxlen = sizeof(enum sched_tunable_scaling),
299 .proc_handler = sched_proc_update_handler,
300 .extra1 = &min_sched_tunable_scaling,
301 .extra2 = &max_sched_tunable_scaling,
304 .procname = "sched_migration_cost",
305 .data = &sysctl_sched_migration_cost,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = proc_dointvec,
311 .procname = "sched_nr_migrate",
312 .data = &sysctl_sched_nr_migrate,
313 .maxlen = sizeof(unsigned int),
315 .proc_handler = proc_dointvec,
318 .procname = "sched_time_avg",
319 .data = &sysctl_sched_time_avg,
320 .maxlen = sizeof(unsigned int),
322 .proc_handler = proc_dointvec,
325 .procname = "sched_shares_window",
326 .data = &sysctl_sched_shares_window,
327 .maxlen = sizeof(unsigned int),
329 .proc_handler = proc_dointvec,
332 .procname = "timer_migration",
333 .data = &sysctl_timer_migration,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = proc_dointvec_minmax,
342 .procname = "sched_rt_period_us",
343 .data = &sysctl_sched_rt_period,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = sched_rt_handler,
349 .procname = "sched_rt_runtime_us",
350 .data = &sysctl_sched_rt_runtime,
351 .maxlen = sizeof(int),
353 .proc_handler = sched_rt_handler,
355 #ifdef CONFIG_SCHED_AUTOGROUP
357 .procname = "sched_autogroup_enabled",
358 .data = &sysctl_sched_autogroup_enabled,
359 .maxlen = sizeof(unsigned int),
361 .proc_handler = proc_dointvec_minmax,
366 #ifdef CONFIG_CFS_BANDWIDTH
368 .procname = "sched_cfs_bandwidth_slice_us",
369 .data = &sysctl_sched_cfs_bandwidth_slice,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = proc_dointvec_minmax,
376 #ifdef CONFIG_PROVE_LOCKING
378 .procname = "prove_locking",
379 .data = &prove_locking,
380 .maxlen = sizeof(int),
382 .proc_handler = proc_dointvec,
385 #ifdef CONFIG_LOCK_STAT
387 .procname = "lock_stat",
389 .maxlen = sizeof(int),
391 .proc_handler = proc_dointvec,
396 .data = &panic_timeout,
397 .maxlen = sizeof(int),
399 .proc_handler = proc_dointvec,
402 .procname = "core_uses_pid",
403 .data = &core_uses_pid,
404 .maxlen = sizeof(int),
406 .proc_handler = proc_dointvec,
409 .procname = "core_pattern",
410 .data = core_pattern,
411 .maxlen = CORENAME_MAX_SIZE,
413 .proc_handler = proc_dostring,
416 .procname = "core_pipe_limit",
417 .data = &core_pipe_limit,
418 .maxlen = sizeof(unsigned int),
420 .proc_handler = proc_dointvec,
422 #ifdef CONFIG_PROC_SYSCTL
424 .procname = "tainted",
425 .maxlen = sizeof(long),
427 .proc_handler = proc_taint,
430 #ifdef CONFIG_LATENCYTOP
432 .procname = "latencytop",
433 .data = &latencytop_enabled,
434 .maxlen = sizeof(int),
436 .proc_handler = proc_dointvec,
439 #ifdef CONFIG_BLK_DEV_INITRD
441 .procname = "real-root-dev",
442 .data = &real_root_dev,
443 .maxlen = sizeof(int),
445 .proc_handler = proc_dointvec,
449 .procname = "print-fatal-signals",
450 .data = &print_fatal_signals,
451 .maxlen = sizeof(int),
453 .proc_handler = proc_dointvec,
457 .procname = "reboot-cmd",
458 .data = reboot_command,
461 .proc_handler = proc_dostring,
464 .procname = "stop-a",
465 .data = &stop_a_enabled,
466 .maxlen = sizeof (int),
468 .proc_handler = proc_dointvec,
471 .procname = "scons-poweroff",
472 .data = &scons_pwroff,
473 .maxlen = sizeof (int),
475 .proc_handler = proc_dointvec,
478 #ifdef CONFIG_SPARC64
480 .procname = "tsb-ratio",
481 .data = &sysctl_tsb_ratio,
482 .maxlen = sizeof (int),
484 .proc_handler = proc_dointvec,
489 .procname = "soft-power",
490 .data = &pwrsw_enabled,
491 .maxlen = sizeof (int),
493 .proc_handler = proc_dointvec,
496 .procname = "unaligned-trap",
497 .data = &unaligned_enabled,
498 .maxlen = sizeof (int),
500 .proc_handler = proc_dointvec,
504 .procname = "ctrl-alt-del",
506 .maxlen = sizeof(int),
508 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_FUNCTION_TRACER
512 .procname = "ftrace_enabled",
513 .data = &ftrace_enabled,
514 .maxlen = sizeof(int),
516 .proc_handler = ftrace_enable_sysctl,
519 #ifdef CONFIG_STACK_TRACER
521 .procname = "stack_tracer_enabled",
522 .data = &stack_tracer_enabled,
523 .maxlen = sizeof(int),
525 .proc_handler = stack_trace_sysctl,
528 #ifdef CONFIG_TRACING
530 .procname = "ftrace_dump_on_oops",
531 .data = &ftrace_dump_on_oops,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec,
537 #ifdef CONFIG_MODULES
539 .procname = "modprobe",
540 .data = &modprobe_path,
541 .maxlen = KMOD_PATH_LEN,
543 .proc_handler = proc_dostring,
546 .procname = "modules_disabled",
547 .data = &modules_disabled,
548 .maxlen = sizeof(int),
550 /* only handle a transition from default "0" to "1" */
551 .proc_handler = proc_dointvec_minmax,
556 #ifdef CONFIG_HOTPLUG
558 .procname = "hotplug",
559 .data = &uevent_helper,
560 .maxlen = UEVENT_HELPER_PATH_LEN,
562 .proc_handler = proc_dostring,
565 #ifdef CONFIG_CHR_DEV_SG
567 .procname = "sg-big-buff",
568 .data = &sg_big_buff,
569 .maxlen = sizeof (int),
571 .proc_handler = proc_dointvec,
574 #ifdef CONFIG_BSD_PROCESS_ACCT
578 .maxlen = 3*sizeof(int),
580 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_MAGIC_SYSRQ
586 .data = &__sysrq_enabled,
587 .maxlen = sizeof (int),
589 .proc_handler = sysrq_sysctl_handler,
592 #ifdef CONFIG_PROC_SYSCTL
594 .procname = "cad_pid",
596 .maxlen = sizeof (int),
598 .proc_handler = proc_do_cad_pid,
602 .procname = "threads-max",
603 .data = &max_threads,
604 .maxlen = sizeof(int),
606 .proc_handler = proc_dointvec,
609 .procname = "random",
611 .child = random_table,
614 .procname = "usermodehelper",
616 .child = usermodehelper_table,
619 .procname = "overflowuid",
620 .data = &overflowuid,
621 .maxlen = sizeof(int),
623 .proc_handler = proc_dointvec_minmax,
624 .extra1 = &minolduid,
625 .extra2 = &maxolduid,
628 .procname = "overflowgid",
629 .data = &overflowgid,
630 .maxlen = sizeof(int),
632 .proc_handler = proc_dointvec_minmax,
633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
637 #ifdef CONFIG_MATHEMU
639 .procname = "ieee_emulation_warnings",
640 .data = &sysctl_ieee_emulation_warnings,
641 .maxlen = sizeof(int),
643 .proc_handler = proc_dointvec,
647 .procname = "userprocess_debug",
648 .data = &show_unhandled_signals,
649 .maxlen = sizeof(int),
651 .proc_handler = proc_dointvec,
655 .procname = "pid_max",
657 .maxlen = sizeof (int),
659 .proc_handler = proc_dointvec_minmax,
660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
663 #if defined(CONFIG_MODULES) && defined(CONFIG_ENTERPRISE_SUPPORT)
665 .procname = "unsupported",
666 .data = &unsupported,
667 .maxlen = sizeof(int),
669 .proc_handler = &proc_dointvec,
673 .procname = "panic_on_oops",
674 .data = &panic_on_oops,
675 .maxlen = sizeof(int),
677 .proc_handler = proc_dointvec,
679 #if defined CONFIG_PRINTK
681 .procname = "printk",
682 .data = &console_loglevel,
683 .maxlen = 4*sizeof(int),
685 .proc_handler = proc_dointvec,
688 .procname = "printk_ratelimit",
689 .data = &printk_ratelimit_state.interval,
690 .maxlen = sizeof(int),
692 .proc_handler = proc_dointvec_jiffies,
695 .procname = "printk_ratelimit_burst",
696 .data = &printk_ratelimit_state.burst,
697 .maxlen = sizeof(int),
699 .proc_handler = proc_dointvec,
702 .procname = "printk_delay",
703 .data = &printk_delay_msec,
704 .maxlen = sizeof(int),
706 .proc_handler = proc_dointvec_minmax,
708 .extra2 = &ten_thousand,
711 .procname = "dmesg_restrict",
712 .data = &dmesg_restrict,
713 .maxlen = sizeof(int),
715 .proc_handler = proc_dointvec_minmax_sysadmin,
720 .procname = "kptr_restrict",
721 .data = &kptr_restrict,
722 .maxlen = sizeof(int),
724 .proc_handler = proc_dointvec_minmax_sysadmin,
730 .procname = "ngroups_max",
731 .data = &ngroups_max,
732 .maxlen = sizeof (int),
734 .proc_handler = proc_dointvec,
737 .procname = "cap_last_cap",
738 .data = (void *)&cap_last_cap,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dointvec,
743 #if defined(CONFIG_LOCKUP_DETECTOR)
745 .procname = "watchdog",
746 .data = &watchdog_enabled,
747 .maxlen = sizeof (int),
749 .proc_handler = proc_dowatchdog,
754 .procname = "watchdog_thresh",
755 .data = &watchdog_thresh,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dowatchdog,
763 .procname = "softlockup_panic",
764 .data = &softlockup_panic,
765 .maxlen = sizeof(int),
767 .proc_handler = proc_dointvec_minmax,
772 .procname = "nmi_watchdog",
773 .data = &watchdog_enabled,
774 .maxlen = sizeof (int),
776 .proc_handler = proc_dowatchdog,
781 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
783 .procname = "unknown_nmi_panic",
784 .data = &unknown_nmi_panic,
785 .maxlen = sizeof (int),
787 .proc_handler = proc_dointvec,
790 #if defined(CONFIG_X86)
792 .procname = "panic_on_unrecovered_nmi",
793 .data = &panic_on_unrecovered_nmi,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec,
799 .procname = "panic_on_io_nmi",
800 .data = &panic_on_io_nmi,
801 .maxlen = sizeof(int),
803 .proc_handler = proc_dointvec,
805 #ifdef CONFIG_DEBUG_STACKOVERFLOW
807 .procname = "panic_on_stackoverflow",
808 .data = &sysctl_panic_on_stackoverflow,
809 .maxlen = sizeof(int),
811 .proc_handler = proc_dointvec,
815 .procname = "bootloader_type",
816 .data = &bootloader_type,
817 .maxlen = sizeof (int),
819 .proc_handler = proc_dointvec,
822 .procname = "bootloader_version",
823 .data = &bootloader_version,
824 .maxlen = sizeof (int),
826 .proc_handler = proc_dointvec,
829 .procname = "kstack_depth_to_print",
830 .data = &kstack_depth_to_print,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec,
836 .procname = "io_delay_type",
837 .data = &io_delay_type,
838 .maxlen = sizeof(int),
840 .proc_handler = proc_dointvec,
843 #if defined(CONFIG_MMU)
845 .procname = "randomize_va_space",
846 .data = &randomize_va_space,
847 .maxlen = sizeof(int),
849 .proc_handler = proc_dointvec,
853 .procname = "suid_dumpable",
854 .data = &suid_dumpable,
855 .maxlen = sizeof(int),
857 .proc_handler = proc_dointvec,
859 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
861 .procname = "spin_retry",
863 .maxlen = sizeof (int),
865 .proc_handler = proc_dointvec,
868 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) && !defined(CONFIG_ACPI_PV_SLEEP)
870 .procname = "acpi_video_flags",
871 .data = &acpi_realmode_flags,
872 .maxlen = sizeof (unsigned long),
874 .proc_handler = proc_doulongvec_minmax,
879 .procname = "ignore-unaligned-usertrap",
880 .data = &no_unaligned_warning,
881 .maxlen = sizeof (int),
883 .proc_handler = proc_dointvec,
886 .procname = "unaligned-dump-stack",
887 .data = &unaligned_dump_stack,
888 .maxlen = sizeof (int),
890 .proc_handler = proc_dointvec,
893 #ifdef CONFIG_DETECT_HUNG_TASK
895 .procname = "hung_task_panic",
896 .data = &sysctl_hung_task_panic,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec_minmax,
904 .procname = "hung_task_check_count",
905 .data = &sysctl_hung_task_check_count,
906 .maxlen = sizeof(unsigned long),
908 .proc_handler = proc_doulongvec_minmax,
911 .procname = "hung_task_timeout_secs",
912 .data = &sysctl_hung_task_timeout_secs,
913 .maxlen = sizeof(unsigned long),
915 .proc_handler = proc_dohung_task_timeout_secs,
918 .procname = "hung_task_warnings",
919 .data = &sysctl_hung_task_warnings,
920 .maxlen = sizeof(unsigned long),
922 .proc_handler = proc_doulongvec_minmax,
927 .procname = "compat-log",
929 .maxlen = sizeof (int),
931 .proc_handler = proc_dointvec,
934 #ifdef CONFIG_RT_MUTEXES
936 .procname = "max_lock_depth",
937 .data = &max_lock_depth,
938 .maxlen = sizeof(int),
940 .proc_handler = proc_dointvec,
944 .procname = "poweroff_cmd",
945 .data = &poweroff_cmd,
946 .maxlen = POWEROFF_CMD_PATH_LEN,
948 .proc_handler = proc_dostring,
954 .child = key_sysctls,
957 #ifdef CONFIG_RCU_TORTURE_TEST
959 .procname = "rcutorture_runnable",
960 .data = &rcutorture_runnable,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec,
966 #ifdef CONFIG_PERF_EVENTS
968 * User-space scripts rely on the existence of this file
969 * as a feature check for perf_events being enabled.
971 * So it's an ABI, do not remove!
974 .procname = "perf_event_paranoid",
975 .data = &sysctl_perf_event_paranoid,
976 .maxlen = sizeof(sysctl_perf_event_paranoid),
978 .proc_handler = proc_dointvec,
981 .procname = "perf_event_mlock_kb",
982 .data = &sysctl_perf_event_mlock,
983 .maxlen = sizeof(sysctl_perf_event_mlock),
985 .proc_handler = proc_dointvec,
988 .procname = "perf_event_max_sample_rate",
989 .data = &sysctl_perf_event_sample_rate,
990 .maxlen = sizeof(sysctl_perf_event_sample_rate),
992 .proc_handler = perf_proc_update_handler,
995 #ifdef CONFIG_KMEMCHECK
997 .procname = "kmemcheck",
998 .data = &kmemcheck_enabled,
999 .maxlen = sizeof(int),
1001 .proc_handler = proc_dointvec,
1006 .procname = "blk_iopoll",
1007 .data = &blk_iopoll_enabled,
1008 .maxlen = sizeof(int),
1010 .proc_handler = proc_dointvec,
1016 static struct ctl_table vm_table[] = {
1018 .procname = "overcommit_memory",
1019 .data = &sysctl_overcommit_memory,
1020 .maxlen = sizeof(sysctl_overcommit_memory),
1022 .proc_handler = proc_dointvec_minmax,
1027 .procname = "panic_on_oom",
1028 .data = &sysctl_panic_on_oom,
1029 .maxlen = sizeof(sysctl_panic_on_oom),
1031 .proc_handler = proc_dointvec_minmax,
1036 .procname = "oom_kill_allocating_task",
1037 .data = &sysctl_oom_kill_allocating_task,
1038 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1040 .proc_handler = proc_dointvec,
1043 .procname = "oom_dump_tasks",
1044 .data = &sysctl_oom_dump_tasks,
1045 .maxlen = sizeof(sysctl_oom_dump_tasks),
1047 .proc_handler = proc_dointvec,
1050 .procname = "overcommit_ratio",
1051 .data = &sysctl_overcommit_ratio,
1052 .maxlen = sizeof(sysctl_overcommit_ratio),
1054 .proc_handler = proc_dointvec,
1057 .procname = "page-cluster",
1058 .data = &page_cluster,
1059 .maxlen = sizeof(int),
1061 .proc_handler = proc_dointvec_minmax,
1065 .procname = "dirty_background_ratio",
1066 .data = &dirty_background_ratio,
1067 .maxlen = sizeof(dirty_background_ratio),
1069 .proc_handler = dirty_background_ratio_handler,
1071 .extra2 = &one_hundred,
1074 .procname = "dirty_background_bytes",
1075 .data = &dirty_background_bytes,
1076 .maxlen = sizeof(dirty_background_bytes),
1078 .proc_handler = dirty_background_bytes_handler,
1082 .procname = "dirty_ratio",
1083 .data = &vm_dirty_ratio,
1084 .maxlen = sizeof(vm_dirty_ratio),
1086 .proc_handler = dirty_ratio_handler,
1088 .extra2 = &one_hundred,
1091 .procname = "dirty_bytes",
1092 .data = &vm_dirty_bytes,
1093 .maxlen = sizeof(vm_dirty_bytes),
1095 .proc_handler = dirty_bytes_handler,
1096 .extra1 = &dirty_bytes_min,
1099 .procname = "dirty_writeback_centisecs",
1100 .data = &dirty_writeback_interval,
1101 .maxlen = sizeof(dirty_writeback_interval),
1103 .proc_handler = dirty_writeback_centisecs_handler,
1106 .procname = "dirty_expire_centisecs",
1107 .data = &dirty_expire_interval,
1108 .maxlen = sizeof(dirty_expire_interval),
1110 .proc_handler = proc_dointvec_minmax,
1114 .procname = "nr_pdflush_threads",
1115 .data = &nr_pdflush_threads,
1116 .maxlen = sizeof nr_pdflush_threads,
1117 .mode = 0444 /* read-only*/,
1118 .proc_handler = proc_dointvec,
1121 .procname = "swappiness",
1122 .data = &vm_swappiness,
1123 .maxlen = sizeof(vm_swappiness),
1125 .proc_handler = proc_dointvec_minmax,
1127 .extra2 = &one_hundred,
1129 #ifdef CONFIG_HUGETLB_PAGE
1131 .procname = "nr_hugepages",
1133 .maxlen = sizeof(unsigned long),
1135 .proc_handler = hugetlb_sysctl_handler,
1136 .extra1 = (void *)&hugetlb_zero,
1137 .extra2 = (void *)&hugetlb_infinity,
1141 .procname = "nr_hugepages_mempolicy",
1143 .maxlen = sizeof(unsigned long),
1145 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1146 .extra1 = (void *)&hugetlb_zero,
1147 .extra2 = (void *)&hugetlb_infinity,
1151 .procname = "hugetlb_shm_group",
1152 .data = &sysctl_hugetlb_shm_group,
1153 .maxlen = sizeof(gid_t),
1155 .proc_handler = proc_dointvec,
1158 .procname = "hugepages_treat_as_movable",
1159 .data = &hugepages_treat_as_movable,
1160 .maxlen = sizeof(int),
1162 .proc_handler = hugetlb_treat_movable_handler,
1165 .procname = "nr_overcommit_hugepages",
1167 .maxlen = sizeof(unsigned long),
1169 .proc_handler = hugetlb_overcommit_handler,
1170 .extra1 = (void *)&hugetlb_zero,
1171 .extra2 = (void *)&hugetlb_infinity,
1175 .procname = "lowmem_reserve_ratio",
1176 .data = &sysctl_lowmem_reserve_ratio,
1177 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1179 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1182 .procname = "drop_caches",
1183 .data = &sysctl_drop_caches,
1184 .maxlen = sizeof(int),
1186 .proc_handler = drop_caches_sysctl_handler,
1190 #ifdef CONFIG_COMPACTION
1192 .procname = "compact_memory",
1193 .data = &sysctl_compact_memory,
1194 .maxlen = sizeof(int),
1196 .proc_handler = sysctl_compaction_handler,
1199 .procname = "extfrag_threshold",
1200 .data = &sysctl_extfrag_threshold,
1201 .maxlen = sizeof(int),
1203 .proc_handler = sysctl_extfrag_handler,
1204 .extra1 = &min_extfrag_threshold,
1205 .extra2 = &max_extfrag_threshold,
1208 #endif /* CONFIG_COMPACTION */
1210 .procname = "min_free_kbytes",
1211 .data = &min_free_kbytes,
1212 .maxlen = sizeof(min_free_kbytes),
1214 .proc_handler = min_free_kbytes_sysctl_handler,
1218 .procname = "percpu_pagelist_fraction",
1219 .data = &percpu_pagelist_fraction,
1220 .maxlen = sizeof(percpu_pagelist_fraction),
1222 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1223 .extra1 = &min_percpu_pagelist_fract,
1227 .procname = "max_map_count",
1228 .data = &sysctl_max_map_count,
1229 .maxlen = sizeof(sysctl_max_map_count),
1231 .proc_handler = proc_dointvec_minmax,
1236 .procname = "nr_trim_pages",
1237 .data = &sysctl_nr_trim_pages,
1238 .maxlen = sizeof(sysctl_nr_trim_pages),
1240 .proc_handler = proc_dointvec_minmax,
1245 .procname = "laptop_mode",
1246 .data = &laptop_mode,
1247 .maxlen = sizeof(laptop_mode),
1249 .proc_handler = proc_dointvec_jiffies,
1252 .procname = "block_dump",
1253 .data = &block_dump,
1254 .maxlen = sizeof(block_dump),
1256 .proc_handler = proc_dointvec,
1260 .procname = "vfs_cache_pressure",
1261 .data = &sysctl_vfs_cache_pressure,
1262 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1264 .proc_handler = proc_dointvec,
1267 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1269 .procname = "legacy_va_layout",
1270 .data = &sysctl_legacy_va_layout,
1271 .maxlen = sizeof(sysctl_legacy_va_layout),
1273 .proc_handler = proc_dointvec,
1279 .procname = "zone_reclaim_mode",
1280 .data = &zone_reclaim_mode,
1281 .maxlen = sizeof(zone_reclaim_mode),
1283 .proc_handler = proc_dointvec,
1287 .procname = "min_unmapped_ratio",
1288 .data = &sysctl_min_unmapped_ratio,
1289 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1291 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1293 .extra2 = &one_hundred,
1296 .procname = "min_slab_ratio",
1297 .data = &sysctl_min_slab_ratio,
1298 .maxlen = sizeof(sysctl_min_slab_ratio),
1300 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1302 .extra2 = &one_hundred,
1307 .procname = "stat_interval",
1308 .data = &sysctl_stat_interval,
1309 .maxlen = sizeof(sysctl_stat_interval),
1311 .proc_handler = proc_dointvec_jiffies,
1316 .procname = "mmap_min_addr",
1317 .data = &dac_mmap_min_addr,
1318 .maxlen = sizeof(unsigned long),
1320 .proc_handler = mmap_min_addr_handler,
1325 .procname = "numa_zonelist_order",
1326 .data = &numa_zonelist_order,
1327 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1329 .proc_handler = numa_zonelist_order_handler,
1332 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1333 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1335 .procname = "vdso_enabled",
1336 .data = &vdso_enabled,
1337 .maxlen = sizeof(vdso_enabled),
1339 .proc_handler = proc_dointvec,
1343 #ifdef CONFIG_HIGHMEM
1345 .procname = "highmem_is_dirtyable",
1346 .data = &vm_highmem_is_dirtyable,
1347 .maxlen = sizeof(vm_highmem_is_dirtyable),
1349 .proc_handler = proc_dointvec_minmax,
1355 .procname = "scan_unevictable_pages",
1356 .data = &scan_unevictable_pages,
1357 .maxlen = sizeof(scan_unevictable_pages),
1359 .proc_handler = scan_unevictable_handler,
1361 #ifdef CONFIG_MEMORY_FAILURE
1363 .procname = "memory_failure_early_kill",
1364 .data = &sysctl_memory_failure_early_kill,
1365 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1367 .proc_handler = proc_dointvec_minmax,
1372 .procname = "memory_failure_recovery",
1373 .data = &sysctl_memory_failure_recovery,
1374 .maxlen = sizeof(sysctl_memory_failure_recovery),
1376 .proc_handler = proc_dointvec_minmax,
1384 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1385 static struct ctl_table binfmt_misc_table[] = {
1390 static struct ctl_table fs_table[] = {
1392 .procname = "inode-nr",
1393 .data = &inodes_stat,
1394 .maxlen = 2*sizeof(int),
1396 .proc_handler = proc_nr_inodes,
1399 .procname = "inode-state",
1400 .data = &inodes_stat,
1401 .maxlen = 7*sizeof(int),
1403 .proc_handler = proc_nr_inodes,
1406 .procname = "file-nr",
1407 .data = &files_stat,
1408 .maxlen = sizeof(files_stat),
1410 .proc_handler = proc_nr_files,
1413 .procname = "file-max",
1414 .data = &files_stat.max_files,
1415 .maxlen = sizeof(files_stat.max_files),
1417 .proc_handler = proc_doulongvec_minmax,
1420 .procname = "nr_open",
1421 .data = &sysctl_nr_open,
1422 .maxlen = sizeof(int),
1424 .proc_handler = proc_dointvec_minmax,
1425 .extra1 = &sysctl_nr_open_min,
1426 .extra2 = &sysctl_nr_open_max,
1429 .procname = "dentry-state",
1430 .data = &dentry_stat,
1431 .maxlen = 6*sizeof(int),
1433 .proc_handler = proc_nr_dentry,
1436 .procname = "overflowuid",
1437 .data = &fs_overflowuid,
1438 .maxlen = sizeof(int),
1440 .proc_handler = proc_dointvec_minmax,
1441 .extra1 = &minolduid,
1442 .extra2 = &maxolduid,
1445 .procname = "overflowgid",
1446 .data = &fs_overflowgid,
1447 .maxlen = sizeof(int),
1449 .proc_handler = proc_dointvec_minmax,
1450 .extra1 = &minolduid,
1451 .extra2 = &maxolduid,
1453 #ifdef CONFIG_FILE_LOCKING
1455 .procname = "leases-enable",
1456 .data = &leases_enable,
1457 .maxlen = sizeof(int),
1459 .proc_handler = proc_dointvec,
1462 #ifdef CONFIG_DNOTIFY
1464 .procname = "dir-notify-enable",
1465 .data = &dir_notify_enable,
1466 .maxlen = sizeof(int),
1468 .proc_handler = proc_dointvec,
1472 #ifdef CONFIG_FILE_LOCKING
1474 .procname = "lease-break-time",
1475 .data = &lease_break_time,
1476 .maxlen = sizeof(int),
1478 .proc_handler = proc_dointvec,
1483 .procname = "aio-nr",
1485 .maxlen = sizeof(aio_nr),
1487 .proc_handler = proc_doulongvec_minmax,
1490 .procname = "aio-max-nr",
1491 .data = &aio_max_nr,
1492 .maxlen = sizeof(aio_max_nr),
1494 .proc_handler = proc_doulongvec_minmax,
1496 #endif /* CONFIG_AIO */
1497 #ifdef CONFIG_INOTIFY_USER
1499 .procname = "inotify",
1501 .child = inotify_table,
1506 .procname = "epoll",
1508 .child = epoll_table,
1513 .procname = "suid_dumpable",
1514 .data = &suid_dumpable,
1515 .maxlen = sizeof(int),
1517 .proc_handler = proc_dointvec_minmax,
1521 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1523 .procname = "binfmt_misc",
1525 .child = binfmt_misc_table,
1529 .procname = "pipe-max-size",
1530 .data = &pipe_max_size,
1531 .maxlen = sizeof(int),
1533 .proc_handler = &pipe_proc_fn,
1534 .extra1 = &pipe_min_size,
1539 static struct ctl_table debug_table[] = {
1540 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1541 defined(CONFIG_S390) || defined(CONFIG_TILE)
1543 .procname = "exception-trace",
1544 .data = &show_unhandled_signals,
1545 .maxlen = sizeof(int),
1547 .proc_handler = proc_dointvec
1550 #if defined(CONFIG_OPTPROBES)
1552 .procname = "kprobes-optimization",
1553 .data = &sysctl_kprobes_optimization,
1554 .maxlen = sizeof(int),
1556 .proc_handler = proc_kprobes_optimization_handler,
1564 static struct ctl_table dev_table[] = {
1568 int __init sysctl_init(void)
1570 register_sysctl_table(sysctl_base_table);
1574 #endif /* CONFIG_SYSCTL */
1580 #ifdef CONFIG_PROC_SYSCTL
1582 static int _proc_do_string(void* data, int maxlen, int write,
1583 void __user *buffer,
1584 size_t *lenp, loff_t *ppos)
1590 if (!data || !maxlen || !*lenp) {
1598 while (len < *lenp) {
1599 if (get_user(c, p++))
1601 if (c == 0 || c == '\n')
1607 if(copy_from_user(data, buffer, len))
1609 ((char *) data)[len] = 0;
1627 if(copy_to_user(buffer, data, len))
1630 if(put_user('\n', ((char __user *) buffer) + len))
1641 * proc_dostring - read a string sysctl
1642 * @table: the sysctl table
1643 * @write: %TRUE if this is a write to the sysctl file
1644 * @buffer: the user buffer
1645 * @lenp: the size of the user buffer
1646 * @ppos: file position
1648 * Reads/writes a string from/to the user buffer. If the kernel
1649 * buffer provided is not large enough to hold the string, the
1650 * string is truncated. The copied string is %NULL-terminated.
1651 * If the string is being read by the user process, it is copied
1652 * and a newline '\n' is added. It is truncated if the buffer is
1655 * Returns 0 on success.
1657 int proc_dostring(struct ctl_table *table, int write,
1658 void __user *buffer, size_t *lenp, loff_t *ppos)
1660 return _proc_do_string(table->data, table->maxlen, write,
1661 buffer, lenp, ppos);
1664 static size_t proc_skip_spaces(char **buf)
1667 char *tmp = skip_spaces(*buf);
1673 static void proc_skip_char(char **buf, size_t *size, const char v)
1683 #define TMPBUFLEN 22
1685 * proc_get_long - reads an ASCII formatted integer from a user buffer
1687 * @buf: a kernel buffer
1688 * @size: size of the kernel buffer
1689 * @val: this is where the number will be stored
1690 * @neg: set to %TRUE if number is negative
1691 * @perm_tr: a vector which contains the allowed trailers
1692 * @perm_tr_len: size of the perm_tr vector
1693 * @tr: pointer to store the trailer character
1695 * In case of success %0 is returned and @buf and @size are updated with
1696 * the amount of bytes read. If @tr is non-NULL and a trailing
1697 * character exists (size is non-zero after returning from this
1698 * function), @tr is updated with the trailing character.
1700 static int proc_get_long(char **buf, size_t *size,
1701 unsigned long *val, bool *neg,
1702 const char *perm_tr, unsigned perm_tr_len, char *tr)
1705 char *p, tmp[TMPBUFLEN];
1711 if (len > TMPBUFLEN - 1)
1712 len = TMPBUFLEN - 1;
1714 memcpy(tmp, *buf, len);
1718 if (*p == '-' && *size > 1) {
1726 *val = simple_strtoul(p, &p, 0);
1730 /* We don't know if the next char is whitespace thus we may accept
1731 * invalid integers (e.g. 1234...a) or two integers instead of one
1732 * (e.g. 123...1). So lets not allow such large numbers. */
1733 if (len == TMPBUFLEN - 1)
1736 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1739 if (tr && (len < *size))
1749 * proc_put_long - converts an integer to a decimal ASCII formatted string
1751 * @buf: the user buffer
1752 * @size: the size of the user buffer
1753 * @val: the integer to be converted
1754 * @neg: sign of the number, %TRUE for negative
1756 * In case of success %0 is returned and @buf and @size are updated with
1757 * the amount of bytes written.
1759 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1763 char tmp[TMPBUFLEN], *p = tmp;
1765 sprintf(p, "%s%lu", neg ? "-" : "", val);
1769 if (copy_to_user(*buf, tmp, len))
1777 static int proc_put_char(void __user **buf, size_t *size, char c)
1780 char __user **buffer = (char __user **)buf;
1781 if (put_user(c, *buffer))
1783 (*size)--, (*buffer)++;
1789 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1791 int write, void *data)
1794 *valp = *negp ? -*lvalp : *lvalp;
1799 *lvalp = (unsigned long)-val;
1802 *lvalp = (unsigned long)val;
1808 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1810 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1811 int write, void __user *buffer,
1812 size_t *lenp, loff_t *ppos,
1813 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1814 int write, void *data),
1817 int *i, vleft, first = 1, err = 0;
1818 unsigned long page = 0;
1822 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1827 i = (int *) tbl_data;
1828 vleft = table->maxlen / sizeof(*i);
1832 conv = do_proc_dointvec_conv;
1835 if (left > PAGE_SIZE - 1)
1836 left = PAGE_SIZE - 1;
1837 page = __get_free_page(GFP_TEMPORARY);
1838 kbuf = (char *) page;
1841 if (copy_from_user(kbuf, buffer, left)) {
1848 for (; left && vleft--; i++, first=0) {
1853 left -= proc_skip_spaces(&kbuf);
1857 err = proc_get_long(&kbuf, &left, &lval, &neg,
1859 sizeof(proc_wspace_sep), NULL);
1862 if (conv(&neg, &lval, i, 1, data)) {
1867 if (conv(&neg, &lval, i, 0, data)) {
1872 err = proc_put_char(&buffer, &left, '\t');
1875 err = proc_put_long(&buffer, &left, lval, neg);
1881 if (!write && !first && left && !err)
1882 err = proc_put_char(&buffer, &left, '\n');
1883 if (write && !err && left)
1884 left -= proc_skip_spaces(&kbuf);
1889 return err ? : -EINVAL;
1896 static int do_proc_dointvec(struct ctl_table *table, int write,
1897 void __user *buffer, size_t *lenp, loff_t *ppos,
1898 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1899 int write, void *data),
1902 return __do_proc_dointvec(table->data, table, write,
1903 buffer, lenp, ppos, conv, data);
1907 * proc_dointvec - read a vector of integers
1908 * @table: the sysctl table
1909 * @write: %TRUE if this is a write to the sysctl file
1910 * @buffer: the user buffer
1911 * @lenp: the size of the user buffer
1912 * @ppos: file position
1914 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1915 * values from/to the user buffer, treated as an ASCII string.
1917 * Returns 0 on success.
1919 int proc_dointvec(struct ctl_table *table, int write,
1920 void __user *buffer, size_t *lenp, loff_t *ppos)
1922 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1927 * Taint values can only be increased
1928 * This means we can safely use a temporary.
1930 static int proc_taint(struct ctl_table *table, int write,
1931 void __user *buffer, size_t *lenp, loff_t *ppos)
1934 unsigned long tmptaint = get_taint();
1937 if (write && !capable(CAP_SYS_ADMIN))
1942 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1948 * Poor man's atomic or. Not worth adding a primitive
1949 * to everyone's atomic.h for this
1952 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1953 if ((tmptaint >> i) & 1)
1961 #ifdef CONFIG_PRINTK
1962 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1963 void __user *buffer, size_t *lenp, loff_t *ppos)
1965 if (write && !capable(CAP_SYS_ADMIN))
1968 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1972 struct do_proc_dointvec_minmax_conv_param {
1977 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1979 int write, void *data)
1981 struct do_proc_dointvec_minmax_conv_param *param = data;
1983 int val = *negp ? -*lvalp : *lvalp;
1984 if ((param->min && *param->min > val) ||
1985 (param->max && *param->max < val))
1992 *lvalp = (unsigned long)-val;
1995 *lvalp = (unsigned long)val;
2002 * proc_dointvec_minmax - read a vector of integers with min/max values
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
2005 * @buffer: the user buffer
2006 * @lenp: the size of the user buffer
2007 * @ppos: file position
2009 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2010 * values from/to the user buffer, treated as an ASCII string.
2012 * This routine will ensure the values are within the range specified by
2013 * table->extra1 (min) and table->extra2 (max).
2015 * Returns 0 on success.
2017 int proc_dointvec_minmax(struct ctl_table *table, int write,
2018 void __user *buffer, size_t *lenp, loff_t *ppos)
2020 struct do_proc_dointvec_minmax_conv_param param = {
2021 .min = (int *) table->extra1,
2022 .max = (int *) table->extra2,
2024 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2025 do_proc_dointvec_minmax_conv, ¶m);
2028 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2029 void __user *buffer,
2030 size_t *lenp, loff_t *ppos,
2031 unsigned long convmul,
2032 unsigned long convdiv)
2034 unsigned long *i, *min, *max;
2035 int vleft, first = 1, err = 0;
2036 unsigned long page = 0;
2040 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2045 i = (unsigned long *) data;
2046 min = (unsigned long *) table->extra1;
2047 max = (unsigned long *) table->extra2;
2048 vleft = table->maxlen / sizeof(unsigned long);
2052 if (left > PAGE_SIZE - 1)
2053 left = PAGE_SIZE - 1;
2054 page = __get_free_page(GFP_TEMPORARY);
2055 kbuf = (char *) page;
2058 if (copy_from_user(kbuf, buffer, left)) {
2065 for (; left && vleft--; i++, first = 0) {
2071 left -= proc_skip_spaces(&kbuf);
2073 err = proc_get_long(&kbuf, &left, &val, &neg,
2075 sizeof(proc_wspace_sep), NULL);
2080 if ((min && val < *min) || (max && val > *max))
2084 val = convdiv * (*i) / convmul;
2086 err = proc_put_char(&buffer, &left, '\t');
2087 err = proc_put_long(&buffer, &left, val, false);
2093 if (!write && !first && left && !err)
2094 err = proc_put_char(&buffer, &left, '\n');
2096 left -= proc_skip_spaces(&kbuf);
2101 return err ? : -EINVAL;
2108 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2109 void __user *buffer,
2110 size_t *lenp, loff_t *ppos,
2111 unsigned long convmul,
2112 unsigned long convdiv)
2114 return __do_proc_doulongvec_minmax(table->data, table, write,
2115 buffer, lenp, ppos, convmul, convdiv);
2119 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2120 * @table: the sysctl table
2121 * @write: %TRUE if this is a write to the sysctl file
2122 * @buffer: the user buffer
2123 * @lenp: the size of the user buffer
2124 * @ppos: file position
2126 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2127 * values from/to the user buffer, treated as an ASCII string.
2129 * This routine will ensure the values are within the range specified by
2130 * table->extra1 (min) and table->extra2 (max).
2132 * Returns 0 on success.
2134 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2135 void __user *buffer, size_t *lenp, loff_t *ppos)
2137 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2141 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2142 * @table: the sysctl table
2143 * @write: %TRUE if this is a write to the sysctl file
2144 * @buffer: the user buffer
2145 * @lenp: the size of the user buffer
2146 * @ppos: file position
2148 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2149 * values from/to the user buffer, treated as an ASCII string. The values
2150 * are treated as milliseconds, and converted to jiffies when they are stored.
2152 * This routine will ensure the values are within the range specified by
2153 * table->extra1 (min) and table->extra2 (max).
2155 * Returns 0 on success.
2157 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2158 void __user *buffer,
2159 size_t *lenp, loff_t *ppos)
2161 return do_proc_doulongvec_minmax(table, write, buffer,
2162 lenp, ppos, HZ, 1000l);
2166 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2168 int write, void *data)
2171 if (*lvalp > LONG_MAX / HZ)
2173 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2179 lval = (unsigned long)-val;
2182 lval = (unsigned long)val;
2189 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2191 int write, void *data)
2194 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2196 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2202 lval = (unsigned long)-val;
2205 lval = (unsigned long)val;
2207 *lvalp = jiffies_to_clock_t(lval);
2212 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2214 int write, void *data)
2217 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2223 lval = (unsigned long)-val;
2226 lval = (unsigned long)val;
2228 *lvalp = jiffies_to_msecs(lval);
2234 * proc_dointvec_jiffies - read a vector of integers as seconds
2235 * @table: the sysctl table
2236 * @write: %TRUE if this is a write to the sysctl file
2237 * @buffer: the user buffer
2238 * @lenp: the size of the user buffer
2239 * @ppos: file position
2241 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2242 * values from/to the user buffer, treated as an ASCII string.
2243 * The values read are assumed to be in seconds, and are converted into
2246 * Returns 0 on success.
2248 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2249 void __user *buffer, size_t *lenp, loff_t *ppos)
2251 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2252 do_proc_dointvec_jiffies_conv,NULL);
2256 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2257 * @table: the sysctl table
2258 * @write: %TRUE if this is a write to the sysctl file
2259 * @buffer: the user buffer
2260 * @lenp: the size of the user buffer
2261 * @ppos: pointer to the file position
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 * The values read are assumed to be in 1/USER_HZ seconds, and
2266 * are converted into jiffies.
2268 * Returns 0 on success.
2270 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2271 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2274 do_proc_dointvec_userhz_jiffies_conv,NULL);
2278 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @buffer: the user buffer
2282 * @lenp: the size of the user buffer
2283 * @ppos: file position
2284 * @ppos: the current position in the file
2286 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2287 * values from/to the user buffer, treated as an ASCII string.
2288 * The values read are assumed to be in 1/1000 seconds, and
2289 * are converted into jiffies.
2291 * Returns 0 on success.
2293 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2297 do_proc_dointvec_ms_jiffies_conv, NULL);
2300 static int proc_do_cad_pid(struct ctl_table *table, int write,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2303 struct pid *new_pid;
2307 tmp = pid_vnr(cad_pid);
2309 r = __do_proc_dointvec(&tmp, table, write, buffer,
2310 lenp, ppos, NULL, NULL);
2314 new_pid = find_get_pid(tmp);
2318 put_pid(xchg(&cad_pid, new_pid));
2323 * proc_do_large_bitmap - read/write from/to a large bitmap
2324 * @table: the sysctl table
2325 * @write: %TRUE if this is a write to the sysctl file
2326 * @buffer: the user buffer
2327 * @lenp: the size of the user buffer
2328 * @ppos: file position
2330 * The bitmap is stored at table->data and the bitmap length (in bits)
2333 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2334 * large bitmaps may be represented in a compact manner. Writing into
2335 * the file will clear the bitmap then update it with the given input.
2337 * Returns 0 on success.
2339 int proc_do_large_bitmap(struct ctl_table *table, int write,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2344 size_t left = *lenp;
2345 unsigned long bitmap_len = table->maxlen;
2346 unsigned long *bitmap = (unsigned long *) table->data;
2347 unsigned long *tmp_bitmap = NULL;
2348 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2350 if (!bitmap_len || !left || (*ppos && !write)) {
2356 unsigned long page = 0;
2359 if (left > PAGE_SIZE - 1)
2360 left = PAGE_SIZE - 1;
2362 page = __get_free_page(GFP_TEMPORARY);
2363 kbuf = (char *) page;
2366 if (copy_from_user(kbuf, buffer, left)) {
2372 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2378 proc_skip_char(&kbuf, &left, '\n');
2379 while (!err && left) {
2380 unsigned long val_a, val_b;
2383 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2387 if (val_a >= bitmap_len || neg) {
2399 err = proc_get_long(&kbuf, &left, &val_b,
2400 &neg, tr_b, sizeof(tr_b),
2404 if (val_b >= bitmap_len || neg ||
2415 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2417 proc_skip_char(&kbuf, &left, '\n');
2421 unsigned long bit_a, bit_b = 0;
2424 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2425 if (bit_a >= bitmap_len)
2427 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2431 err = proc_put_char(&buffer, &left, ',');
2435 err = proc_put_long(&buffer, &left, bit_a, false);
2438 if (bit_a != bit_b) {
2439 err = proc_put_char(&buffer, &left, '-');
2442 err = proc_put_long(&buffer, &left, bit_b, false);
2450 err = proc_put_char(&buffer, &left, '\n');
2456 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2458 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2470 #else /* CONFIG_PROC_SYSCTL */
2472 int proc_dostring(struct ctl_table *table, int write,
2473 void __user *buffer, size_t *lenp, loff_t *ppos)
2478 int proc_dointvec(struct ctl_table *table, int write,
2479 void __user *buffer, size_t *lenp, loff_t *ppos)
2484 int proc_dointvec_minmax(struct ctl_table *table, int write,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2490 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2496 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2497 void __user *buffer, size_t *lenp, loff_t *ppos)
2502 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2508 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2509 void __user *buffer, size_t *lenp, loff_t *ppos)
2514 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2515 void __user *buffer,
2516 size_t *lenp, loff_t *ppos)
2522 #endif /* CONFIG_PROC_SYSCTL */
2525 * No sense putting this after each symbol definition, twice,
2526 * exception granted :-)
2528 EXPORT_SYMBOL(proc_dointvec);
2529 EXPORT_SYMBOL(proc_dointvec_jiffies);
2530 EXPORT_SYMBOL(proc_dointvec_minmax);
2531 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2532 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2533 EXPORT_SYMBOL(proc_dostring);
2534 EXPORT_SYMBOL(proc_doulongvec_minmax);
2535 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);