blob: 6f79c7f81c960a3da9d6b3832a92f4deaad9c7d0 [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>
David Howells12e22c52009-04-03 16:42:35 +010053#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020054#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050055#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020056#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#include <asm/uaccess.h>
59#include <asm/processor.h>
60
Andi Kleen29cbc782006-09-30 01:47:55 +020061#ifdef CONFIG_X86
62#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010063#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010064#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020065#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080066#ifdef CONFIG_BSD_PROCESS_ACCT
67#include <linux/acct.h>
68#endif
Dave Young4f0e0562010-03-10 15:24:09 -080069#ifdef CONFIG_RT_MUTEXES
70#include <linux/rtmutex.h>
71#endif
Dave Young2edf5e42010-03-10 15:24:10 -080072#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
73#include <linux/lockdep.h>
74#endif
Dave Young15485a42010-03-10 15:24:07 -080075#ifdef CONFIG_CHR_DEV_SG
76#include <scsi/sg.h>
77#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020078
Don Zickus58687ac2010-05-07 17:11:44 -040079#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050080#include <linux/nmi.h>
81#endif
82
Eric W. Biederman7058cb02007-10-18 03:05:58 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#if defined(CONFIG_SYSCTL)
85
86/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087extern int sysctl_overcommit_memory;
88extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070089extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070090extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080091extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070094extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070096extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max;
98extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -0800100extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800101extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200102extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100103extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400104extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000105#ifndef CONFIG_MMU
106extern int sysctl_nr_trim_pages;
107#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200108#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200109extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400113#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200115static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116#endif
117
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700119static int __maybe_unused one = 1;
120static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800121static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700126
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700127/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131static int maxolduid = 65535;
132static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800133static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static int ngroups_max = NGROUPS_MAX;
136
David S. Miller72c57ed2008-09-11 23:29:54 -0700137#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700138#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif
140
David S. Miller08714202008-11-16 23:49:24 -0800141#ifdef CONFIG_SPARC64
142extern int sysctl_tsb_ratio;
143#endif
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef __hppa__
146extern int pwrsw_enabled;
147extern int unaligned_enabled;
148#endif
149
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800150#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#ifdef CONFIG_MATHEMU
152extern int sysctl_ieee_emulation_warnings;
153#endif
154extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700155extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#endif
157
Jes Sorensend2b176e2006-02-28 09:42:23 -0800158#ifdef CONFIG_IA64
159extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800160extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800161#endif
162
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200163extern struct ratelimit_state printk_ratelimit_state;
164
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700166static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800169 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700171
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700172#ifdef CONFIG_MAGIC_SYSRQ
173static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
174
175static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
177 loff_t *ppos)
178{
179 int error;
180
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
182 if (error)
183 return error;
184
185 if (write)
186 sysrq_toggle_support(__sysrq_enabled);
187
188 return 0;
189}
190
191#endif
192
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100194static struct ctl_table_root sysctl_table_root;
195static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100196 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100197 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400200 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201};
202static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100205};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700207static struct ctl_table kern_table[];
208static struct ctl_table vm_table[];
209static struct ctl_table fs_table[];
210static struct ctl_table debug_table[];
211static struct ctl_table dev_table[];
212extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700213#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700214extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400215#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800216#ifdef CONFIG_EPOLL
217extern struct ctl_table epoll_table[];
218#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
221int sysctl_legacy_va_layout;
222#endif
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* The default sysctl tables: */
225
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700226static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .procname = "kernel",
229 .mode = 0555,
230 .child = kern_table,
231 },
232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .procname = "vm",
234 .mode = 0555,
235 .child = vm_table,
236 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .procname = "fs",
239 .mode = 0555,
240 .child = fs_table,
241 },
242 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .procname = "debug",
244 .mode = 0555,
245 .child = debug_table,
246 },
247 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 .procname = "dev",
249 .mode = 0555,
250 .child = dev_table,
251 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700252/*
253 * NOTE: do not add new entries to this table unless you have read
254 * Documentation/sysctl/ctl_unnumbered.txt
255 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700256 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257};
258
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100260static int min_sched_granularity_ns = 100000; /* 100 usecs */
261static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
262static int min_wakeup_granularity_ns; /* 0 usecs */
263static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100264static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100266static int min_sched_shares_ratelimit = 100000; /* 100 usec */
267static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268#endif
269
Mel Gorman5e771902010-05-24 14:32:31 -0700270#ifdef CONFIG_COMPACTION
271static int min_extfrag_threshold;
272static int max_extfrag_threshold = 1000;
273#endif
274
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700275static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800281 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200282 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283#ifdef CONFIG_SCHED_DEBUG
284 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100285 .procname = "sched_min_granularity_ns",
286 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800289 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 },
293 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200294 .procname = "sched_latency_ns",
295 .data = &sysctl_sched_latency,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
301 },
302 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200303 .procname = "sched_wakeup_granularity_ns",
304 .data = &sysctl_sched_wakeup_granularity,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308 .extra1 = &min_wakeup_granularity_ns,
309 .extra2 = &max_wakeup_granularity_ns,
310 },
311 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200312 .procname = "sched_shares_ratelimit",
313 .data = &sysctl_sched_shares_ratelimit,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800316 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100317 .extra1 = &min_sched_shares_ratelimit,
318 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200319 },
320 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100321 .procname = "sched_tunable_scaling",
322 .data = &sysctl_sched_tunable_scaling,
323 .maxlen = sizeof(enum sched_tunable_scaling),
324 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800325 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100326 .extra1 = &min_sched_tunable_scaling,
327 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200328 },
329 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200330 .procname = "sched_shares_thresh",
331 .data = &sysctl_sched_shares_thresh,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800334 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200335 .extra1 = &zero,
336 },
337 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200338 .procname = "sched_migration_cost",
339 .data = &sysctl_sched_migration_cost,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800342 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200343 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100344 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100345 .procname = "sched_nr_migrate",
346 .data = &sysctl_sched_nr_migrate,
347 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800349 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100350 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200352 .procname = "sched_time_avg",
353 .data = &sysctl_sched_time_avg,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200357 },
358 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530359 .procname = "timer_migration",
360 .data = &sysctl_timer_migration,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530364 .extra1 = &zero,
365 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530366 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200367#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200368 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100369 .procname = "sched_rt_period_us",
370 .data = &sysctl_sched_rt_period,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800373 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100374 },
375 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100376 .procname = "sched_rt_runtime_us",
377 .data = &sysctl_sched_rt_runtime,
378 .maxlen = sizeof(int),
379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800380 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100381 },
382 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200383 .procname = "sched_compat_yield",
384 .data = &sysctl_sched_compat_yield,
385 .maxlen = sizeof(unsigned int),
386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800387 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200388 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700389#ifdef CONFIG_PROVE_LOCKING
390 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700391 .procname = "prove_locking",
392 .data = &prove_locking,
393 .maxlen = sizeof(int),
394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800395 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700396 },
397#endif
398#ifdef CONFIG_LOCK_STAT
399 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700400 .procname = "lock_stat",
401 .data = &lock_stat,
402 .maxlen = sizeof(int),
403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800404 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700405 },
406#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .procname = "panic",
409 .data = &panic_timeout,
410 .maxlen = sizeof(int),
411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800412 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 },
414 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .procname = "core_uses_pid",
416 .data = &core_uses_pid,
417 .maxlen = sizeof(int),
418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800419 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 },
421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .procname = "core_pattern",
423 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700424 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800426 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 },
Neil Hormana2939802009-09-23 15:56:56 -0700428 {
Neil Hormana2939802009-09-23 15:56:56 -0700429 .procname = "core_pipe_limit",
430 .data = &core_pipe_limit,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700434 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700438 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800442#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100443#ifdef CONFIG_LATENCYTOP
444 {
445 .procname = "latencytop",
446 .data = &latencytop_enabled,
447 .maxlen = sizeof(int),
448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800449 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100450 },
451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#ifdef CONFIG_BLK_DEV_INITRD
453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "real-root-dev",
455 .data = &real_root_dev,
456 .maxlen = sizeof(int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700461 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700462 .procname = "print-fatal-signals",
463 .data = &print_fatal_signals,
464 .maxlen = sizeof(int),
465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800466 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700467 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700468#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 .procname = "reboot-cmd",
471 .data = reboot_command,
472 .maxlen = 256,
473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800474 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 },
476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .procname = "stop-a",
478 .data = &stop_a_enabled,
479 .maxlen = sizeof (int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 },
483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 .procname = "scons-poweroff",
485 .data = &scons_pwroff,
486 .maxlen = sizeof (int),
487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800488 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 },
490#endif
David S. Miller08714202008-11-16 23:49:24 -0800491#ifdef CONFIG_SPARC64
492 {
David S. Miller08714202008-11-16 23:49:24 -0800493 .procname = "tsb-ratio",
494 .data = &sysctl_tsb_ratio,
495 .maxlen = sizeof (int),
496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800497 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800498 },
499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#ifdef __hppa__
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "soft-power",
503 .data = &pwrsw_enabled,
504 .maxlen = sizeof (int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
508 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .procname = "unaligned-trap",
510 .data = &unaligned_enabled,
511 .maxlen = sizeof (int),
512 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800513 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 },
515#endif
516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .procname = "ctrl-alt-del",
518 .data = &C_A_D,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400523#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200524 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200525 .procname = "ftrace_enabled",
526 .data = &ftrace_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800529 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200530 },
531#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500532#ifdef CONFIG_STACK_TRACER
533 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500534 .procname = "stack_tracer_enabled",
535 .data = &stack_tracer_enabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800538 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500539 },
540#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400541#ifdef CONFIG_TRACING
542 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100543 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400544 .data = &ftrace_dump_on_oops,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400548 },
549#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200550#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "modprobe",
553 .data = &modprobe_path,
554 .maxlen = KMOD_PATH_LEN,
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
Kees Cook3d433212009-04-02 15:49:29 -0700558 {
Kees Cook3d433212009-04-02 15:49:29 -0700559 .procname = "modules_disabled",
560 .data = &modules_disabled,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800564 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700565 .extra1 = &one,
566 .extra2 = &one,
567 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700569#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100572 .data = &uevent_helper,
573 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
577#endif
578#ifdef CONFIG_CHR_DEV_SG
579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "sg-big-buff",
581 .data = &sg_big_buff,
582 .maxlen = sizeof (int),
583 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586#endif
587#ifdef CONFIG_BSD_PROCESS_ACCT
588 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .procname = "acct",
590 .data = &acct_parm,
591 .maxlen = 3*sizeof(int),
592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800593 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 },
595#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#ifdef CONFIG_MAGIC_SYSRQ
597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800599 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .maxlen = sizeof (int),
601 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700602 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 },
604#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700605#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700608 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .maxlen = sizeof (int),
610 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "threads-max",
616 .data = &max_threads,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 },
621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "random",
623 .mode = 0555,
624 .child = random_table,
625 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .procname = "overflowuid",
628 .data = &overflowuid,
629 .maxlen = sizeof(int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
634 },
635 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .procname = "overflowgid",
637 .data = &overflowgid,
638 .maxlen = sizeof(int),
639 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800640 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .extra1 = &minolduid,
642 .extra2 = &maxolduid,
643 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800644#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#ifdef CONFIG_MATHEMU
646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "ieee_emulation_warnings",
648 .data = &sysctl_ieee_emulation_warnings,
649 .maxlen = sizeof(int),
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 },
653#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200656 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .maxlen = sizeof(int),
658 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 },
661#endif
662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .procname = "pid_max",
664 .data = &pid_max,
665 .maxlen = sizeof (int),
666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800667 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .extra1 = &pid_max_min,
669 .extra2 = &pid_max_max,
670 },
671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .procname = "panic_on_oops",
673 .data = &panic_on_oops,
674 .maxlen = sizeof(int),
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800678#if defined CONFIG_PRINTK
679 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800680 .procname = "printk",
681 .data = &console_loglevel,
682 .maxlen = 4*sizeof(int),
683 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800685 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700688 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .maxlen = sizeof(int),
690 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800691 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700695 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .maxlen = sizeof(int),
697 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800698 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
Dave Youngaf913222009-09-22 16:43:33 -0700700 {
Dave Youngaf913222009-09-22 16:43:33 -0700701 .procname = "printk_delay",
702 .data = &printk_delay_msec,
703 .maxlen = sizeof(int),
704 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800705 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700706 .extra1 = &zero,
707 .extra2 = &ten_thousand,
708 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800709#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 .procname = "ngroups_max",
712 .data = &ngroups_max,
713 .maxlen = sizeof (int),
714 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800715 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 },
Don Zickus58687ac2010-05-07 17:11:44 -0400717#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500718 {
Don Zickus58687ac2010-05-07 17:11:44 -0400719 .procname = "watchdog",
720 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500721 .maxlen = sizeof (int),
722 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400723 .proc_handler = proc_dowatchdog_enabled,
724 },
725 {
726 .procname = "watchdog_thresh",
727 .data = &softlockup_thresh,
728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = proc_dowatchdog_thresh,
731 .extra1 = &neg_one,
732 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500733 },
Don Zickus2508ce12010-05-07 17:11:46 -0400734 {
735 .procname = "softlockup_panic",
736 .data = &softlockup_panic,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = proc_dointvec_minmax,
740 .extra1 = &zero,
741 .extra2 = &one,
742 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500743#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400744#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "unknown_nmi_panic",
747 .data = &unknown_nmi_panic,
748 .maxlen = sizeof (int),
749 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
Don Zickus407984f2006-09-26 10:52:27 +0200752 {
Don Zickus407984f2006-09-26 10:52:27 +0200753 .procname = "nmi_watchdog",
754 .data = &nmi_watchdog_enabled,
755 .maxlen = sizeof (int),
756 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800757 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 },
759#endif
760#if defined(CONFIG_X86)
761 {
Don Zickus8da5add2006-09-26 10:52:27 +0200762 .procname = "panic_on_unrecovered_nmi",
763 .data = &panic_on_unrecovered_nmi,
764 .maxlen = sizeof(int),
765 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800766 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200767 },
768 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700769 .procname = "panic_on_io_nmi",
770 .data = &panic_on_io_nmi,
771 .maxlen = sizeof(int),
772 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700774 },
775 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 .procname = "bootloader_type",
777 .data = &bootloader_type,
778 .maxlen = sizeof (int),
779 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100782 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700783 .procname = "bootloader_version",
784 .data = &bootloader_version,
785 .maxlen = sizeof (int),
786 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700788 },
789 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100790 .procname = "kstack_depth_to_print",
791 .data = &kstack_depth_to_print,
792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100795 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100796 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100797 .procname = "io_delay_type",
798 .data = &io_delay_type,
799 .maxlen = sizeof(int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100802 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800804#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 .procname = "randomize_va_space",
807 .data = &randomize_va_space,
808 .maxlen = sizeof(int),
809 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800810 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800812#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800813#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700814 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700815 .procname = "spin_retry",
816 .data = &spin_retry,
817 .maxlen = sizeof (int),
818 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800819 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700820 },
821#endif
Len Brown673d5b42007-07-28 03:33:16 -0400822#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800823 {
Pavel Machekc255d842006-02-20 18:27:58 -0800824 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700825 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800826 .maxlen = sizeof (unsigned long),
827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800828 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800829 },
830#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800831#ifdef CONFIG_IA64
832 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800833 .procname = "ignore-unaligned-usertrap",
834 .data = &no_unaligned_warning,
835 .maxlen = sizeof (int),
836 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800838 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800839 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800840 .procname = "unaligned-dump-stack",
841 .data = &unaligned_dump_stack,
842 .maxlen = sizeof (int),
843 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800844 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800845 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800846#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800847#ifdef CONFIG_DETECT_HUNG_TASK
848 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800849 .procname = "hung_task_panic",
850 .data = &sysctl_hung_task_panic,
851 .maxlen = sizeof(int),
852 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800853 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800854 .extra1 = &zero,
855 .extra2 = &one,
856 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100857 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .procname = "hung_task_check_count",
859 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100860 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 },
864 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100865 .procname = "hung_task_timeout_secs",
866 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100867 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800869 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100870 },
871 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100872 .procname = "hung_task_warnings",
873 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100874 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800876 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700878#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200879#ifdef CONFIG_COMPAT
880 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200881 .procname = "compat-log",
882 .data = &compat_log,
883 .maxlen = sizeof (int),
884 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800885 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200886 },
887#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700888#ifdef CONFIG_RT_MUTEXES
889 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700890 .procname = "max_lock_depth",
891 .data = &max_lock_depth,
892 .maxlen = sizeof(int),
893 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800894 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700895 },
896#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700897 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700898 .procname = "poweroff_cmd",
899 .data = &poweroff_cmd,
900 .maxlen = POWEROFF_CMD_PATH_LEN,
901 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800902 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700903 },
David Howells0b77f5b2008-04-29 01:01:32 -0700904#ifdef CONFIG_KEYS
905 {
David Howells0b77f5b2008-04-29 01:01:32 -0700906 .procname = "keys",
907 .mode = 0555,
908 .child = key_sysctls,
909 },
910#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700911#ifdef CONFIG_RCU_TORTURE_TEST
912 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700913 .procname = "rcutorture_runnable",
914 .data = &rcutorture_runnable,
915 .maxlen = sizeof(int),
916 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800917 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700918 },
919#endif
David Howells12e22c52009-04-03 16:42:35 +0100920#ifdef CONFIG_SLOW_WORK
921 {
David Howells12e22c52009-04-03 16:42:35 +0100922 .procname = "slow-work",
923 .mode = 0555,
924 .child = slow_work_sysctls,
925 },
926#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200927#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200928 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200929 .procname = "perf_event_paranoid",
930 .data = &sysctl_perf_event_paranoid,
931 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200932 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800933 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200934 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200935 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200936 .procname = "perf_event_mlock_kb",
937 .data = &sysctl_perf_event_mlock,
938 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200939 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800940 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200941 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200942 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200943 .procname = "perf_event_max_sample_rate",
944 .data = &sysctl_perf_event_sample_rate,
945 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200946 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800947 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200948 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200949#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200950#ifdef CONFIG_KMEMCHECK
951 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200952 .procname = "kmemcheck",
953 .data = &kmemcheck_enabled,
954 .maxlen = sizeof(int),
955 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800956 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200957 },
958#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200959#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200960 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200961 .procname = "blk_iopoll",
962 .data = &blk_iopoll_enabled,
963 .maxlen = sizeof(int),
964 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800965 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200966 },
Jens Axboecb684b52009-09-15 21:53:11 +0200967#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700968/*
969 * NOTE: do not add new entries to this table unless you have read
970 * Documentation/sysctl/ctl_unnumbered.txt
971 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700972 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973};
974
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700975static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 .procname = "overcommit_memory",
978 .data = &sysctl_overcommit_memory,
979 .maxlen = sizeof(sysctl_overcommit_memory),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 },
983 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700984 .procname = "panic_on_oom",
985 .data = &sysctl_panic_on_oom,
986 .maxlen = sizeof(sysctl_panic_on_oom),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700989 },
990 {
David Rientjesfe071d72007-10-16 23:25:56 -0700991 .procname = "oom_kill_allocating_task",
992 .data = &sysctl_oom_kill_allocating_task,
993 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700996 },
997 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800998 .procname = "oom_dump_tasks",
999 .data = &sysctl_oom_dump_tasks,
1000 .maxlen = sizeof(sysctl_oom_dump_tasks),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001003 },
1004 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .procname = "overcommit_ratio",
1006 .data = &sysctl_overcommit_ratio,
1007 .maxlen = sizeof(sysctl_overcommit_ratio),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "page-cluster",
1013 .data = &page_cluster,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 },
1018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "dirty_background_ratio",
1020 .data = &dirty_background_ratio,
1021 .maxlen = sizeof(dirty_background_ratio),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .extra1 = &zero,
1025 .extra2 = &one_hundred,
1026 },
1027 {
David Rientjes2da02992009-01-06 14:39:31 -08001028 .procname = "dirty_background_bytes",
1029 .data = &dirty_background_bytes,
1030 .maxlen = sizeof(dirty_background_bytes),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001033 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001034 },
1035 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .procname = "dirty_ratio",
1037 .data = &vm_dirty_ratio,
1038 .maxlen = sizeof(vm_dirty_ratio),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 .extra1 = &zero,
1042 .extra2 = &one_hundred,
1043 },
1044 {
David Rientjes2da02992009-01-06 14:39:31 -08001045 .procname = "dirty_bytes",
1046 .data = &vm_dirty_bytes,
1047 .maxlen = sizeof(vm_dirty_bytes),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001050 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001051 },
1052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001054 .data = &dirty_writeback_interval,
1055 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 },
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001061 .data = &dirty_expire_interval,
1062 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "nr_pdflush_threads",
1068 .data = &nr_pdflush_threads,
1069 .maxlen = sizeof nr_pdflush_threads,
1070 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 },
1073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .procname = "swappiness",
1075 .data = &vm_swappiness,
1076 .maxlen = sizeof(vm_swappiness),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 .extra1 = &zero,
1080 .extra2 = &one_hundred,
1081 },
1082#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001083 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001085 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .maxlen = sizeof(unsigned long),
1087 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001088 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .extra1 = (void *)&hugetlb_zero,
1090 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001091 },
1092#ifdef CONFIG_NUMA
1093 {
1094 .procname = "nr_hugepages_mempolicy",
1095 .data = NULL,
1096 .maxlen = sizeof(unsigned long),
1097 .mode = 0644,
1098 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1099 .extra1 = (void *)&hugetlb_zero,
1100 .extra2 = (void *)&hugetlb_infinity,
1101 },
1102#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 .procname = "hugetlb_shm_group",
1105 .data = &sysctl_hugetlb_shm_group,
1106 .maxlen = sizeof(gid_t),
1107 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001108 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 },
Mel Gorman396faf02007-07-17 04:03:13 -07001110 {
Mel Gorman396faf02007-07-17 04:03:13 -07001111 .procname = "hugepages_treat_as_movable",
1112 .data = &hugepages_treat_as_movable,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001115 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001116 },
Adam Litke54f9f802007-10-16 01:26:20 -07001117 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001118 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001119 .data = NULL,
1120 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001121 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001122 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001123 .extra1 = (void *)&hugetlb_zero,
1124 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001125 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126#endif
1127 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 .procname = "lowmem_reserve_ratio",
1129 .data = &sysctl_lowmem_reserve_ratio,
1130 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1131 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001132 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 },
1134 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001135 .procname = "drop_caches",
1136 .data = &sysctl_drop_caches,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001140 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001141#ifdef CONFIG_COMPACTION
1142 {
1143 .procname = "compact_memory",
1144 .data = &sysctl_compact_memory,
1145 .maxlen = sizeof(int),
1146 .mode = 0200,
1147 .proc_handler = sysctl_compaction_handler,
1148 },
Mel Gorman5e771902010-05-24 14:32:31 -07001149 {
1150 .procname = "extfrag_threshold",
1151 .data = &sysctl_extfrag_threshold,
1152 .maxlen = sizeof(int),
1153 .mode = 0644,
1154 .proc_handler = sysctl_extfrag_handler,
1155 .extra1 = &min_extfrag_threshold,
1156 .extra2 = &max_extfrag_threshold,
1157 },
1158
Mel Gorman76ab0f52010-05-24 14:32:28 -07001159#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001160 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 .procname = "min_free_kbytes",
1162 .data = &min_free_kbytes,
1163 .maxlen = sizeof(min_free_kbytes),
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 .extra1 = &zero,
1167 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001168 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001169 .procname = "percpu_pagelist_fraction",
1170 .data = &percpu_pagelist_fraction,
1171 .maxlen = sizeof(percpu_pagelist_fraction),
1172 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001173 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001174 .extra1 = &min_percpu_pagelist_fract,
1175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#ifdef CONFIG_MMU
1177 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 .procname = "max_map_count",
1179 .data = &sysctl_max_map_count,
1180 .maxlen = sizeof(sysctl_max_map_count),
1181 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001182 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001183 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001185#else
1186 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001187 .procname = "nr_trim_pages",
1188 .data = &sysctl_nr_trim_pages,
1189 .maxlen = sizeof(sysctl_nr_trim_pages),
1190 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001191 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001192 .extra1 = &zero,
1193 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194#endif
1195 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 .procname = "laptop_mode",
1197 .data = &laptop_mode,
1198 .maxlen = sizeof(laptop_mode),
1199 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001200 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 },
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "block_dump",
1204 .data = &block_dump,
1205 .maxlen = sizeof(block_dump),
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .procname = "vfs_cache_pressure",
1212 .data = &sysctl_vfs_cache_pressure,
1213 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1214 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001215 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .extra1 = &zero,
1217 },
1218#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1219 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 .procname = "legacy_va_layout",
1221 .data = &sysctl_legacy_va_layout,
1222 .maxlen = sizeof(sysctl_legacy_va_layout),
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 .extra1 = &zero,
1226 },
1227#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001228#ifdef CONFIG_NUMA
1229 {
Christoph Lameter17436602006-01-18 17:42:32 -08001230 .procname = "zone_reclaim_mode",
1231 .data = &zone_reclaim_mode,
1232 .maxlen = sizeof(zone_reclaim_mode),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001235 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001236 },
Christoph Lameter96146342006-07-03 00:24:13 -07001237 {
Christoph Lameter96146342006-07-03 00:24:13 -07001238 .procname = "min_unmapped_ratio",
1239 .data = &sysctl_min_unmapped_ratio,
1240 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1241 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001242 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001243 .extra1 = &zero,
1244 .extra2 = &one_hundred,
1245 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001246 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001247 .procname = "min_slab_ratio",
1248 .data = &sysctl_min_slab_ratio,
1249 .maxlen = sizeof(sysctl_min_slab_ratio),
1250 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001251 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001252 .extra1 = &zero,
1253 .extra2 = &one_hundred,
1254 },
Christoph Lameter17436602006-01-18 17:42:32 -08001255#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001256#ifdef CONFIG_SMP
1257 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001258 .procname = "stat_interval",
1259 .data = &sysctl_stat_interval,
1260 .maxlen = sizeof(sysctl_stat_interval),
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001263 },
1264#endif
David Howells6e141542009-12-15 19:27:45 +00001265#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001266 {
Eric Parised032182007-06-28 15:55:21 -04001267 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001268 .data = &dac_mmap_min_addr,
1269 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001271 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001272 },
David Howells6e141542009-12-15 19:27:45 +00001273#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001274#ifdef CONFIG_NUMA
1275 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001276 .procname = "numa_zonelist_order",
1277 .data = &numa_zonelist_order,
1278 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001280 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001281 },
1282#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001283#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001284 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001285 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001286 .procname = "vdso_enabled",
1287 .data = &vdso_enabled,
1288 .maxlen = sizeof(vdso_enabled),
1289 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001290 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001291 .extra1 = &zero,
1292 },
1293#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001294#ifdef CONFIG_HIGHMEM
1295 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001296 .procname = "highmem_is_dirtyable",
1297 .data = &vm_highmem_is_dirtyable,
1298 .maxlen = sizeof(vm_highmem_is_dirtyable),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001301 .extra1 = &zero,
1302 .extra2 = &one,
1303 },
1304#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001305 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001306 .procname = "scan_unevictable_pages",
1307 .data = &scan_unevictable_pages,
1308 .maxlen = sizeof(scan_unevictable_pages),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001311 },
Andi Kleen6a460792009-09-16 11:50:15 +02001312#ifdef CONFIG_MEMORY_FAILURE
1313 {
Andi Kleen6a460792009-09-16 11:50:15 +02001314 .procname = "memory_failure_early_kill",
1315 .data = &sysctl_memory_failure_early_kill,
1316 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1317 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001318 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001319 .extra1 = &zero,
1320 .extra2 = &one,
1321 },
1322 {
Andi Kleen6a460792009-09-16 11:50:15 +02001323 .procname = "memory_failure_recovery",
1324 .data = &sysctl_memory_failure_recovery,
1325 .maxlen = sizeof(sysctl_memory_failure_recovery),
1326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001327 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001328 .extra1 = &zero,
1329 .extra2 = &one,
1330 },
1331#endif
1332
Andrew Morton2be7fe02007-07-15 23:41:21 -07001333/*
1334 * NOTE: do not add new entries to this table unless you have read
1335 * Documentation/sysctl/ctl_unnumbered.txt
1336 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001337 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338};
1339
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001340#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001341static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001342 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001343};
1344#endif
1345
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001346static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "inode-nr",
1349 .data = &inodes_stat,
1350 .maxlen = 2*sizeof(int),
1351 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 },
1354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "inode-state",
1356 .data = &inodes_stat,
1357 .maxlen = 7*sizeof(int),
1358 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001359 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
1361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .procname = "file-nr",
1363 .data = &files_stat,
1364 .maxlen = 3*sizeof(int),
1365 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001366 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 },
1368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .procname = "file-max",
1370 .data = &files_stat.max_files,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001373 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 },
1375 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001376 .procname = "nr_open",
1377 .data = &sysctl_nr_open,
1378 .maxlen = sizeof(int),
1379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001381 .extra1 = &sysctl_nr_open_min,
1382 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001383 },
1384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .procname = "dentry-state",
1386 .data = &dentry_stat,
1387 .maxlen = 6*sizeof(int),
1388 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001389 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 },
1391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "overflowuid",
1393 .data = &fs_overflowuid,
1394 .maxlen = sizeof(int),
1395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001396 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .extra1 = &minolduid,
1398 .extra2 = &maxolduid,
1399 },
1400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .procname = "overflowgid",
1402 .data = &fs_overflowgid,
1403 .maxlen = sizeof(int),
1404 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001405 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .extra1 = &minolduid,
1407 .extra2 = &maxolduid,
1408 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001409#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .procname = "leases-enable",
1412 .data = &leases_enable,
1413 .maxlen = sizeof(int),
1414 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001415 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001417#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418#ifdef CONFIG_DNOTIFY
1419 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .procname = "dir-notify-enable",
1421 .data = &dir_notify_enable,
1422 .maxlen = sizeof(int),
1423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001424 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 },
1426#endif
1427#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001428#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "lease-break-time",
1431 .data = &lease_break_time,
1432 .maxlen = sizeof(int),
1433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001434 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001436#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001437#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 .procname = "aio-nr",
1440 .data = &aio_nr,
1441 .maxlen = sizeof(aio_nr),
1442 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 },
1445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .procname = "aio-max-nr",
1447 .data = &aio_max_nr,
1448 .maxlen = sizeof(aio_max_nr),
1449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001452#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001453#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001454 {
Robert Love0399cb02005-07-13 12:38:18 -04001455 .procname = "inotify",
1456 .mode = 0555,
1457 .child = inotify_table,
1458 },
1459#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001460#ifdef CONFIG_EPOLL
1461 {
1462 .procname = "epoll",
1463 .mode = 0555,
1464 .child = epoll_table,
1465 },
1466#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001468 {
Alan Coxd6e71142005-06-23 00:09:43 -07001469 .procname = "suid_dumpable",
1470 .data = &suid_dumpable,
1471 .maxlen = sizeof(int),
1472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001473 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001474 .extra1 = &zero,
1475 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001476 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001477#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1478 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001479 .procname = "binfmt_misc",
1480 .mode = 0555,
1481 .child = binfmt_misc_table,
1482 },
1483#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001484 {
Jens Axboeff9da692010-06-03 14:54:39 +02001485 .procname = "pipe-max-size",
1486 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001487 .maxlen = sizeof(int),
1488 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001489 .proc_handler = &pipe_proc_fn,
1490 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001491 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001492/*
1493 * NOTE: do not add new entries to this table unless you have read
1494 * Documentation/sysctl/ctl_unnumbered.txt
1495 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001496 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497};
1498
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001499static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001500#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1501 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001502 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001503 .procname = "exception-trace",
1504 .data = &show_unhandled_signals,
1505 .maxlen = sizeof(int),
1506 .mode = 0644,
1507 .proc_handler = proc_dointvec
1508 },
1509#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001510#if defined(CONFIG_OPTPROBES)
1511 {
1512 .procname = "kprobes-optimization",
1513 .data = &sysctl_kprobes_optimization,
1514 .maxlen = sizeof(int),
1515 .mode = 0644,
1516 .proc_handler = proc_kprobes_optimization_handler,
1517 .extra1 = &zero,
1518 .extra2 = &one,
1519 },
1520#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001521 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522};
1523
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001524static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001525 { }
Robert Love0eeca282005-07-12 17:06:03 -04001526};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
Al Viro330d57f2005-11-04 10:18:40 +00001528static DEFINE_SPINLOCK(sysctl_lock);
1529
1530/* called under sysctl_lock */
1531static int use_table(struct ctl_table_header *p)
1532{
1533 if (unlikely(p->unregistering))
1534 return 0;
1535 p->used++;
1536 return 1;
1537}
1538
1539/* called under sysctl_lock */
1540static void unuse_table(struct ctl_table_header *p)
1541{
1542 if (!--p->used)
1543 if (unlikely(p->unregistering))
1544 complete(p->unregistering);
1545}
1546
1547/* called under sysctl_lock, will reacquire if has to wait */
1548static void start_unregistering(struct ctl_table_header *p)
1549{
1550 /*
1551 * if p->used is 0, nobody will ever touch that entry again;
1552 * we'll eliminate all paths to it before dropping sysctl_lock
1553 */
1554 if (unlikely(p->used)) {
1555 struct completion wait;
1556 init_completion(&wait);
1557 p->unregistering = &wait;
1558 spin_unlock(&sysctl_lock);
1559 wait_for_completion(&wait);
1560 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001561 } else {
1562 /* anything non-NULL; we'll never dereference it */
1563 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001564 }
1565 /*
1566 * do not remove from the list until nobody holds it; walking the
1567 * list in do_sysctl() relies on that.
1568 */
1569 list_del_init(&p->ctl_entry);
1570}
1571
Al Virof7e6ced2008-07-15 01:44:23 -04001572void sysctl_head_get(struct ctl_table_header *head)
1573{
1574 spin_lock(&sysctl_lock);
1575 head->count++;
1576 spin_unlock(&sysctl_lock);
1577}
1578
1579void sysctl_head_put(struct ctl_table_header *head)
1580{
1581 spin_lock(&sysctl_lock);
1582 if (!--head->count)
1583 kfree(head);
1584 spin_unlock(&sysctl_lock);
1585}
1586
1587struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1588{
1589 if (!head)
1590 BUG();
1591 spin_lock(&sysctl_lock);
1592 if (!use_table(head))
1593 head = ERR_PTR(-ENOENT);
1594 spin_unlock(&sysctl_lock);
1595 return head;
1596}
1597
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001598void sysctl_head_finish(struct ctl_table_header *head)
1599{
1600 if (!head)
1601 return;
1602 spin_lock(&sysctl_lock);
1603 unuse_table(head);
1604 spin_unlock(&sysctl_lock);
1605}
1606
Al Viro73455092008-07-14 21:22:20 -04001607static struct ctl_table_set *
1608lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1609{
1610 struct ctl_table_set *set = &root->default_set;
1611 if (root->lookup)
1612 set = root->lookup(root, namespaces);
1613 return set;
1614}
1615
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001616static struct list_head *
1617lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001618{
Al Viro73455092008-07-14 21:22:20 -04001619 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1620 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621}
1622
1623struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1624 struct ctl_table_header *prev)
1625{
1626 struct ctl_table_root *root;
1627 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001628 struct ctl_table_header *head;
1629 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001630
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 spin_lock(&sysctl_lock);
1632 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001633 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001634 tmp = &prev->ctl_entry;
1635 unuse_table(prev);
1636 goto next;
1637 }
1638 tmp = &root_table_header.ctl_entry;
1639 for (;;) {
1640 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1641
1642 if (!use_table(head))
1643 goto next;
1644 spin_unlock(&sysctl_lock);
1645 return head;
1646 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001647 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001648 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001649 header_list = lookup_header_list(root, namespaces);
1650 if (tmp != header_list)
1651 continue;
1652
1653 do {
1654 root = list_entry(root->root_list.next,
1655 struct ctl_table_root, root_list);
1656 if (root == &sysctl_table_root)
1657 goto out;
1658 header_list = lookup_header_list(root, namespaces);
1659 } while (list_empty(header_list));
1660 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001661 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001662out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001663 spin_unlock(&sysctl_lock);
1664 return NULL;
1665}
1666
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001667struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1668{
1669 return __sysctl_head_next(current->nsproxy, prev);
1670}
1671
1672void register_sysctl_root(struct ctl_table_root *root)
1673{
1674 spin_lock(&sysctl_lock);
1675 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1676 spin_unlock(&sysctl_lock);
1677}
1678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001680 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 * some sysctl variables are readonly even to root.
1682 */
1683
1684static int test_perm(int mode, int op)
1685{
David Howells76aac0e2008-11-14 10:39:12 +11001686 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 mode >>= 6;
1688 else if (in_egroup_p(0))
1689 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001690 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 return 0;
1692 return -EACCES;
1693}
1694
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001695int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696{
1697 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001698 int mode;
1699
Al Viroe6305c42008-07-15 21:03:57 -04001700 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (error)
1702 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001703
1704 if (root->permissions)
1705 mode = root->permissions(root, current->nsproxy, table);
1706 else
1707 mode = table->mode;
1708
1709 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001712static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1713{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001714 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001715 table->parent = parent;
1716 if (table->child)
1717 sysctl_set_parent(table, table->child);
1718 }
1719}
1720
1721static __init int sysctl_init(void)
1722{
1723 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001724#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1725 {
1726 int err;
1727 err = sysctl_check_table(current->nsproxy, root_table);
1728 }
1729#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001730 return 0;
1731}
1732
1733core_initcall(sysctl_init);
1734
Al Virobfbcf032008-07-27 06:31:22 +01001735static struct ctl_table *is_branch_in(struct ctl_table *branch,
1736 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001737{
1738 struct ctl_table *p;
1739 const char *s = branch->procname;
1740
1741 /* branch should have named subdirectory as its first element */
1742 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001743 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001744
1745 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001746 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001747 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001748
1749 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001750 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001751 if (!p->child)
1752 continue;
1753 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001754 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001755 }
Al Virobfbcf032008-07-27 06:31:22 +01001756 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001757}
1758
1759/* see if attaching q to p would be an improvement */
1760static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1761{
1762 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001763 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001764 int is_better = 0;
1765 int not_in_parent = !p->attached_by;
1766
Al Virobfbcf032008-07-27 06:31:22 +01001767 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001768 if (by == q->attached_by)
1769 is_better = 1;
1770 if (to == p->attached_by)
1771 not_in_parent = 1;
1772 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001773 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001774 }
1775
1776 if (is_better && not_in_parent) {
1777 q->attached_by = by;
1778 q->attached_to = to;
1779 q->parent = p;
1780 }
1781}
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001784 * __register_sysctl_paths - register a sysctl hierarchy
1785 * @root: List of sysctl headers to register on
1786 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001787 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 *
1790 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001791 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001793 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1796 * enter a sysctl file
1797 *
1798 * data - a pointer to data for use by proc_handler
1799 *
1800 * maxlen - the maximum size in bytes of the data
1801 *
1802 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1803 *
1804 * child - a pointer to the child sysctl table if this entry is a directory, or
1805 * %NULL.
1806 *
1807 * proc_handler - the text handler routine (described below)
1808 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 * de - for internal use by the sysctl routines
1810 *
1811 * extra1, extra2 - extra pointers usable by the proc handler routines
1812 *
1813 * Leaf nodes in the sysctl tree will be represented by a single file
1814 * under /proc; non-leaf nodes will be represented by directories.
1815 *
1816 * sysctl(2) can automatically manage read and write requests through
1817 * the sysctl table. The data and maxlen fields of the ctl_table
1818 * struct enable minimal validation of the values being written to be
1819 * performed, and the mode field allows minimal authentication.
1820 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 * There must be a proc_handler routine for any terminal nodes
1822 * mirrored under /proc/sys (non-terminals are handled by a built-in
1823 * directory handler). Several default handlers are available to
1824 * cover common cases -
1825 *
1826 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1827 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1828 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1829 *
1830 * It is the handler's job to read the input buffer from user memory
1831 * and process it. The handler should return 0 on success.
1832 *
1833 * This routine returns %NULL on a failure to register, and a pointer
1834 * to the table header on success.
1835 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001836struct ctl_table_header *__register_sysctl_paths(
1837 struct ctl_table_root *root,
1838 struct nsproxy *namespaces,
1839 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841 struct ctl_table_header *header;
1842 struct ctl_table *new, **prevp;
1843 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001844 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001845
1846 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001847 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001848 ;
1849
1850 /*
1851 * For each path component, allocate a 2-element ctl_table array.
1852 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001853 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001854 *
1855 * We allocate everything in one go so that we don't have to
1856 * worry about freeing additional memory in unregister_sysctl_table.
1857 */
1858 header = kzalloc(sizeof(struct ctl_table_header) +
1859 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1860 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862
1863 new = (struct ctl_table *) (header + 1);
1864
1865 /* Now connect the dots */
1866 prevp = &header->ctl_table;
1867 for (n = 0; n < npath; ++n, ++path) {
1868 /* Copy the procname */
1869 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001870 new->mode = 0555;
1871
1872 *prevp = new;
1873 prevp = &new->child;
1874
1875 new += 2;
1876 }
1877 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001878 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879
1880 INIT_LIST_HEAD(&header->ctl_entry);
1881 header->used = 0;
1882 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001883 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001884 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001885 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001886#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001887 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001888 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001889 return NULL;
1890 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001891#endif
Al Viro330d57f2005-11-04 10:18:40 +00001892 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001893 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001894 header->attached_by = header->ctl_table;
1895 header->attached_to = root_table;
1896 header->parent = &root_table_header;
1897 for (set = header->set; set; set = set->parent) {
1898 struct ctl_table_header *p;
1899 list_for_each_entry(p, &set->list, ctl_entry) {
1900 if (p->unregistering)
1901 continue;
1902 try_attach(p, header);
1903 }
1904 }
1905 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001906 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001907 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001908
1909 return header;
1910}
1911
1912/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001913 * register_sysctl_table_path - register a sysctl table hierarchy
1914 * @path: The path to the directory the sysctl table is in.
1915 * @table: the top-level table structure
1916 *
1917 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1918 * array. A completely 0 filled entry terminates the table.
1919 *
1920 * See __register_sysctl_paths for more details.
1921 */
1922struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1923 struct ctl_table *table)
1924{
1925 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1926 path, table);
1927}
1928
1929/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001930 * register_sysctl_table - register a sysctl table hierarchy
1931 * @table: the top-level table structure
1932 *
1933 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1934 * array. A completely 0 filled entry terminates the table.
1935 *
1936 * See register_sysctl_paths for more details.
1937 */
1938struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1939{
1940 static const struct ctl_path null_path[] = { {} };
1941
1942 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944
1945/**
1946 * unregister_sysctl_table - unregister a sysctl table hierarchy
1947 * @header: the header returned from register_sysctl_table
1948 *
1949 * Unregisters the sysctl table and all children. proc entries may not
1950 * actually be removed until they are no longer used by anyone.
1951 */
1952void unregister_sysctl_table(struct ctl_table_header * header)
1953{
Al Viro330d57f2005-11-04 10:18:40 +00001954 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001955
1956 if (header == NULL)
1957 return;
1958
Al Viro330d57f2005-11-04 10:18:40 +00001959 spin_lock(&sysctl_lock);
1960 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001961 if (!--header->parent->count) {
1962 WARN_ON(1);
1963 kfree(header->parent);
1964 }
Al Virof7e6ced2008-07-15 01:44:23 -04001965 if (!--header->count)
1966 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001967 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968}
1969
Al Viro90434762008-07-15 08:54:06 -04001970int sysctl_is_seen(struct ctl_table_header *p)
1971{
1972 struct ctl_table_set *set = p->set;
1973 int res;
1974 spin_lock(&sysctl_lock);
1975 if (p->unregistering)
1976 res = 0;
1977 else if (!set->is_seen)
1978 res = 1;
1979 else
1980 res = set->is_seen(set);
1981 spin_unlock(&sysctl_lock);
1982 return res;
1983}
1984
Al Viro73455092008-07-14 21:22:20 -04001985void setup_sysctl_set(struct ctl_table_set *p,
1986 struct ctl_table_set *parent,
1987 int (*is_seen)(struct ctl_table_set *))
1988{
1989 INIT_LIST_HEAD(&p->list);
1990 p->parent = parent ? parent : &sysctl_table_root.default_set;
1991 p->is_seen = is_seen;
1992}
1993
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001994#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001995struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001996{
1997 return NULL;
1998}
1999
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002000struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2001 struct ctl_table *table)
2002{
2003 return NULL;
2004}
2005
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002006void unregister_sysctl_table(struct ctl_table_header * table)
2007{
2008}
2009
Al Viro73455092008-07-14 21:22:20 -04002010void setup_sysctl_set(struct ctl_table_set *p,
2011 struct ctl_table_set *parent,
2012 int (*is_seen)(struct ctl_table_set *))
2013{
2014}
2015
Al Virof7e6ced2008-07-15 01:44:23 -04002016void sysctl_head_put(struct ctl_table_header *head)
2017{
2018}
2019
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002020#endif /* CONFIG_SYSCTL */
2021
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022/*
2023 * /proc/sys support
2024 */
2025
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002026#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002028static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002029 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002030 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002031{
2032 size_t len;
2033 char __user *p;
2034 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002035
2036 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002037 *lenp = 0;
2038 return 0;
2039 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002040
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002041 if (write) {
2042 len = 0;
2043 p = buffer;
2044 while (len < *lenp) {
2045 if (get_user(c, p++))
2046 return -EFAULT;
2047 if (c == 0 || c == '\n')
2048 break;
2049 len++;
2050 }
2051 if (len >= maxlen)
2052 len = maxlen-1;
2053 if(copy_from_user(data, buffer, len))
2054 return -EFAULT;
2055 ((char *) data)[len] = 0;
2056 *ppos += *lenp;
2057 } else {
2058 len = strlen(data);
2059 if (len > maxlen)
2060 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002061
2062 if (*ppos > len) {
2063 *lenp = 0;
2064 return 0;
2065 }
2066
2067 data += *ppos;
2068 len -= *ppos;
2069
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002070 if (len > *lenp)
2071 len = *lenp;
2072 if (len)
2073 if(copy_to_user(buffer, data, len))
2074 return -EFAULT;
2075 if (len < *lenp) {
2076 if(put_user('\n', ((char __user *) buffer) + len))
2077 return -EFAULT;
2078 len++;
2079 }
2080 *lenp = len;
2081 *ppos += len;
2082 }
2083 return 0;
2084}
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086/**
2087 * proc_dostring - read a string sysctl
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 * @buffer: the user buffer
2091 * @lenp: the size of the user buffer
2092 * @ppos: file position
2093 *
2094 * Reads/writes a string from/to the user buffer. If the kernel
2095 * buffer provided is not large enough to hold the string, the
2096 * string is truncated. The copied string is %NULL-terminated.
2097 * If the string is being read by the user process, it is copied
2098 * and a newline '\n' is added. It is truncated if the buffer is
2099 * not large enough.
2100 *
2101 * Returns 0 on success.
2102 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002103int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 void __user *buffer, size_t *lenp, loff_t *ppos)
2105{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002106 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002107 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108}
2109
Amerigo Wang00b7c332010-05-05 00:26:45 +00002110static size_t proc_skip_spaces(char **buf)
2111{
2112 size_t ret;
2113 char *tmp = skip_spaces(*buf);
2114 ret = tmp - *buf;
2115 *buf = tmp;
2116 return ret;
2117}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002119static void proc_skip_char(char **buf, size_t *size, const char v)
2120{
2121 while (*size) {
2122 if (**buf != v)
2123 break;
2124 (*size)--;
2125 (*buf)++;
2126 }
2127}
2128
Amerigo Wang00b7c332010-05-05 00:26:45 +00002129#define TMPBUFLEN 22
2130/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002131 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002132 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002133 * @buf: a kernel buffer
2134 * @size: size of the kernel buffer
2135 * @val: this is where the number will be stored
2136 * @neg: set to %TRUE if number is negative
2137 * @perm_tr: a vector which contains the allowed trailers
2138 * @perm_tr_len: size of the perm_tr vector
2139 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002141 * In case of success %0 is returned and @buf and @size are updated with
2142 * the amount of bytes read. If @tr is non-NULL and a trailing
2143 * character exists (size is non-zero after returning from this
2144 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002145 */
2146static int proc_get_long(char **buf, size_t *size,
2147 unsigned long *val, bool *neg,
2148 const char *perm_tr, unsigned perm_tr_len, char *tr)
2149{
2150 int len;
2151 char *p, tmp[TMPBUFLEN];
2152
2153 if (!*size)
2154 return -EINVAL;
2155
2156 len = *size;
2157 if (len > TMPBUFLEN - 1)
2158 len = TMPBUFLEN - 1;
2159
2160 memcpy(tmp, *buf, len);
2161
2162 tmp[len] = 0;
2163 p = tmp;
2164 if (*p == '-' && *size > 1) {
2165 *neg = true;
2166 p++;
2167 } else
2168 *neg = false;
2169 if (!isdigit(*p))
2170 return -EINVAL;
2171
2172 *val = simple_strtoul(p, &p, 0);
2173
2174 len = p - tmp;
2175
2176 /* We don't know if the next char is whitespace thus we may accept
2177 * invalid integers (e.g. 1234...a) or two integers instead of one
2178 * (e.g. 123...1). So lets not allow such large numbers. */
2179 if (len == TMPBUFLEN - 1)
2180 return -EINVAL;
2181
2182 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2183 return -EINVAL;
2184
2185 if (tr && (len < *size))
2186 *tr = *p;
2187
2188 *buf += len;
2189 *size -= len;
2190
2191 return 0;
2192}
2193
2194/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002195 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002197 * @buf: the user buffer
2198 * @size: the size of the user buffer
2199 * @val: the integer to be converted
2200 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002201 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002202 * In case of success %0 is returned and @buf and @size are updated with
2203 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002204 */
2205static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2206 bool neg)
2207{
2208 int len;
2209 char tmp[TMPBUFLEN], *p = tmp;
2210
2211 sprintf(p, "%s%lu", neg ? "-" : "", val);
2212 len = strlen(tmp);
2213 if (len > *size)
2214 len = *size;
2215 if (copy_to_user(*buf, tmp, len))
2216 return -EFAULT;
2217 *size -= len;
2218 *buf += len;
2219 return 0;
2220}
2221#undef TMPBUFLEN
2222
2223static int proc_put_char(void __user **buf, size_t *size, char c)
2224{
2225 if (*size) {
2226 char __user **buffer = (char __user **)buf;
2227 if (put_user(c, *buffer))
2228 return -EFAULT;
2229 (*size)--, (*buffer)++;
2230 *buf = *buffer;
2231 }
2232 return 0;
2233}
2234
2235static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 int *valp,
2237 int write, void *data)
2238{
2239 if (write) {
2240 *valp = *negp ? -*lvalp : *lvalp;
2241 } else {
2242 int val = *valp;
2243 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002244 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 *lvalp = (unsigned long)-val;
2246 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002247 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 *lvalp = (unsigned long)val;
2249 }
2250 }
2251 return 0;
2252}
2253
Amerigo Wang00b7c332010-05-05 00:26:45 +00002254static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2255
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002256static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002257 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002258 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002259 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 int write, void *data),
2261 void *data)
2262{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 int *i, vleft, first = 1, err = 0;
2264 unsigned long page = 0;
2265 size_t left;
2266 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 *lenp = 0;
2270 return 0;
2271 }
2272
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 vleft = table->maxlen / sizeof(*i);
2275 left = *lenp;
2276
2277 if (!conv)
2278 conv = do_proc_dointvec_conv;
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281 if (left > PAGE_SIZE - 1)
2282 left = PAGE_SIZE - 1;
2283 page = __get_free_page(GFP_TEMPORARY);
2284 kbuf = (char *) page;
2285 if (!kbuf)
2286 return -ENOMEM;
2287 if (copy_from_user(kbuf, buffer, left)) {
2288 err = -EFAULT;
2289 goto free;
2290 }
2291 kbuf[left] = 0;
2292 }
2293
2294 for (; left && vleft--; i++, first=0) {
2295 unsigned long lval;
2296 bool neg;
2297
2298 if (write) {
2299 left -= proc_skip_spaces(&kbuf);
2300
J. R. Okajima563b0462010-05-25 16:10:14 -07002301 if (!left)
2302 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 err = proc_get_long(&kbuf, &left, &lval, &neg,
2304 proc_wspace_sep,
2305 sizeof(proc_wspace_sep), NULL);
2306 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002308 if (conv(&neg, &lval, i, 1, data)) {
2309 err = -EINVAL;
2310 break;
2311 }
2312 } else {
2313 if (conv(&neg, &lval, i, 0, data)) {
2314 err = -EINVAL;
2315 break;
2316 }
2317 if (!first)
2318 err = proc_put_char(&buffer, &left, '\t');
2319 if (err)
2320 break;
2321 err = proc_put_long(&buffer, &left, lval, neg);
2322 if (err)
2323 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 }
2325 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002326
2327 if (!write && !first && left && !err)
2328 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002329 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330 left -= proc_skip_spaces(&kbuf);
2331free:
2332 if (write) {
2333 free_page(page);
2334 if (first)
2335 return err ? : -EINVAL;
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 *lenp -= left;
2338 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340}
2341
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002342static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002343 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002344 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002345 int write, void *data),
2346 void *data)
2347{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002348 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002349 buffer, lenp, ppos, conv, data);
2350}
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352/**
2353 * proc_dointvec - read a vector of integers
2354 * @table: the sysctl table
2355 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 * @buffer: the user buffer
2357 * @lenp: the size of the user buffer
2358 * @ppos: file position
2359 *
2360 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2361 * values from/to the user buffer, treated as an ASCII string.
2362 *
2363 * Returns 0 on success.
2364 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002365int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 void __user *buffer, size_t *lenp, loff_t *ppos)
2367{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 NULL,NULL);
2370}
2371
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002373 * Taint values can only be increased
2374 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002376static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377 void __user *buffer, size_t *lenp, loff_t *ppos)
2378{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002379 struct ctl_table t;
2380 unsigned long tmptaint = get_taint();
2381 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002382
Bastian Blank91fcd412007-04-23 14:41:14 -07002383 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002384 return -EPERM;
2385
Andi Kleen25ddbb12008-10-15 22:01:41 -07002386 t = *table;
2387 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002388 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 if (err < 0)
2390 return err;
2391
2392 if (write) {
2393 /*
2394 * Poor man's atomic or. Not worth adding a primitive
2395 * to everyone's atomic.h for this
2396 */
2397 int i;
2398 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2399 if ((tmptaint >> i) & 1)
2400 add_taint(i);
2401 }
2402 }
2403
2404 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002405}
2406
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407struct do_proc_dointvec_minmax_conv_param {
2408 int *min;
2409 int *max;
2410};
2411
Amerigo Wang00b7c332010-05-05 00:26:45 +00002412static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2413 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 int write, void *data)
2415{
2416 struct do_proc_dointvec_minmax_conv_param *param = data;
2417 if (write) {
2418 int val = *negp ? -*lvalp : *lvalp;
2419 if ((param->min && *param->min > val) ||
2420 (param->max && *param->max < val))
2421 return -EINVAL;
2422 *valp = val;
2423 } else {
2424 int val = *valp;
2425 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002426 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 *lvalp = (unsigned long)-val;
2428 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002429 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 *lvalp = (unsigned long)val;
2431 }
2432 }
2433 return 0;
2434}
2435
2436/**
2437 * proc_dointvec_minmax - read a vector of integers with min/max values
2438 * @table: the sysctl table
2439 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 * @buffer: the user buffer
2441 * @lenp: the size of the user buffer
2442 * @ppos: file position
2443 *
2444 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2445 * values from/to the user buffer, treated as an ASCII string.
2446 *
2447 * This routine will ensure the values are within the range specified by
2448 * table->extra1 (min) and table->extra2 (max).
2449 *
2450 * Returns 0 on success.
2451 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002452int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 void __user *buffer, size_t *lenp, loff_t *ppos)
2454{
2455 struct do_proc_dointvec_minmax_conv_param param = {
2456 .min = (int *) table->extra1,
2457 .max = (int *) table->extra2,
2458 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002459 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 do_proc_dointvec_minmax_conv, &param);
2461}
2462
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002463static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 void __user *buffer,
2465 size_t *lenp, loff_t *ppos,
2466 unsigned long convmul,
2467 unsigned long convdiv)
2468{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002469 unsigned long *i, *min, *max;
2470 int vleft, first = 1, err = 0;
2471 unsigned long page = 0;
2472 size_t left;
2473 char *kbuf;
2474
2475 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 *lenp = 0;
2477 return 0;
2478 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002479
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002480 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 min = (unsigned long *) table->extra1;
2482 max = (unsigned long *) table->extra2;
2483 vleft = table->maxlen / sizeof(unsigned long);
2484 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002485
2486 if (write) {
2487 if (left > PAGE_SIZE - 1)
2488 left = PAGE_SIZE - 1;
2489 page = __get_free_page(GFP_TEMPORARY);
2490 kbuf = (char *) page;
2491 if (!kbuf)
2492 return -ENOMEM;
2493 if (copy_from_user(kbuf, buffer, left)) {
2494 err = -EFAULT;
2495 goto free;
2496 }
2497 kbuf[left] = 0;
2498 }
2499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 for (; left && vleft--; i++, min++, max++, first=0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002501 unsigned long val;
2502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002504 bool neg;
2505
2506 left -= proc_skip_spaces(&kbuf);
2507
2508 err = proc_get_long(&kbuf, &left, &val, &neg,
2509 proc_wspace_sep,
2510 sizeof(proc_wspace_sep), NULL);
2511 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 break;
2513 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 continue;
2515 if ((min && val < *min) || (max && val > *max))
2516 continue;
2517 *i = val;
2518 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002519 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002521 err = proc_put_char(&buffer, &left, '\t');
2522 err = proc_put_long(&buffer, &left, val, false);
2523 if (err)
2524 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 }
2526 }
2527
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 if (!write && !first && left && !err)
2529 err = proc_put_char(&buffer, &left, '\n');
2530 if (write && !err)
2531 left -= proc_skip_spaces(&kbuf);
2532free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 free_page(page);
2535 if (first)
2536 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 *lenp -= left;
2539 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002540 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541}
2542
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002543static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002544 void __user *buffer,
2545 size_t *lenp, loff_t *ppos,
2546 unsigned long convmul,
2547 unsigned long convdiv)
2548{
2549 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002550 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002551}
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553/**
2554 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2555 * @table: the sysctl table
2556 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 * @buffer: the user buffer
2558 * @lenp: the size of the user buffer
2559 * @ppos: file position
2560 *
2561 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2562 * values from/to the user buffer, treated as an ASCII string.
2563 *
2564 * This routine will ensure the values are within the range specified by
2565 * table->extra1 (min) and table->extra2 (max).
2566 *
2567 * Returns 0 on success.
2568 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002569int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 void __user *buffer, size_t *lenp, loff_t *ppos)
2571{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002572 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573}
2574
2575/**
2576 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 * @buffer: the user buffer
2580 * @lenp: the size of the user buffer
2581 * @ppos: file position
2582 *
2583 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2584 * values from/to the user buffer, treated as an ASCII string. The values
2585 * are treated as milliseconds, and converted to jiffies when they are stored.
2586 *
2587 * This routine will ensure the values are within the range specified by
2588 * table->extra1 (min) and table->extra2 (max).
2589 *
2590 * Returns 0 on success.
2591 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002592int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 void __user *buffer,
2594 size_t *lenp, loff_t *ppos)
2595{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002596 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 lenp, ppos, HZ, 1000l);
2598}
2599
2600
Amerigo Wang00b7c332010-05-05 00:26:45 +00002601static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 int *valp,
2603 int write, void *data)
2604{
2605 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002606 if (*lvalp > LONG_MAX / HZ)
2607 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2609 } else {
2610 int val = *valp;
2611 unsigned long lval;
2612 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002613 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 lval = (unsigned long)-val;
2615 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002616 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 lval = (unsigned long)val;
2618 }
2619 *lvalp = lval / HZ;
2620 }
2621 return 0;
2622}
2623
Amerigo Wang00b7c332010-05-05 00:26:45 +00002624static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 int *valp,
2626 int write, void *data)
2627{
2628 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002629 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2630 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2632 } else {
2633 int val = *valp;
2634 unsigned long lval;
2635 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002636 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 lval = (unsigned long)-val;
2638 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002639 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 lval = (unsigned long)val;
2641 }
2642 *lvalp = jiffies_to_clock_t(lval);
2643 }
2644 return 0;
2645}
2646
Amerigo Wang00b7c332010-05-05 00:26:45 +00002647static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 int *valp,
2649 int write, void *data)
2650{
2651 if (write) {
2652 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2653 } else {
2654 int val = *valp;
2655 unsigned long lval;
2656 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002657 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 lval = (unsigned long)-val;
2659 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002660 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 lval = (unsigned long)val;
2662 }
2663 *lvalp = jiffies_to_msecs(lval);
2664 }
2665 return 0;
2666}
2667
2668/**
2669 * proc_dointvec_jiffies - read a vector of integers as seconds
2670 * @table: the sysctl table
2671 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 * @buffer: the user buffer
2673 * @lenp: the size of the user buffer
2674 * @ppos: file position
2675 *
2676 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2677 * values from/to the user buffer, treated as an ASCII string.
2678 * The values read are assumed to be in seconds, and are converted into
2679 * jiffies.
2680 *
2681 * Returns 0 on success.
2682 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002683int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 void __user *buffer, size_t *lenp, loff_t *ppos)
2685{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002686 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 do_proc_dointvec_jiffies_conv,NULL);
2688}
2689
2690/**
2691 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2692 * @table: the sysctl table
2693 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 * @buffer: the user buffer
2695 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002696 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 *
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2699 * values from/to the user buffer, treated as an ASCII string.
2700 * The values read are assumed to be in 1/USER_HZ seconds, and
2701 * are converted into jiffies.
2702 *
2703 * Returns 0 on success.
2704 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002705int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 void __user *buffer, size_t *lenp, loff_t *ppos)
2707{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002708 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 do_proc_dointvec_userhz_jiffies_conv,NULL);
2710}
2711
2712/**
2713 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2714 * @table: the sysctl table
2715 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 * @buffer: the user buffer
2717 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002718 * @ppos: file position
2719 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 *
2721 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2722 * values from/to the user buffer, treated as an ASCII string.
2723 * The values read are assumed to be in 1/1000 seconds, and
2724 * are converted into jiffies.
2725 *
2726 * Returns 0 on success.
2727 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002728int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 void __user *buffer, size_t *lenp, loff_t *ppos)
2730{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002731 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 do_proc_dointvec_ms_jiffies_conv, NULL);
2733}
2734
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002736 void __user *buffer, size_t *lenp, loff_t *ppos)
2737{
2738 struct pid *new_pid;
2739 pid_t tmp;
2740 int r;
2741
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002742 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002743
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002744 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002745 lenp, ppos, NULL, NULL);
2746 if (r || !write)
2747 return r;
2748
2749 new_pid = find_get_pid(tmp);
2750 if (!new_pid)
2751 return -ESRCH;
2752
2753 put_pid(xchg(&cad_pid, new_pid));
2754 return 0;
2755}
2756
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002757/**
2758 * proc_do_large_bitmap - read/write from/to a large bitmap
2759 * @table: the sysctl table
2760 * @write: %TRUE if this is a write to the sysctl file
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
2763 * @ppos: file position
2764 *
2765 * The bitmap is stored at table->data and the bitmap length (in bits)
2766 * in table->maxlen.
2767 *
2768 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2769 * large bitmaps may be represented in a compact manner. Writing into
2770 * the file will clear the bitmap then update it with the given input.
2771 *
2772 * Returns 0 on success.
2773 */
2774int proc_do_large_bitmap(struct ctl_table *table, int write,
2775 void __user *buffer, size_t *lenp, loff_t *ppos)
2776{
2777 int err = 0;
2778 bool first = 1;
2779 size_t left = *lenp;
2780 unsigned long bitmap_len = table->maxlen;
2781 unsigned long *bitmap = (unsigned long *) table->data;
2782 unsigned long *tmp_bitmap = NULL;
2783 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2784
2785 if (!bitmap_len || !left || (*ppos && !write)) {
2786 *lenp = 0;
2787 return 0;
2788 }
2789
2790 if (write) {
2791 unsigned long page = 0;
2792 char *kbuf;
2793
2794 if (left > PAGE_SIZE - 1)
2795 left = PAGE_SIZE - 1;
2796
2797 page = __get_free_page(GFP_TEMPORARY);
2798 kbuf = (char *) page;
2799 if (!kbuf)
2800 return -ENOMEM;
2801 if (copy_from_user(kbuf, buffer, left)) {
2802 free_page(page);
2803 return -EFAULT;
2804 }
2805 kbuf[left] = 0;
2806
2807 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2808 GFP_KERNEL);
2809 if (!tmp_bitmap) {
2810 free_page(page);
2811 return -ENOMEM;
2812 }
2813 proc_skip_char(&kbuf, &left, '\n');
2814 while (!err && left) {
2815 unsigned long val_a, val_b;
2816 bool neg;
2817
2818 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2819 sizeof(tr_a), &c);
2820 if (err)
2821 break;
2822 if (val_a >= bitmap_len || neg) {
2823 err = -EINVAL;
2824 break;
2825 }
2826
2827 val_b = val_a;
2828 if (left) {
2829 kbuf++;
2830 left--;
2831 }
2832
2833 if (c == '-') {
2834 err = proc_get_long(&kbuf, &left, &val_b,
2835 &neg, tr_b, sizeof(tr_b),
2836 &c);
2837 if (err)
2838 break;
2839 if (val_b >= bitmap_len || neg ||
2840 val_a > val_b) {
2841 err = -EINVAL;
2842 break;
2843 }
2844 if (left) {
2845 kbuf++;
2846 left--;
2847 }
2848 }
2849
2850 while (val_a <= val_b)
2851 set_bit(val_a++, tmp_bitmap);
2852
2853 first = 0;
2854 proc_skip_char(&kbuf, &left, '\n');
2855 }
2856 free_page(page);
2857 } else {
2858 unsigned long bit_a, bit_b = 0;
2859
2860 while (left) {
2861 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2862 if (bit_a >= bitmap_len)
2863 break;
2864 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2865 bit_a + 1) - 1;
2866
2867 if (!first) {
2868 err = proc_put_char(&buffer, &left, ',');
2869 if (err)
2870 break;
2871 }
2872 err = proc_put_long(&buffer, &left, bit_a, false);
2873 if (err)
2874 break;
2875 if (bit_a != bit_b) {
2876 err = proc_put_char(&buffer, &left, '-');
2877 if (err)
2878 break;
2879 err = proc_put_long(&buffer, &left, bit_b, false);
2880 if (err)
2881 break;
2882 }
2883
2884 first = 0; bit_b++;
2885 }
2886 if (!err)
2887 err = proc_put_char(&buffer, &left, '\n');
2888 }
2889
2890 if (!err) {
2891 if (write) {
2892 if (*ppos)
2893 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2894 else
2895 memcpy(bitmap, tmp_bitmap,
2896 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2897 }
2898 kfree(tmp_bitmap);
2899 *lenp -= left;
2900 *ppos += *lenp;
2901 return 0;
2902 } else {
2903 kfree(tmp_bitmap);
2904 return err;
2905 }
2906}
2907
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908#else /* CONFIG_PROC_FS */
2909
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002910int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 void __user *buffer, size_t *lenp, loff_t *ppos)
2912{
2913 return -ENOSYS;
2914}
2915
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002916int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *buffer, size_t *lenp, loff_t *ppos)
2918{
2919 return -ENOSYS;
2920}
2921
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002922int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *buffer, size_t *lenp, loff_t *ppos)
2924{
2925 return -ENOSYS;
2926}
2927
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
2931 return -ENOSYS;
2932}
2933
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 void __user *buffer, size_t *lenp, loff_t *ppos)
2936{
2937 return -ENOSYS;
2938}
2939
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer, size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002946int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *buffer, size_t *lenp, loff_t *ppos)
2948{
2949 return -ENOSYS;
2950}
2951
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002952int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *buffer,
2954 size_t *lenp, loff_t *ppos)
2955{
2956 return -ENOSYS;
2957}
2958
2959
2960#endif /* CONFIG_PROC_FS */
2961
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962/*
2963 * No sense putting this after each symbol definition, twice,
2964 * exception granted :-)
2965 */
2966EXPORT_SYMBOL(proc_dointvec);
2967EXPORT_SYMBOL(proc_dointvec_jiffies);
2968EXPORT_SYMBOL(proc_dointvec_minmax);
2969EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2970EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2971EXPORT_SYMBOL(proc_dostring);
2972EXPORT_SYMBOL(proc_doulongvec_minmax);
2973EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2974EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002975EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976EXPORT_SYMBOL(unregister_sysctl_table);