blob: 6d850bf0a5178f3b6c5c435e89f6d6f2dfb8cfa5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070028#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070040#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070043#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/times.h>
45#include <linux/limits.h>
46#include <linux/dcache.h>
47#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070048#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080049#include <linux/nfs_fs.h>
50#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070051#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020052#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050054#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020055#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/uaccess.h>
58#include <asm/processor.h>
59
Andi Kleen29cbc782006-09-30 01:47:55 +020060#ifdef CONFIG_X86
61#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010062#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010063#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020064#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080065#ifdef CONFIG_BSD_PROCESS_ACCT
66#include <linux/acct.h>
67#endif
Dave Young4f0e0562010-03-10 15:24:09 -080068#ifdef CONFIG_RT_MUTEXES
69#include <linux/rtmutex.h>
70#endif
Dave Young2edf5e42010-03-10 15:24:10 -080071#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
72#include <linux/lockdep.h>
73#endif
Dave Young15485a42010-03-10 15:24:07 -080074#ifdef CONFIG_CHR_DEV_SG
75#include <scsi/sg.h>
76#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020077
Don Zickus58687ac2010-05-07 17:11:44 -040078#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050079#include <linux/nmi.h>
80#endif
81
Eric W. Biederman7058cb02007-10-18 03:05:58 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#if defined(CONFIG_SYSCTL)
84
85/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086extern int sysctl_overcommit_memory;
87extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070088extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070089extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080090extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080099extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800100extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200101extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100102extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400103extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000104#ifndef CONFIG_MMU
105extern int sysctl_nr_trim_pages;
106#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200107#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200108extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200114static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115#endif
116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700118static int __maybe_unused one = 1;
119static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800120static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700121static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700122#ifdef CONFIG_PRINTK
123static int ten_thousand = 10000;
124#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700126/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130static int maxolduid = 65535;
131static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800132static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static int ngroups_max = NGROUPS_MAX;
135
David S. Miller72c57ed2008-09-11 23:29:54 -0700136#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700137#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
David S. Miller08714202008-11-16 23:49:24 -0800140#ifdef CONFIG_SPARC64
141extern int sysctl_tsb_ratio;
142#endif
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef __hppa__
145extern int pwrsw_enabled;
146extern int unaligned_enabled;
147#endif
148
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800149#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#ifdef CONFIG_MATHEMU
151extern int sysctl_ieee_emulation_warnings;
152#endif
153extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700154extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#endif
156
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#ifdef CONFIG_IA64
158extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800159extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#endif
161
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200162extern struct ratelimit_state printk_ratelimit_state;
163
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700165static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800168 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700171#ifdef CONFIG_MAGIC_SYSRQ
172static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
173
174static int sysrq_sysctl_handler(ctl_table *table, int write,
175 void __user *buffer, size_t *lenp,
176 loff_t *ppos)
177{
178 int error;
179
180 error = proc_dointvec(table, write, buffer, lenp, ppos);
181 if (error)
182 return error;
183
184 if (write)
185 sysrq_toggle_support(__sysrq_enabled);
186
187 return 0;
188}
189
190#endif
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100193static struct ctl_table_root sysctl_table_root;
194static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100195 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400197 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100198 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400199 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200};
201static struct ctl_table_root sysctl_table_root = {
202 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400203 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700206static struct ctl_table kern_table[];
207static struct ctl_table vm_table[];
208static struct ctl_table fs_table[];
209static struct ctl_table debug_table[];
210static struct ctl_table dev_table[];
211extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700212#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700213extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400214#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800215#ifdef CONFIG_EPOLL
216extern struct ctl_table epoll_table[];
217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220int sysctl_legacy_va_layout;
221#endif
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223/* The default sysctl tables: */
224
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700225static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .procname = "kernel",
228 .mode = 0555,
229 .child = kern_table,
230 },
231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "vm",
233 .mode = 0555,
234 .child = vm_table,
235 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "fs",
238 .mode = 0555,
239 .child = fs_table,
240 },
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "debug",
243 .mode = 0555,
244 .child = debug_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "dev",
248 .mode = 0555,
249 .child = dev_table,
250 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700251/*
252 * NOTE: do not add new entries to this table unless you have read
253 * Documentation/sysctl/ctl_unnumbered.txt
254 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700255 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256};
257
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100259static int min_sched_granularity_ns = 100000; /* 100 usecs */
260static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261static int min_wakeup_granularity_ns; /* 0 usecs */
262static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100263static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100265static int min_sched_shares_ratelimit = 100000; /* 100 usec */
266static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267#endif
268
Mel Gorman5e771902010-05-24 14:32:31 -0700269#ifdef CONFIG_COMPACTION
270static int min_extfrag_threshold;
271static int max_extfrag_threshold = 1000;
272#endif
273
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700274static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800280 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282#ifdef CONFIG_SCHED_DEBUG
283 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800288 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291 },
292 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800297 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
300 },
301 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800306 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
309 },
310 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200311 .procname = "sched_shares_ratelimit",
312 .data = &sysctl_sched_shares_ratelimit,
313 .maxlen = sizeof(unsigned int),
314 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800315 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100316 .extra1 = &min_sched_shares_ratelimit,
317 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200318 },
319 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100320 .procname = "sched_tunable_scaling",
321 .data = &sysctl_sched_tunable_scaling,
322 .maxlen = sizeof(enum sched_tunable_scaling),
323 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800324 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100325 .extra1 = &min_sched_tunable_scaling,
326 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200327 },
328 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200329 .procname = "sched_shares_thresh",
330 .data = &sysctl_sched_shares_thresh,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200334 .extra1 = &zero,
335 },
336 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200337 .procname = "sched_migration_cost",
338 .data = &sysctl_sched_migration_cost,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800341 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200342 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100343 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100344 .procname = "sched_nr_migrate",
345 .data = &sysctl_sched_nr_migrate,
346 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100347 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800348 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100349 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530350 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200351 .procname = "sched_time_avg",
352 .data = &sysctl_sched_time_avg,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800355 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200356 },
357 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530358 .procname = "timer_migration",
359 .data = &sysctl_timer_migration,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800362 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530363 .extra1 = &zero,
364 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530365 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200366#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200367 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100368 .procname = "sched_rt_period_us",
369 .data = &sysctl_sched_rt_period,
370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800372 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100373 },
374 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100375 .procname = "sched_rt_runtime_us",
376 .data = &sysctl_sched_rt_runtime,
377 .maxlen = sizeof(int),
378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800379 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100380 },
381 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200382 .procname = "sched_compat_yield",
383 .data = &sysctl_sched_compat_yield,
384 .maxlen = sizeof(unsigned int),
385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800386 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200387 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700388#ifdef CONFIG_PROVE_LOCKING
389 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700390 .procname = "prove_locking",
391 .data = &prove_locking,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800394 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700395 },
396#endif
397#ifdef CONFIG_LOCK_STAT
398 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700399 .procname = "lock_stat",
400 .data = &lock_stat,
401 .maxlen = sizeof(int),
402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700404 },
405#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .procname = "panic",
408 .data = &panic_timeout,
409 .maxlen = sizeof(int),
410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800411 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 },
413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "core_uses_pid",
415 .data = &core_uses_pid,
416 .maxlen = sizeof(int),
417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800418 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 },
420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "core_pattern",
422 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700423 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800425 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
Neil Hormana2939802009-09-23 15:56:56 -0700427 {
Neil Hormana2939802009-09-23 15:56:56 -0700428 .procname = "core_pipe_limit",
429 .data = &core_pipe_limit,
430 .maxlen = sizeof(unsigned int),
431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800432 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700433 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800434#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700437 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800439 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800441#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100442#ifdef CONFIG_LATENCYTOP
443 {
444 .procname = "latencytop",
445 .data = &latencytop_enabled,
446 .maxlen = sizeof(int),
447 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800448 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100449 },
450#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#ifdef CONFIG_BLK_DEV_INITRD
452 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 .procname = "real-root-dev",
454 .data = &real_root_dev,
455 .maxlen = sizeof(int),
456 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800457 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 },
459#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700460 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700461 .procname = "print-fatal-signals",
462 .data = &print_fatal_signals,
463 .maxlen = sizeof(int),
464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800465 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700466 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700467#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "reboot-cmd",
470 .data = reboot_command,
471 .maxlen = 256,
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 },
475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .procname = "stop-a",
477 .data = &stop_a_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 },
482 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .procname = "scons-poweroff",
484 .data = &scons_pwroff,
485 .maxlen = sizeof (int),
486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800487 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 },
489#endif
David S. Miller08714202008-11-16 23:49:24 -0800490#ifdef CONFIG_SPARC64
491 {
David S. Miller08714202008-11-16 23:49:24 -0800492 .procname = "tsb-ratio",
493 .data = &sysctl_tsb_ratio,
494 .maxlen = sizeof (int),
495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800496 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800497 },
498#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#ifdef __hppa__
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800505 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "unaligned-trap",
509 .data = &unaligned_enabled,
510 .maxlen = sizeof (int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
514#endif
515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "ctrl-alt-del",
517 .data = &C_A_D,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400522#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200523 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200524 .procname = "ftrace_enabled",
525 .data = &ftrace_enabled,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800528 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200529 },
530#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500531#ifdef CONFIG_STACK_TRACER
532 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500533 .procname = "stack_tracer_enabled",
534 .data = &stack_tracer_enabled,
535 .maxlen = sizeof(int),
536 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800537 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500538 },
539#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400540#ifdef CONFIG_TRACING
541 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100542 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400543 .data = &ftrace_dump_on_oops,
544 .maxlen = sizeof(int),
545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800546 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400547 },
548#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200549#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 .procname = "modprobe",
552 .data = &modprobe_path,
553 .maxlen = KMOD_PATH_LEN,
554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 },
Kees Cook3d433212009-04-02 15:49:29 -0700557 {
Kees Cook3d433212009-04-02 15:49:29 -0700558 .procname = "modules_disabled",
559 .data = &modules_disabled,
560 .maxlen = sizeof(int),
561 .mode = 0644,
562 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800563 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700564 .extra1 = &one,
565 .extra2 = &one,
566 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100568#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100571 .data = &uevent_helper,
572 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
576#endif
577#ifdef CONFIG_CHR_DEV_SG
578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "sg-big-buff",
580 .data = &sg_big_buff,
581 .maxlen = sizeof (int),
582 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
586#ifdef CONFIG_BSD_PROCESS_ACCT
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "acct",
589 .data = &acct_parm,
590 .maxlen = 3*sizeof(int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#ifdef CONFIG_MAGIC_SYSRQ
596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800598 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .maxlen = sizeof (int),
600 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700601 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 },
603#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700604#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700607 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .maxlen = sizeof (int),
609 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700612#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "threads-max",
615 .data = &max_threads,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800618 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 },
620 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .procname = "random",
622 .mode = 0555,
623 .child = random_table,
624 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .procname = "overflowuid",
627 .data = &overflowuid,
628 .maxlen = sizeof(int),
629 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800630 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
633 },
634 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 .procname = "overflowgid",
636 .data = &overflowgid,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800639 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .extra1 = &minolduid,
641 .extra2 = &maxolduid,
642 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800643#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644#ifdef CONFIG_MATHEMU
645 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 .procname = "ieee_emulation_warnings",
647 .data = &sysctl_ieee_emulation_warnings,
648 .maxlen = sizeof(int),
649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800650 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 },
652#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200655 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .maxlen = sizeof(int),
657 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800658 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 },
660#endif
661 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .procname = "pid_max",
663 .data = &pid_max,
664 .maxlen = sizeof (int),
665 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800666 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .extra1 = &pid_max_min,
668 .extra2 = &pid_max_max,
669 },
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "panic_on_oops",
672 .data = &panic_on_oops,
673 .maxlen = sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800677#if defined CONFIG_PRINTK
678 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800679 .procname = "printk",
680 .data = &console_loglevel,
681 .maxlen = 4*sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800684 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700687 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700694 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .maxlen = sizeof(int),
696 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800697 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 },
Dave Youngaf913222009-09-22 16:43:33 -0700699 {
Dave Youngaf913222009-09-22 16:43:33 -0700700 .procname = "printk_delay",
701 .data = &printk_delay_msec,
702 .maxlen = sizeof(int),
703 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800704 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700705 .extra1 = &zero,
706 .extra2 = &ten_thousand,
707 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800708#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "ngroups_max",
711 .data = &ngroups_max,
712 .maxlen = sizeof (int),
713 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800714 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 },
Don Zickus58687ac2010-05-07 17:11:44 -0400716#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500717 {
Don Zickus58687ac2010-05-07 17:11:44 -0400718 .procname = "watchdog",
719 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500720 .maxlen = sizeof (int),
721 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400722 .proc_handler = proc_dowatchdog_enabled,
723 },
724 {
725 .procname = "watchdog_thresh",
726 .data = &softlockup_thresh,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = proc_dowatchdog_thresh,
730 .extra1 = &neg_one,
731 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500732 },
Don Zickus2508ce12010-05-07 17:11:46 -0400733 {
734 .procname = "softlockup_panic",
735 .data = &softlockup_panic,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = proc_dointvec_minmax,
739 .extra1 = &zero,
740 .extra2 = &one,
741 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500742#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400743#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .procname = "unknown_nmi_panic",
746 .data = &unknown_nmi_panic,
747 .maxlen = sizeof (int),
748 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800749 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 },
Don Zickus407984f2006-09-26 10:52:27 +0200751 {
Don Zickus407984f2006-09-26 10:52:27 +0200752 .procname = "nmi_watchdog",
753 .data = &nmi_watchdog_enabled,
754 .maxlen = sizeof (int),
755 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800756 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 },
758#endif
759#if defined(CONFIG_X86)
760 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200761 .procname = "panic_on_unrecovered_nmi",
762 .data = &panic_on_unrecovered_nmi,
763 .maxlen = sizeof(int),
764 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800765 .proc_handler = proc_dointvec,
Don Zickus8da5adda2006-09-26 10:52:27 +0200766 },
767 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700768 .procname = "panic_on_io_nmi",
769 .data = &panic_on_io_nmi,
770 .maxlen = sizeof(int),
771 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800772 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700773 },
774 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .procname = "bootloader_type",
776 .data = &bootloader_type,
777 .maxlen = sizeof (int),
778 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800779 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100781 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700782 .procname = "bootloader_version",
783 .data = &bootloader_version,
784 .maxlen = sizeof (int),
785 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800786 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700787 },
788 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100789 .procname = "kstack_depth_to_print",
790 .data = &kstack_depth_to_print,
791 .maxlen = sizeof(int),
792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800793 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100794 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100795 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100796 .procname = "io_delay_type",
797 .data = &io_delay_type,
798 .maxlen = sizeof(int),
799 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800800 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100801 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800803#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 .procname = "randomize_va_space",
806 .data = &randomize_va_space,
807 .maxlen = sizeof(int),
808 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800809 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800811#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800812#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700813 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700814 .procname = "spin_retry",
815 .data = &spin_retry,
816 .maxlen = sizeof (int),
817 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800818 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700819 },
820#endif
Len Brown673d5b42007-07-28 03:33:16 -0400821#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800822 {
Pavel Machekc255d842006-02-20 18:27:58 -0800823 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700824 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800825 .maxlen = sizeof (unsigned long),
826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800828 },
829#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800830#ifdef CONFIG_IA64
831 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800832 .procname = "ignore-unaligned-usertrap",
833 .data = &no_unaligned_warning,
834 .maxlen = sizeof (int),
835 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800836 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800837 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800838 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800839 .procname = "unaligned-dump-stack",
840 .data = &unaligned_dump_stack,
841 .maxlen = sizeof (int),
842 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800843 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800844 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800845#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800846#ifdef CONFIG_DETECT_HUNG_TASK
847 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800848 .procname = "hung_task_panic",
849 .data = &sysctl_hung_task_panic,
850 .maxlen = sizeof(int),
851 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800852 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800853 .extra1 = &zero,
854 .extra2 = &one,
855 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100857 .procname = "hung_task_check_count",
858 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100859 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100860 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800861 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100862 },
863 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100864 .procname = "hung_task_timeout_secs",
865 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100866 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100869 },
870 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100871 .procname = "hung_task_warnings",
872 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100873 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100874 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800875 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100876 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700877#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200878#ifdef CONFIG_COMPAT
879 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200880 .procname = "compat-log",
881 .data = &compat_log,
882 .maxlen = sizeof (int),
883 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200885 },
886#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700887#ifdef CONFIG_RT_MUTEXES
888 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700889 .procname = "max_lock_depth",
890 .data = &max_lock_depth,
891 .maxlen = sizeof(int),
892 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800893 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700894 },
895#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700896 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700897 .procname = "poweroff_cmd",
898 .data = &poweroff_cmd,
899 .maxlen = POWEROFF_CMD_PATH_LEN,
900 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800901 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700902 },
David Howells0b77f5b2008-04-29 01:01:32 -0700903#ifdef CONFIG_KEYS
904 {
David Howells0b77f5b2008-04-29 01:01:32 -0700905 .procname = "keys",
906 .mode = 0555,
907 .child = key_sysctls,
908 },
909#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700910#ifdef CONFIG_RCU_TORTURE_TEST
911 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700912 .procname = "rcutorture_runnable",
913 .data = &rcutorture_runnable,
914 .maxlen = sizeof(int),
915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700917 },
918#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200919#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200920 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200921 .procname = "perf_event_paranoid",
922 .data = &sysctl_perf_event_paranoid,
923 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200924 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800925 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200926 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200927 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200928 .procname = "perf_event_mlock_kb",
929 .data = &sysctl_perf_event_mlock,
930 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200931 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800932 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200933 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200934 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200935 .procname = "perf_event_max_sample_rate",
936 .data = &sysctl_perf_event_sample_rate,
937 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200938 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800939 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200940 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200941#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200942#ifdef CONFIG_KMEMCHECK
943 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200944 .procname = "kmemcheck",
945 .data = &kmemcheck_enabled,
946 .maxlen = sizeof(int),
947 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800948 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200949 },
950#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200951#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200952 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200953 .procname = "blk_iopoll",
954 .data = &blk_iopoll_enabled,
955 .maxlen = sizeof(int),
956 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800957 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200958 },
Jens Axboecb684b52009-09-15 21:53:11 +0200959#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700960/*
961 * NOTE: do not add new entries to this table unless you have read
962 * Documentation/sysctl/ctl_unnumbered.txt
963 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700964 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965};
966
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700967static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 .procname = "overcommit_memory",
970 .data = &sysctl_overcommit_memory,
971 .maxlen = sizeof(sysctl_overcommit_memory),
972 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800973 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 },
975 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700976 .procname = "panic_on_oom",
977 .data = &sysctl_panic_on_oom,
978 .maxlen = sizeof(sysctl_panic_on_oom),
979 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800980 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700981 },
982 {
David Rientjesfe071d72007-10-16 23:25:56 -0700983 .procname = "oom_kill_allocating_task",
984 .data = &sysctl_oom_kill_allocating_task,
985 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700988 },
989 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800990 .procname = "oom_dump_tasks",
991 .data = &sysctl_oom_dump_tasks,
992 .maxlen = sizeof(sysctl_oom_dump_tasks),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800995 },
996 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 .procname = "overcommit_ratio",
998 .data = &sysctl_overcommit_ratio,
999 .maxlen = sizeof(sysctl_overcommit_ratio),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 },
1003 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .procname = "page-cluster",
1005 .data = &page_cluster,
1006 .maxlen = sizeof(int),
1007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 },
1010 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 .procname = "dirty_background_ratio",
1012 .data = &dirty_background_ratio,
1013 .maxlen = sizeof(dirty_background_ratio),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .extra1 = &zero,
1017 .extra2 = &one_hundred,
1018 },
1019 {
David Rientjes2da02992009-01-06 14:39:31 -08001020 .procname = "dirty_background_bytes",
1021 .data = &dirty_background_bytes,
1022 .maxlen = sizeof(dirty_background_bytes),
1023 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001024 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001025 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001026 },
1027 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .procname = "dirty_ratio",
1029 .data = &vm_dirty_ratio,
1030 .maxlen = sizeof(vm_dirty_ratio),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .extra1 = &zero,
1034 .extra2 = &one_hundred,
1035 },
1036 {
David Rientjes2da02992009-01-06 14:39:31 -08001037 .procname = "dirty_bytes",
1038 .data = &vm_dirty_bytes,
1039 .maxlen = sizeof(vm_dirty_bytes),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001042 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001043 },
1044 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001046 .data = &dirty_writeback_interval,
1047 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 },
1051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001053 .data = &dirty_expire_interval,
1054 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .procname = "nr_pdflush_threads",
1060 .data = &nr_pdflush_threads,
1061 .maxlen = sizeof nr_pdflush_threads,
1062 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 },
1065 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .procname = "swappiness",
1067 .data = &vm_swappiness,
1068 .maxlen = sizeof(vm_swappiness),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .extra1 = &zero,
1072 .extra2 = &one_hundred,
1073 },
1074#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001077 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 .maxlen = sizeof(unsigned long),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001083 },
1084#ifdef CONFIG_NUMA
1085 {
1086 .procname = "nr_hugepages_mempolicy",
1087 .data = NULL,
1088 .maxlen = sizeof(unsigned long),
1089 .mode = 0644,
1090 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
1093 },
1094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .procname = "hugetlb_shm_group",
1097 .data = &sysctl_hugetlb_shm_group,
1098 .maxlen = sizeof(gid_t),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 },
Mel Gorman396faf02007-07-17 04:03:13 -07001102 {
Mel Gorman396faf02007-07-17 04:03:13 -07001103 .procname = "hugepages_treat_as_movable",
1104 .data = &hugepages_treat_as_movable,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001107 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001108 },
Adam Litke54f9f802007-10-16 01:26:20 -07001109 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001110 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001111 .data = NULL,
1112 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001115 .extra1 = (void *)&hugetlb_zero,
1116 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001117 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118#endif
1119 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 .procname = "lowmem_reserve_ratio",
1121 .data = &sysctl_lowmem_reserve_ratio,
1122 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1123 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001124 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 },
1126 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001127 .procname = "drop_caches",
1128 .data = &sysctl_drop_caches,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001132 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001133#ifdef CONFIG_COMPACTION
1134 {
1135 .procname = "compact_memory",
1136 .data = &sysctl_compact_memory,
1137 .maxlen = sizeof(int),
1138 .mode = 0200,
1139 .proc_handler = sysctl_compaction_handler,
1140 },
Mel Gorman5e771902010-05-24 14:32:31 -07001141 {
1142 .procname = "extfrag_threshold",
1143 .data = &sysctl_extfrag_threshold,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = sysctl_extfrag_handler,
1147 .extra1 = &min_extfrag_threshold,
1148 .extra2 = &max_extfrag_threshold,
1149 },
1150
Mel Gorman76ab0f52010-05-24 14:32:28 -07001151#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001152 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 .procname = "min_free_kbytes",
1154 .data = &min_free_kbytes,
1155 .maxlen = sizeof(min_free_kbytes),
1156 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001157 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 .extra1 = &zero,
1159 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001160 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001161 .procname = "percpu_pagelist_fraction",
1162 .data = &percpu_pagelist_fraction,
1163 .maxlen = sizeof(percpu_pagelist_fraction),
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001166 .extra1 = &min_percpu_pagelist_fract,
1167 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168#ifdef CONFIG_MMU
1169 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 .procname = "max_map_count",
1171 .data = &sysctl_max_map_count,
1172 .maxlen = sizeof(sysctl_max_map_count),
1173 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001174 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001175 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001177#else
1178 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001179 .procname = "nr_trim_pages",
1180 .data = &sysctl_nr_trim_pages,
1181 .maxlen = sizeof(sysctl_nr_trim_pages),
1182 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001183 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001184 .extra1 = &zero,
1185 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186#endif
1187 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 .procname = "laptop_mode",
1189 .data = &laptop_mode,
1190 .maxlen = sizeof(laptop_mode),
1191 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001192 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 },
1194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "block_dump",
1196 .data = &block_dump,
1197 .maxlen = sizeof(block_dump),
1198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001199 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .extra1 = &zero,
1201 },
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "vfs_cache_pressure",
1204 .data = &sysctl_vfs_cache_pressure,
1205 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .extra1 = &zero,
1209 },
1210#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .procname = "legacy_va_layout",
1213 .data = &sysctl_legacy_va_layout,
1214 .maxlen = sizeof(sysctl_legacy_va_layout),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .extra1 = &zero,
1218 },
1219#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001220#ifdef CONFIG_NUMA
1221 {
Christoph Lameter17436602006-01-18 17:42:32 -08001222 .procname = "zone_reclaim_mode",
1223 .data = &zone_reclaim_mode,
1224 .maxlen = sizeof(zone_reclaim_mode),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001227 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001228 },
Christoph Lameter96146342006-07-03 00:24:13 -07001229 {
Christoph Lameter96146342006-07-03 00:24:13 -07001230 .procname = "min_unmapped_ratio",
1231 .data = &sysctl_min_unmapped_ratio,
1232 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001235 .extra1 = &zero,
1236 .extra2 = &one_hundred,
1237 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001238 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001239 .procname = "min_slab_ratio",
1240 .data = &sysctl_min_slab_ratio,
1241 .maxlen = sizeof(sysctl_min_slab_ratio),
1242 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001243 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001244 .extra1 = &zero,
1245 .extra2 = &one_hundred,
1246 },
Christoph Lameter17436602006-01-18 17:42:32 -08001247#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001248#ifdef CONFIG_SMP
1249 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001250 .procname = "stat_interval",
1251 .data = &sysctl_stat_interval,
1252 .maxlen = sizeof(sysctl_stat_interval),
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001255 },
1256#endif
David Howells6e141542009-12-15 19:27:45 +00001257#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001258 {
Eric Parised032182007-06-28 15:55:21 -04001259 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001260 .data = &dac_mmap_min_addr,
1261 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001262 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001263 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001264 },
David Howells6e141542009-12-15 19:27:45 +00001265#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001266#ifdef CONFIG_NUMA
1267 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001268 .procname = "numa_zonelist_order",
1269 .data = &numa_zonelist_order,
1270 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001273 },
1274#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001275#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001276 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001277 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001278 .procname = "vdso_enabled",
1279 .data = &vdso_enabled,
1280 .maxlen = sizeof(vdso_enabled),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001283 .extra1 = &zero,
1284 },
1285#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001286#ifdef CONFIG_HIGHMEM
1287 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001288 .procname = "highmem_is_dirtyable",
1289 .data = &vm_highmem_is_dirtyable,
1290 .maxlen = sizeof(vm_highmem_is_dirtyable),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001293 .extra1 = &zero,
1294 .extra2 = &one,
1295 },
1296#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001297 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001298 .procname = "scan_unevictable_pages",
1299 .data = &scan_unevictable_pages,
1300 .maxlen = sizeof(scan_unevictable_pages),
1301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001303 },
Andi Kleen6a460792009-09-16 11:50:15 +02001304#ifdef CONFIG_MEMORY_FAILURE
1305 {
Andi Kleen6a460792009-09-16 11:50:15 +02001306 .procname = "memory_failure_early_kill",
1307 .data = &sysctl_memory_failure_early_kill,
1308 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001311 .extra1 = &zero,
1312 .extra2 = &one,
1313 },
1314 {
Andi Kleen6a460792009-09-16 11:50:15 +02001315 .procname = "memory_failure_recovery",
1316 .data = &sysctl_memory_failure_recovery,
1317 .maxlen = sizeof(sysctl_memory_failure_recovery),
1318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001319 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001320 .extra1 = &zero,
1321 .extra2 = &one,
1322 },
1323#endif
1324
Andrew Morton2be7fe02007-07-15 23:41:21 -07001325/*
1326 * NOTE: do not add new entries to this table unless you have read
1327 * Documentation/sysctl/ctl_unnumbered.txt
1328 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001329 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330};
1331
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001332#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001333static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001334 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001335};
1336#endif
1337
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001338static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 .procname = "inode-nr",
1341 .data = &inodes_stat,
1342 .maxlen = 2*sizeof(int),
1343 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001344 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 },
1346 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 .procname = "inode-state",
1348 .data = &inodes_stat,
1349 .maxlen = 7*sizeof(int),
1350 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001351 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 },
1353 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .procname = "file-nr",
1355 .data = &files_stat,
1356 .maxlen = 3*sizeof(int),
1357 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001358 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 },
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .procname = "file-max",
1362 .data = &files_stat.max_files,
1363 .maxlen = sizeof(int),
1364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001365 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 },
1367 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001368 .procname = "nr_open",
1369 .data = &sysctl_nr_open,
1370 .maxlen = sizeof(int),
1371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001372 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001373 .extra1 = &sysctl_nr_open_min,
1374 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001375 },
1376 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 .procname = "dentry-state",
1378 .data = &dentry_stat,
1379 .maxlen = 6*sizeof(int),
1380 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001381 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 },
1383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .procname = "overflowuid",
1385 .data = &fs_overflowuid,
1386 .maxlen = sizeof(int),
1387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001388 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .extra1 = &minolduid,
1390 .extra2 = &maxolduid,
1391 },
1392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .procname = "overflowgid",
1394 .data = &fs_overflowgid,
1395 .maxlen = sizeof(int),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .extra1 = &minolduid,
1399 .extra2 = &maxolduid,
1400 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001401#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .procname = "leases-enable",
1404 .data = &leases_enable,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001407 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001409#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410#ifdef CONFIG_DNOTIFY
1411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .procname = "dir-notify-enable",
1413 .data = &dir_notify_enable,
1414 .maxlen = sizeof(int),
1415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001416 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 },
1418#endif
1419#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001420#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 .procname = "lease-break-time",
1423 .data = &lease_break_time,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001426 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001428#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001429#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 .procname = "aio-nr",
1432 .data = &aio_nr,
1433 .maxlen = sizeof(aio_nr),
1434 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001435 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 },
1437 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 .procname = "aio-max-nr",
1439 .data = &aio_max_nr,
1440 .maxlen = sizeof(aio_max_nr),
1441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001442 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001444#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001445#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001446 {
Robert Love0399cb02005-07-13 12:38:18 -04001447 .procname = "inotify",
1448 .mode = 0555,
1449 .child = inotify_table,
1450 },
1451#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001452#ifdef CONFIG_EPOLL
1453 {
1454 .procname = "epoll",
1455 .mode = 0555,
1456 .child = epoll_table,
1457 },
1458#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001460 {
Alan Coxd6e71142005-06-23 00:09:43 -07001461 .procname = "suid_dumpable",
1462 .data = &suid_dumpable,
1463 .maxlen = sizeof(int),
1464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001465 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001466 .extra1 = &zero,
1467 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001468 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001469#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1470 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001471 .procname = "binfmt_misc",
1472 .mode = 0555,
1473 .child = binfmt_misc_table,
1474 },
1475#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001476 {
Jens Axboeff9da692010-06-03 14:54:39 +02001477 .procname = "pipe-max-size",
1478 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001479 .maxlen = sizeof(int),
1480 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001481 .proc_handler = &pipe_proc_fn,
1482 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001483 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001484/*
1485 * NOTE: do not add new entries to this table unless you have read
1486 * Documentation/sysctl/ctl_unnumbered.txt
1487 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001488 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489};
1490
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001491static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001492#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1493 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001494 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001495 .procname = "exception-trace",
1496 .data = &show_unhandled_signals,
1497 .maxlen = sizeof(int),
1498 .mode = 0644,
1499 .proc_handler = proc_dointvec
1500 },
1501#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001502#if defined(CONFIG_OPTPROBES)
1503 {
1504 .procname = "kprobes-optimization",
1505 .data = &sysctl_kprobes_optimization,
1506 .maxlen = sizeof(int),
1507 .mode = 0644,
1508 .proc_handler = proc_kprobes_optimization_handler,
1509 .extra1 = &zero,
1510 .extra2 = &one,
1511 },
1512#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001513 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514};
1515
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001516static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001517 { }
Robert Love0eeca282005-07-12 17:06:03 -04001518};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Al Viro330d57f2005-11-04 10:18:40 +00001520static DEFINE_SPINLOCK(sysctl_lock);
1521
1522/* called under sysctl_lock */
1523static int use_table(struct ctl_table_header *p)
1524{
1525 if (unlikely(p->unregistering))
1526 return 0;
1527 p->used++;
1528 return 1;
1529}
1530
1531/* called under sysctl_lock */
1532static void unuse_table(struct ctl_table_header *p)
1533{
1534 if (!--p->used)
1535 if (unlikely(p->unregistering))
1536 complete(p->unregistering);
1537}
1538
1539/* called under sysctl_lock, will reacquire if has to wait */
1540static void start_unregistering(struct ctl_table_header *p)
1541{
1542 /*
1543 * if p->used is 0, nobody will ever touch that entry again;
1544 * we'll eliminate all paths to it before dropping sysctl_lock
1545 */
1546 if (unlikely(p->used)) {
1547 struct completion wait;
1548 init_completion(&wait);
1549 p->unregistering = &wait;
1550 spin_unlock(&sysctl_lock);
1551 wait_for_completion(&wait);
1552 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001553 } else {
1554 /* anything non-NULL; we'll never dereference it */
1555 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001556 }
1557 /*
1558 * do not remove from the list until nobody holds it; walking the
1559 * list in do_sysctl() relies on that.
1560 */
1561 list_del_init(&p->ctl_entry);
1562}
1563
Al Virof7e6ced2008-07-15 01:44:23 -04001564void sysctl_head_get(struct ctl_table_header *head)
1565{
1566 spin_lock(&sysctl_lock);
1567 head->count++;
1568 spin_unlock(&sysctl_lock);
1569}
1570
1571void sysctl_head_put(struct ctl_table_header *head)
1572{
1573 spin_lock(&sysctl_lock);
1574 if (!--head->count)
1575 kfree(head);
1576 spin_unlock(&sysctl_lock);
1577}
1578
1579struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1580{
1581 if (!head)
1582 BUG();
1583 spin_lock(&sysctl_lock);
1584 if (!use_table(head))
1585 head = ERR_PTR(-ENOENT);
1586 spin_unlock(&sysctl_lock);
1587 return head;
1588}
1589
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001590void sysctl_head_finish(struct ctl_table_header *head)
1591{
1592 if (!head)
1593 return;
1594 spin_lock(&sysctl_lock);
1595 unuse_table(head);
1596 spin_unlock(&sysctl_lock);
1597}
1598
Al Viro73455092008-07-14 21:22:20 -04001599static struct ctl_table_set *
1600lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1601{
1602 struct ctl_table_set *set = &root->default_set;
1603 if (root->lookup)
1604 set = root->lookup(root, namespaces);
1605 return set;
1606}
1607
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001608static struct list_head *
1609lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001610{
Al Viro73455092008-07-14 21:22:20 -04001611 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1612 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001613}
1614
1615struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1616 struct ctl_table_header *prev)
1617{
1618 struct ctl_table_root *root;
1619 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001620 struct ctl_table_header *head;
1621 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001622
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001623 spin_lock(&sysctl_lock);
1624 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001625 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001626 tmp = &prev->ctl_entry;
1627 unuse_table(prev);
1628 goto next;
1629 }
1630 tmp = &root_table_header.ctl_entry;
1631 for (;;) {
1632 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1633
1634 if (!use_table(head))
1635 goto next;
1636 spin_unlock(&sysctl_lock);
1637 return head;
1638 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001640 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001641 header_list = lookup_header_list(root, namespaces);
1642 if (tmp != header_list)
1643 continue;
1644
1645 do {
1646 root = list_entry(root->root_list.next,
1647 struct ctl_table_root, root_list);
1648 if (root == &sysctl_table_root)
1649 goto out;
1650 header_list = lookup_header_list(root, namespaces);
1651 } while (list_empty(header_list));
1652 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001653 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001654out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 spin_unlock(&sysctl_lock);
1656 return NULL;
1657}
1658
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001659struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1660{
1661 return __sysctl_head_next(current->nsproxy, prev);
1662}
1663
1664void register_sysctl_root(struct ctl_table_root *root)
1665{
1666 spin_lock(&sysctl_lock);
1667 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1668 spin_unlock(&sysctl_lock);
1669}
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001672 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 * some sysctl variables are readonly even to root.
1674 */
1675
1676static int test_perm(int mode, int op)
1677{
David Howells76aac0e2008-11-14 10:39:12 +11001678 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 mode >>= 6;
1680 else if (in_egroup_p(0))
1681 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001682 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 return 0;
1684 return -EACCES;
1685}
1686
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001687int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
1689 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001690 int mode;
1691
Al Viroe6305c42008-07-15 21:03:57 -04001692 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 if (error)
1694 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001695
1696 if (root->permissions)
1697 mode = root->permissions(root, current->nsproxy, table);
1698 else
1699 mode = table->mode;
1700
1701 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001704static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1705{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001706 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001707 table->parent = parent;
1708 if (table->child)
1709 sysctl_set_parent(table, table->child);
1710 }
1711}
1712
1713static __init int sysctl_init(void)
1714{
1715 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001716#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1717 {
1718 int err;
1719 err = sysctl_check_table(current->nsproxy, root_table);
1720 }
1721#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001722 return 0;
1723}
1724
1725core_initcall(sysctl_init);
1726
Al Virobfbcf032008-07-27 06:31:22 +01001727static struct ctl_table *is_branch_in(struct ctl_table *branch,
1728 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001729{
1730 struct ctl_table *p;
1731 const char *s = branch->procname;
1732
1733 /* branch should have named subdirectory as its first element */
1734 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001735 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001736
1737 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001738 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001739 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001740
1741 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001742 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001743 if (!p->child)
1744 continue;
1745 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001746 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001747 }
Al Virobfbcf032008-07-27 06:31:22 +01001748 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001749}
1750
1751/* see if attaching q to p would be an improvement */
1752static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1753{
1754 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001755 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001756 int is_better = 0;
1757 int not_in_parent = !p->attached_by;
1758
Al Virobfbcf032008-07-27 06:31:22 +01001759 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001760 if (by == q->attached_by)
1761 is_better = 1;
1762 if (to == p->attached_by)
1763 not_in_parent = 1;
1764 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001765 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001766 }
1767
1768 if (is_better && not_in_parent) {
1769 q->attached_by = by;
1770 q->attached_to = to;
1771 q->parent = p;
1772 }
1773}
1774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001776 * __register_sysctl_paths - register a sysctl hierarchy
1777 * @root: List of sysctl headers to register on
1778 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001779 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 *
1782 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001783 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001785 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1788 * enter a sysctl file
1789 *
1790 * data - a pointer to data for use by proc_handler
1791 *
1792 * maxlen - the maximum size in bytes of the data
1793 *
1794 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1795 *
1796 * child - a pointer to the child sysctl table if this entry is a directory, or
1797 * %NULL.
1798 *
1799 * proc_handler - the text handler routine (described below)
1800 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 * de - for internal use by the sysctl routines
1802 *
1803 * extra1, extra2 - extra pointers usable by the proc handler routines
1804 *
1805 * Leaf nodes in the sysctl tree will be represented by a single file
1806 * under /proc; non-leaf nodes will be represented by directories.
1807 *
1808 * sysctl(2) can automatically manage read and write requests through
1809 * the sysctl table. The data and maxlen fields of the ctl_table
1810 * struct enable minimal validation of the values being written to be
1811 * performed, and the mode field allows minimal authentication.
1812 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 * There must be a proc_handler routine for any terminal nodes
1814 * mirrored under /proc/sys (non-terminals are handled by a built-in
1815 * directory handler). Several default handlers are available to
1816 * cover common cases -
1817 *
1818 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1819 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1820 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1821 *
1822 * It is the handler's job to read the input buffer from user memory
1823 * and process it. The handler should return 0 on success.
1824 *
1825 * This routine returns %NULL on a failure to register, and a pointer
1826 * to the table header on success.
1827 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001828struct ctl_table_header *__register_sysctl_paths(
1829 struct ctl_table_root *root,
1830 struct nsproxy *namespaces,
1831 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001833 struct ctl_table_header *header;
1834 struct ctl_table *new, **prevp;
1835 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001836 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001837
1838 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001839 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001840 ;
1841
1842 /*
1843 * For each path component, allocate a 2-element ctl_table array.
1844 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001845 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001846 *
1847 * We allocate everything in one go so that we don't have to
1848 * worry about freeing additional memory in unregister_sysctl_table.
1849 */
1850 header = kzalloc(sizeof(struct ctl_table_header) +
1851 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1852 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001854
1855 new = (struct ctl_table *) (header + 1);
1856
1857 /* Now connect the dots */
1858 prevp = &header->ctl_table;
1859 for (n = 0; n < npath; ++n, ++path) {
1860 /* Copy the procname */
1861 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862 new->mode = 0555;
1863
1864 *prevp = new;
1865 prevp = &new->child;
1866
1867 new += 2;
1868 }
1869 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001870 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871
1872 INIT_LIST_HEAD(&header->ctl_entry);
1873 header->used = 0;
1874 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001875 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001876 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001877 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001878#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001879 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001880 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001881 return NULL;
1882 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001883#endif
Al Viro330d57f2005-11-04 10:18:40 +00001884 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001885 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001886 header->attached_by = header->ctl_table;
1887 header->attached_to = root_table;
1888 header->parent = &root_table_header;
1889 for (set = header->set; set; set = set->parent) {
1890 struct ctl_table_header *p;
1891 list_for_each_entry(p, &set->list, ctl_entry) {
1892 if (p->unregistering)
1893 continue;
1894 try_attach(p, header);
1895 }
1896 }
1897 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001898 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001899 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001900
1901 return header;
1902}
1903
1904/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001905 * register_sysctl_table_path - register a sysctl table hierarchy
1906 * @path: The path to the directory the sysctl table is in.
1907 * @table: the top-level table structure
1908 *
1909 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1910 * array. A completely 0 filled entry terminates the table.
1911 *
1912 * See __register_sysctl_paths for more details.
1913 */
1914struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1915 struct ctl_table *table)
1916{
1917 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1918 path, table);
1919}
1920
1921/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001922 * register_sysctl_table - register a sysctl table hierarchy
1923 * @table: the top-level table structure
1924 *
1925 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1926 * array. A completely 0 filled entry terminates the table.
1927 *
1928 * See register_sysctl_paths for more details.
1929 */
1930struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1931{
1932 static const struct ctl_path null_path[] = { {} };
1933
1934 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935}
1936
1937/**
1938 * unregister_sysctl_table - unregister a sysctl table hierarchy
1939 * @header: the header returned from register_sysctl_table
1940 *
1941 * Unregisters the sysctl table and all children. proc entries may not
1942 * actually be removed until they are no longer used by anyone.
1943 */
1944void unregister_sysctl_table(struct ctl_table_header * header)
1945{
Al Viro330d57f2005-11-04 10:18:40 +00001946 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001947
1948 if (header == NULL)
1949 return;
1950
Al Viro330d57f2005-11-04 10:18:40 +00001951 spin_lock(&sysctl_lock);
1952 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001953 if (!--header->parent->count) {
1954 WARN_ON(1);
1955 kfree(header->parent);
1956 }
Al Virof7e6ced2008-07-15 01:44:23 -04001957 if (!--header->count)
1958 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001959 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960}
1961
Al Viro90434762008-07-15 08:54:06 -04001962int sysctl_is_seen(struct ctl_table_header *p)
1963{
1964 struct ctl_table_set *set = p->set;
1965 int res;
1966 spin_lock(&sysctl_lock);
1967 if (p->unregistering)
1968 res = 0;
1969 else if (!set->is_seen)
1970 res = 1;
1971 else
1972 res = set->is_seen(set);
1973 spin_unlock(&sysctl_lock);
1974 return res;
1975}
1976
Al Viro73455092008-07-14 21:22:20 -04001977void setup_sysctl_set(struct ctl_table_set *p,
1978 struct ctl_table_set *parent,
1979 int (*is_seen)(struct ctl_table_set *))
1980{
1981 INIT_LIST_HEAD(&p->list);
1982 p->parent = parent ? parent : &sysctl_table_root.default_set;
1983 p->is_seen = is_seen;
1984}
1985
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001986#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001987struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001988{
1989 return NULL;
1990}
1991
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001992struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1993 struct ctl_table *table)
1994{
1995 return NULL;
1996}
1997
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001998void unregister_sysctl_table(struct ctl_table_header * table)
1999{
2000}
2001
Al Viro73455092008-07-14 21:22:20 -04002002void setup_sysctl_set(struct ctl_table_set *p,
2003 struct ctl_table_set *parent,
2004 int (*is_seen)(struct ctl_table_set *))
2005{
2006}
2007
Al Virof7e6ced2008-07-15 01:44:23 -04002008void sysctl_head_put(struct ctl_table_header *head)
2009{
2010}
2011
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002012#endif /* CONFIG_SYSCTL */
2013
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014/*
2015 * /proc/sys support
2016 */
2017
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002018#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002020static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002021 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002022 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002023{
2024 size_t len;
2025 char __user *p;
2026 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002027
2028 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002029 *lenp = 0;
2030 return 0;
2031 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002032
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002033 if (write) {
2034 len = 0;
2035 p = buffer;
2036 while (len < *lenp) {
2037 if (get_user(c, p++))
2038 return -EFAULT;
2039 if (c == 0 || c == '\n')
2040 break;
2041 len++;
2042 }
2043 if (len >= maxlen)
2044 len = maxlen-1;
2045 if(copy_from_user(data, buffer, len))
2046 return -EFAULT;
2047 ((char *) data)[len] = 0;
2048 *ppos += *lenp;
2049 } else {
2050 len = strlen(data);
2051 if (len > maxlen)
2052 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002053
2054 if (*ppos > len) {
2055 *lenp = 0;
2056 return 0;
2057 }
2058
2059 data += *ppos;
2060 len -= *ppos;
2061
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002062 if (len > *lenp)
2063 len = *lenp;
2064 if (len)
2065 if(copy_to_user(buffer, data, len))
2066 return -EFAULT;
2067 if (len < *lenp) {
2068 if(put_user('\n', ((char __user *) buffer) + len))
2069 return -EFAULT;
2070 len++;
2071 }
2072 *lenp = len;
2073 *ppos += len;
2074 }
2075 return 0;
2076}
2077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078/**
2079 * proc_dostring - read a string sysctl
2080 * @table: the sysctl table
2081 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 * @buffer: the user buffer
2083 * @lenp: the size of the user buffer
2084 * @ppos: file position
2085 *
2086 * Reads/writes a string from/to the user buffer. If the kernel
2087 * buffer provided is not large enough to hold the string, the
2088 * string is truncated. The copied string is %NULL-terminated.
2089 * If the string is being read by the user process, it is copied
2090 * and a newline '\n' is added. It is truncated if the buffer is
2091 * not large enough.
2092 *
2093 * Returns 0 on success.
2094 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002095int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 void __user *buffer, size_t *lenp, loff_t *ppos)
2097{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002098 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002099 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
Amerigo Wang00b7c332010-05-05 00:26:45 +00002102static size_t proc_skip_spaces(char **buf)
2103{
2104 size_t ret;
2105 char *tmp = skip_spaces(*buf);
2106 ret = tmp - *buf;
2107 *buf = tmp;
2108 return ret;
2109}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002111static void proc_skip_char(char **buf, size_t *size, const char v)
2112{
2113 while (*size) {
2114 if (**buf != v)
2115 break;
2116 (*size)--;
2117 (*buf)++;
2118 }
2119}
2120
Amerigo Wang00b7c332010-05-05 00:26:45 +00002121#define TMPBUFLEN 22
2122/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002123 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002125 * @buf: a kernel buffer
2126 * @size: size of the kernel buffer
2127 * @val: this is where the number will be stored
2128 * @neg: set to %TRUE if number is negative
2129 * @perm_tr: a vector which contains the allowed trailers
2130 * @perm_tr_len: size of the perm_tr vector
2131 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002132 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002133 * In case of success %0 is returned and @buf and @size are updated with
2134 * the amount of bytes read. If @tr is non-NULL and a trailing
2135 * character exists (size is non-zero after returning from this
2136 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002137 */
2138static int proc_get_long(char **buf, size_t *size,
2139 unsigned long *val, bool *neg,
2140 const char *perm_tr, unsigned perm_tr_len, char *tr)
2141{
2142 int len;
2143 char *p, tmp[TMPBUFLEN];
2144
2145 if (!*size)
2146 return -EINVAL;
2147
2148 len = *size;
2149 if (len > TMPBUFLEN - 1)
2150 len = TMPBUFLEN - 1;
2151
2152 memcpy(tmp, *buf, len);
2153
2154 tmp[len] = 0;
2155 p = tmp;
2156 if (*p == '-' && *size > 1) {
2157 *neg = true;
2158 p++;
2159 } else
2160 *neg = false;
2161 if (!isdigit(*p))
2162 return -EINVAL;
2163
2164 *val = simple_strtoul(p, &p, 0);
2165
2166 len = p - tmp;
2167
2168 /* We don't know if the next char is whitespace thus we may accept
2169 * invalid integers (e.g. 1234...a) or two integers instead of one
2170 * (e.g. 123...1). So lets not allow such large numbers. */
2171 if (len == TMPBUFLEN - 1)
2172 return -EINVAL;
2173
2174 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2175 return -EINVAL;
2176
2177 if (tr && (len < *size))
2178 *tr = *p;
2179
2180 *buf += len;
2181 *size -= len;
2182
2183 return 0;
2184}
2185
2186/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002187 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002188 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002189 * @buf: the user buffer
2190 * @size: the size of the user buffer
2191 * @val: the integer to be converted
2192 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002193 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002194 * In case of success %0 is returned and @buf and @size are updated with
2195 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 */
2197static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2198 bool neg)
2199{
2200 int len;
2201 char tmp[TMPBUFLEN], *p = tmp;
2202
2203 sprintf(p, "%s%lu", neg ? "-" : "", val);
2204 len = strlen(tmp);
2205 if (len > *size)
2206 len = *size;
2207 if (copy_to_user(*buf, tmp, len))
2208 return -EFAULT;
2209 *size -= len;
2210 *buf += len;
2211 return 0;
2212}
2213#undef TMPBUFLEN
2214
2215static int proc_put_char(void __user **buf, size_t *size, char c)
2216{
2217 if (*size) {
2218 char __user **buffer = (char __user **)buf;
2219 if (put_user(c, *buffer))
2220 return -EFAULT;
2221 (*size)--, (*buffer)++;
2222 *buf = *buffer;
2223 }
2224 return 0;
2225}
2226
2227static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 int *valp,
2229 int write, void *data)
2230{
2231 if (write) {
2232 *valp = *negp ? -*lvalp : *lvalp;
2233 } else {
2234 int val = *valp;
2235 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002236 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 *lvalp = (unsigned long)-val;
2238 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 *lvalp = (unsigned long)val;
2241 }
2242 }
2243 return 0;
2244}
2245
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2247
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002248static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002249 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002250 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002251 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 int write, void *data),
2253 void *data)
2254{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255 int *i, vleft, first = 1, err = 0;
2256 unsigned long page = 0;
2257 size_t left;
2258 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Amerigo Wang00b7c332010-05-05 00:26:45 +00002260 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 *lenp = 0;
2262 return 0;
2263 }
2264
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002265 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 vleft = table->maxlen / sizeof(*i);
2267 left = *lenp;
2268
2269 if (!conv)
2270 conv = do_proc_dointvec_conv;
2271
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 if (left > PAGE_SIZE - 1)
2274 left = PAGE_SIZE - 1;
2275 page = __get_free_page(GFP_TEMPORARY);
2276 kbuf = (char *) page;
2277 if (!kbuf)
2278 return -ENOMEM;
2279 if (copy_from_user(kbuf, buffer, left)) {
2280 err = -EFAULT;
2281 goto free;
2282 }
2283 kbuf[left] = 0;
2284 }
2285
2286 for (; left && vleft--; i++, first=0) {
2287 unsigned long lval;
2288 bool neg;
2289
2290 if (write) {
2291 left -= proc_skip_spaces(&kbuf);
2292
J. R. Okajima563b0462010-05-25 16:10:14 -07002293 if (!left)
2294 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002295 err = proc_get_long(&kbuf, &left, &lval, &neg,
2296 proc_wspace_sep,
2297 sizeof(proc_wspace_sep), NULL);
2298 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002300 if (conv(&neg, &lval, i, 1, data)) {
2301 err = -EINVAL;
2302 break;
2303 }
2304 } else {
2305 if (conv(&neg, &lval, i, 0, data)) {
2306 err = -EINVAL;
2307 break;
2308 }
2309 if (!first)
2310 err = proc_put_char(&buffer, &left, '\t');
2311 if (err)
2312 break;
2313 err = proc_put_long(&buffer, &left, lval, neg);
2314 if (err)
2315 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
2317 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318
2319 if (!write && !first && left && !err)
2320 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002321 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 left -= proc_skip_spaces(&kbuf);
2323free:
2324 if (write) {
2325 free_page(page);
2326 if (first)
2327 return err ? : -EINVAL;
2328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 *lenp -= left;
2330 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002331 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332}
2333
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002334static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002335 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337 int write, void *data),
2338 void *data)
2339{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002340 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002341 buffer, lenp, ppos, conv, data);
2342}
2343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344/**
2345 * proc_dointvec - read a vector of integers
2346 * @table: the sysctl table
2347 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 * @buffer: the user buffer
2349 * @lenp: the size of the user buffer
2350 * @ppos: file position
2351 *
2352 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353 * values from/to the user buffer, treated as an ASCII string.
2354 *
2355 * Returns 0 on success.
2356 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002357int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 void __user *buffer, size_t *lenp, loff_t *ppos)
2359{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002360 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 NULL,NULL);
2362}
2363
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002364/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002365 * Taint values can only be increased
2366 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002369 void __user *buffer, size_t *lenp, loff_t *ppos)
2370{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002371 struct ctl_table t;
2372 unsigned long tmptaint = get_taint();
2373 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002374
Bastian Blank91fcd412007-04-23 14:41:14 -07002375 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376 return -EPERM;
2377
Andi Kleen25ddbb12008-10-15 22:01:41 -07002378 t = *table;
2379 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002380 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002381 if (err < 0)
2382 return err;
2383
2384 if (write) {
2385 /*
2386 * Poor man's atomic or. Not worth adding a primitive
2387 * to everyone's atomic.h for this
2388 */
2389 int i;
2390 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2391 if ((tmptaint >> i) & 1)
2392 add_taint(i);
2393 }
2394 }
2395
2396 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002397}
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399struct do_proc_dointvec_minmax_conv_param {
2400 int *min;
2401 int *max;
2402};
2403
Amerigo Wang00b7c332010-05-05 00:26:45 +00002404static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2405 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 int write, void *data)
2407{
2408 struct do_proc_dointvec_minmax_conv_param *param = data;
2409 if (write) {
2410 int val = *negp ? -*lvalp : *lvalp;
2411 if ((param->min && *param->min > val) ||
2412 (param->max && *param->max < val))
2413 return -EINVAL;
2414 *valp = val;
2415 } else {
2416 int val = *valp;
2417 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002418 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 *lvalp = (unsigned long)-val;
2420 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002421 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 *lvalp = (unsigned long)val;
2423 }
2424 }
2425 return 0;
2426}
2427
2428/**
2429 * proc_dointvec_minmax - read a vector of integers with min/max values
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2435 *
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2438 *
2439 * This routine will ensure the values are within the range specified by
2440 * table->extra1 (min) and table->extra2 (max).
2441 *
2442 * Returns 0 on success.
2443 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002444int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 void __user *buffer, size_t *lenp, loff_t *ppos)
2446{
2447 struct do_proc_dointvec_minmax_conv_param param = {
2448 .min = (int *) table->extra1,
2449 .max = (int *) table->extra2,
2450 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002451 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 do_proc_dointvec_minmax_conv, &param);
2453}
2454
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002455static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 void __user *buffer,
2457 size_t *lenp, loff_t *ppos,
2458 unsigned long convmul,
2459 unsigned long convdiv)
2460{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002461 unsigned long *i, *min, *max;
2462 int vleft, first = 1, err = 0;
2463 unsigned long page = 0;
2464 size_t left;
2465 char *kbuf;
2466
2467 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 *lenp = 0;
2469 return 0;
2470 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002471
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002472 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 min = (unsigned long *) table->extra1;
2474 max = (unsigned long *) table->extra2;
2475 vleft = table->maxlen / sizeof(unsigned long);
2476 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002477
2478 if (write) {
2479 if (left > PAGE_SIZE - 1)
2480 left = PAGE_SIZE - 1;
2481 page = __get_free_page(GFP_TEMPORARY);
2482 kbuf = (char *) page;
2483 if (!kbuf)
2484 return -ENOMEM;
2485 if (copy_from_user(kbuf, buffer, left)) {
2486 err = -EFAULT;
2487 goto free;
2488 }
2489 kbuf[left] = 0;
2490 }
2491
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 for (; left && vleft--; i++, min++, max++, first=0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002493 unsigned long val;
2494
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002496 bool neg;
2497
2498 left -= proc_skip_spaces(&kbuf);
2499
2500 err = proc_get_long(&kbuf, &left, &val, &neg,
2501 proc_wspace_sep,
2502 sizeof(proc_wspace_sep), NULL);
2503 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 break;
2505 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 continue;
2507 if ((min && val < *min) || (max && val > *max))
2508 continue;
2509 *i = val;
2510 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002511 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513 err = proc_put_char(&buffer, &left, '\t');
2514 err = proc_put_long(&buffer, &left, val, false);
2515 if (err)
2516 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 }
2518 }
2519
Amerigo Wang00b7c332010-05-05 00:26:45 +00002520 if (!write && !first && left && !err)
2521 err = proc_put_char(&buffer, &left, '\n');
2522 if (write && !err)
2523 left -= proc_skip_spaces(&kbuf);
2524free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002526 free_page(page);
2527 if (first)
2528 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 *lenp -= left;
2531 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002532 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533}
2534
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002535static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002536 void __user *buffer,
2537 size_t *lenp, loff_t *ppos,
2538 unsigned long convmul,
2539 unsigned long convdiv)
2540{
2541 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002542 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002543}
2544
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545/**
2546 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2547 * @table: the sysctl table
2548 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 * @buffer: the user buffer
2550 * @lenp: the size of the user buffer
2551 * @ppos: file position
2552 *
2553 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2554 * values from/to the user buffer, treated as an ASCII string.
2555 *
2556 * This routine will ensure the values are within the range specified by
2557 * table->extra1 (min) and table->extra2 (max).
2558 *
2559 * Returns 0 on success.
2560 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002561int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 void __user *buffer, size_t *lenp, loff_t *ppos)
2563{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002564 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565}
2566
2567/**
2568 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2569 * @table: the sysctl table
2570 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 * @buffer: the user buffer
2572 * @lenp: the size of the user buffer
2573 * @ppos: file position
2574 *
2575 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2576 * values from/to the user buffer, treated as an ASCII string. The values
2577 * are treated as milliseconds, and converted to jiffies when they are stored.
2578 *
2579 * This routine will ensure the values are within the range specified by
2580 * table->extra1 (min) and table->extra2 (max).
2581 *
2582 * Returns 0 on success.
2583 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002584int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 void __user *buffer,
2586 size_t *lenp, loff_t *ppos)
2587{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002588 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 lenp, ppos, HZ, 1000l);
2590}
2591
2592
Amerigo Wang00b7c332010-05-05 00:26:45 +00002593static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 int *valp,
2595 int write, void *data)
2596{
2597 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002598 if (*lvalp > LONG_MAX / HZ)
2599 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2601 } else {
2602 int val = *valp;
2603 unsigned long lval;
2604 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002605 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 lval = (unsigned long)-val;
2607 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002608 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 lval = (unsigned long)val;
2610 }
2611 *lvalp = lval / HZ;
2612 }
2613 return 0;
2614}
2615
Amerigo Wang00b7c332010-05-05 00:26:45 +00002616static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 int *valp,
2618 int write, void *data)
2619{
2620 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002621 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2622 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2624 } else {
2625 int val = *valp;
2626 unsigned long lval;
2627 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002628 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 lval = (unsigned long)-val;
2630 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002631 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 lval = (unsigned long)val;
2633 }
2634 *lvalp = jiffies_to_clock_t(lval);
2635 }
2636 return 0;
2637}
2638
Amerigo Wang00b7c332010-05-05 00:26:45 +00002639static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 int *valp,
2641 int write, void *data)
2642{
2643 if (write) {
2644 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2645 } else {
2646 int val = *valp;
2647 unsigned long lval;
2648 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002649 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 lval = (unsigned long)-val;
2651 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002652 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 lval = (unsigned long)val;
2654 }
2655 *lvalp = jiffies_to_msecs(lval);
2656 }
2657 return 0;
2658}
2659
2660/**
2661 * proc_dointvec_jiffies - read a vector of integers as seconds
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: file position
2667 *
2668 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2669 * values from/to the user buffer, treated as an ASCII string.
2670 * The values read are assumed to be in seconds, and are converted into
2671 * jiffies.
2672 *
2673 * Returns 0 on success.
2674 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002675int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 void __user *buffer, size_t *lenp, loff_t *ppos)
2677{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002678 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 do_proc_dointvec_jiffies_conv,NULL);
2680}
2681
2682/**
2683 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 * @buffer: the user buffer
2687 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002688 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 *
2690 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2691 * values from/to the user buffer, treated as an ASCII string.
2692 * The values read are assumed to be in 1/USER_HZ seconds, and
2693 * are converted into jiffies.
2694 *
2695 * Returns 0 on success.
2696 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002697int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002700 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 do_proc_dointvec_userhz_jiffies_conv,NULL);
2702}
2703
2704/**
2705 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2706 * @table: the sysctl table
2707 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 * @buffer: the user buffer
2709 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002710 * @ppos: file position
2711 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 *
2713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2714 * values from/to the user buffer, treated as an ASCII string.
2715 * The values read are assumed to be in 1/1000 seconds, and
2716 * are converted into jiffies.
2717 *
2718 * Returns 0 on success.
2719 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002720int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 void __user *buffer, size_t *lenp, loff_t *ppos)
2722{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 do_proc_dointvec_ms_jiffies_conv, NULL);
2725}
2726
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002727static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002728 void __user *buffer, size_t *lenp, loff_t *ppos)
2729{
2730 struct pid *new_pid;
2731 pid_t tmp;
2732 int r;
2733
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002734 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002735
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002736 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002737 lenp, ppos, NULL, NULL);
2738 if (r || !write)
2739 return r;
2740
2741 new_pid = find_get_pid(tmp);
2742 if (!new_pid)
2743 return -ESRCH;
2744
2745 put_pid(xchg(&cad_pid, new_pid));
2746 return 0;
2747}
2748
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002749/**
2750 * proc_do_large_bitmap - read/write from/to a large bitmap
2751 * @table: the sysctl table
2752 * @write: %TRUE if this is a write to the sysctl file
2753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
2755 * @ppos: file position
2756 *
2757 * The bitmap is stored at table->data and the bitmap length (in bits)
2758 * in table->maxlen.
2759 *
2760 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2761 * large bitmaps may be represented in a compact manner. Writing into
2762 * the file will clear the bitmap then update it with the given input.
2763 *
2764 * Returns 0 on success.
2765 */
2766int proc_do_large_bitmap(struct ctl_table *table, int write,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2768{
2769 int err = 0;
2770 bool first = 1;
2771 size_t left = *lenp;
2772 unsigned long bitmap_len = table->maxlen;
2773 unsigned long *bitmap = (unsigned long *) table->data;
2774 unsigned long *tmp_bitmap = NULL;
2775 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2776
2777 if (!bitmap_len || !left || (*ppos && !write)) {
2778 *lenp = 0;
2779 return 0;
2780 }
2781
2782 if (write) {
2783 unsigned long page = 0;
2784 char *kbuf;
2785
2786 if (left > PAGE_SIZE - 1)
2787 left = PAGE_SIZE - 1;
2788
2789 page = __get_free_page(GFP_TEMPORARY);
2790 kbuf = (char *) page;
2791 if (!kbuf)
2792 return -ENOMEM;
2793 if (copy_from_user(kbuf, buffer, left)) {
2794 free_page(page);
2795 return -EFAULT;
2796 }
2797 kbuf[left] = 0;
2798
2799 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2800 GFP_KERNEL);
2801 if (!tmp_bitmap) {
2802 free_page(page);
2803 return -ENOMEM;
2804 }
2805 proc_skip_char(&kbuf, &left, '\n');
2806 while (!err && left) {
2807 unsigned long val_a, val_b;
2808 bool neg;
2809
2810 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2811 sizeof(tr_a), &c);
2812 if (err)
2813 break;
2814 if (val_a >= bitmap_len || neg) {
2815 err = -EINVAL;
2816 break;
2817 }
2818
2819 val_b = val_a;
2820 if (left) {
2821 kbuf++;
2822 left--;
2823 }
2824
2825 if (c == '-') {
2826 err = proc_get_long(&kbuf, &left, &val_b,
2827 &neg, tr_b, sizeof(tr_b),
2828 &c);
2829 if (err)
2830 break;
2831 if (val_b >= bitmap_len || neg ||
2832 val_a > val_b) {
2833 err = -EINVAL;
2834 break;
2835 }
2836 if (left) {
2837 kbuf++;
2838 left--;
2839 }
2840 }
2841
2842 while (val_a <= val_b)
2843 set_bit(val_a++, tmp_bitmap);
2844
2845 first = 0;
2846 proc_skip_char(&kbuf, &left, '\n');
2847 }
2848 free_page(page);
2849 } else {
2850 unsigned long bit_a, bit_b = 0;
2851
2852 while (left) {
2853 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2854 if (bit_a >= bitmap_len)
2855 break;
2856 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2857 bit_a + 1) - 1;
2858
2859 if (!first) {
2860 err = proc_put_char(&buffer, &left, ',');
2861 if (err)
2862 break;
2863 }
2864 err = proc_put_long(&buffer, &left, bit_a, false);
2865 if (err)
2866 break;
2867 if (bit_a != bit_b) {
2868 err = proc_put_char(&buffer, &left, '-');
2869 if (err)
2870 break;
2871 err = proc_put_long(&buffer, &left, bit_b, false);
2872 if (err)
2873 break;
2874 }
2875
2876 first = 0; bit_b++;
2877 }
2878 if (!err)
2879 err = proc_put_char(&buffer, &left, '\n');
2880 }
2881
2882 if (!err) {
2883 if (write) {
2884 if (*ppos)
2885 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2886 else
2887 memcpy(bitmap, tmp_bitmap,
2888 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2889 }
2890 kfree(tmp_bitmap);
2891 *lenp -= left;
2892 *ppos += *lenp;
2893 return 0;
2894 } else {
2895 kfree(tmp_bitmap);
2896 return err;
2897 }
2898}
2899
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900#else /* CONFIG_PROC_FS */
2901
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002902int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 void __user *buffer, size_t *lenp, loff_t *ppos)
2904{
2905 return -ENOSYS;
2906}
2907
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002908int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 void __user *buffer, size_t *lenp, loff_t *ppos)
2910{
2911 return -ENOSYS;
2912}
2913
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002914int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 void __user *buffer, size_t *lenp, loff_t *ppos)
2916{
2917 return -ENOSYS;
2918}
2919
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002920int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 void __user *buffer, size_t *lenp, loff_t *ppos)
2922{
2923 return -ENOSYS;
2924}
2925
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002926int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
2929 return -ENOSYS;
2930}
2931
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002932int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 void __user *buffer, size_t *lenp, loff_t *ppos)
2934{
2935 return -ENOSYS;
2936}
2937
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002938int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 void __user *buffer, size_t *lenp, loff_t *ppos)
2940{
2941 return -ENOSYS;
2942}
2943
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002944int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 void __user *buffer,
2946 size_t *lenp, loff_t *ppos)
2947{
2948 return -ENOSYS;
2949}
2950
2951
2952#endif /* CONFIG_PROC_FS */
2953
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954/*
2955 * No sense putting this after each symbol definition, twice,
2956 * exception granted :-)
2957 */
2958EXPORT_SYMBOL(proc_dointvec);
2959EXPORT_SYMBOL(proc_dointvec_jiffies);
2960EXPORT_SYMBOL(proc_dointvec_minmax);
2961EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2962EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2963EXPORT_SYMBOL(proc_dostring);
2964EXPORT_SYMBOL(proc_doulongvec_minmax);
2965EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2966EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002967EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968EXPORT_SYMBOL(unregister_sysctl_table);