ARM: cpu topology: Add debugfs interface for cpu_power
[cmplus.git] / kernel / sysctl.c
blob5b6afb27e8b26149959db96ce1e85232343fe42a
1 /*
2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
32 #include <linux/fs.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
59 #include <linux/kmod.h>
61 #include <asm/uaccess.h>
62 #include <asm/processor.h>
64 #ifdef CONFIG_X86
65 #include <asm/nmi.h>
66 #include <asm/stacktrace.h>
67 #include <asm/io.h>
68 #endif
69 #ifdef CONFIG_BSD_PROCESS_ACCT
70 #include <linux/acct.h>
71 #endif
72 #ifdef CONFIG_RT_MUTEXES
73 #include <linux/rtmutex.h>
74 #endif
75 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
76 #include <linux/lockdep.h>
77 #endif
78 #ifdef CONFIG_CHR_DEV_SG
79 #include <scsi/sg.h>
80 #endif
82 #ifdef CONFIG_LOCKUP_DETECTOR
83 #include <linux/nmi.h>
84 #endif
87 #if defined(CONFIG_SYSCTL)
89 /* External variables not in a header file. */
90 extern int sysctl_overcommit_memory;
91 extern int sysctl_overcommit_ratio;
92 extern int max_threads;
93 extern int core_uses_pid;
94 extern int suid_dumpable;
95 extern char core_pattern[];
96 extern unsigned int core_pipe_limit;
97 extern int pid_max;
98 extern int min_free_kbytes;
99 extern int min_free_order_shift;
100 extern int pid_max_min, pid_max_max;
101 extern int sysctl_drop_caches;
102 extern int percpu_pagelist_fraction;
103 extern int compat_log;
104 extern int latencytop_enabled;
105 extern int sysctl_nr_open_min, sysctl_nr_open_max;
106 #ifndef CONFIG_MMU
107 extern int sysctl_nr_trim_pages;
108 #endif
109 #ifdef CONFIG_BLOCK
110 extern int blk_iopoll_enabled;
111 #endif
113 /* Constants used for minimum and maximum */
114 #ifdef CONFIG_LOCKUP_DETECTOR
115 static int sixty = 60;
116 static int neg_one = -1;
117 #endif
119 static int zero;
120 static int __maybe_unused one = 1;
121 static int __maybe_unused two = 2;
122 static int __maybe_unused three = 3;
123 static unsigned long one_ul = 1;
124 static int one_hundred = 100;
125 #ifdef CONFIG_PRINTK
126 static int ten_thousand = 10000;
127 #endif
129 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
130 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
133 static int maxolduid = 65535;
134 static int minolduid;
135 static int min_percpu_pagelist_fract = 8;
137 static int ngroups_max = NGROUPS_MAX;
139 #ifdef CONFIG_INOTIFY_USER
140 #include <linux/inotify.h>
141 #endif
142 #ifdef CONFIG_SPARC
143 #include <asm/system.h>
144 #endif
146 #ifdef CONFIG_SPARC64
147 extern int sysctl_tsb_ratio;
148 #endif
150 #ifdef __hppa__
151 extern int pwrsw_enabled;
152 extern int unaligned_enabled;
153 #endif
155 #ifdef CONFIG_S390
156 #ifdef CONFIG_MATHEMU
157 extern int sysctl_ieee_emulation_warnings;
158 #endif
159 extern int sysctl_userprocess_debug;
160 extern int spin_retry;
161 #endif
163 #ifdef CONFIG_IA64
164 extern int no_unaligned_warning;
165 extern int unaligned_dump_stack;
166 #endif
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
173 #endif
175 #ifdef CONFIG_PRINTK
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
177 void __user *buffer, size_t *lenp, loff_t *ppos);
178 #endif
180 #ifdef CONFIG_MAGIC_SYSRQ
181 /* Note: sysrq code uses it's own private copy */
182 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
184 static int sysrq_sysctl_handler(ctl_table *table, int write,
185 void __user *buffer, size_t *lenp,
186 loff_t *ppos)
188 int error;
190 error = proc_dointvec(table, write, buffer, lenp, ppos);
191 if (error)
192 return error;
194 if (write)
195 sysrq_toggle_support(__sysrq_enabled);
197 return 0;
200 #endif
202 static struct ctl_table root_table[];
203 static struct ctl_table_root sysctl_table_root;
204 static struct ctl_table_header root_table_header = {
205 {{.count = 1,
206 .ctl_table = root_table,
207 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
208 .root = &sysctl_table_root,
209 .set = &sysctl_table_root.default_set,
211 static struct ctl_table_root sysctl_table_root = {
212 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
213 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
216 static struct ctl_table kern_table[];
217 static struct ctl_table vm_table[];
218 static struct ctl_table fs_table[];
219 static struct ctl_table debug_table[];
220 static struct ctl_table dev_table[];
221 extern struct ctl_table random_table[];
222 #ifdef CONFIG_EPOLL
223 extern struct ctl_table epoll_table[];
224 #endif
226 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
227 int sysctl_legacy_va_layout;
228 #endif
230 /* The default sysctl tables: */
232 static struct ctl_table root_table[] = {
234 .procname = "kernel",
235 .mode = 0555,
236 .child = kern_table,
239 .procname = "vm",
240 .mode = 0555,
241 .child = vm_table,
244 .procname = "fs",
245 .mode = 0555,
246 .child = fs_table,
249 .procname = "debug",
250 .mode = 0555,
251 .child = debug_table,
254 .procname = "dev",
255 .mode = 0555,
256 .child = dev_table,
261 #ifdef CONFIG_SCHED_DEBUG
262 static int min_sched_granularity_ns = 100000; /* 100 usecs */
263 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_wakeup_granularity_ns; /* 0 usecs */
265 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
266 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
267 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
268 #endif
270 #ifdef CONFIG_COMPACTION
271 static int min_extfrag_threshold;
272 static int max_extfrag_threshold = 1000;
273 #endif
275 static struct ctl_table kern_table[] = {
277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
281 .proc_handler = proc_dointvec,
283 #ifdef CONFIG_SCHED_DEBUG
285 .procname = "sched_min_granularity_ns",
286 .data = &sysctl_sched_min_granularity,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = sched_proc_update_handler,
290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
294 .procname = "sched_latency_ns",
295 .data = &sysctl_sched_latency,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
303 .procname = "sched_wakeup_granularity_ns",
304 .data = &sysctl_sched_wakeup_granularity,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_wakeup_granularity_ns,
309 .extra2 = &max_wakeup_granularity_ns,
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
315 .mode = 0644,
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
321 .procname = "sched_migration_cost",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
325 .proc_handler = proc_dointvec,
328 .procname = "sched_nr_migrate",
329 .data = &sysctl_sched_nr_migrate,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
332 .proc_handler = proc_dointvec,
335 .procname = "sched_time_avg",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = proc_dointvec,
342 .procname = "sched_shares_window",
343 .data = &sysctl_sched_shares_window,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
346 .proc_handler = proc_dointvec,
349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = proc_dointvec_minmax,
354 .extra1 = &zero,
355 .extra2 = &one,
357 #endif
359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = sched_rt_handler,
366 .procname = "sched_rt_runtime_us",
367 .data = &sysctl_sched_rt_runtime,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = sched_rt_handler,
372 #ifdef CONFIG_SCHED_AUTOGROUP
374 .procname = "sched_autogroup_enabled",
375 .data = &sysctl_sched_autogroup_enabled,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = proc_dointvec_minmax,
379 .extra1 = &zero,
380 .extra2 = &one,
382 #endif
383 #ifdef CONFIG_PROVE_LOCKING
385 .procname = "prove_locking",
386 .data = &prove_locking,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = proc_dointvec,
391 #endif
392 #ifdef CONFIG_LOCK_STAT
394 .procname = "lock_stat",
395 .data = &lock_stat,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = proc_dointvec,
400 #endif
402 .procname = "panic",
403 .data = &panic_timeout,
404 .maxlen = sizeof(int),
405 .mode = 0644,
406 .proc_handler = proc_dointvec,
409 .procname = "core_uses_pid",
410 .data = &core_uses_pid,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = proc_dointvec,
416 .procname = "core_pattern",
417 .data = core_pattern,
418 .maxlen = CORENAME_MAX_SIZE,
419 .mode = 0644,
420 .proc_handler = proc_dostring,
423 .procname = "core_pipe_limit",
424 .data = &core_pipe_limit,
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
427 .proc_handler = proc_dointvec,
429 #ifdef CONFIG_PROC_SYSCTL
431 .procname = "tainted",
432 .maxlen = sizeof(long),
433 .mode = 0644,
434 .proc_handler = proc_taint,
436 #endif
437 #ifdef CONFIG_LATENCYTOP
439 .procname = "latencytop",
440 .data = &latencytop_enabled,
441 .maxlen = sizeof(int),
442 .mode = 0644,
443 .proc_handler = proc_dointvec,
445 #endif
446 #ifdef CONFIG_BLK_DEV_INITRD
448 .procname = "real-root-dev",
449 .data = &real_root_dev,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = proc_dointvec,
454 #endif
456 .procname = "print-fatal-signals",
457 .data = &print_fatal_signals,
458 .maxlen = sizeof(int),
459 .mode = 0644,
460 .proc_handler = proc_dointvec,
462 #ifdef CONFIG_SPARC
464 .procname = "reboot-cmd",
465 .data = reboot_command,
466 .maxlen = 256,
467 .mode = 0644,
468 .proc_handler = proc_dostring,
471 .procname = "stop-a",
472 .data = &stop_a_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = proc_dointvec,
478 .procname = "scons-poweroff",
479 .data = &scons_pwroff,
480 .maxlen = sizeof (int),
481 .mode = 0644,
482 .proc_handler = proc_dointvec,
484 #endif
485 #ifdef CONFIG_SPARC64
487 .procname = "tsb-ratio",
488 .data = &sysctl_tsb_ratio,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = proc_dointvec,
493 #endif
494 #ifdef __hppa__
496 .procname = "soft-power",
497 .data = &pwrsw_enabled,
498 .maxlen = sizeof (int),
499 .mode = 0644,
500 .proc_handler = proc_dointvec,
503 .procname = "unaligned-trap",
504 .data = &unaligned_enabled,
505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = proc_dointvec,
509 #endif
511 .procname = "ctrl-alt-del",
512 .data = &C_A_D,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = proc_dointvec,
517 #ifdef CONFIG_FUNCTION_TRACER
519 .procname = "ftrace_enabled",
520 .data = &ftrace_enabled,
521 .maxlen = sizeof(int),
522 .mode = 0644,
523 .proc_handler = ftrace_enable_sysctl,
525 #endif
526 #ifdef CONFIG_STACK_TRACER
528 .procname = "stack_tracer_enabled",
529 .data = &stack_tracer_enabled,
530 .maxlen = sizeof(int),
531 .mode = 0644,
532 .proc_handler = stack_trace_sysctl,
534 #endif
535 #ifdef CONFIG_TRACING
537 .procname = "ftrace_dump_on_oops",
538 .data = &ftrace_dump_on_oops,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = proc_dointvec,
543 #endif
544 #ifdef CONFIG_MODULES
546 .procname = "modprobe",
547 .data = &modprobe_path,
548 .maxlen = KMOD_PATH_LEN,
549 .mode = 0644,
550 .proc_handler = proc_dostring,
553 .procname = "modules_disabled",
554 .data = &modules_disabled,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 /* only handle a transition from default "0" to "1" */
558 .proc_handler = proc_dointvec_minmax,
559 .extra1 = &one,
560 .extra2 = &one,
562 #endif
563 #ifdef CONFIG_HOTPLUG
565 .procname = "hotplug",
566 .data = &uevent_helper,
567 .maxlen = UEVENT_HELPER_PATH_LEN,
568 .mode = 0644,
569 .proc_handler = proc_dostring,
571 #endif
572 #ifdef CONFIG_CHR_DEV_SG
574 .procname = "sg-big-buff",
575 .data = &sg_big_buff,
576 .maxlen = sizeof (int),
577 .mode = 0444,
578 .proc_handler = proc_dointvec,
580 #endif
581 #ifdef CONFIG_BSD_PROCESS_ACCT
583 .procname = "acct",
584 .data = &acct_parm,
585 .maxlen = 3*sizeof(int),
586 .mode = 0644,
587 .proc_handler = proc_dointvec,
589 #endif
590 #ifdef CONFIG_MAGIC_SYSRQ
592 .procname = "sysrq",
593 .data = &__sysrq_enabled,
594 .maxlen = sizeof (int),
595 .mode = 0644,
596 .proc_handler = sysrq_sysctl_handler,
598 #endif
599 #ifdef CONFIG_PROC_SYSCTL
601 .procname = "cad_pid",
602 .data = NULL,
603 .maxlen = sizeof (int),
604 .mode = 0600,
605 .proc_handler = proc_do_cad_pid,
607 #endif
609 .procname = "threads-max",
610 .data = &max_threads,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = proc_dointvec,
616 .procname = "random",
617 .mode = 0555,
618 .child = random_table,
621 .procname = "usermodehelper",
622 .mode = 0555,
623 .child = usermodehelper_table,
626 .procname = "overflowuid",
627 .data = &overflowuid,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = proc_dointvec_minmax,
631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
635 .procname = "overflowgid",
636 .data = &overflowgid,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = proc_dointvec_minmax,
640 .extra1 = &minolduid,
641 .extra2 = &maxolduid,
643 #ifdef CONFIG_S390
644 #ifdef CONFIG_MATHEMU
646 .procname = "ieee_emulation_warnings",
647 .data = &sysctl_ieee_emulation_warnings,
648 .maxlen = sizeof(int),
649 .mode = 0644,
650 .proc_handler = proc_dointvec,
652 #endif
654 .procname = "userprocess_debug",
655 .data = &show_unhandled_signals,
656 .maxlen = sizeof(int),
657 .mode = 0644,
658 .proc_handler = proc_dointvec,
660 #endif
662 .procname = "pid_max",
663 .data = &pid_max,
664 .maxlen = sizeof (int),
665 .mode = 0644,
666 .proc_handler = proc_dointvec_minmax,
667 .extra1 = &pid_max_min,
668 .extra2 = &pid_max_max,
671 .procname = "panic_on_oops",
672 .data = &panic_on_oops,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = proc_dointvec,
677 #if defined CONFIG_PRINTK
679 .procname = "printk",
680 .data = &console_loglevel,
681 .maxlen = 4*sizeof(int),
682 .mode = 0644,
683 .proc_handler = proc_dointvec,
686 .procname = "printk_ratelimit",
687 .data = &printk_ratelimit_state.interval,
688 .maxlen = sizeof(int),
689 .mode = 0644,
690 .proc_handler = proc_dointvec_jiffies,
693 .procname = "printk_ratelimit_burst",
694 .data = &printk_ratelimit_state.burst,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = proc_dointvec,
700 .procname = "printk_delay",
701 .data = &printk_delay_msec,
702 .maxlen = sizeof(int),
703 .mode = 0644,
704 .proc_handler = proc_dointvec_minmax,
705 .extra1 = &zero,
706 .extra2 = &ten_thousand,
709 .procname = "dmesg_restrict",
710 .data = &dmesg_restrict,
711 .maxlen = sizeof(int),
712 .mode = 0644,
713 .proc_handler = proc_dointvec_minmax_sysadmin,
714 .extra1 = &zero,
715 .extra2 = &one,
718 .procname = "kptr_restrict",
719 .data = &kptr_restrict,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = proc_dointvec_minmax_sysadmin,
723 .extra1 = &zero,
724 .extra2 = &two,
726 #endif
728 .procname = "ngroups_max",
729 .data = &ngroups_max,
730 .maxlen = sizeof (int),
731 .mode = 0444,
732 .proc_handler = proc_dointvec,
734 #if defined(CONFIG_LOCKUP_DETECTOR)
736 .procname = "watchdog",
737 .data = &watchdog_enabled,
738 .maxlen = sizeof (int),
739 .mode = 0644,
740 .proc_handler = proc_dowatchdog,
741 .extra1 = &zero,
742 .extra2 = &one,
745 .procname = "watchdog_thresh",
746 .data = &watchdog_thresh,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dowatchdog,
750 .extra1 = &neg_one,
751 .extra2 = &sixty,
754 .procname = "softlockup_panic",
755 .data = &softlockup_panic,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = proc_dointvec_minmax,
759 .extra1 = &zero,
760 .extra2 = &one,
763 .procname = "nmi_watchdog",
764 .data = &watchdog_enabled,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = proc_dowatchdog,
768 .extra1 = &zero,
769 .extra2 = &one,
771 #endif
772 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
774 .procname = "unknown_nmi_panic",
775 .data = &unknown_nmi_panic,
776 .maxlen = sizeof (int),
777 .mode = 0644,
778 .proc_handler = proc_dointvec,
780 #endif
781 #if defined(CONFIG_X86)
783 .procname = "panic_on_unrecovered_nmi",
784 .data = &panic_on_unrecovered_nmi,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = proc_dointvec,
790 .procname = "panic_on_io_nmi",
791 .data = &panic_on_io_nmi,
792 .maxlen = sizeof(int),
793 .mode = 0644,
794 .proc_handler = proc_dointvec,
797 .procname = "bootloader_type",
798 .data = &bootloader_type,
799 .maxlen = sizeof (int),
800 .mode = 0444,
801 .proc_handler = proc_dointvec,
804 .procname = "bootloader_version",
805 .data = &bootloader_version,
806 .maxlen = sizeof (int),
807 .mode = 0444,
808 .proc_handler = proc_dointvec,
811 .procname = "kstack_depth_to_print",
812 .data = &kstack_depth_to_print,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = proc_dointvec,
818 .procname = "io_delay_type",
819 .data = &io_delay_type,
820 .maxlen = sizeof(int),
821 .mode = 0644,
822 .proc_handler = proc_dointvec,
824 #endif
825 #if defined(CONFIG_MMU)
827 .procname = "randomize_va_space",
828 .data = &randomize_va_space,
829 .maxlen = sizeof(int),
830 .mode = 0644,
831 .proc_handler = proc_dointvec,
833 #endif
834 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
836 .procname = "spin_retry",
837 .data = &spin_retry,
838 .maxlen = sizeof (int),
839 .mode = 0644,
840 .proc_handler = proc_dointvec,
842 #endif
843 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
845 .procname = "acpi_video_flags",
846 .data = &acpi_realmode_flags,
847 .maxlen = sizeof (unsigned long),
848 .mode = 0644,
849 .proc_handler = proc_doulongvec_minmax,
851 #endif
852 #ifdef CONFIG_IA64
854 .procname = "ignore-unaligned-usertrap",
855 .data = &no_unaligned_warning,
856 .maxlen = sizeof (int),
857 .mode = 0644,
858 .proc_handler = proc_dointvec,
861 .procname = "unaligned-dump-stack",
862 .data = &unaligned_dump_stack,
863 .maxlen = sizeof (int),
864 .mode = 0644,
865 .proc_handler = proc_dointvec,
867 #endif
868 #ifdef CONFIG_DETECT_HUNG_TASK
870 .procname = "hung_task_panic",
871 .data = &sysctl_hung_task_panic,
872 .maxlen = sizeof(int),
873 .mode = 0644,
874 .proc_handler = proc_dointvec_minmax,
875 .extra1 = &zero,
876 .extra2 = &one,
879 .procname = "hung_task_check_count",
880 .data = &sysctl_hung_task_check_count,
881 .maxlen = sizeof(unsigned long),
882 .mode = 0644,
883 .proc_handler = proc_doulongvec_minmax,
886 .procname = "hung_task_timeout_secs",
887 .data = &sysctl_hung_task_timeout_secs,
888 .maxlen = sizeof(unsigned long),
889 .mode = 0644,
890 .proc_handler = proc_dohung_task_timeout_secs,
893 .procname = "hung_task_warnings",
894 .data = &sysctl_hung_task_warnings,
895 .maxlen = sizeof(unsigned long),
896 .mode = 0644,
897 .proc_handler = proc_doulongvec_minmax,
899 #endif
900 #ifdef CONFIG_COMPAT
902 .procname = "compat-log",
903 .data = &compat_log,
904 .maxlen = sizeof (int),
905 .mode = 0644,
906 .proc_handler = proc_dointvec,
908 #endif
909 #ifdef CONFIG_RT_MUTEXES
911 .procname = "max_lock_depth",
912 .data = &max_lock_depth,
913 .maxlen = sizeof(int),
914 .mode = 0644,
915 .proc_handler = proc_dointvec,
917 #endif
919 .procname = "poweroff_cmd",
920 .data = &poweroff_cmd,
921 .maxlen = POWEROFF_CMD_PATH_LEN,
922 .mode = 0644,
923 .proc_handler = proc_dostring,
925 #ifdef CONFIG_KEYS
927 .procname = "keys",
928 .mode = 0555,
929 .child = key_sysctls,
931 #endif
932 #ifdef CONFIG_RCU_TORTURE_TEST
934 .procname = "rcutorture_runnable",
935 .data = &rcutorture_runnable,
936 .maxlen = sizeof(int),
937 .mode = 0644,
938 .proc_handler = proc_dointvec,
940 #endif
941 #ifdef CONFIG_PERF_EVENTS
943 * User-space scripts rely on the existence of this file
944 * as a feature check for perf_events being enabled.
946 * So it's an ABI, do not remove!
949 .procname = "perf_event_paranoid",
950 .data = &sysctl_perf_event_paranoid,
951 .maxlen = sizeof(sysctl_perf_event_paranoid),
952 .mode = 0644,
953 .proc_handler = proc_dointvec,
956 .procname = "perf_event_mlock_kb",
957 .data = &sysctl_perf_event_mlock,
958 .maxlen = sizeof(sysctl_perf_event_mlock),
959 .mode = 0644,
960 .proc_handler = proc_dointvec,
963 .procname = "perf_event_max_sample_rate",
964 .data = &sysctl_perf_event_sample_rate,
965 .maxlen = sizeof(sysctl_perf_event_sample_rate),
966 .mode = 0644,
967 .proc_handler = perf_proc_update_handler,
969 #endif
970 #ifdef CONFIG_KMEMCHECK
972 .procname = "kmemcheck",
973 .data = &kmemcheck_enabled,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec,
978 #endif
979 #ifdef CONFIG_BLOCK
981 .procname = "blk_iopoll",
982 .data = &blk_iopoll_enabled,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = proc_dointvec,
987 #endif
991 static struct ctl_table vm_table[] = {
993 .procname = "overcommit_memory",
994 .data = &sysctl_overcommit_memory,
995 .maxlen = sizeof(sysctl_overcommit_memory),
996 .mode = 0644,
997 .proc_handler = proc_dointvec_minmax,
998 .extra1 = &zero,
999 .extra2 = &two,
1002 .procname = "panic_on_oom",
1003 .data = &sysctl_panic_on_oom,
1004 .maxlen = sizeof(sysctl_panic_on_oom),
1005 .mode = 0644,
1006 .proc_handler = proc_dointvec_minmax,
1007 .extra1 = &zero,
1008 .extra2 = &two,
1011 .procname = "oom_kill_allocating_task",
1012 .data = &sysctl_oom_kill_allocating_task,
1013 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1014 .mode = 0644,
1015 .proc_handler = proc_dointvec,
1018 .procname = "oom_dump_tasks",
1019 .data = &sysctl_oom_dump_tasks,
1020 .maxlen = sizeof(sysctl_oom_dump_tasks),
1021 .mode = 0644,
1022 .proc_handler = proc_dointvec,
1025 .procname = "overcommit_ratio",
1026 .data = &sysctl_overcommit_ratio,
1027 .maxlen = sizeof(sysctl_overcommit_ratio),
1028 .mode = 0644,
1029 .proc_handler = proc_dointvec,
1032 .procname = "page-cluster",
1033 .data = &page_cluster,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
1036 .proc_handler = proc_dointvec_minmax,
1037 .extra1 = &zero,
1040 .procname = "dirty_background_ratio",
1041 .data = &dirty_background_ratio,
1042 .maxlen = sizeof(dirty_background_ratio),
1043 .mode = 0644,
1044 .proc_handler = dirty_background_ratio_handler,
1045 .extra1 = &zero,
1046 .extra2 = &one_hundred,
1049 .procname = "dirty_background_bytes",
1050 .data = &dirty_background_bytes,
1051 .maxlen = sizeof(dirty_background_bytes),
1052 .mode = 0644,
1053 .proc_handler = dirty_background_bytes_handler,
1054 .extra1 = &one_ul,
1057 .procname = "dirty_ratio",
1058 .data = &vm_dirty_ratio,
1059 .maxlen = sizeof(vm_dirty_ratio),
1060 .mode = 0644,
1061 .proc_handler = dirty_ratio_handler,
1062 .extra1 = &zero,
1063 .extra2 = &one_hundred,
1066 .procname = "dirty_bytes",
1067 .data = &vm_dirty_bytes,
1068 .maxlen = sizeof(vm_dirty_bytes),
1069 .mode = 0644,
1070 .proc_handler = dirty_bytes_handler,
1071 .extra1 = &dirty_bytes_min,
1074 .procname = "dirty_writeback_centisecs",
1075 .data = &dirty_writeback_interval,
1076 .maxlen = sizeof(dirty_writeback_interval),
1077 .mode = 0644,
1078 .proc_handler = dirty_writeback_centisecs_handler,
1081 .procname = "dirty_expire_centisecs",
1082 .data = &dirty_expire_interval,
1083 .maxlen = sizeof(dirty_expire_interval),
1084 .mode = 0644,
1085 .proc_handler = proc_dointvec_minmax,
1086 .extra1 = &zero,
1089 .procname = "nr_pdflush_threads",
1090 .data = &nr_pdflush_threads,
1091 .maxlen = sizeof nr_pdflush_threads,
1092 .mode = 0444 /* read-only*/,
1093 .proc_handler = proc_dointvec,
1096 .procname = "swappiness",
1097 .data = &vm_swappiness,
1098 .maxlen = sizeof(vm_swappiness),
1099 .mode = 0644,
1100 .proc_handler = proc_dointvec_minmax,
1101 .extra1 = &zero,
1102 .extra2 = &one_hundred,
1104 #ifdef CONFIG_HUGETLB_PAGE
1106 .procname = "nr_hugepages",
1107 .data = NULL,
1108 .maxlen = sizeof(unsigned long),
1109 .mode = 0644,
1110 .proc_handler = hugetlb_sysctl_handler,
1111 .extra1 = (void *)&hugetlb_zero,
1112 .extra2 = (void *)&hugetlb_infinity,
1114 #ifdef CONFIG_NUMA
1116 .procname = "nr_hugepages_mempolicy",
1117 .data = NULL,
1118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
1120 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1121 .extra1 = (void *)&hugetlb_zero,
1122 .extra2 = (void *)&hugetlb_infinity,
1124 #endif
1126 .procname = "hugetlb_shm_group",
1127 .data = &sysctl_hugetlb_shm_group,
1128 .maxlen = sizeof(gid_t),
1129 .mode = 0644,
1130 .proc_handler = proc_dointvec,
1133 .procname = "hugepages_treat_as_movable",
1134 .data = &hugepages_treat_as_movable,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = hugetlb_treat_movable_handler,
1140 .procname = "nr_overcommit_hugepages",
1141 .data = NULL,
1142 .maxlen = sizeof(unsigned long),
1143 .mode = 0644,
1144 .proc_handler = hugetlb_overcommit_handler,
1145 .extra1 = (void *)&hugetlb_zero,
1146 .extra2 = (void *)&hugetlb_infinity,
1148 #endif
1150 .procname = "lowmem_reserve_ratio",
1151 .data = &sysctl_lowmem_reserve_ratio,
1152 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1153 .mode = 0644,
1154 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1157 .procname = "drop_caches",
1158 .data = &sysctl_drop_caches,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = drop_caches_sysctl_handler,
1162 .extra1 = &one,
1163 .extra2 = &three,
1165 #ifdef CONFIG_COMPACTION
1167 .procname = "compact_memory",
1168 .data = &sysctl_compact_memory,
1169 .maxlen = sizeof(int),
1170 .mode = 0200,
1171 .proc_handler = sysctl_compaction_handler,
1174 .procname = "extfrag_threshold",
1175 .data = &sysctl_extfrag_threshold,
1176 .maxlen = sizeof(int),
1177 .mode = 0644,
1178 .proc_handler = sysctl_extfrag_handler,
1179 .extra1 = &min_extfrag_threshold,
1180 .extra2 = &max_extfrag_threshold,
1183 #endif /* CONFIG_COMPACTION */
1185 .procname = "min_free_kbytes",
1186 .data = &min_free_kbytes,
1187 .maxlen = sizeof(min_free_kbytes),
1188 .mode = 0644,
1189 .proc_handler = min_free_kbytes_sysctl_handler,
1190 .extra1 = &zero,
1193 .procname = "min_free_order_shift",
1194 .data = &min_free_order_shift,
1195 .maxlen = sizeof(min_free_order_shift),
1196 .mode = 0644,
1197 .proc_handler = &proc_dointvec
1200 .procname = "percpu_pagelist_fraction",
1201 .data = &percpu_pagelist_fraction,
1202 .maxlen = sizeof(percpu_pagelist_fraction),
1203 .mode = 0644,
1204 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1205 .extra1 = &min_percpu_pagelist_fract,
1207 #ifdef CONFIG_MMU
1209 .procname = "max_map_count",
1210 .data = &sysctl_max_map_count,
1211 .maxlen = sizeof(sysctl_max_map_count),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec_minmax,
1214 .extra1 = &zero,
1216 #else
1218 .procname = "nr_trim_pages",
1219 .data = &sysctl_nr_trim_pages,
1220 .maxlen = sizeof(sysctl_nr_trim_pages),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec_minmax,
1223 .extra1 = &zero,
1225 #endif
1227 .procname = "laptop_mode",
1228 .data = &laptop_mode,
1229 .maxlen = sizeof(laptop_mode),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec_jiffies,
1234 .procname = "block_dump",
1235 .data = &block_dump,
1236 .maxlen = sizeof(block_dump),
1237 .mode = 0644,
1238 .proc_handler = proc_dointvec,
1239 .extra1 = &zero,
1242 .procname = "vfs_cache_pressure",
1243 .data = &sysctl_vfs_cache_pressure,
1244 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1245 .mode = 0644,
1246 .proc_handler = proc_dointvec,
1247 .extra1 = &zero,
1249 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1251 .procname = "legacy_va_layout",
1252 .data = &sysctl_legacy_va_layout,
1253 .maxlen = sizeof(sysctl_legacy_va_layout),
1254 .mode = 0644,
1255 .proc_handler = proc_dointvec,
1256 .extra1 = &zero,
1258 #endif
1259 #ifdef CONFIG_NUMA
1261 .procname = "zone_reclaim_mode",
1262 .data = &zone_reclaim_mode,
1263 .maxlen = sizeof(zone_reclaim_mode),
1264 .mode = 0644,
1265 .proc_handler = proc_dointvec,
1266 .extra1 = &zero,
1269 .procname = "min_unmapped_ratio",
1270 .data = &sysctl_min_unmapped_ratio,
1271 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1272 .mode = 0644,
1273 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1274 .extra1 = &zero,
1275 .extra2 = &one_hundred,
1278 .procname = "min_slab_ratio",
1279 .data = &sysctl_min_slab_ratio,
1280 .maxlen = sizeof(sysctl_min_slab_ratio),
1281 .mode = 0644,
1282 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1283 .extra1 = &zero,
1284 .extra2 = &one_hundred,
1286 #endif
1287 #ifdef CONFIG_SMP
1289 .procname = "stat_interval",
1290 .data = &sysctl_stat_interval,
1291 .maxlen = sizeof(sysctl_stat_interval),
1292 .mode = 0644,
1293 .proc_handler = proc_dointvec_jiffies,
1295 #endif
1296 #ifdef CONFIG_MMU
1298 .procname = "mmap_min_addr",
1299 .data = &dac_mmap_min_addr,
1300 .maxlen = sizeof(unsigned long),
1301 .mode = 0644,
1302 .proc_handler = mmap_min_addr_handler,
1304 #endif
1305 #ifdef CONFIG_NUMA
1307 .procname = "numa_zonelist_order",
1308 .data = &numa_zonelist_order,
1309 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1310 .mode = 0644,
1311 .proc_handler = numa_zonelist_order_handler,
1313 #endif
1314 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1315 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1317 .procname = "vdso_enabled",
1318 .data = &vdso_enabled,
1319 .maxlen = sizeof(vdso_enabled),
1320 .mode = 0644,
1321 .proc_handler = proc_dointvec,
1322 .extra1 = &zero,
1324 #endif
1325 #ifdef CONFIG_HIGHMEM
1327 .procname = "highmem_is_dirtyable",
1328 .data = &vm_highmem_is_dirtyable,
1329 .maxlen = sizeof(vm_highmem_is_dirtyable),
1330 .mode = 0644,
1331 .proc_handler = proc_dointvec_minmax,
1332 .extra1 = &zero,
1333 .extra2 = &one,
1335 #endif
1337 .procname = "scan_unevictable_pages",
1338 .data = &scan_unevictable_pages,
1339 .maxlen = sizeof(scan_unevictable_pages),
1340 .mode = 0644,
1341 .proc_handler = scan_unevictable_handler,
1343 #ifdef CONFIG_MEMORY_FAILURE
1345 .procname = "memory_failure_early_kill",
1346 .data = &sysctl_memory_failure_early_kill,
1347 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1348 .mode = 0644,
1349 .proc_handler = proc_dointvec_minmax,
1350 .extra1 = &zero,
1351 .extra2 = &one,
1354 .procname = "memory_failure_recovery",
1355 .data = &sysctl_memory_failure_recovery,
1356 .maxlen = sizeof(sysctl_memory_failure_recovery),
1357 .mode = 0644,
1358 .proc_handler = proc_dointvec_minmax,
1359 .extra1 = &zero,
1360 .extra2 = &one,
1362 #endif
1366 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1367 static struct ctl_table binfmt_misc_table[] = {
1370 #endif
1372 static struct ctl_table fs_table[] = {
1374 .procname = "inode-nr",
1375 .data = &inodes_stat,
1376 .maxlen = 2*sizeof(int),
1377 .mode = 0444,
1378 .proc_handler = proc_nr_inodes,
1381 .procname = "inode-state",
1382 .data = &inodes_stat,
1383 .maxlen = 7*sizeof(int),
1384 .mode = 0444,
1385 .proc_handler = proc_nr_inodes,
1388 .procname = "file-nr",
1389 .data = &files_stat,
1390 .maxlen = sizeof(files_stat),
1391 .mode = 0444,
1392 .proc_handler = proc_nr_files,
1395 .procname = "file-max",
1396 .data = &files_stat.max_files,
1397 .maxlen = sizeof(files_stat.max_files),
1398 .mode = 0644,
1399 .proc_handler = proc_doulongvec_minmax,
1402 .procname = "nr_open",
1403 .data = &sysctl_nr_open,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
1406 .proc_handler = proc_dointvec_minmax,
1407 .extra1 = &sysctl_nr_open_min,
1408 .extra2 = &sysctl_nr_open_max,
1411 .procname = "dentry-state",
1412 .data = &dentry_stat,
1413 .maxlen = 6*sizeof(int),
1414 .mode = 0444,
1415 .proc_handler = proc_nr_dentry,
1418 .procname = "overflowuid",
1419 .data = &fs_overflowuid,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = proc_dointvec_minmax,
1423 .extra1 = &minolduid,
1424 .extra2 = &maxolduid,
1427 .procname = "overflowgid",
1428 .data = &fs_overflowgid,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
1431 .proc_handler = proc_dointvec_minmax,
1432 .extra1 = &minolduid,
1433 .extra2 = &maxolduid,
1435 #ifdef CONFIG_FILE_LOCKING
1437 .procname = "leases-enable",
1438 .data = &leases_enable,
1439 .maxlen = sizeof(int),
1440 .mode = 0644,
1441 .proc_handler = proc_dointvec,
1443 #endif
1444 #ifdef CONFIG_DNOTIFY
1446 .procname = "dir-notify-enable",
1447 .data = &dir_notify_enable,
1448 .maxlen = sizeof(int),
1449 .mode = 0644,
1450 .proc_handler = proc_dointvec,
1452 #endif
1453 #ifdef CONFIG_MMU
1454 #ifdef CONFIG_FILE_LOCKING
1456 .procname = "lease-break-time",
1457 .data = &lease_break_time,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
1460 .proc_handler = proc_dointvec,
1462 #endif
1463 #ifdef CONFIG_AIO
1465 .procname = "aio-nr",
1466 .data = &aio_nr,
1467 .maxlen = sizeof(aio_nr),
1468 .mode = 0444,
1469 .proc_handler = proc_doulongvec_minmax,
1472 .procname = "aio-max-nr",
1473 .data = &aio_max_nr,
1474 .maxlen = sizeof(aio_max_nr),
1475 .mode = 0644,
1476 .proc_handler = proc_doulongvec_minmax,
1478 #endif /* CONFIG_AIO */
1479 #ifdef CONFIG_INOTIFY_USER
1481 .procname = "inotify",
1482 .mode = 0555,
1483 .child = inotify_table,
1485 #endif
1486 #ifdef CONFIG_EPOLL
1488 .procname = "epoll",
1489 .mode = 0555,
1490 .child = epoll_table,
1492 #endif
1493 #endif
1495 .procname = "suid_dumpable",
1496 .data = &suid_dumpable,
1497 .maxlen = sizeof(int),
1498 .mode = 0644,
1499 .proc_handler = proc_dointvec_minmax,
1500 .extra1 = &zero,
1501 .extra2 = &two,
1503 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1505 .procname = "binfmt_misc",
1506 .mode = 0555,
1507 .child = binfmt_misc_table,
1509 #endif
1511 .procname = "pipe-max-size",
1512 .data = &pipe_max_size,
1513 .maxlen = sizeof(int),
1514 .mode = 0644,
1515 .proc_handler = &pipe_proc_fn,
1516 .extra1 = &pipe_min_size,
1521 static struct ctl_table debug_table[] = {
1522 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1523 defined(CONFIG_S390) || defined(CONFIG_TILE)
1525 .procname = "exception-trace",
1526 .data = &show_unhandled_signals,
1527 .maxlen = sizeof(int),
1528 .mode = 0644,
1529 .proc_handler = proc_dointvec
1531 #endif
1532 #if defined(CONFIG_OPTPROBES)
1534 .procname = "kprobes-optimization",
1535 .data = &sysctl_kprobes_optimization,
1536 .maxlen = sizeof(int),
1537 .mode = 0644,
1538 .proc_handler = proc_kprobes_optimization_handler,
1539 .extra1 = &zero,
1540 .extra2 = &one,
1542 #endif
1546 static struct ctl_table dev_table[] = {
1550 static DEFINE_SPINLOCK(sysctl_lock);
1552 /* called under sysctl_lock */
1553 static int use_table(struct ctl_table_header *p)
1555 if (unlikely(p->unregistering))
1556 return 0;
1557 p->used++;
1558 return 1;
1561 /* called under sysctl_lock */
1562 static void unuse_table(struct ctl_table_header *p)
1564 if (!--p->used)
1565 if (unlikely(p->unregistering))
1566 complete(p->unregistering);
1569 /* called under sysctl_lock, will reacquire if has to wait */
1570 static void start_unregistering(struct ctl_table_header *p)
1573 * if p->used is 0, nobody will ever touch that entry again;
1574 * we'll eliminate all paths to it before dropping sysctl_lock
1576 if (unlikely(p->used)) {
1577 struct completion wait;
1578 init_completion(&wait);
1579 p->unregistering = &wait;
1580 spin_unlock(&sysctl_lock);
1581 wait_for_completion(&wait);
1582 spin_lock(&sysctl_lock);
1583 } else {
1584 /* anything non-NULL; we'll never dereference it */
1585 p->unregistering = ERR_PTR(-EINVAL);
1588 * do not remove from the list until nobody holds it; walking the
1589 * list in do_sysctl() relies on that.
1591 list_del_init(&p->ctl_entry);
1594 void sysctl_head_get(struct ctl_table_header *head)
1596 spin_lock(&sysctl_lock);
1597 head->count++;
1598 spin_unlock(&sysctl_lock);
1601 static void free_head(struct rcu_head *rcu)
1603 kfree(container_of(rcu, struct ctl_table_header, rcu));
1606 void sysctl_head_put(struct ctl_table_header *head)
1608 spin_lock(&sysctl_lock);
1609 if (!--head->count)
1610 call_rcu(&head->rcu, free_head);
1611 spin_unlock(&sysctl_lock);
1614 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1616 if (!head)
1617 BUG();
1618 spin_lock(&sysctl_lock);
1619 if (!use_table(head))
1620 head = ERR_PTR(-ENOENT);
1621 spin_unlock(&sysctl_lock);
1622 return head;
1625 void sysctl_head_finish(struct ctl_table_header *head)
1627 if (!head)
1628 return;
1629 spin_lock(&sysctl_lock);
1630 unuse_table(head);
1631 spin_unlock(&sysctl_lock);
1634 static struct ctl_table_set *
1635 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1637 struct ctl_table_set *set = &root->default_set;
1638 if (root->lookup)
1639 set = root->lookup(root, namespaces);
1640 return set;
1643 static struct list_head *
1644 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1646 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1647 return &set->list;
1650 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1651 struct ctl_table_header *prev)
1653 struct ctl_table_root *root;
1654 struct list_head *header_list;
1655 struct ctl_table_header *head;
1656 struct list_head *tmp;
1658 spin_lock(&sysctl_lock);
1659 if (prev) {
1660 head = prev;
1661 tmp = &prev->ctl_entry;
1662 unuse_table(prev);
1663 goto next;
1665 tmp = &root_table_header.ctl_entry;
1666 for (;;) {
1667 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1669 if (!use_table(head))
1670 goto next;
1671 spin_unlock(&sysctl_lock);
1672 return head;
1673 next:
1674 root = head->root;
1675 tmp = tmp->next;
1676 header_list = lookup_header_list(root, namespaces);
1677 if (tmp != header_list)
1678 continue;
1680 do {
1681 root = list_entry(root->root_list.next,
1682 struct ctl_table_root, root_list);
1683 if (root == &sysctl_table_root)
1684 goto out;
1685 header_list = lookup_header_list(root, namespaces);
1686 } while (list_empty(header_list));
1687 tmp = header_list->next;
1689 out:
1690 spin_unlock(&sysctl_lock);
1691 return NULL;
1694 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1696 return __sysctl_head_next(current->nsproxy, prev);
1699 void register_sysctl_root(struct ctl_table_root *root)
1701 spin_lock(&sysctl_lock);
1702 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1703 spin_unlock(&sysctl_lock);
1707 * sysctl_perm does NOT grant the superuser all rights automatically, because
1708 * some sysctl variables are readonly even to root.
1711 static int test_perm(int mode, int op)
1713 if (!current_euid())
1714 mode >>= 6;
1715 else if (in_egroup_p(0))
1716 mode >>= 3;
1717 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1718 return 0;
1719 return -EACCES;
1722 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1724 int mode;
1726 if (root->permissions)
1727 mode = root->permissions(root, current->nsproxy, table);
1728 else
1729 mode = table->mode;
1731 return test_perm(mode, op);
1734 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1736 for (; table->procname; table++) {
1737 table->parent = parent;
1738 if (table->child)
1739 sysctl_set_parent(table, table->child);
1743 static __init int sysctl_init(void)
1745 sysctl_set_parent(NULL, root_table);
1746 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1747 sysctl_check_table(current->nsproxy, root_table);
1748 #endif
1749 return 0;
1752 core_initcall(sysctl_init);
1754 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1755 struct ctl_table *table)
1757 struct ctl_table *p;
1758 const char *s = branch->procname;
1760 /* branch should have named subdirectory as its first element */
1761 if (!s || !branch->child)
1762 return NULL;
1764 /* ... and nothing else */
1765 if (branch[1].procname)
1766 return NULL;
1768 /* table should contain subdirectory with the same name */
1769 for (p = table; p->procname; p++) {
1770 if (!p->child)
1771 continue;
1772 if (p->procname && strcmp(p->procname, s) == 0)
1773 return p;
1775 return NULL;
1778 /* see if attaching q to p would be an improvement */
1779 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1781 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1782 struct ctl_table *next;
1783 int is_better = 0;
1784 int not_in_parent = !p->attached_by;
1786 while ((next = is_branch_in(by, to)) != NULL) {
1787 if (by == q->attached_by)
1788 is_better = 1;
1789 if (to == p->attached_by)
1790 not_in_parent = 1;
1791 by = by->child;
1792 to = next->child;
1795 if (is_better && not_in_parent) {
1796 q->attached_by = by;
1797 q->attached_to = to;
1798 q->parent = p;
1803 * __register_sysctl_paths - register a sysctl hierarchy
1804 * @root: List of sysctl headers to register on
1805 * @namespaces: Data to compute which lists of sysctl entries are visible
1806 * @path: The path to the directory the sysctl table is in.
1807 * @table: the top-level table structure
1809 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1810 * array. A completely 0 filled entry terminates the table.
1812 * The members of the &struct ctl_table structure are used as follows:
1814 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1815 * enter a sysctl file
1817 * data - a pointer to data for use by proc_handler
1819 * maxlen - the maximum size in bytes of the data
1821 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1823 * child - a pointer to the child sysctl table if this entry is a directory, or
1824 * %NULL.
1826 * proc_handler - the text handler routine (described below)
1828 * de - for internal use by the sysctl routines
1830 * extra1, extra2 - extra pointers usable by the proc handler routines
1832 * Leaf nodes in the sysctl tree will be represented by a single file
1833 * under /proc; non-leaf nodes will be represented by directories.
1835 * sysctl(2) can automatically manage read and write requests through
1836 * the sysctl table. The data and maxlen fields of the ctl_table
1837 * struct enable minimal validation of the values being written to be
1838 * performed, and the mode field allows minimal authentication.
1840 * There must be a proc_handler routine for any terminal nodes
1841 * mirrored under /proc/sys (non-terminals are handled by a built-in
1842 * directory handler). Several default handlers are available to
1843 * cover common cases -
1845 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1846 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1847 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1849 * It is the handler's job to read the input buffer from user memory
1850 * and process it. The handler should return 0 on success.
1852 * This routine returns %NULL on a failure to register, and a pointer
1853 * to the table header on success.
1855 struct ctl_table_header *__register_sysctl_paths(
1856 struct ctl_table_root *root,
1857 struct nsproxy *namespaces,
1858 const struct ctl_path *path, struct ctl_table *table)
1860 struct ctl_table_header *header;
1861 struct ctl_table *new, **prevp;
1862 unsigned int n, npath;
1863 struct ctl_table_set *set;
1865 /* Count the path components */
1866 for (npath = 0; path[npath].procname; ++npath)
1870 * For each path component, allocate a 2-element ctl_table array.
1871 * The first array element will be filled with the sysctl entry
1872 * for this, the second will be the sentinel (procname == 0).
1874 * We allocate everything in one go so that we don't have to
1875 * worry about freeing additional memory in unregister_sysctl_table.
1877 header = kzalloc(sizeof(struct ctl_table_header) +
1878 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1879 if (!header)
1880 return NULL;
1882 new = (struct ctl_table *) (header + 1);
1884 /* Now connect the dots */
1885 prevp = &header->ctl_table;
1886 for (n = 0; n < npath; ++n, ++path) {
1887 /* Copy the procname */
1888 new->procname = path->procname;
1889 new->mode = 0555;
1891 *prevp = new;
1892 prevp = &new->child;
1894 new += 2;
1896 *prevp = table;
1897 header->ctl_table_arg = table;
1899 INIT_LIST_HEAD(&header->ctl_entry);
1900 header->used = 0;
1901 header->unregistering = NULL;
1902 header->root = root;
1903 sysctl_set_parent(NULL, header->ctl_table);
1904 header->count = 1;
1905 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1906 if (sysctl_check_table(namespaces, header->ctl_table)) {
1907 kfree(header);
1908 return NULL;
1910 #endif
1911 spin_lock(&sysctl_lock);
1912 header->set = lookup_header_set(root, namespaces);
1913 header->attached_by = header->ctl_table;
1914 header->attached_to = root_table;
1915 header->parent = &root_table_header;
1916 for (set = header->set; set; set = set->parent) {
1917 struct ctl_table_header *p;
1918 list_for_each_entry(p, &set->list, ctl_entry) {
1919 if (p->unregistering)
1920 continue;
1921 try_attach(p, header);
1924 header->parent->count++;
1925 list_add_tail(&header->ctl_entry, &header->set->list);
1926 spin_unlock(&sysctl_lock);
1928 return header;
1932 * register_sysctl_table_path - register a sysctl table hierarchy
1933 * @path: The path to the directory the sysctl table is in.
1934 * @table: the top-level table structure
1936 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1937 * array. A completely 0 filled entry terminates the table.
1939 * See __register_sysctl_paths for more details.
1941 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1942 struct ctl_table *table)
1944 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1945 path, table);
1949 * register_sysctl_table - register a sysctl table hierarchy
1950 * @table: the top-level table structure
1952 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1953 * array. A completely 0 filled entry terminates the table.
1955 * See register_sysctl_paths for more details.
1957 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1959 static const struct ctl_path null_path[] = { {} };
1961 return register_sysctl_paths(null_path, table);
1965 * unregister_sysctl_table - unregister a sysctl table hierarchy
1966 * @header: the header returned from register_sysctl_table
1968 * Unregisters the sysctl table and all children. proc entries may not
1969 * actually be removed until they are no longer used by anyone.
1971 void unregister_sysctl_table(struct ctl_table_header * header)
1973 might_sleep();
1975 if (header == NULL)
1976 return;
1978 spin_lock(&sysctl_lock);
1979 start_unregistering(header);
1980 if (!--header->parent->count) {
1981 WARN_ON(1);
1982 call_rcu(&header->parent->rcu, free_head);
1984 if (!--header->count)
1985 call_rcu(&header->rcu, free_head);
1986 spin_unlock(&sysctl_lock);
1989 int sysctl_is_seen(struct ctl_table_header *p)
1991 struct ctl_table_set *set = p->set;
1992 int res;
1993 spin_lock(&sysctl_lock);
1994 if (p->unregistering)
1995 res = 0;
1996 else if (!set->is_seen)
1997 res = 1;
1998 else
1999 res = set->is_seen(set);
2000 spin_unlock(&sysctl_lock);
2001 return res;
2004 void setup_sysctl_set(struct ctl_table_set *p,
2005 struct ctl_table_set *parent,
2006 int (*is_seen)(struct ctl_table_set *))
2008 INIT_LIST_HEAD(&p->list);
2009 p->parent = parent ? parent : &sysctl_table_root.default_set;
2010 p->is_seen = is_seen;
2013 #else /* !CONFIG_SYSCTL */
2014 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2016 return NULL;
2019 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2020 struct ctl_table *table)
2022 return NULL;
2025 void unregister_sysctl_table(struct ctl_table_header * table)
2029 void setup_sysctl_set(struct ctl_table_set *p,
2030 struct ctl_table_set *parent,
2031 int (*is_seen)(struct ctl_table_set *))
2035 void sysctl_head_put(struct ctl_table_header *head)
2039 #endif /* CONFIG_SYSCTL */
2042 * /proc/sys support
2045 #ifdef CONFIG_PROC_SYSCTL
2047 static int _proc_do_string(void* data, int maxlen, int write,
2048 void __user *buffer,
2049 size_t *lenp, loff_t *ppos)
2051 size_t len;
2052 char __user *p;
2053 char c;
2055 if (!data || !maxlen || !*lenp) {
2056 *lenp = 0;
2057 return 0;
2060 if (write) {
2061 len = 0;
2062 p = buffer;
2063 while (len < *lenp) {
2064 if (get_user(c, p++))
2065 return -EFAULT;
2066 if (c == 0 || c == '\n')
2067 break;
2068 len++;
2070 if (len >= maxlen)
2071 len = maxlen-1;
2072 if(copy_from_user(data, buffer, len))
2073 return -EFAULT;
2074 ((char *) data)[len] = 0;
2075 *ppos += *lenp;
2076 } else {
2077 len = strlen(data);
2078 if (len > maxlen)
2079 len = maxlen;
2081 if (*ppos > len) {
2082 *lenp = 0;
2083 return 0;
2086 data += *ppos;
2087 len -= *ppos;
2089 if (len > *lenp)
2090 len = *lenp;
2091 if (len)
2092 if(copy_to_user(buffer, data, len))
2093 return -EFAULT;
2094 if (len < *lenp) {
2095 if(put_user('\n', ((char __user *) buffer) + len))
2096 return -EFAULT;
2097 len++;
2099 *lenp = len;
2100 *ppos += len;
2102 return 0;
2106 * proc_dostring - read a string sysctl
2107 * @table: the sysctl table
2108 * @write: %TRUE if this is a write to the sysctl file
2109 * @buffer: the user buffer
2110 * @lenp: the size of the user buffer
2111 * @ppos: file position
2113 * Reads/writes a string from/to the user buffer. If the kernel
2114 * buffer provided is not large enough to hold the string, the
2115 * string is truncated. The copied string is %NULL-terminated.
2116 * If the string is being read by the user process, it is copied
2117 * and a newline '\n' is added. It is truncated if the buffer is
2118 * not large enough.
2120 * Returns 0 on success.
2122 int proc_dostring(struct ctl_table *table, int write,
2123 void __user *buffer, size_t *lenp, loff_t *ppos)
2125 return _proc_do_string(table->data, table->maxlen, write,
2126 buffer, lenp, ppos);
2129 static size_t proc_skip_spaces(char **buf)
2131 size_t ret;
2132 char *tmp = skip_spaces(*buf);
2133 ret = tmp - *buf;
2134 *buf = tmp;
2135 return ret;
2138 static void proc_skip_char(char **buf, size_t *size, const char v)
2140 while (*size) {
2141 if (**buf != v)
2142 break;
2143 (*size)--;
2144 (*buf)++;
2148 #define TMPBUFLEN 22
2150 * proc_get_long - reads an ASCII formatted integer from a user buffer
2152 * @buf: a kernel buffer
2153 * @size: size of the kernel buffer
2154 * @val: this is where the number will be stored
2155 * @neg: set to %TRUE if number is negative
2156 * @perm_tr: a vector which contains the allowed trailers
2157 * @perm_tr_len: size of the perm_tr vector
2158 * @tr: pointer to store the trailer character
2160 * In case of success %0 is returned and @buf and @size are updated with
2161 * the amount of bytes read. If @tr is non-NULL and a trailing
2162 * character exists (size is non-zero after returning from this
2163 * function), @tr is updated with the trailing character.
2165 static int proc_get_long(char **buf, size_t *size,
2166 unsigned long *val, bool *neg,
2167 const char *perm_tr, unsigned perm_tr_len, char *tr)
2169 int len;
2170 char *p, tmp[TMPBUFLEN];
2172 if (!*size)
2173 return -EINVAL;
2175 len = *size;
2176 if (len > TMPBUFLEN - 1)
2177 len = TMPBUFLEN - 1;
2179 memcpy(tmp, *buf, len);
2181 tmp[len] = 0;
2182 p = tmp;
2183 if (*p == '-' && *size > 1) {
2184 *neg = true;
2185 p++;
2186 } else
2187 *neg = false;
2188 if (!isdigit(*p))
2189 return -EINVAL;
2191 *val = simple_strtoul(p, &p, 0);
2193 len = p - tmp;
2195 /* We don't know if the next char is whitespace thus we may accept
2196 * invalid integers (e.g. 1234...a) or two integers instead of one
2197 * (e.g. 123...1). So lets not allow such large numbers. */
2198 if (len == TMPBUFLEN - 1)
2199 return -EINVAL;
2201 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2202 return -EINVAL;
2204 if (tr && (len < *size))
2205 *tr = *p;
2207 *buf += len;
2208 *size -= len;
2210 return 0;
2214 * proc_put_long - converts an integer to a decimal ASCII formatted string
2216 * @buf: the user buffer
2217 * @size: the size of the user buffer
2218 * @val: the integer to be converted
2219 * @neg: sign of the number, %TRUE for negative
2221 * In case of success %0 is returned and @buf and @size are updated with
2222 * the amount of bytes written.
2224 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2225 bool neg)
2227 int len;
2228 char tmp[TMPBUFLEN], *p = tmp;
2230 sprintf(p, "%s%lu", neg ? "-" : "", val);
2231 len = strlen(tmp);
2232 if (len > *size)
2233 len = *size;
2234 if (copy_to_user(*buf, tmp, len))
2235 return -EFAULT;
2236 *size -= len;
2237 *buf += len;
2238 return 0;
2240 #undef TMPBUFLEN
2242 static int proc_put_char(void __user **buf, size_t *size, char c)
2244 if (*size) {
2245 char __user **buffer = (char __user **)buf;
2246 if (put_user(c, *buffer))
2247 return -EFAULT;
2248 (*size)--, (*buffer)++;
2249 *buf = *buffer;
2251 return 0;
2254 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2255 int *valp,
2256 int write, void *data)
2258 if (write) {
2259 *valp = *negp ? -*lvalp : *lvalp;
2260 } else {
2261 int val = *valp;
2262 if (val < 0) {
2263 *negp = true;
2264 *lvalp = (unsigned long)-val;
2265 } else {
2266 *negp = false;
2267 *lvalp = (unsigned long)val;
2270 return 0;
2273 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2275 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2276 int write, void __user *buffer,
2277 size_t *lenp, loff_t *ppos,
2278 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2279 int write, void *data),
2280 void *data)
2282 int *i, vleft, first = 1, err = 0;
2283 unsigned long page = 0;
2284 size_t left;
2285 char *kbuf;
2287 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2288 *lenp = 0;
2289 return 0;
2292 i = (int *) tbl_data;
2293 vleft = table->maxlen / sizeof(*i);
2294 left = *lenp;
2296 if (!conv)
2297 conv = do_proc_dointvec_conv;
2299 if (write) {
2300 if (left > PAGE_SIZE - 1)
2301 left = PAGE_SIZE - 1;
2302 page = __get_free_page(GFP_TEMPORARY);
2303 kbuf = (char *) page;
2304 if (!kbuf)
2305 return -ENOMEM;
2306 if (copy_from_user(kbuf, buffer, left)) {
2307 err = -EFAULT;
2308 goto free;
2310 kbuf[left] = 0;
2313 for (; left && vleft--; i++, first=0) {
2314 unsigned long lval;
2315 bool neg;
2317 if (write) {
2318 left -= proc_skip_spaces(&kbuf);
2320 if (!left)
2321 break;
2322 err = proc_get_long(&kbuf, &left, &lval, &neg,
2323 proc_wspace_sep,
2324 sizeof(proc_wspace_sep), NULL);
2325 if (err)
2326 break;
2327 if (conv(&neg, &lval, i, 1, data)) {
2328 err = -EINVAL;
2329 break;
2331 } else {
2332 if (conv(&neg, &lval, i, 0, data)) {
2333 err = -EINVAL;
2334 break;
2336 if (!first)
2337 err = proc_put_char(&buffer, &left, '\t');
2338 if (err)
2339 break;
2340 err = proc_put_long(&buffer, &left, lval, neg);
2341 if (err)
2342 break;
2346 if (!write && !first && left && !err)
2347 err = proc_put_char(&buffer, &left, '\n');
2348 if (write && !err && left)
2349 left -= proc_skip_spaces(&kbuf);
2350 free:
2351 if (write) {
2352 free_page(page);
2353 if (first)
2354 return err ? : -EINVAL;
2356 *lenp -= left;
2357 *ppos += *lenp;
2358 return err;
2361 static int do_proc_dointvec(struct ctl_table *table, int write,
2362 void __user *buffer, size_t *lenp, loff_t *ppos,
2363 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2364 int write, void *data),
2365 void *data)
2367 return __do_proc_dointvec(table->data, table, write,
2368 buffer, lenp, ppos, conv, data);
2372 * proc_dointvec - read a vector of integers
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2382 * Returns 0 on success.
2384 int proc_dointvec(struct ctl_table *table, int write,
2385 void __user *buffer, size_t *lenp, loff_t *ppos)
2387 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2388 NULL,NULL);
2392 * Taint values can only be increased
2393 * This means we can safely use a temporary.
2395 static int proc_taint(struct ctl_table *table, int write,
2396 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 struct ctl_table t;
2399 unsigned long tmptaint = get_taint();
2400 int err;
2402 if (write && !capable(CAP_SYS_ADMIN))
2403 return -EPERM;
2405 t = *table;
2406 t.data = &tmptaint;
2407 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2408 if (err < 0)
2409 return err;
2411 if (write) {
2413 * Poor man's atomic or. Not worth adding a primitive
2414 * to everyone's atomic.h for this
2416 int i;
2417 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2418 if ((tmptaint >> i) & 1)
2419 add_taint(i);
2423 return err;
2426 #ifdef CONFIG_PRINTK
2427 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2430 if (write && !capable(CAP_SYS_ADMIN))
2431 return -EPERM;
2433 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2435 #endif
2437 struct do_proc_dointvec_minmax_conv_param {
2438 int *min;
2439 int *max;
2442 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2443 int *valp,
2444 int write, void *data)
2446 struct do_proc_dointvec_minmax_conv_param *param = data;
2447 if (write) {
2448 int val = *negp ? -*lvalp : *lvalp;
2449 if ((param->min && *param->min > val) ||
2450 (param->max && *param->max < val))
2451 return -EINVAL;
2452 *valp = val;
2453 } else {
2454 int val = *valp;
2455 if (val < 0) {
2456 *negp = true;
2457 *lvalp = (unsigned long)-val;
2458 } else {
2459 *negp = false;
2460 *lvalp = (unsigned long)val;
2463 return 0;
2467 * proc_dointvec_minmax - read a vector of integers with min/max values
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2477 * This routine will ensure the values are within the range specified by
2478 * table->extra1 (min) and table->extra2 (max).
2480 * Returns 0 on success.
2482 int proc_dointvec_minmax(struct ctl_table *table, int write,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2485 struct do_proc_dointvec_minmax_conv_param param = {
2486 .min = (int *) table->extra1,
2487 .max = (int *) table->extra2,
2489 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2490 do_proc_dointvec_minmax_conv, &param);
2493 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2494 void __user *buffer,
2495 size_t *lenp, loff_t *ppos,
2496 unsigned long convmul,
2497 unsigned long convdiv)
2499 unsigned long *i, *min, *max;
2500 int vleft, first = 1, err = 0;
2501 unsigned long page = 0;
2502 size_t left;
2503 char *kbuf;
2505 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2506 *lenp = 0;
2507 return 0;
2510 i = (unsigned long *) data;
2511 min = (unsigned long *) table->extra1;
2512 max = (unsigned long *) table->extra2;
2513 vleft = table->maxlen / sizeof(unsigned long);
2514 left = *lenp;
2516 if (write) {
2517 if (left > PAGE_SIZE - 1)
2518 left = PAGE_SIZE - 1;
2519 page = __get_free_page(GFP_TEMPORARY);
2520 kbuf = (char *) page;
2521 if (!kbuf)
2522 return -ENOMEM;
2523 if (copy_from_user(kbuf, buffer, left)) {
2524 err = -EFAULT;
2525 goto free;
2527 kbuf[left] = 0;
2530 for (; left && vleft--; i++, first = 0) {
2531 unsigned long val;
2533 if (write) {
2534 bool neg;
2536 left -= proc_skip_spaces(&kbuf);
2538 err = proc_get_long(&kbuf, &left, &val, &neg,
2539 proc_wspace_sep,
2540 sizeof(proc_wspace_sep), NULL);
2541 if (err)
2542 break;
2543 if (neg)
2544 continue;
2545 if ((min && val < *min) || (max && val > *max))
2546 continue;
2547 *i = val;
2548 } else {
2549 val = convdiv * (*i) / convmul;
2550 if (!first)
2551 err = proc_put_char(&buffer, &left, '\t');
2552 err = proc_put_long(&buffer, &left, val, false);
2553 if (err)
2554 break;
2558 if (!write && !first && left && !err)
2559 err = proc_put_char(&buffer, &left, '\n');
2560 if (write && !err)
2561 left -= proc_skip_spaces(&kbuf);
2562 free:
2563 if (write) {
2564 free_page(page);
2565 if (first)
2566 return err ? : -EINVAL;
2568 *lenp -= left;
2569 *ppos += *lenp;
2570 return err;
2573 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2574 void __user *buffer,
2575 size_t *lenp, loff_t *ppos,
2576 unsigned long convmul,
2577 unsigned long convdiv)
2579 return __do_proc_doulongvec_minmax(table->data, table, write,
2580 buffer, lenp, ppos, convmul, convdiv);
2584 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
2587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
2589 * @ppos: file position
2591 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2592 * values from/to the user buffer, treated as an ASCII string.
2594 * This routine will ensure the values are within the range specified by
2595 * table->extra1 (min) and table->extra2 (max).
2597 * Returns 0 on success.
2599 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2600 void __user *buffer, size_t *lenp, loff_t *ppos)
2602 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2606 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
2609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
2611 * @ppos: file position
2613 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2614 * values from/to the user buffer, treated as an ASCII string. The values
2615 * are treated as milliseconds, and converted to jiffies when they are stored.
2617 * This routine will ensure the values are within the range specified by
2618 * table->extra1 (min) and table->extra2 (max).
2620 * Returns 0 on success.
2622 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2623 void __user *buffer,
2624 size_t *lenp, loff_t *ppos)
2626 return do_proc_doulongvec_minmax(table, write, buffer,
2627 lenp, ppos, HZ, 1000l);
2631 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2632 int *valp,
2633 int write, void *data)
2635 if (write) {
2636 if (*lvalp > LONG_MAX / HZ)
2637 return 1;
2638 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2639 } else {
2640 int val = *valp;
2641 unsigned long lval;
2642 if (val < 0) {
2643 *negp = true;
2644 lval = (unsigned long)-val;
2645 } else {
2646 *negp = false;
2647 lval = (unsigned long)val;
2649 *lvalp = lval / HZ;
2651 return 0;
2654 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2655 int *valp,
2656 int write, void *data)
2658 if (write) {
2659 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2660 return 1;
2661 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2662 } else {
2663 int val = *valp;
2664 unsigned long lval;
2665 if (val < 0) {
2666 *negp = true;
2667 lval = (unsigned long)-val;
2668 } else {
2669 *negp = false;
2670 lval = (unsigned long)val;
2672 *lvalp = jiffies_to_clock_t(lval);
2674 return 0;
2677 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2678 int *valp,
2679 int write, void *data)
2681 if (write) {
2682 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2683 } else {
2684 int val = *valp;
2685 unsigned long lval;
2686 if (val < 0) {
2687 *negp = true;
2688 lval = (unsigned long)-val;
2689 } else {
2690 *negp = false;
2691 lval = (unsigned long)val;
2693 *lvalp = jiffies_to_msecs(lval);
2695 return 0;
2699 * proc_dointvec_jiffies - read a vector of integers as seconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
2702 * @buffer: the user buffer
2703 * @lenp: the size of the user buffer
2704 * @ppos: file position
2706 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2707 * values from/to the user buffer, treated as an ASCII string.
2708 * The values read are assumed to be in seconds, and are converted into
2709 * jiffies.
2711 * Returns 0 on success.
2713 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2714 void __user *buffer, size_t *lenp, loff_t *ppos)
2716 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2717 do_proc_dointvec_jiffies_conv,NULL);
2721 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2722 * @table: the sysctl table
2723 * @write: %TRUE if this is a write to the sysctl file
2724 * @buffer: the user buffer
2725 * @lenp: the size of the user buffer
2726 * @ppos: pointer to the file position
2728 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2729 * values from/to the user buffer, treated as an ASCII string.
2730 * The values read are assumed to be in 1/USER_HZ seconds, and
2731 * are converted into jiffies.
2733 * Returns 0 on success.
2735 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2736 void __user *buffer, size_t *lenp, loff_t *ppos)
2738 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2739 do_proc_dointvec_userhz_jiffies_conv,NULL);
2743 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2744 * @table: the sysctl table
2745 * @write: %TRUE if this is a write to the sysctl file
2746 * @buffer: the user buffer
2747 * @lenp: the size of the user buffer
2748 * @ppos: file position
2749 * @ppos: the current position in the file
2751 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2752 * values from/to the user buffer, treated as an ASCII string.
2753 * The values read are assumed to be in 1/1000 seconds, and
2754 * are converted into jiffies.
2756 * Returns 0 on success.
2758 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2759 void __user *buffer, size_t *lenp, loff_t *ppos)
2761 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2762 do_proc_dointvec_ms_jiffies_conv, NULL);
2765 static int proc_do_cad_pid(struct ctl_table *table, int write,
2766 void __user *buffer, size_t *lenp, loff_t *ppos)
2768 struct pid *new_pid;
2769 pid_t tmp;
2770 int r;
2772 tmp = pid_vnr(cad_pid);
2774 r = __do_proc_dointvec(&tmp, table, write, buffer,
2775 lenp, ppos, NULL, NULL);
2776 if (r || !write)
2777 return r;
2779 new_pid = find_get_pid(tmp);
2780 if (!new_pid)
2781 return -ESRCH;
2783 put_pid(xchg(&cad_pid, new_pid));
2784 return 0;
2788 * proc_do_large_bitmap - read/write from/to a large bitmap
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @buffer: the user buffer
2792 * @lenp: the size of the user buffer
2793 * @ppos: file position
2795 * The bitmap is stored at table->data and the bitmap length (in bits)
2796 * in table->maxlen.
2798 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2799 * large bitmaps may be represented in a compact manner. Writing into
2800 * the file will clear the bitmap then update it with the given input.
2802 * Returns 0 on success.
2804 int proc_do_large_bitmap(struct ctl_table *table, int write,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
2807 int err = 0;
2808 bool first = 1;
2809 size_t left = *lenp;
2810 unsigned long bitmap_len = table->maxlen;
2811 unsigned long *bitmap = (unsigned long *) table->data;
2812 unsigned long *tmp_bitmap = NULL;
2813 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2815 if (!bitmap_len || !left || (*ppos && !write)) {
2816 *lenp = 0;
2817 return 0;
2820 if (write) {
2821 unsigned long page = 0;
2822 char *kbuf;
2824 if (left > PAGE_SIZE - 1)
2825 left = PAGE_SIZE - 1;
2827 page = __get_free_page(GFP_TEMPORARY);
2828 kbuf = (char *) page;
2829 if (!kbuf)
2830 return -ENOMEM;
2831 if (copy_from_user(kbuf, buffer, left)) {
2832 free_page(page);
2833 return -EFAULT;
2835 kbuf[left] = 0;
2837 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2838 GFP_KERNEL);
2839 if (!tmp_bitmap) {
2840 free_page(page);
2841 return -ENOMEM;
2843 proc_skip_char(&kbuf, &left, '\n');
2844 while (!err && left) {
2845 unsigned long val_a, val_b;
2846 bool neg;
2848 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2849 sizeof(tr_a), &c);
2850 if (err)
2851 break;
2852 if (val_a >= bitmap_len || neg) {
2853 err = -EINVAL;
2854 break;
2857 val_b = val_a;
2858 if (left) {
2859 kbuf++;
2860 left--;
2863 if (c == '-') {
2864 err = proc_get_long(&kbuf, &left, &val_b,
2865 &neg, tr_b, sizeof(tr_b),
2866 &c);
2867 if (err)
2868 break;
2869 if (val_b >= bitmap_len || neg ||
2870 val_a > val_b) {
2871 err = -EINVAL;
2872 break;
2874 if (left) {
2875 kbuf++;
2876 left--;
2880 while (val_a <= val_b)
2881 set_bit(val_a++, tmp_bitmap);
2883 first = 0;
2884 proc_skip_char(&kbuf, &left, '\n');
2886 free_page(page);
2887 } else {
2888 unsigned long bit_a, bit_b = 0;
2890 while (left) {
2891 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2892 if (bit_a >= bitmap_len)
2893 break;
2894 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2895 bit_a + 1) - 1;
2897 if (!first) {
2898 err = proc_put_char(&buffer, &left, ',');
2899 if (err)
2900 break;
2902 err = proc_put_long(&buffer, &left, bit_a, false);
2903 if (err)
2904 break;
2905 if (bit_a != bit_b) {
2906 err = proc_put_char(&buffer, &left, '-');
2907 if (err)
2908 break;
2909 err = proc_put_long(&buffer, &left, bit_b, false);
2910 if (err)
2911 break;
2914 first = 0; bit_b++;
2916 if (!err)
2917 err = proc_put_char(&buffer, &left, '\n');
2920 if (!err) {
2921 if (write) {
2922 if (*ppos)
2923 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2924 else
2925 memcpy(bitmap, tmp_bitmap,
2926 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2928 kfree(tmp_bitmap);
2929 *lenp -= left;
2930 *ppos += *lenp;
2931 return 0;
2932 } else {
2933 kfree(tmp_bitmap);
2934 return err;
2938 #else /* CONFIG_PROC_SYSCTL */
2940 int proc_dostring(struct ctl_table *table, int write,
2941 void __user *buffer, size_t *lenp, loff_t *ppos)
2943 return -ENOSYS;
2946 int proc_dointvec(struct ctl_table *table, int write,
2947 void __user *buffer, size_t *lenp, loff_t *ppos)
2949 return -ENOSYS;
2952 int proc_dointvec_minmax(struct ctl_table *table, int write,
2953 void __user *buffer, size_t *lenp, loff_t *ppos)
2955 return -ENOSYS;
2958 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2959 void __user *buffer, size_t *lenp, loff_t *ppos)
2961 return -ENOSYS;
2964 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2965 void __user *buffer, size_t *lenp, loff_t *ppos)
2967 return -ENOSYS;
2970 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2971 void __user *buffer, size_t *lenp, loff_t *ppos)
2973 return -ENOSYS;
2976 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2977 void __user *buffer, size_t *lenp, loff_t *ppos)
2979 return -ENOSYS;
2982 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2983 void __user *buffer,
2984 size_t *lenp, loff_t *ppos)
2986 return -ENOSYS;
2990 #endif /* CONFIG_PROC_SYSCTL */
2993 * No sense putting this after each symbol definition, twice,
2994 * exception granted :-)
2996 EXPORT_SYMBOL(proc_dointvec);
2997 EXPORT_SYMBOL(proc_dointvec_jiffies);
2998 EXPORT_SYMBOL(proc_dointvec_minmax);
2999 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3000 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3001 EXPORT_SYMBOL(proc_dostring);
3002 EXPORT_SYMBOL(proc_doulongvec_minmax);
3003 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3004 EXPORT_SYMBOL(register_sysctl_table);
3005 EXPORT_SYMBOL(register_sysctl_paths);
3006 EXPORT_SYMBOL(unregister_sysctl_table);