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 min_free_order_shift;
106 extern int pid_max_min, pid_max_max;
107 extern int sysctl_drop_caches;
108 extern int percpu_pagelist_fraction;
109 extern int compat_log;
110 extern int latencytop_enabled;
111 extern int sysctl_nr_open_min, sysctl_nr_open_max;
113 extern int sysctl_nr_trim_pages;
116 extern int blk_iopoll_enabled;
119 /* Constants used for minimum and maximum */
120 #ifdef CONFIG_LOCKUP_DETECTOR
121 static int sixty = 60;
122 static int neg_one = -1;
126 static int __maybe_unused one = 1;
127 static int __maybe_unused two = 2;
128 static int __maybe_unused three = 3;
129 static unsigned long one_ul = 1;
130 static int one_hundred = 100;
132 static int ten_thousand = 10000;
135 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
136 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
139 static int maxolduid = 65535;
140 static int minolduid;
141 static int min_percpu_pagelist_fract = 8;
143 static int ngroups_max = NGROUPS_MAX;
144 static const int cap_last_cap = CAP_LAST_CAP;
146 #ifdef CONFIG_INOTIFY_USER
147 #include <linux/inotify.h>
152 #ifdef CONFIG_SPARC64
153 extern int sysctl_tsb_ratio;
157 extern int pwrsw_enabled;
158 extern int unaligned_enabled;
162 extern int no_unaligned_warning;
163 extern int unaligned_dump_stack;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
174 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
178 #ifdef CONFIG_MAGIC_SYSRQ
179 /* Note: sysrq code uses it's own private copy */
180 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
182 static int sysrq_sysctl_handler(ctl_table *table, int write,
183 void __user *buffer, size_t *lenp,
188 error = proc_dointvec(table, write, buffer, lenp, ppos);
193 sysrq_toggle_support(__sysrq_enabled);
200 static struct ctl_table kern_table[];
201 static struct ctl_table vm_table[];
202 static struct ctl_table fs_table[];
203 static struct ctl_table debug_table[];
204 static struct ctl_table dev_table[];
205 extern struct ctl_table random_table[];
207 extern struct ctl_table epoll_table[];
210 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
211 int sysctl_legacy_va_layout;
214 /* The default sysctl tables: */
216 static struct ctl_table sysctl_base_table[] = {
218 .procname = "kernel",
235 .child = debug_table,
245 #ifdef CONFIG_SCHED_DEBUG
246 static int min_sched_granularity_ns = 100000; /* 100 usecs */
247 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
248 static int min_wakeup_granularity_ns; /* 0 usecs */
249 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
250 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
251 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
254 #ifdef CONFIG_COMPACTION
255 static int min_extfrag_threshold;
256 static int max_extfrag_threshold = 1000;
259 static struct ctl_table kern_table[] = {
261 .procname = "sched_child_runs_first",
262 .data = &sysctl_sched_child_runs_first,
263 .maxlen = sizeof(unsigned int),
265 .proc_handler = proc_dointvec,
267 #ifdef CONFIG_SCHED_DEBUG
269 .procname = "sched_min_granularity_ns",
270 .data = &sysctl_sched_min_granularity,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = sched_proc_update_handler,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
278 .procname = "sched_latency_ns",
279 .data = &sysctl_sched_latency,
280 .maxlen = sizeof(unsigned int),
282 .proc_handler = sched_proc_update_handler,
283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
287 .procname = "sched_wakeup_granularity_ns",
288 .data = &sysctl_sched_wakeup_granularity,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = sched_proc_update_handler,
292 .extra1 = &min_wakeup_granularity_ns,
293 .extra2 = &max_wakeup_granularity_ns,
296 .procname = "sched_tunable_scaling",
297 .data = &sysctl_sched_tunable_scaling,
298 .maxlen = sizeof(enum sched_tunable_scaling),
300 .proc_handler = sched_proc_update_handler,
301 .extra1 = &min_sched_tunable_scaling,
302 .extra2 = &max_sched_tunable_scaling,
305 .procname = "sched_migration_cost",
306 .data = &sysctl_sched_migration_cost,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = proc_dointvec,
312 .procname = "sched_nr_migrate",
313 .data = &sysctl_sched_nr_migrate,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = proc_dointvec,
319 .procname = "sched_time_avg",
320 .data = &sysctl_sched_time_avg,
321 .maxlen = sizeof(unsigned int),
323 .proc_handler = proc_dointvec,
326 .procname = "sched_shares_window",
327 .data = &sysctl_sched_shares_window,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = proc_dointvec,
333 .procname = "timer_migration",
334 .data = &sysctl_timer_migration,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = proc_dointvec_minmax,
343 .procname = "sched_rt_period_us",
344 .data = &sysctl_sched_rt_period,
345 .maxlen = sizeof(unsigned int),
347 .proc_handler = sched_rt_handler,
350 .procname = "sched_rt_runtime_us",
351 .data = &sysctl_sched_rt_runtime,
352 .maxlen = sizeof(int),
354 .proc_handler = sched_rt_handler,
356 #ifdef CONFIG_SCHED_AUTOGROUP
358 .procname = "sched_autogroup_enabled",
359 .data = &sysctl_sched_autogroup_enabled,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = proc_dointvec_minmax,
367 #ifdef CONFIG_CFS_BANDWIDTH
369 .procname = "sched_cfs_bandwidth_slice_us",
370 .data = &sysctl_sched_cfs_bandwidth_slice,
371 .maxlen = sizeof(unsigned int),
373 .proc_handler = proc_dointvec_minmax,
377 #ifdef CONFIG_PROVE_LOCKING
379 .procname = "prove_locking",
380 .data = &prove_locking,
381 .maxlen = sizeof(int),
383 .proc_handler = proc_dointvec,
386 #ifdef CONFIG_LOCK_STAT
388 .procname = "lock_stat",
390 .maxlen = sizeof(int),
392 .proc_handler = proc_dointvec,
397 .data = &panic_timeout,
398 .maxlen = sizeof(int),
400 .proc_handler = proc_dointvec,
403 .procname = "core_uses_pid",
404 .data = &core_uses_pid,
405 .maxlen = sizeof(int),
407 .proc_handler = proc_dointvec,
410 .procname = "core_pattern",
411 .data = core_pattern,
412 .maxlen = CORENAME_MAX_SIZE,
414 .proc_handler = proc_dostring,
417 .procname = "core_pipe_limit",
418 .data = &core_pipe_limit,
419 .maxlen = sizeof(unsigned int),
421 .proc_handler = proc_dointvec,
423 #ifdef CONFIG_PROC_SYSCTL
425 .procname = "tainted",
426 .maxlen = sizeof(long),
428 .proc_handler = proc_taint,
431 #ifdef CONFIG_LATENCYTOP
433 .procname = "latencytop",
434 .data = &latencytop_enabled,
435 .maxlen = sizeof(int),
437 .proc_handler = proc_dointvec,
440 #ifdef CONFIG_BLK_DEV_INITRD
442 .procname = "real-root-dev",
443 .data = &real_root_dev,
444 .maxlen = sizeof(int),
446 .proc_handler = proc_dointvec,
450 .procname = "print-fatal-signals",
451 .data = &print_fatal_signals,
452 .maxlen = sizeof(int),
454 .proc_handler = proc_dointvec,
458 .procname = "reboot-cmd",
459 .data = reboot_command,
462 .proc_handler = proc_dostring,
465 .procname = "stop-a",
466 .data = &stop_a_enabled,
467 .maxlen = sizeof (int),
469 .proc_handler = proc_dointvec,
472 .procname = "scons-poweroff",
473 .data = &scons_pwroff,
474 .maxlen = sizeof (int),
476 .proc_handler = proc_dointvec,
479 #ifdef CONFIG_SPARC64
481 .procname = "tsb-ratio",
482 .data = &sysctl_tsb_ratio,
483 .maxlen = sizeof (int),
485 .proc_handler = proc_dointvec,
490 .procname = "soft-power",
491 .data = &pwrsw_enabled,
492 .maxlen = sizeof (int),
494 .proc_handler = proc_dointvec,
497 .procname = "unaligned-trap",
498 .data = &unaligned_enabled,
499 .maxlen = sizeof (int),
501 .proc_handler = proc_dointvec,
505 .procname = "ctrl-alt-del",
507 .maxlen = sizeof(int),
509 .proc_handler = proc_dointvec,
511 #ifdef CONFIG_FUNCTION_TRACER
513 .procname = "ftrace_enabled",
514 .data = &ftrace_enabled,
515 .maxlen = sizeof(int),
517 .proc_handler = ftrace_enable_sysctl,
520 #ifdef CONFIG_STACK_TRACER
522 .procname = "stack_tracer_enabled",
523 .data = &stack_tracer_enabled,
524 .maxlen = sizeof(int),
526 .proc_handler = stack_trace_sysctl,
529 #ifdef CONFIG_TRACING
531 .procname = "ftrace_dump_on_oops",
532 .data = &ftrace_dump_on_oops,
533 .maxlen = sizeof(int),
535 .proc_handler = proc_dointvec,
538 #ifdef CONFIG_MODULES
540 .procname = "modprobe",
541 .data = &modprobe_path,
542 .maxlen = KMOD_PATH_LEN,
544 .proc_handler = proc_dostring,
547 .procname = "modules_disabled",
548 .data = &modules_disabled,
549 .maxlen = sizeof(int),
551 /* only handle a transition from default "0" to "1" */
552 .proc_handler = proc_dointvec_minmax,
557 #ifdef CONFIG_HOTPLUG
559 .procname = "hotplug",
560 .data = &uevent_helper,
561 .maxlen = UEVENT_HELPER_PATH_LEN,
563 .proc_handler = proc_dostring,
566 #ifdef CONFIG_CHR_DEV_SG
568 .procname = "sg-big-buff",
569 .data = &sg_big_buff,
570 .maxlen = sizeof (int),
572 .proc_handler = proc_dointvec,
575 #ifdef CONFIG_BSD_PROCESS_ACCT
579 .maxlen = 3*sizeof(int),
581 .proc_handler = proc_dointvec,
584 #ifdef CONFIG_MAGIC_SYSRQ
587 .data = &__sysrq_enabled,
588 .maxlen = sizeof (int),
590 .proc_handler = sysrq_sysctl_handler,
593 #ifdef CONFIG_PROC_SYSCTL
595 .procname = "cad_pid",
597 .maxlen = sizeof (int),
599 .proc_handler = proc_do_cad_pid,
603 .procname = "threads-max",
604 .data = &max_threads,
605 .maxlen = sizeof(int),
607 .proc_handler = proc_dointvec,
610 .procname = "random",
612 .child = random_table,
615 .procname = "usermodehelper",
617 .child = usermodehelper_table,
620 .procname = "overflowuid",
621 .data = &overflowuid,
622 .maxlen = sizeof(int),
624 .proc_handler = proc_dointvec_minmax,
625 .extra1 = &minolduid,
626 .extra2 = &maxolduid,
629 .procname = "overflowgid",
630 .data = &overflowgid,
631 .maxlen = sizeof(int),
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
638 #ifdef CONFIG_MATHEMU
640 .procname = "ieee_emulation_warnings",
641 .data = &sysctl_ieee_emulation_warnings,
642 .maxlen = sizeof(int),
644 .proc_handler = proc_dointvec,
648 .procname = "userprocess_debug",
649 .data = &show_unhandled_signals,
650 .maxlen = sizeof(int),
652 .proc_handler = proc_dointvec,
656 .procname = "pid_max",
658 .maxlen = sizeof (int),
660 .proc_handler = proc_dointvec_minmax,
661 .extra1 = &pid_max_min,
662 .extra2 = &pid_max_max,
665 .procname = "panic_on_oops",
666 .data = &panic_on_oops,
667 .maxlen = sizeof(int),
669 .proc_handler = proc_dointvec,
671 #if defined CONFIG_PRINTK
673 .procname = "printk",
674 .data = &console_loglevel,
675 .maxlen = 4*sizeof(int),
677 .proc_handler = proc_dointvec,
680 .procname = "printk_ratelimit",
681 .data = &printk_ratelimit_state.interval,
682 .maxlen = sizeof(int),
684 .proc_handler = proc_dointvec_jiffies,
687 .procname = "printk_ratelimit_burst",
688 .data = &printk_ratelimit_state.burst,
689 .maxlen = sizeof(int),
691 .proc_handler = proc_dointvec,
694 .procname = "printk_delay",
695 .data = &printk_delay_msec,
696 .maxlen = sizeof(int),
698 .proc_handler = proc_dointvec_minmax,
700 .extra2 = &ten_thousand,
703 .procname = "dmesg_restrict",
704 .data = &dmesg_restrict,
705 .maxlen = sizeof(int),
707 .proc_handler = proc_dointvec_minmax_sysadmin,
712 .procname = "kptr_restrict",
713 .data = &kptr_restrict,
714 .maxlen = sizeof(int),
716 .proc_handler = proc_dointvec_minmax_sysadmin,
722 .procname = "ngroups_max",
723 .data = &ngroups_max,
724 .maxlen = sizeof (int),
726 .proc_handler = proc_dointvec,
729 .procname = "cap_last_cap",
730 .data = (void *)&cap_last_cap,
731 .maxlen = sizeof(int),
733 .proc_handler = proc_dointvec,
735 #if defined(CONFIG_LOCKUP_DETECTOR)
737 .procname = "watchdog",
738 .data = &watchdog_enabled,
739 .maxlen = sizeof (int),
741 .proc_handler = proc_dowatchdog,
746 .procname = "watchdog_thresh",
747 .data = &watchdog_thresh,
748 .maxlen = sizeof(int),
750 .proc_handler = proc_dowatchdog,
755 .procname = "softlockup_panic",
756 .data = &softlockup_panic,
757 .maxlen = sizeof(int),
759 .proc_handler = proc_dointvec_minmax,
764 .procname = "nmi_watchdog",
765 .data = &watchdog_enabled,
766 .maxlen = sizeof (int),
768 .proc_handler = proc_dowatchdog,
773 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
775 .procname = "unknown_nmi_panic",
776 .data = &unknown_nmi_panic,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dointvec,
782 #if defined(CONFIG_X86)
784 .procname = "panic_on_unrecovered_nmi",
785 .data = &panic_on_unrecovered_nmi,
786 .maxlen = sizeof(int),
788 .proc_handler = proc_dointvec,
791 .procname = "panic_on_io_nmi",
792 .data = &panic_on_io_nmi,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec,
797 #ifdef CONFIG_DEBUG_STACKOVERFLOW
799 .procname = "panic_on_stackoverflow",
800 .data = &sysctl_panic_on_stackoverflow,
801 .maxlen = sizeof(int),
803 .proc_handler = proc_dointvec,
807 .procname = "bootloader_type",
808 .data = &bootloader_type,
809 .maxlen = sizeof (int),
811 .proc_handler = proc_dointvec,
814 .procname = "bootloader_version",
815 .data = &bootloader_version,
816 .maxlen = sizeof (int),
818 .proc_handler = proc_dointvec,
821 .procname = "kstack_depth_to_print",
822 .data = &kstack_depth_to_print,
823 .maxlen = sizeof(int),
825 .proc_handler = proc_dointvec,
828 .procname = "io_delay_type",
829 .data = &io_delay_type,
830 .maxlen = sizeof(int),
832 .proc_handler = proc_dointvec,
835 #if defined(CONFIG_MMU)
837 .procname = "randomize_va_space",
838 .data = &randomize_va_space,
839 .maxlen = sizeof(int),
841 .proc_handler = proc_dointvec,
844 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
846 .procname = "spin_retry",
848 .maxlen = sizeof (int),
850 .proc_handler = proc_dointvec,
853 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
855 .procname = "acpi_video_flags",
856 .data = &acpi_realmode_flags,
857 .maxlen = sizeof (unsigned long),
859 .proc_handler = proc_doulongvec_minmax,
864 .procname = "ignore-unaligned-usertrap",
865 .data = &no_unaligned_warning,
866 .maxlen = sizeof (int),
868 .proc_handler = proc_dointvec,
871 .procname = "unaligned-dump-stack",
872 .data = &unaligned_dump_stack,
873 .maxlen = sizeof (int),
875 .proc_handler = proc_dointvec,
878 #ifdef CONFIG_DETECT_HUNG_TASK
880 .procname = "hung_task_panic",
881 .data = &sysctl_hung_task_panic,
882 .maxlen = sizeof(int),
884 .proc_handler = proc_dointvec_minmax,
889 .procname = "hung_task_check_count",
890 .data = &sysctl_hung_task_check_count,
891 .maxlen = sizeof(unsigned long),
893 .proc_handler = proc_doulongvec_minmax,
896 .procname = "hung_task_timeout_secs",
897 .data = &sysctl_hung_task_timeout_secs,
898 .maxlen = sizeof(unsigned long),
900 .proc_handler = proc_dohung_task_timeout_secs,
903 .procname = "hung_task_warnings",
904 .data = &sysctl_hung_task_warnings,
905 .maxlen = sizeof(unsigned long),
907 .proc_handler = proc_doulongvec_minmax,
912 .procname = "compat-log",
914 .maxlen = sizeof (int),
916 .proc_handler = proc_dointvec,
919 #ifdef CONFIG_RT_MUTEXES
921 .procname = "max_lock_depth",
922 .data = &max_lock_depth,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_dointvec,
929 .procname = "poweroff_cmd",
930 .data = &poweroff_cmd,
931 .maxlen = POWEROFF_CMD_PATH_LEN,
933 .proc_handler = proc_dostring,
939 .child = key_sysctls,
942 #ifdef CONFIG_RCU_TORTURE_TEST
944 .procname = "rcutorture_runnable",
945 .data = &rcutorture_runnable,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec,
951 #ifdef CONFIG_PERF_EVENTS
953 * User-space scripts rely on the existence of this file
954 * as a feature check for perf_events being enabled.
956 * So it's an ABI, do not remove!
959 .procname = "perf_event_paranoid",
960 .data = &sysctl_perf_event_paranoid,
961 .maxlen = sizeof(sysctl_perf_event_paranoid),
963 .proc_handler = proc_dointvec,
966 .procname = "perf_event_mlock_kb",
967 .data = &sysctl_perf_event_mlock,
968 .maxlen = sizeof(sysctl_perf_event_mlock),
970 .proc_handler = proc_dointvec,
973 .procname = "perf_event_max_sample_rate",
974 .data = &sysctl_perf_event_sample_rate,
975 .maxlen = sizeof(sysctl_perf_event_sample_rate),
977 .proc_handler = perf_proc_update_handler,
980 #ifdef CONFIG_KMEMCHECK
982 .procname = "kmemcheck",
983 .data = &kmemcheck_enabled,
984 .maxlen = sizeof(int),
986 .proc_handler = proc_dointvec,
991 .procname = "blk_iopoll",
992 .data = &blk_iopoll_enabled,
993 .maxlen = sizeof(int),
995 .proc_handler = proc_dointvec,
1001 static struct ctl_table vm_table[] = {
1003 .procname = "overcommit_memory",
1004 .data = &sysctl_overcommit_memory,
1005 .maxlen = sizeof(sysctl_overcommit_memory),
1007 .proc_handler = proc_dointvec_minmax,
1012 .procname = "panic_on_oom",
1013 .data = &sysctl_panic_on_oom,
1014 .maxlen = sizeof(sysctl_panic_on_oom),
1016 .proc_handler = proc_dointvec_minmax,
1021 .procname = "oom_kill_allocating_task",
1022 .data = &sysctl_oom_kill_allocating_task,
1023 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1025 .proc_handler = proc_dointvec,
1028 .procname = "oom_dump_tasks",
1029 .data = &sysctl_oom_dump_tasks,
1030 .maxlen = sizeof(sysctl_oom_dump_tasks),
1032 .proc_handler = proc_dointvec,
1035 .procname = "overcommit_ratio",
1036 .data = &sysctl_overcommit_ratio,
1037 .maxlen = sizeof(sysctl_overcommit_ratio),
1039 .proc_handler = proc_dointvec,
1042 .procname = "page-cluster",
1043 .data = &page_cluster,
1044 .maxlen = sizeof(int),
1046 .proc_handler = proc_dointvec_minmax,
1050 .procname = "dirty_background_ratio",
1051 .data = &dirty_background_ratio,
1052 .maxlen = sizeof(dirty_background_ratio),
1054 .proc_handler = dirty_background_ratio_handler,
1056 .extra2 = &one_hundred,
1059 .procname = "dirty_background_bytes",
1060 .data = &dirty_background_bytes,
1061 .maxlen = sizeof(dirty_background_bytes),
1063 .proc_handler = dirty_background_bytes_handler,
1067 .procname = "dirty_ratio",
1068 .data = &vm_dirty_ratio,
1069 .maxlen = sizeof(vm_dirty_ratio),
1071 .proc_handler = dirty_ratio_handler,
1073 .extra2 = &one_hundred,
1076 .procname = "dirty_bytes",
1077 .data = &vm_dirty_bytes,
1078 .maxlen = sizeof(vm_dirty_bytes),
1080 .proc_handler = dirty_bytes_handler,
1081 .extra1 = &dirty_bytes_min,
1084 .procname = "dirty_writeback_centisecs",
1085 .data = &dirty_writeback_interval,
1086 .maxlen = sizeof(dirty_writeback_interval),
1088 .proc_handler = dirty_writeback_centisecs_handler,
1091 .procname = "dirty_expire_centisecs",
1092 .data = &dirty_expire_interval,
1093 .maxlen = sizeof(dirty_expire_interval),
1095 .proc_handler = proc_dointvec_minmax,
1099 .procname = "nr_pdflush_threads",
1100 .data = &nr_pdflush_threads,
1101 .maxlen = sizeof nr_pdflush_threads,
1102 .mode = 0444 /* read-only*/,
1103 .proc_handler = proc_dointvec,
1106 .procname = "swappiness",
1107 .data = &vm_swappiness,
1108 .maxlen = sizeof(vm_swappiness),
1110 .proc_handler = proc_dointvec_minmax,
1112 .extra2 = &one_hundred,
1114 #ifdef CONFIG_HUGETLB_PAGE
1116 .procname = "nr_hugepages",
1118 .maxlen = sizeof(unsigned long),
1120 .proc_handler = hugetlb_sysctl_handler,
1121 .extra1 = (void *)&hugetlb_zero,
1122 .extra2 = (void *)&hugetlb_infinity,
1126 .procname = "nr_hugepages_mempolicy",
1128 .maxlen = sizeof(unsigned long),
1130 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1131 .extra1 = (void *)&hugetlb_zero,
1132 .extra2 = (void *)&hugetlb_infinity,
1136 .procname = "hugetlb_shm_group",
1137 .data = &sysctl_hugetlb_shm_group,
1138 .maxlen = sizeof(gid_t),
1140 .proc_handler = proc_dointvec,
1143 .procname = "hugepages_treat_as_movable",
1144 .data = &hugepages_treat_as_movable,
1145 .maxlen = sizeof(int),
1147 .proc_handler = hugetlb_treat_movable_handler,
1150 .procname = "nr_overcommit_hugepages",
1152 .maxlen = sizeof(unsigned long),
1154 .proc_handler = hugetlb_overcommit_handler,
1155 .extra1 = (void *)&hugetlb_zero,
1156 .extra2 = (void *)&hugetlb_infinity,
1160 .procname = "lowmem_reserve_ratio",
1161 .data = &sysctl_lowmem_reserve_ratio,
1162 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1164 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1167 .procname = "drop_caches",
1168 .data = &sysctl_drop_caches,
1169 .maxlen = sizeof(int),
1171 .proc_handler = drop_caches_sysctl_handler,
1175 #ifdef CONFIG_COMPACTION
1177 .procname = "compact_memory",
1178 .data = &sysctl_compact_memory,
1179 .maxlen = sizeof(int),
1181 .proc_handler = sysctl_compaction_handler,
1184 .procname = "extfrag_threshold",
1185 .data = &sysctl_extfrag_threshold,
1186 .maxlen = sizeof(int),
1188 .proc_handler = sysctl_extfrag_handler,
1189 .extra1 = &min_extfrag_threshold,
1190 .extra2 = &max_extfrag_threshold,
1193 #endif /* CONFIG_COMPACTION */
1195 .procname = "min_free_kbytes",
1196 .data = &min_free_kbytes,
1197 .maxlen = sizeof(min_free_kbytes),
1199 .proc_handler = min_free_kbytes_sysctl_handler,
1203 .procname = "min_free_order_shift",
1204 .data = &min_free_order_shift,
1205 .maxlen = sizeof(min_free_order_shift),
1207 .proc_handler = &proc_dointvec
1210 .procname = "percpu_pagelist_fraction",
1211 .data = &percpu_pagelist_fraction,
1212 .maxlen = sizeof(percpu_pagelist_fraction),
1214 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1215 .extra1 = &min_percpu_pagelist_fract,
1219 .procname = "max_map_count",
1220 .data = &sysctl_max_map_count,
1221 .maxlen = sizeof(sysctl_max_map_count),
1223 .proc_handler = proc_dointvec_minmax,
1228 .procname = "nr_trim_pages",
1229 .data = &sysctl_nr_trim_pages,
1230 .maxlen = sizeof(sysctl_nr_trim_pages),
1232 .proc_handler = proc_dointvec_minmax,
1237 .procname = "laptop_mode",
1238 .data = &laptop_mode,
1239 .maxlen = sizeof(laptop_mode),
1241 .proc_handler = proc_dointvec_jiffies,
1244 .procname = "block_dump",
1245 .data = &block_dump,
1246 .maxlen = sizeof(block_dump),
1248 .proc_handler = proc_dointvec,
1252 .procname = "vfs_cache_pressure",
1253 .data = &sysctl_vfs_cache_pressure,
1254 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1256 .proc_handler = proc_dointvec,
1259 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1261 .procname = "legacy_va_layout",
1262 .data = &sysctl_legacy_va_layout,
1263 .maxlen = sizeof(sysctl_legacy_va_layout),
1265 .proc_handler = proc_dointvec,
1271 .procname = "zone_reclaim_mode",
1272 .data = &zone_reclaim_mode,
1273 .maxlen = sizeof(zone_reclaim_mode),
1275 .proc_handler = proc_dointvec,
1279 .procname = "min_unmapped_ratio",
1280 .data = &sysctl_min_unmapped_ratio,
1281 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1283 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1285 .extra2 = &one_hundred,
1288 .procname = "min_slab_ratio",
1289 .data = &sysctl_min_slab_ratio,
1290 .maxlen = sizeof(sysctl_min_slab_ratio),
1292 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1294 .extra2 = &one_hundred,
1299 .procname = "stat_interval",
1300 .data = &sysctl_stat_interval,
1301 .maxlen = sizeof(sysctl_stat_interval),
1303 .proc_handler = proc_dointvec_jiffies,
1308 .procname = "mmap_min_addr",
1309 .data = &dac_mmap_min_addr,
1310 .maxlen = sizeof(unsigned long),
1312 .proc_handler = mmap_min_addr_handler,
1317 .procname = "numa_zonelist_order",
1318 .data = &numa_zonelist_order,
1319 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1321 .proc_handler = numa_zonelist_order_handler,
1324 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1325 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1327 .procname = "vdso_enabled",
1328 .data = &vdso_enabled,
1329 .maxlen = sizeof(vdso_enabled),
1331 .proc_handler = proc_dointvec,
1335 #ifdef CONFIG_HIGHMEM
1337 .procname = "highmem_is_dirtyable",
1338 .data = &vm_highmem_is_dirtyable,
1339 .maxlen = sizeof(vm_highmem_is_dirtyable),
1341 .proc_handler = proc_dointvec_minmax,
1347 .procname = "scan_unevictable_pages",
1348 .data = &scan_unevictable_pages,
1349 .maxlen = sizeof(scan_unevictable_pages),
1351 .proc_handler = scan_unevictable_handler,
1353 #ifdef CONFIG_MEMORY_FAILURE
1355 .procname = "memory_failure_early_kill",
1356 .data = &sysctl_memory_failure_early_kill,
1357 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1359 .proc_handler = proc_dointvec_minmax,
1364 .procname = "memory_failure_recovery",
1365 .data = &sysctl_memory_failure_recovery,
1366 .maxlen = sizeof(sysctl_memory_failure_recovery),
1368 .proc_handler = proc_dointvec_minmax,
1376 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1377 static struct ctl_table binfmt_misc_table[] = {
1382 static struct ctl_table fs_table[] = {
1384 .procname = "inode-nr",
1385 .data = &inodes_stat,
1386 .maxlen = 2*sizeof(int),
1388 .proc_handler = proc_nr_inodes,
1391 .procname = "inode-state",
1392 .data = &inodes_stat,
1393 .maxlen = 7*sizeof(int),
1395 .proc_handler = proc_nr_inodes,
1398 .procname = "file-nr",
1399 .data = &files_stat,
1400 .maxlen = sizeof(files_stat),
1402 .proc_handler = proc_nr_files,
1405 .procname = "file-max",
1406 .data = &files_stat.max_files,
1407 .maxlen = sizeof(files_stat.max_files),
1409 .proc_handler = proc_doulongvec_minmax,
1412 .procname = "nr_open",
1413 .data = &sysctl_nr_open,
1414 .maxlen = sizeof(int),
1416 .proc_handler = proc_dointvec_minmax,
1417 .extra1 = &sysctl_nr_open_min,
1418 .extra2 = &sysctl_nr_open_max,
1421 .procname = "dentry-state",
1422 .data = &dentry_stat,
1423 .maxlen = 6*sizeof(int),
1425 .proc_handler = proc_nr_dentry,
1428 .procname = "overflowuid",
1429 .data = &fs_overflowuid,
1430 .maxlen = sizeof(int),
1432 .proc_handler = proc_dointvec_minmax,
1433 .extra1 = &minolduid,
1434 .extra2 = &maxolduid,
1437 .procname = "overflowgid",
1438 .data = &fs_overflowgid,
1439 .maxlen = sizeof(int),
1441 .proc_handler = proc_dointvec_minmax,
1442 .extra1 = &minolduid,
1443 .extra2 = &maxolduid,
1445 #ifdef CONFIG_FILE_LOCKING
1447 .procname = "leases-enable",
1448 .data = &leases_enable,
1449 .maxlen = sizeof(int),
1451 .proc_handler = proc_dointvec,
1454 #ifdef CONFIG_DNOTIFY
1456 .procname = "dir-notify-enable",
1457 .data = &dir_notify_enable,
1458 .maxlen = sizeof(int),
1460 .proc_handler = proc_dointvec,
1464 #ifdef CONFIG_FILE_LOCKING
1466 .procname = "lease-break-time",
1467 .data = &lease_break_time,
1468 .maxlen = sizeof(int),
1470 .proc_handler = proc_dointvec,
1475 .procname = "aio-nr",
1477 .maxlen = sizeof(aio_nr),
1479 .proc_handler = proc_doulongvec_minmax,
1482 .procname = "aio-max-nr",
1483 .data = &aio_max_nr,
1484 .maxlen = sizeof(aio_max_nr),
1486 .proc_handler = proc_doulongvec_minmax,
1488 #endif /* CONFIG_AIO */
1489 #ifdef CONFIG_INOTIFY_USER
1491 .procname = "inotify",
1493 .child = inotify_table,
1498 .procname = "epoll",
1500 .child = epoll_table,
1505 .procname = "suid_dumpable",
1506 .data = &suid_dumpable,
1507 .maxlen = sizeof(int),
1509 .proc_handler = proc_dointvec_minmax,
1513 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1515 .procname = "binfmt_misc",
1517 .child = binfmt_misc_table,
1521 .procname = "pipe-max-size",
1522 .data = &pipe_max_size,
1523 .maxlen = sizeof(int),
1525 .proc_handler = &pipe_proc_fn,
1526 .extra1 = &pipe_min_size,
1531 static struct ctl_table debug_table[] = {
1532 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1533 defined(CONFIG_S390) || defined(CONFIG_TILE)
1535 .procname = "exception-trace",
1536 .data = &show_unhandled_signals,
1537 .maxlen = sizeof(int),
1539 .proc_handler = proc_dointvec
1542 #if defined(CONFIG_OPTPROBES)
1544 .procname = "kprobes-optimization",
1545 .data = &sysctl_kprobes_optimization,
1546 .maxlen = sizeof(int),
1548 .proc_handler = proc_kprobes_optimization_handler,
1556 static struct ctl_table dev_table[] = {
1560 int __init sysctl_init(void)
1562 register_sysctl_table(sysctl_base_table);
1566 #endif /* CONFIG_SYSCTL */
1572 #ifdef CONFIG_PROC_SYSCTL
1574 static int _proc_do_string(void* data, int maxlen, int write,
1575 void __user *buffer,
1576 size_t *lenp, loff_t *ppos)
1582 if (!data || !maxlen || !*lenp) {
1590 while (len < *lenp) {
1591 if (get_user(c, p++))
1593 if (c == 0 || c == '\n')
1599 if(copy_from_user(data, buffer, len))
1601 ((char *) data)[len] = 0;
1619 if(copy_to_user(buffer, data, len))
1622 if(put_user('\n', ((char __user *) buffer) + len))
1633 * proc_dostring - read a string sysctl
1634 * @table: the sysctl table
1635 * @write: %TRUE if this is a write to the sysctl file
1636 * @buffer: the user buffer
1637 * @lenp: the size of the user buffer
1638 * @ppos: file position
1640 * Reads/writes a string from/to the user buffer. If the kernel
1641 * buffer provided is not large enough to hold the string, the
1642 * string is truncated. The copied string is %NULL-terminated.
1643 * If the string is being read by the user process, it is copied
1644 * and a newline '\n' is added. It is truncated if the buffer is
1647 * Returns 0 on success.
1649 int proc_dostring(struct ctl_table *table, int write,
1650 void __user *buffer, size_t *lenp, loff_t *ppos)
1652 return _proc_do_string(table->data, table->maxlen, write,
1653 buffer, lenp, ppos);
1656 static size_t proc_skip_spaces(char **buf)
1659 char *tmp = skip_spaces(*buf);
1665 static void proc_skip_char(char **buf, size_t *size, const char v)
1675 #define TMPBUFLEN 22
1677 * proc_get_long - reads an ASCII formatted integer from a user buffer
1679 * @buf: a kernel buffer
1680 * @size: size of the kernel buffer
1681 * @val: this is where the number will be stored
1682 * @neg: set to %TRUE if number is negative
1683 * @perm_tr: a vector which contains the allowed trailers
1684 * @perm_tr_len: size of the perm_tr vector
1685 * @tr: pointer to store the trailer character
1687 * In case of success %0 is returned and @buf and @size are updated with
1688 * the amount of bytes read. If @tr is non-NULL and a trailing
1689 * character exists (size is non-zero after returning from this
1690 * function), @tr is updated with the trailing character.
1692 static int proc_get_long(char **buf, size_t *size,
1693 unsigned long *val, bool *neg,
1694 const char *perm_tr, unsigned perm_tr_len, char *tr)
1697 char *p, tmp[TMPBUFLEN];
1703 if (len > TMPBUFLEN - 1)
1704 len = TMPBUFLEN - 1;
1706 memcpy(tmp, *buf, len);
1710 if (*p == '-' && *size > 1) {
1718 *val = simple_strtoul(p, &p, 0);
1722 /* We don't know if the next char is whitespace thus we may accept
1723 * invalid integers (e.g. 1234...a) or two integers instead of one
1724 * (e.g. 123...1). So lets not allow such large numbers. */
1725 if (len == TMPBUFLEN - 1)
1728 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1731 if (tr && (len < *size))
1741 * proc_put_long - converts an integer to a decimal ASCII formatted string
1743 * @buf: the user buffer
1744 * @size: the size of the user buffer
1745 * @val: the integer to be converted
1746 * @neg: sign of the number, %TRUE for negative
1748 * In case of success %0 is returned and @buf and @size are updated with
1749 * the amount of bytes written.
1751 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1755 char tmp[TMPBUFLEN], *p = tmp;
1757 sprintf(p, "%s%lu", neg ? "-" : "", val);
1761 if (copy_to_user(*buf, tmp, len))
1769 static int proc_put_char(void __user **buf, size_t *size, char c)
1772 char __user **buffer = (char __user **)buf;
1773 if (put_user(c, *buffer))
1775 (*size)--, (*buffer)++;
1781 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1783 int write, void *data)
1786 *valp = *negp ? -*lvalp : *lvalp;
1791 *lvalp = (unsigned long)-val;
1794 *lvalp = (unsigned long)val;
1800 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1802 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1803 int write, void __user *buffer,
1804 size_t *lenp, loff_t *ppos,
1805 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1806 int write, void *data),
1809 int *i, vleft, first = 1, err = 0;
1810 unsigned long page = 0;
1814 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1819 i = (int *) tbl_data;
1820 vleft = table->maxlen / sizeof(*i);
1824 conv = do_proc_dointvec_conv;
1827 if (left > PAGE_SIZE - 1)
1828 left = PAGE_SIZE - 1;
1829 page = __get_free_page(GFP_TEMPORARY);
1830 kbuf = (char *) page;
1833 if (copy_from_user(kbuf, buffer, left)) {
1840 for (; left && vleft--; i++, first=0) {
1845 left -= proc_skip_spaces(&kbuf);
1849 err = proc_get_long(&kbuf, &left, &lval, &neg,
1851 sizeof(proc_wspace_sep), NULL);
1854 if (conv(&neg, &lval, i, 1, data)) {
1859 if (conv(&neg, &lval, i, 0, data)) {
1864 err = proc_put_char(&buffer, &left, '\t');
1867 err = proc_put_long(&buffer, &left, lval, neg);
1873 if (!write && !first && left && !err)
1874 err = proc_put_char(&buffer, &left, '\n');
1875 if (write && !err && left)
1876 left -= proc_skip_spaces(&kbuf);
1881 return err ? : -EINVAL;
1888 static int do_proc_dointvec(struct ctl_table *table, int write,
1889 void __user *buffer, size_t *lenp, loff_t *ppos,
1890 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1891 int write, void *data),
1894 return __do_proc_dointvec(table->data, table, write,
1895 buffer, lenp, ppos, conv, data);
1899 * proc_dointvec - read a vector of integers
1900 * @table: the sysctl table
1901 * @write: %TRUE if this is a write to the sysctl file
1902 * @buffer: the user buffer
1903 * @lenp: the size of the user buffer
1904 * @ppos: file position
1906 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1907 * values from/to the user buffer, treated as an ASCII string.
1909 * Returns 0 on success.
1911 int proc_dointvec(struct ctl_table *table, int write,
1912 void __user *buffer, size_t *lenp, loff_t *ppos)
1914 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1919 * Taint values can only be increased
1920 * This means we can safely use a temporary.
1922 static int proc_taint(struct ctl_table *table, int write,
1923 void __user *buffer, size_t *lenp, loff_t *ppos)
1926 unsigned long tmptaint = get_taint();
1929 if (write && !capable(CAP_SYS_ADMIN))
1934 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1940 * Poor man's atomic or. Not worth adding a primitive
1941 * to everyone's atomic.h for this
1944 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
1945 if ((tmptaint >> i) & 1)
1953 #ifdef CONFIG_PRINTK
1954 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
1955 void __user *buffer, size_t *lenp, loff_t *ppos)
1957 if (write && !capable(CAP_SYS_ADMIN))
1960 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1964 struct do_proc_dointvec_minmax_conv_param {
1969 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
1971 int write, void *data)
1973 struct do_proc_dointvec_minmax_conv_param *param = data;
1975 int val = *negp ? -*lvalp : *lvalp;
1976 if ((param->min && *param->min > val) ||
1977 (param->max && *param->max < val))
1984 *lvalp = (unsigned long)-val;
1987 *lvalp = (unsigned long)val;
1994 * proc_dointvec_minmax - read a vector of integers with min/max values
1995 * @table: the sysctl table
1996 * @write: %TRUE if this is a write to the sysctl file
1997 * @buffer: the user buffer
1998 * @lenp: the size of the user buffer
1999 * @ppos: file position
2001 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2002 * values from/to the user buffer, treated as an ASCII string.
2004 * This routine will ensure the values are within the range specified by
2005 * table->extra1 (min) and table->extra2 (max).
2007 * Returns 0 on success.
2009 int proc_dointvec_minmax(struct ctl_table *table, int write,
2010 void __user *buffer, size_t *lenp, loff_t *ppos)
2012 struct do_proc_dointvec_minmax_conv_param param = {
2013 .min = (int *) table->extra1,
2014 .max = (int *) table->extra2,
2016 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2017 do_proc_dointvec_minmax_conv, ¶m);
2020 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2021 void __user *buffer,
2022 size_t *lenp, loff_t *ppos,
2023 unsigned long convmul,
2024 unsigned long convdiv)
2026 unsigned long *i, *min, *max;
2027 int vleft, first = 1, err = 0;
2028 unsigned long page = 0;
2032 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2037 i = (unsigned long *) data;
2038 min = (unsigned long *) table->extra1;
2039 max = (unsigned long *) table->extra2;
2040 vleft = table->maxlen / sizeof(unsigned long);
2044 if (left > PAGE_SIZE - 1)
2045 left = PAGE_SIZE - 1;
2046 page = __get_free_page(GFP_TEMPORARY);
2047 kbuf = (char *) page;
2050 if (copy_from_user(kbuf, buffer, left)) {
2057 for (; left && vleft--; i++, first = 0) {
2063 left -= proc_skip_spaces(&kbuf);
2065 err = proc_get_long(&kbuf, &left, &val, &neg,
2067 sizeof(proc_wspace_sep), NULL);
2072 if ((min && val < *min) || (max && val > *max))
2076 val = convdiv * (*i) / convmul;
2078 err = proc_put_char(&buffer, &left, '\t');
2079 err = proc_put_long(&buffer, &left, val, false);
2085 if (!write && !first && left && !err)
2086 err = proc_put_char(&buffer, &left, '\n');
2088 left -= proc_skip_spaces(&kbuf);
2093 return err ? : -EINVAL;
2100 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2101 void __user *buffer,
2102 size_t *lenp, loff_t *ppos,
2103 unsigned long convmul,
2104 unsigned long convdiv)
2106 return __do_proc_doulongvec_minmax(table->data, table, write,
2107 buffer, lenp, ppos, convmul, convdiv);
2111 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2112 * @table: the sysctl table
2113 * @write: %TRUE if this is a write to the sysctl file
2114 * @buffer: the user buffer
2115 * @lenp: the size of the user buffer
2116 * @ppos: file position
2118 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2119 * values from/to the user buffer, treated as an ASCII string.
2121 * This routine will ensure the values are within the range specified by
2122 * table->extra1 (min) and table->extra2 (max).
2124 * Returns 0 on success.
2126 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2127 void __user *buffer, size_t *lenp, loff_t *ppos)
2129 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2133 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2134 * @table: the sysctl table
2135 * @write: %TRUE if this is a write to the sysctl file
2136 * @buffer: the user buffer
2137 * @lenp: the size of the user buffer
2138 * @ppos: file position
2140 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2141 * values from/to the user buffer, treated as an ASCII string. The values
2142 * are treated as milliseconds, and converted to jiffies when they are stored.
2144 * This routine will ensure the values are within the range specified by
2145 * table->extra1 (min) and table->extra2 (max).
2147 * Returns 0 on success.
2149 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2150 void __user *buffer,
2151 size_t *lenp, loff_t *ppos)
2153 return do_proc_doulongvec_minmax(table, write, buffer,
2154 lenp, ppos, HZ, 1000l);
2158 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2160 int write, void *data)
2163 if (*lvalp > LONG_MAX / HZ)
2165 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2171 lval = (unsigned long)-val;
2174 lval = (unsigned long)val;
2181 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2183 int write, void *data)
2186 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2188 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2194 lval = (unsigned long)-val;
2197 lval = (unsigned long)val;
2199 *lvalp = jiffies_to_clock_t(lval);
2204 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2206 int write, void *data)
2209 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2215 lval = (unsigned long)-val;
2218 lval = (unsigned long)val;
2220 *lvalp = jiffies_to_msecs(lval);
2226 * proc_dointvec_jiffies - read a vector of integers as seconds
2227 * @table: the sysctl table
2228 * @write: %TRUE if this is a write to the sysctl file
2229 * @buffer: the user buffer
2230 * @lenp: the size of the user buffer
2231 * @ppos: file position
2233 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2234 * values from/to the user buffer, treated as an ASCII string.
2235 * The values read are assumed to be in seconds, and are converted into
2238 * Returns 0 on success.
2240 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2241 void __user *buffer, size_t *lenp, loff_t *ppos)
2243 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2244 do_proc_dointvec_jiffies_conv,NULL);
2248 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2249 * @table: the sysctl table
2250 * @write: %TRUE if this is a write to the sysctl file
2251 * @buffer: the user buffer
2252 * @lenp: the size of the user buffer
2253 * @ppos: pointer to the file position
2255 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2256 * values from/to the user buffer, treated as an ASCII string.
2257 * The values read are assumed to be in 1/USER_HZ seconds, and
2258 * are converted into jiffies.
2260 * Returns 0 on success.
2262 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2263 void __user *buffer, size_t *lenp, loff_t *ppos)
2265 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2266 do_proc_dointvec_userhz_jiffies_conv,NULL);
2270 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2271 * @table: the sysctl table
2272 * @write: %TRUE if this is a write to the sysctl file
2273 * @buffer: the user buffer
2274 * @lenp: the size of the user buffer
2275 * @ppos: file position
2276 * @ppos: the current position in the file
2278 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2279 * values from/to the user buffer, treated as an ASCII string.
2280 * The values read are assumed to be in 1/1000 seconds, and
2281 * are converted into jiffies.
2283 * Returns 0 on success.
2285 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2288 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2289 do_proc_dointvec_ms_jiffies_conv, NULL);
2292 static int proc_do_cad_pid(struct ctl_table *table, int write,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2295 struct pid *new_pid;
2299 tmp = pid_vnr(cad_pid);
2301 r = __do_proc_dointvec(&tmp, table, write, buffer,
2302 lenp, ppos, NULL, NULL);
2306 new_pid = find_get_pid(tmp);
2310 put_pid(xchg(&cad_pid, new_pid));
2315 * proc_do_large_bitmap - read/write from/to a large bitmap
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * The bitmap is stored at table->data and the bitmap length (in bits)
2325 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2326 * large bitmaps may be represented in a compact manner. Writing into
2327 * the file will clear the bitmap then update it with the given input.
2329 * Returns 0 on success.
2331 int proc_do_large_bitmap(struct ctl_table *table, int write,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2336 size_t left = *lenp;
2337 unsigned long bitmap_len = table->maxlen;
2338 unsigned long *bitmap = (unsigned long *) table->data;
2339 unsigned long *tmp_bitmap = NULL;
2340 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2342 if (!bitmap_len || !left || (*ppos && !write)) {
2348 unsigned long page = 0;
2351 if (left > PAGE_SIZE - 1)
2352 left = PAGE_SIZE - 1;
2354 page = __get_free_page(GFP_TEMPORARY);
2355 kbuf = (char *) page;
2358 if (copy_from_user(kbuf, buffer, left)) {
2364 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2370 proc_skip_char(&kbuf, &left, '\n');
2371 while (!err && left) {
2372 unsigned long val_a, val_b;
2375 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2379 if (val_a >= bitmap_len || neg) {
2391 err = proc_get_long(&kbuf, &left, &val_b,
2392 &neg, tr_b, sizeof(tr_b),
2396 if (val_b >= bitmap_len || neg ||
2407 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2409 proc_skip_char(&kbuf, &left, '\n');
2413 unsigned long bit_a, bit_b = 0;
2416 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2417 if (bit_a >= bitmap_len)
2419 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2423 err = proc_put_char(&buffer, &left, ',');
2427 err = proc_put_long(&buffer, &left, bit_a, false);
2430 if (bit_a != bit_b) {
2431 err = proc_put_char(&buffer, &left, '-');
2434 err = proc_put_long(&buffer, &left, bit_b, false);
2442 err = proc_put_char(&buffer, &left, '\n');
2448 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2450 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2462 #else /* CONFIG_PROC_SYSCTL */
2464 int proc_dostring(struct ctl_table *table, int write,
2465 void __user *buffer, size_t *lenp, loff_t *ppos)
2470 int proc_dointvec(struct ctl_table *table, int write,
2471 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 int proc_dointvec_minmax(struct ctl_table *table, int write,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2489 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2495 void __user *buffer, size_t *lenp, loff_t *ppos)
2500 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2501 void __user *buffer, size_t *lenp, loff_t *ppos)
2506 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2507 void __user *buffer,
2508 size_t *lenp, loff_t *ppos)
2514 #endif /* CONFIG_PROC_SYSCTL */
2517 * No sense putting this after each symbol definition, twice,
2518 * exception granted :-)
2520 EXPORT_SYMBOL(proc_dointvec);
2521 EXPORT_SYMBOL(proc_dointvec_jiffies);
2522 EXPORT_SYMBOL(proc_dointvec_minmax);
2523 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2524 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2525 EXPORT_SYMBOL(proc_dostring);
2526 EXPORT_SYMBOL(proc_doulongvec_minmax);
2527 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);