blob: 3dd0c46fa3bbd68d1d4774e23e0189c54508fd0b [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>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/uaccess.h>
61#include <asm/processor.h>
62
Andi Kleen29cbc782006-09-30 01:47:55 +020063#ifdef CONFIG_X86
64#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010065#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010066#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020067#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080068#ifdef CONFIG_BSD_PROCESS_ACCT
69#include <linux/acct.h>
70#endif
Dave Young4f0e0562010-03-10 15:24:09 -080071#ifdef CONFIG_RT_MUTEXES
72#include <linux/rtmutex.h>
73#endif
Dave Young2edf5e42010-03-10 15:24:10 -080074#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75#include <linux/lockdep.h>
76#endif
Dave Young15485a42010-03-10 15:24:07 -080077#ifdef CONFIG_CHR_DEV_SG
78#include <scsi/sg.h>
79#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020080
Don Zickus58687ac2010-05-07 17:11:44 -040081#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050082#include <linux/nmi.h>
83#endif
84
Eric W. Biederman7058cb02007-10-18 03:05:58 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#if defined(CONFIG_SYSCTL)
87
88/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int sysctl_overcommit_memory;
90extern int sysctl_overcommit_ratio;
91extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080099extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800100extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200101extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100102extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400103extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000104#ifndef CONFIG_MMU
105extern int sysctl_nr_trim_pages;
106#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200107#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200108extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200114static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115#endif
116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700118static int __maybe_unused one = 1;
119static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700120static int __maybe_unused three = 3;
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
Dave Youngd14f1722010-02-25 20:28:57 -0500137#ifdef CONFIG_INOTIFY_USER
138#include <linux/inotify.h>
139#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700140#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700141#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
David S. Miller08714202008-11-16 23:49:24 -0800144#ifdef CONFIG_SPARC64
145extern int sysctl_tsb_ratio;
146#endif
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef __hppa__
149extern int pwrsw_enabled;
150extern int unaligned_enabled;
151#endif
152
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800153#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#ifdef CONFIG_MATHEMU
155extern int sysctl_ieee_emulation_warnings;
156#endif
157extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700158extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#endif
160
Jes Sorensend2b176e2006-02-28 09:42:23 -0800161#ifdef CONFIG_IA64
162extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800163extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800164#endif
165
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700168 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800170 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700171#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700172
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700173#ifdef CONFIG_PRINTK
174static int proc_dmesg_restrict(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176#endif
177
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700178#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800179/* Note: sysrq code uses it's own private copy */
180static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700181
182static int sysrq_sysctl_handler(ctl_table *table, int write,
183 void __user *buffer, size_t *lenp,
184 loff_t *ppos)
185{
186 int error;
187
188 error = proc_dointvec(table, write, buffer, lenp, ppos);
189 if (error)
190 return error;
191
192 if (write)
193 sysrq_toggle_support(__sysrq_enabled);
194
195 return 0;
196}
197
198#endif
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201static struct ctl_table_root sysctl_table_root;
202static struct ctl_table_header root_table_header = {
Al Virodfef6dcd32011-03-08 01:25:28 -0500203 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204 .ctl_table = root_table,
Al Virodfef6dcd32011-03-08 01:25:28 -0500205 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100206 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400207 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100208};
209static struct ctl_table_root sysctl_table_root = {
210 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400211 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100212};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700214static struct ctl_table kern_table[];
215static struct ctl_table vm_table[];
216static struct ctl_table fs_table[];
217static struct ctl_table debug_table[];
218static struct ctl_table dev_table[];
219extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800220#ifdef CONFIG_EPOLL
221extern struct ctl_table epoll_table[];
222#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225int sysctl_legacy_va_layout;
226#endif
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228/* The default sysctl tables: */
229
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700230static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "kernel",
233 .mode = 0555,
234 .child = kern_table,
235 },
236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "vm",
238 .mode = 0555,
239 .child = vm_table,
240 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "fs",
243 .mode = 0555,
244 .child = fs_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "debug",
248 .mode = 0555,
249 .child = debug_table,
250 },
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "dev",
253 .mode = 0555,
254 .child = dev_table,
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;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200266#endif
267
Mel Gorman5e771902010-05-24 14:32:31 -0700268#ifdef CONFIG_COMPACTION
269static int min_extfrag_threshold;
270static int max_extfrag_threshold = 1000;
271#endif
272
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700273static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200274 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800279 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200280 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200281#ifdef CONFIG_SCHED_DEBUG
282 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800287 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290 },
291 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800296 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
299 },
300 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .procname = "sched_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800305 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
308 },
309 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100310 .procname = "sched_tunable_scaling",
311 .data = &sysctl_sched_tunable_scaling,
312 .maxlen = sizeof(enum sched_tunable_scaling),
313 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800314 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100315 .extra1 = &min_sched_tunable_scaling,
316 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200317 },
318 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 .procname = "sched_migration_cost",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800323 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200324 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100325 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100331 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530332 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200333 .procname = "sched_time_avg",
334 .data = &sysctl_sched_time_avg,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800337 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200338 },
339 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800340 .procname = "sched_shares_window",
341 .data = &sysctl_sched_shares_window,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec,
345 },
346 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800351 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530352 .extra1 = &zero,
353 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530354 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200355#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200356 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 .procname = "sched_rt_period_us",
358 .data = &sysctl_sched_rt_period,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800361 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100362 },
363 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 .procname = "sched_rt_runtime_us",
365 .data = &sysctl_sched_rt_runtime,
366 .maxlen = sizeof(int),
367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800368 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100369 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100370#ifdef CONFIG_SCHED_AUTOGROUP
371 {
372 .procname = "sched_autogroup_enabled",
373 .data = &sysctl_sched_autogroup_enabled,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800376 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100377 .extra1 = &zero,
378 .extra2 = &one,
379 },
380#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700381#ifdef CONFIG_PROVE_LOCKING
382 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700383 .procname = "prove_locking",
384 .data = &prove_locking,
385 .maxlen = sizeof(int),
386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800387 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700388 },
389#endif
390#ifdef CONFIG_LOCK_STAT
391 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392 .procname = "lock_stat",
393 .data = &lock_stat,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800396 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700397 },
398#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .procname = "panic",
401 .data = &panic_timeout,
402 .maxlen = sizeof(int),
403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800404 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 },
406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .procname = "core_uses_pid",
408 .data = &core_uses_pid,
409 .maxlen = sizeof(int),
410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800411 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 },
413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "core_pattern",
415 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700416 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800418 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 },
Neil Hormana2939802009-09-23 15:56:56 -0700420 {
Neil Hormana2939802009-09-23 15:56:56 -0700421 .procname = "core_pipe_limit",
422 .data = &core_pipe_limit,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800425 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700426 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800427#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700430 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800432 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800434#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100435#ifdef CONFIG_LATENCYTOP
436 {
437 .procname = "latencytop",
438 .data = &latencytop_enabled,
439 .maxlen = sizeof(int),
440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800441 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100442 },
443#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#ifdef CONFIG_BLK_DEV_INITRD
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800450 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700453 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700454 .procname = "print-fatal-signals",
455 .data = &print_fatal_signals,
456 .maxlen = sizeof(int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700459 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700460#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .procname = "reboot-cmd",
463 .data = reboot_command,
464 .maxlen = 256,
465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800466 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 },
475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .procname = "scons-poweroff",
477 .data = &scons_pwroff,
478 .maxlen = sizeof (int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 },
482#endif
David S. Miller08714202008-11-16 23:49:24 -0800483#ifdef CONFIG_SPARC64
484 {
David S. Miller08714202008-11-16 23:49:24 -0800485 .procname = "tsb-ratio",
486 .data = &sysctl_tsb_ratio,
487 .maxlen = sizeof (int),
488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800489 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800490 },
491#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#ifdef __hppa__
493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "soft-power",
495 .data = &pwrsw_enabled,
496 .maxlen = sizeof (int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "unaligned-trap",
502 .data = &unaligned_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800505 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
507#endif
508 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .procname = "ctrl-alt-del",
510 .data = &C_A_D,
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 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400515#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200516 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200517 .procname = "ftrace_enabled",
518 .data = &ftrace_enabled,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200522 },
523#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500524#ifdef CONFIG_STACK_TRACER
525 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500526 .procname = "stack_tracer_enabled",
527 .data = &stack_tracer_enabled,
528 .maxlen = sizeof(int),
529 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800530 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500531 },
532#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400533#ifdef CONFIG_TRACING
534 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100535 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400536 .data = &ftrace_dump_on_oops,
537 .maxlen = sizeof(int),
538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800539 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400540 },
541#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200542#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "modprobe",
545 .data = &modprobe_path,
546 .maxlen = KMOD_PATH_LEN,
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
Kees Cook3d433212009-04-02 15:49:29 -0700550 {
Kees Cook3d433212009-04-02 15:49:29 -0700551 .procname = "modules_disabled",
552 .data = &modules_disabled,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700557 .extra1 = &one,
558 .extra2 = &one,
559 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100561#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100564 .data = &uevent_helper,
565 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800567 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 },
569#endif
570#ifdef CONFIG_CHR_DEV_SG
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "sg-big-buff",
573 .data = &sg_big_buff,
574 .maxlen = sizeof (int),
575 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
578#endif
579#ifdef CONFIG_BSD_PROCESS_ACCT
580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "acct",
582 .data = &acct_parm,
583 .maxlen = 3*sizeof(int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#ifdef CONFIG_MAGIC_SYSRQ
589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800591 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .maxlen = sizeof (int),
593 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700594 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 },
596#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700597#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700600 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .maxlen = sizeof (int),
602 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "threads-max",
608 .data = &max_threads,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "random",
615 .mode = 0555,
616 .child = random_table,
617 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "overflowuid",
620 .data = &overflowuid,
621 .maxlen = sizeof(int),
622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800623 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .extra1 = &minolduid,
625 .extra2 = &maxolduid,
626 },
627 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .procname = "overflowgid",
629 .data = &overflowgid,
630 .maxlen = sizeof(int),
631 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800632 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
635 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800636#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#ifdef CONFIG_MATHEMU
638 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .procname = "ieee_emulation_warnings",
640 .data = &sysctl_ieee_emulation_warnings,
641 .maxlen = sizeof(int),
642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800643 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200648 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .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
654 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .procname = "pid_max",
656 .data = &pid_max,
657 .maxlen = sizeof (int),
658 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
662 },
663 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .procname = "panic_on_oops",
665 .data = &panic_on_oops,
666 .maxlen = sizeof(int),
667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800670#if defined CONFIG_PRINTK
671 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800672 .procname = "printk",
673 .data = &console_loglevel,
674 .maxlen = 4*sizeof(int),
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800677 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700680 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 .maxlen = sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700687 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
Dave Youngaf913222009-09-22 16:43:33 -0700692 {
Dave Youngaf913222009-09-22 16:43:33 -0700693 .procname = "printk_delay",
694 .data = &printk_delay_msec,
695 .maxlen = sizeof(int),
696 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800697 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700698 .extra1 = &zero,
699 .extra2 = &ten_thousand,
700 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800702 .procname = "dmesg_restrict",
703 .data = &dmesg_restrict,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = proc_dointvec_minmax,
707 .extra1 = &zero,
708 .extra2 = &one,
709 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800710 {
711 .procname = "kptr_restrict",
712 .data = &kptr_restrict,
713 .maxlen = sizeof(int),
714 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700715 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800716 .extra1 = &zero,
717 .extra2 = &two,
718 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800719#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "ngroups_max",
722 .data = &ngroups_max,
723 .maxlen = sizeof (int),
724 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800725 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
Don Zickus58687ac2010-05-07 17:11:44 -0400727#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500728 {
Don Zickus58687ac2010-05-07 17:11:44 -0400729 .procname = "watchdog",
730 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500731 .maxlen = sizeof (int),
732 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700733 .proc_handler = proc_dowatchdog,
734 .extra1 = &zero,
735 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400736 },
737 {
738 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700739 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400740 .maxlen = sizeof(int),
741 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700742 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400743 .extra1 = &neg_one,
744 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500745 },
Don Zickus2508ce12010-05-07 17:11:46 -0400746 {
747 .procname = "softlockup_panic",
748 .data = &softlockup_panic,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = proc_dointvec_minmax,
752 .extra1 = &zero,
753 .extra2 = &one,
754 },
Don Zickus5dc30552010-11-29 17:07:17 -0500755 {
756 .procname = "nmi_watchdog",
757 .data = &watchdog_enabled,
758 .maxlen = sizeof (int),
759 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700760 .proc_handler = proc_dowatchdog,
761 .extra1 = &zero,
762 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500763 },
764#endif
765#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
766 {
767 .procname = "unknown_nmi_panic",
768 .data = &unknown_nmi_panic,
769 .maxlen = sizeof (int),
770 .mode = 0644,
771 .proc_handler = proc_dointvec,
772 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500773#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774#if defined(CONFIG_X86)
775 {
Don Zickus8da5add2006-09-26 10:52:27 +0200776 .procname = "panic_on_unrecovered_nmi",
777 .data = &panic_on_unrecovered_nmi,
778 .maxlen = sizeof(int),
779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200781 },
782 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700783 .procname = "panic_on_io_nmi",
784 .data = &panic_on_io_nmi,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700788 },
789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
793 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100796 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700797 .procname = "bootloader_version",
798 .data = &bootloader_version,
799 .maxlen = sizeof (int),
800 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700802 },
803 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100804 .procname = "kstack_depth_to_print",
805 .data = &kstack_depth_to_print,
806 .maxlen = sizeof(int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100809 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100810 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100811 .procname = "io_delay_type",
812 .data = &io_delay_type,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100816 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800818#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 .procname = "randomize_va_space",
821 .data = &randomize_va_space,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800826#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800827#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700828 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700829 .procname = "spin_retry",
830 .data = &spin_retry,
831 .maxlen = sizeof (int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700834 },
835#endif
Len Brown673d5b42007-07-28 03:33:16 -0400836#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800837 {
Pavel Machekc255d842006-02-20 18:27:58 -0800838 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700839 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800840 .maxlen = sizeof (unsigned long),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800843 },
844#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800845#ifdef CONFIG_IA64
846 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800847 .procname = "ignore-unaligned-usertrap",
848 .data = &no_unaligned_warning,
849 .maxlen = sizeof (int),
850 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800851 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800852 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800853 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800859 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800860#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800861#ifdef CONFIG_DETECT_HUNG_TASK
862 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800863 .procname = "hung_task_panic",
864 .data = &sysctl_hung_task_panic,
865 .maxlen = sizeof(int),
866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800868 .extra1 = &zero,
869 .extra2 = &one,
870 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100871 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100872 .procname = "hung_task_check_count",
873 .data = &sysctl_hung_task_check_count,
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 },
878 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .procname = "hung_task_timeout_secs",
880 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100881 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800883 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100884 },
885 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .procname = "hung_task_warnings",
887 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100888 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100891 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700892#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200893#ifdef CONFIG_COMPAT
894 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200895 .procname = "compat-log",
896 .data = &compat_log,
897 .maxlen = sizeof (int),
898 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800899 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200900 },
901#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700902#ifdef CONFIG_RT_MUTEXES
903 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700904 .procname = "max_lock_depth",
905 .data = &max_lock_depth,
906 .maxlen = sizeof(int),
907 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800908 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700909 },
910#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700911 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700912 .procname = "poweroff_cmd",
913 .data = &poweroff_cmd,
914 .maxlen = POWEROFF_CMD_PATH_LEN,
915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700917 },
David Howells0b77f5b2008-04-29 01:01:32 -0700918#ifdef CONFIG_KEYS
919 {
David Howells0b77f5b2008-04-29 01:01:32 -0700920 .procname = "keys",
921 .mode = 0555,
922 .child = key_sysctls,
923 },
924#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700925#ifdef CONFIG_RCU_TORTURE_TEST
926 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700927 .procname = "rcutorture_runnable",
928 .data = &rcutorture_runnable,
929 .maxlen = sizeof(int),
930 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800931 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700932 },
933#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200934#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200935 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200936 .procname = "perf_event_paranoid",
937 .data = &sysctl_perf_event_paranoid,
938 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200939 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800940 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200941 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200942 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200943 .procname = "perf_event_mlock_kb",
944 .data = &sysctl_perf_event_mlock,
945 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200946 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800947 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200948 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200949 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200950 .procname = "perf_event_max_sample_rate",
951 .data = &sysctl_perf_event_sample_rate,
952 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200953 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100954 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200955 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200956#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200957#ifdef CONFIG_KMEMCHECK
958 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200959 .procname = "kmemcheck",
960 .data = &kmemcheck_enabled,
961 .maxlen = sizeof(int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200964 },
965#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200966#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200967 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200968 .procname = "blk_iopoll",
969 .data = &blk_iopoll_enabled,
970 .maxlen = sizeof(int),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200973 },
Jens Axboecb684b52009-09-15 21:53:11 +0200974#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700975 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976};
977
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700978static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 .procname = "overcommit_memory",
981 .data = &sysctl_overcommit_memory,
982 .maxlen = sizeof(sysctl_overcommit_memory),
983 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700984 .proc_handler = proc_dointvec_minmax,
985 .extra1 = &zero,
986 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 },
988 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700989 .procname = "panic_on_oom",
990 .data = &sysctl_panic_on_oom,
991 .maxlen = sizeof(sysctl_panic_on_oom),
992 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700993 .proc_handler = proc_dointvec_minmax,
994 .extra1 = &zero,
995 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700996 },
997 {
David Rientjesfe071d72007-10-16 23:25:56 -0700998 .procname = "oom_kill_allocating_task",
999 .data = &sysctl_oom_kill_allocating_task,
1000 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001003 },
1004 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001005 .procname = "oom_dump_tasks",
1006 .data = &sysctl_oom_dump_tasks,
1007 .maxlen = sizeof(sysctl_oom_dump_tasks),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "overcommit_ratio",
1013 .data = &sysctl_overcommit_ratio,
1014 .maxlen = sizeof(sysctl_overcommit_ratio),
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 = "page-cluster",
1020 .data = &page_cluster,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001023 .proc_handler = proc_dointvec_minmax,
1024 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 },
1026 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 .procname = "dirty_background_ratio",
1028 .data = &dirty_background_ratio,
1029 .maxlen = sizeof(dirty_background_ratio),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .extra1 = &zero,
1033 .extra2 = &one_hundred,
1034 },
1035 {
David Rientjes2da02992009-01-06 14:39:31 -08001036 .procname = "dirty_background_bytes",
1037 .data = &dirty_background_bytes,
1038 .maxlen = sizeof(dirty_background_bytes),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001041 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001042 },
1043 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 .procname = "dirty_ratio",
1045 .data = &vm_dirty_ratio,
1046 .maxlen = sizeof(vm_dirty_ratio),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .extra1 = &zero,
1050 .extra2 = &one_hundred,
1051 },
1052 {
David Rientjes2da02992009-01-06 14:39:31 -08001053 .procname = "dirty_bytes",
1054 .data = &vm_dirty_bytes,
1055 .maxlen = sizeof(vm_dirty_bytes),
1056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001058 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001059 },
1060 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001062 .data = &dirty_writeback_interval,
1063 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001065 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 },
1067 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001069 .data = &dirty_expire_interval,
1070 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001072 .proc_handler = proc_dointvec_minmax,
1073 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 },
1075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "nr_pdflush_threads",
1077 .data = &nr_pdflush_threads,
1078 .maxlen = sizeof nr_pdflush_threads,
1079 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 },
1082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "swappiness",
1084 .data = &vm_swappiness,
1085 .maxlen = sizeof(vm_swappiness),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 .extra1 = &zero,
1089 .extra2 = &one_hundred,
1090 },
1091#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001092 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001094 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 .maxlen = sizeof(unsigned long),
1096 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001097 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 .extra1 = (void *)&hugetlb_zero,
1099 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001100 },
1101#ifdef CONFIG_NUMA
1102 {
1103 .procname = "nr_hugepages_mempolicy",
1104 .data = NULL,
1105 .maxlen = sizeof(unsigned long),
1106 .mode = 0644,
1107 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1108 .extra1 = (void *)&hugetlb_zero,
1109 .extra2 = (void *)&hugetlb_infinity,
1110 },
1111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 .procname = "hugetlb_shm_group",
1114 .data = &sysctl_hugetlb_shm_group,
1115 .maxlen = sizeof(gid_t),
1116 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001117 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 },
Mel Gorman396faf02007-07-17 04:03:13 -07001119 {
Mel Gorman396faf02007-07-17 04:03:13 -07001120 .procname = "hugepages_treat_as_movable",
1121 .data = &hugepages_treat_as_movable,
1122 .maxlen = sizeof(int),
1123 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001124 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001125 },
Adam Litke54f9f802007-10-16 01:26:20 -07001126 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001127 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001128 .data = NULL,
1129 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001130 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001131 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001132 .extra1 = (void *)&hugetlb_zero,
1133 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001134 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135#endif
1136 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 .procname = "lowmem_reserve_ratio",
1138 .data = &sysctl_lowmem_reserve_ratio,
1139 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1140 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001141 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 },
1143 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001144 .procname = "drop_caches",
1145 .data = &sysctl_drop_caches,
1146 .maxlen = sizeof(int),
1147 .mode = 0644,
1148 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001149 .extra1 = &one,
1150 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001151 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001152#ifdef CONFIG_COMPACTION
1153 {
1154 .procname = "compact_memory",
1155 .data = &sysctl_compact_memory,
1156 .maxlen = sizeof(int),
1157 .mode = 0200,
1158 .proc_handler = sysctl_compaction_handler,
1159 },
Mel Gorman5e771902010-05-24 14:32:31 -07001160 {
1161 .procname = "extfrag_threshold",
1162 .data = &sysctl_extfrag_threshold,
1163 .maxlen = sizeof(int),
1164 .mode = 0644,
1165 .proc_handler = sysctl_extfrag_handler,
1166 .extra1 = &min_extfrag_threshold,
1167 .extra2 = &max_extfrag_threshold,
1168 },
1169
Mel Gorman76ab0f52010-05-24 14:32:28 -07001170#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001171 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 .procname = "min_free_kbytes",
1173 .data = &min_free_kbytes,
1174 .maxlen = sizeof(min_free_kbytes),
1175 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001176 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 .extra1 = &zero,
1178 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001179 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001180 .procname = "percpu_pagelist_fraction",
1181 .data = &percpu_pagelist_fraction,
1182 .maxlen = sizeof(percpu_pagelist_fraction),
1183 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001184 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001185 .extra1 = &min_percpu_pagelist_fract,
1186 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187#ifdef CONFIG_MMU
1188 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 .procname = "max_map_count",
1190 .data = &sysctl_max_map_count,
1191 .maxlen = sizeof(sysctl_max_map_count),
1192 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001193 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001194 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001196#else
1197 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001198 .procname = "nr_trim_pages",
1199 .data = &sysctl_nr_trim_pages,
1200 .maxlen = sizeof(sysctl_nr_trim_pages),
1201 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001202 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001203 .extra1 = &zero,
1204 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#endif
1206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 .procname = "laptop_mode",
1208 .data = &laptop_mode,
1209 .maxlen = sizeof(laptop_mode),
1210 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001211 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 },
1213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 .procname = "block_dump",
1215 .data = &block_dump,
1216 .maxlen = sizeof(block_dump),
1217 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001218 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 .extra1 = &zero,
1220 },
1221 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .procname = "vfs_cache_pressure",
1223 .data = &sysctl_vfs_cache_pressure,
1224 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .extra1 = &zero,
1228 },
1229#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1230 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 .procname = "legacy_va_layout",
1232 .data = &sysctl_legacy_va_layout,
1233 .maxlen = sizeof(sysctl_legacy_va_layout),
1234 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001235 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 .extra1 = &zero,
1237 },
1238#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001239#ifdef CONFIG_NUMA
1240 {
Christoph Lameter17436602006-01-18 17:42:32 -08001241 .procname = "zone_reclaim_mode",
1242 .data = &zone_reclaim_mode,
1243 .maxlen = sizeof(zone_reclaim_mode),
1244 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001245 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001246 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001247 },
Christoph Lameter96146342006-07-03 00:24:13 -07001248 {
Christoph Lameter96146342006-07-03 00:24:13 -07001249 .procname = "min_unmapped_ratio",
1250 .data = &sysctl_min_unmapped_ratio,
1251 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1252 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001253 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001254 .extra1 = &zero,
1255 .extra2 = &one_hundred,
1256 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001257 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001258 .procname = "min_slab_ratio",
1259 .data = &sysctl_min_slab_ratio,
1260 .maxlen = sizeof(sysctl_min_slab_ratio),
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001263 .extra1 = &zero,
1264 .extra2 = &one_hundred,
1265 },
Christoph Lameter17436602006-01-18 17:42:32 -08001266#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001267#ifdef CONFIG_SMP
1268 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001269 .procname = "stat_interval",
1270 .data = &sysctl_stat_interval,
1271 .maxlen = sizeof(sysctl_stat_interval),
1272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001274 },
1275#endif
David Howells6e141542009-12-15 19:27:45 +00001276#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001277 {
Eric Parised032182007-06-28 15:55:21 -04001278 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001279 .data = &dac_mmap_min_addr,
1280 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001283 },
David Howells6e141542009-12-15 19:27:45 +00001284#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001285#ifdef CONFIG_NUMA
1286 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001287 .procname = "numa_zonelist_order",
1288 .data = &numa_zonelist_order,
1289 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1290 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001291 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001292 },
1293#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001294#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001295 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001296 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001297 .procname = "vdso_enabled",
1298 .data = &vdso_enabled,
1299 .maxlen = sizeof(vdso_enabled),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001302 .extra1 = &zero,
1303 },
1304#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001305#ifdef CONFIG_HIGHMEM
1306 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001307 .procname = "highmem_is_dirtyable",
1308 .data = &vm_highmem_is_dirtyable,
1309 .maxlen = sizeof(vm_highmem_is_dirtyable),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001312 .extra1 = &zero,
1313 .extra2 = &one,
1314 },
1315#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001316 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001317 .procname = "scan_unevictable_pages",
1318 .data = &scan_unevictable_pages,
1319 .maxlen = sizeof(scan_unevictable_pages),
1320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001321 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001322 },
Andi Kleen6a460792009-09-16 11:50:15 +02001323#ifdef CONFIG_MEMORY_FAILURE
1324 {
Andi Kleen6a460792009-09-16 11:50:15 +02001325 .procname = "memory_failure_early_kill",
1326 .data = &sysctl_memory_failure_early_kill,
1327 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001329 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001330 .extra1 = &zero,
1331 .extra2 = &one,
1332 },
1333 {
Andi Kleen6a460792009-09-16 11:50:15 +02001334 .procname = "memory_failure_recovery",
1335 .data = &sysctl_memory_failure_recovery,
1336 .maxlen = sizeof(sysctl_memory_failure_recovery),
1337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001338 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001339 .extra1 = &zero,
1340 .extra2 = &one,
1341 },
1342#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001343 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344};
1345
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001346#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001347static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001348 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001349};
1350#endif
1351
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001352static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .procname = "inode-nr",
1355 .data = &inodes_stat,
1356 .maxlen = 2*sizeof(int),
1357 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001358 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 },
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .procname = "inode-state",
1362 .data = &inodes_stat,
1363 .maxlen = 7*sizeof(int),
1364 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001365 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 },
1367 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 .procname = "file-nr",
1369 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001370 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001372 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 },
1374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .procname = "file-max",
1376 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001377 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001379 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 },
1381 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001382 .procname = "nr_open",
1383 .data = &sysctl_nr_open,
1384 .maxlen = sizeof(int),
1385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001386 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001387 .extra1 = &sysctl_nr_open_min,
1388 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001389 },
1390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .procname = "dentry-state",
1392 .data = &dentry_stat,
1393 .maxlen = 6*sizeof(int),
1394 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001395 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "overflowuid",
1399 .data = &fs_overflowuid,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .extra1 = &minolduid,
1404 .extra2 = &maxolduid,
1405 },
1406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 .procname = "overflowgid",
1408 .data = &fs_overflowgid,
1409 .maxlen = sizeof(int),
1410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001411 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 .extra1 = &minolduid,
1413 .extra2 = &maxolduid,
1414 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001415#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "leases-enable",
1418 .data = &leases_enable,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001423#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424#ifdef CONFIG_DNOTIFY
1425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .procname = "dir-notify-enable",
1427 .data = &dir_notify_enable,
1428 .maxlen = sizeof(int),
1429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001430 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 },
1432#endif
1433#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001434#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 .procname = "lease-break-time",
1437 .data = &lease_break_time,
1438 .maxlen = sizeof(int),
1439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001442#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001443#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 .procname = "aio-nr",
1446 .data = &aio_nr,
1447 .maxlen = sizeof(aio_nr),
1448 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001449 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 },
1451 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .procname = "aio-max-nr",
1453 .data = &aio_max_nr,
1454 .maxlen = sizeof(aio_max_nr),
1455 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001456 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001458#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001459#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001460 {
Robert Love0399cb02005-07-13 12:38:18 -04001461 .procname = "inotify",
1462 .mode = 0555,
1463 .child = inotify_table,
1464 },
1465#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001466#ifdef CONFIG_EPOLL
1467 {
1468 .procname = "epoll",
1469 .mode = 0555,
1470 .child = epoll_table,
1471 },
1472#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001474 {
Alan Coxd6e71142005-06-23 00:09:43 -07001475 .procname = "suid_dumpable",
1476 .data = &suid_dumpable,
1477 .maxlen = sizeof(int),
1478 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001479 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001480 .extra1 = &zero,
1481 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001482 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001483#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1484 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001485 .procname = "binfmt_misc",
1486 .mode = 0555,
1487 .child = binfmt_misc_table,
1488 },
1489#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001490 {
Jens Axboeff9da692010-06-03 14:54:39 +02001491 .procname = "pipe-max-size",
1492 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001493 .maxlen = sizeof(int),
1494 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001495 .proc_handler = &pipe_proc_fn,
1496 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001497 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001498 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499};
1500
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001501static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001502#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1503 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001504 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001505 .procname = "exception-trace",
1506 .data = &show_unhandled_signals,
1507 .maxlen = sizeof(int),
1508 .mode = 0644,
1509 .proc_handler = proc_dointvec
1510 },
1511#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001512#if defined(CONFIG_OPTPROBES)
1513 {
1514 .procname = "kprobes-optimization",
1515 .data = &sysctl_kprobes_optimization,
1516 .maxlen = sizeof(int),
1517 .mode = 0644,
1518 .proc_handler = proc_kprobes_optimization_handler,
1519 .extra1 = &zero,
1520 .extra2 = &one,
1521 },
1522#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001523 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524};
1525
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001526static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001527 { }
Robert Love0eeca282005-07-12 17:06:03 -04001528};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Al Viro330d57f2005-11-04 10:18:40 +00001530static DEFINE_SPINLOCK(sysctl_lock);
1531
1532/* called under sysctl_lock */
1533static int use_table(struct ctl_table_header *p)
1534{
1535 if (unlikely(p->unregistering))
1536 return 0;
1537 p->used++;
1538 return 1;
1539}
1540
1541/* called under sysctl_lock */
1542static void unuse_table(struct ctl_table_header *p)
1543{
1544 if (!--p->used)
1545 if (unlikely(p->unregistering))
1546 complete(p->unregistering);
1547}
1548
1549/* called under sysctl_lock, will reacquire if has to wait */
1550static void start_unregistering(struct ctl_table_header *p)
1551{
1552 /*
1553 * if p->used is 0, nobody will ever touch that entry again;
1554 * we'll eliminate all paths to it before dropping sysctl_lock
1555 */
1556 if (unlikely(p->used)) {
1557 struct completion wait;
1558 init_completion(&wait);
1559 p->unregistering = &wait;
1560 spin_unlock(&sysctl_lock);
1561 wait_for_completion(&wait);
1562 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001563 } else {
1564 /* anything non-NULL; we'll never dereference it */
1565 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001566 }
1567 /*
1568 * do not remove from the list until nobody holds it; walking the
1569 * list in do_sysctl() relies on that.
1570 */
1571 list_del_init(&p->ctl_entry);
1572}
1573
Al Virof7e6ced2008-07-15 01:44:23 -04001574void sysctl_head_get(struct ctl_table_header *head)
1575{
1576 spin_lock(&sysctl_lock);
1577 head->count++;
1578 spin_unlock(&sysctl_lock);
1579}
1580
Al Virodfef6dcd32011-03-08 01:25:28 -05001581static void free_head(struct rcu_head *rcu)
1582{
1583 kfree(container_of(rcu, struct ctl_table_header, rcu));
1584}
1585
Al Virof7e6ced2008-07-15 01:44:23 -04001586void sysctl_head_put(struct ctl_table_header *head)
1587{
1588 spin_lock(&sysctl_lock);
1589 if (!--head->count)
Al Virodfef6dcd32011-03-08 01:25:28 -05001590 call_rcu(&head->rcu, free_head);
Al Virof7e6ced2008-07-15 01:44:23 -04001591 spin_unlock(&sysctl_lock);
1592}
1593
1594struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1595{
1596 if (!head)
1597 BUG();
1598 spin_lock(&sysctl_lock);
1599 if (!use_table(head))
1600 head = ERR_PTR(-ENOENT);
1601 spin_unlock(&sysctl_lock);
1602 return head;
1603}
1604
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605void sysctl_head_finish(struct ctl_table_header *head)
1606{
1607 if (!head)
1608 return;
1609 spin_lock(&sysctl_lock);
1610 unuse_table(head);
1611 spin_unlock(&sysctl_lock);
1612}
1613
Al Viro73455092008-07-14 21:22:20 -04001614static struct ctl_table_set *
1615lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1616{
1617 struct ctl_table_set *set = &root->default_set;
1618 if (root->lookup)
1619 set = root->lookup(root, namespaces);
1620 return set;
1621}
1622
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623static struct list_head *
1624lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625{
Al Viro73455092008-07-14 21:22:20 -04001626 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1627 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628}
1629
1630struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1631 struct ctl_table_header *prev)
1632{
1633 struct ctl_table_root *root;
1634 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001635 struct ctl_table_header *head;
1636 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001637
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001638 spin_lock(&sysctl_lock);
1639 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001640 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001641 tmp = &prev->ctl_entry;
1642 unuse_table(prev);
1643 goto next;
1644 }
1645 tmp = &root_table_header.ctl_entry;
1646 for (;;) {
1647 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1648
1649 if (!use_table(head))
1650 goto next;
1651 spin_unlock(&sysctl_lock);
1652 return head;
1653 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001654 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001656 header_list = lookup_header_list(root, namespaces);
1657 if (tmp != header_list)
1658 continue;
1659
1660 do {
1661 root = list_entry(root->root_list.next,
1662 struct ctl_table_root, root_list);
1663 if (root == &sysctl_table_root)
1664 goto out;
1665 header_list = lookup_header_list(root, namespaces);
1666 } while (list_empty(header_list));
1667 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001668 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001669out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001670 spin_unlock(&sysctl_lock);
1671 return NULL;
1672}
1673
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001674struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1675{
1676 return __sysctl_head_next(current->nsproxy, prev);
1677}
1678
1679void register_sysctl_root(struct ctl_table_root *root)
1680{
1681 spin_lock(&sysctl_lock);
1682 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1683 spin_unlock(&sysctl_lock);
1684}
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001687 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 * some sysctl variables are readonly even to root.
1689 */
1690
1691static int test_perm(int mode, int op)
1692{
David Howells76aac0e2008-11-14 10:39:12 +11001693 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 mode >>= 6;
1695 else if (in_egroup_p(0))
1696 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001697 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 return 0;
1699 return -EACCES;
1700}
1701
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001702int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001704 int mode;
1705
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001706 if (root->permissions)
1707 mode = root->permissions(root, current->nsproxy, table);
1708 else
1709 mode = table->mode;
1710
1711 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712}
1713
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001714static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1715{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001716 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001717 table->parent = parent;
1718 if (table->child)
1719 sysctl_set_parent(table, table->child);
1720 }
1721}
1722
1723static __init int sysctl_init(void)
1724{
1725 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001726#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001727 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001728#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001729 return 0;
1730}
1731
1732core_initcall(sysctl_init);
1733
Al Virobfbcf032008-07-27 06:31:22 +01001734static struct ctl_table *is_branch_in(struct ctl_table *branch,
1735 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001736{
1737 struct ctl_table *p;
1738 const char *s = branch->procname;
1739
1740 /* branch should have named subdirectory as its first element */
1741 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001742 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001743
1744 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001745 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001746 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001747
1748 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001749 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001750 if (!p->child)
1751 continue;
1752 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001753 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001754 }
Al Virobfbcf032008-07-27 06:31:22 +01001755 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001756}
1757
1758/* see if attaching q to p would be an improvement */
1759static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1760{
1761 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001762 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001763 int is_better = 0;
1764 int not_in_parent = !p->attached_by;
1765
Al Virobfbcf032008-07-27 06:31:22 +01001766 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001767 if (by == q->attached_by)
1768 is_better = 1;
1769 if (to == p->attached_by)
1770 not_in_parent = 1;
1771 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001772 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001773 }
1774
1775 if (is_better && not_in_parent) {
1776 q->attached_by = by;
1777 q->attached_to = to;
1778 q->parent = p;
1779 }
1780}
1781
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001783 * __register_sysctl_paths - register a sysctl hierarchy
1784 * @root: List of sysctl headers to register on
1785 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001786 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 *
1789 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001790 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001792 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1795 * enter a sysctl file
1796 *
1797 * data - a pointer to data for use by proc_handler
1798 *
1799 * maxlen - the maximum size in bytes of the data
1800 *
1801 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1802 *
1803 * child - a pointer to the child sysctl table if this entry is a directory, or
1804 * %NULL.
1805 *
1806 * proc_handler - the text handler routine (described below)
1807 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 * de - for internal use by the sysctl routines
1809 *
1810 * extra1, extra2 - extra pointers usable by the proc handler routines
1811 *
1812 * Leaf nodes in the sysctl tree will be represented by a single file
1813 * under /proc; non-leaf nodes will be represented by directories.
1814 *
1815 * sysctl(2) can automatically manage read and write requests through
1816 * the sysctl table. The data and maxlen fields of the ctl_table
1817 * struct enable minimal validation of the values being written to be
1818 * performed, and the mode field allows minimal authentication.
1819 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 * There must be a proc_handler routine for any terminal nodes
1821 * mirrored under /proc/sys (non-terminals are handled by a built-in
1822 * directory handler). Several default handlers are available to
1823 * cover common cases -
1824 *
1825 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1826 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1827 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1828 *
1829 * It is the handler's job to read the input buffer from user memory
1830 * and process it. The handler should return 0 on success.
1831 *
1832 * This routine returns %NULL on a failure to register, and a pointer
1833 * to the table header on success.
1834 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001835struct ctl_table_header *__register_sysctl_paths(
1836 struct ctl_table_root *root,
1837 struct nsproxy *namespaces,
1838 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001840 struct ctl_table_header *header;
1841 struct ctl_table *new, **prevp;
1842 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001843 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001844
1845 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001846 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001847 ;
1848
1849 /*
1850 * For each path component, allocate a 2-element ctl_table array.
1851 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001852 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001853 *
1854 * We allocate everything in one go so that we don't have to
1855 * worry about freeing additional memory in unregister_sysctl_table.
1856 */
1857 header = kzalloc(sizeof(struct ctl_table_header) +
1858 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1859 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001861
1862 new = (struct ctl_table *) (header + 1);
1863
1864 /* Now connect the dots */
1865 prevp = &header->ctl_table;
1866 for (n = 0; n < npath; ++n, ++path) {
1867 /* Copy the procname */
1868 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001869 new->mode = 0555;
1870
1871 *prevp = new;
1872 prevp = &new->child;
1873
1874 new += 2;
1875 }
1876 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001877 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001878
1879 INIT_LIST_HEAD(&header->ctl_entry);
1880 header->used = 0;
1881 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001882 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001883 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001884 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001885#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001886 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001887 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001888 return NULL;
1889 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001890#endif
Al Viro330d57f2005-11-04 10:18:40 +00001891 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001892 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001893 header->attached_by = header->ctl_table;
1894 header->attached_to = root_table;
1895 header->parent = &root_table_header;
1896 for (set = header->set; set; set = set->parent) {
1897 struct ctl_table_header *p;
1898 list_for_each_entry(p, &set->list, ctl_entry) {
1899 if (p->unregistering)
1900 continue;
1901 try_attach(p, header);
1902 }
1903 }
1904 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001905 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001906 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001907
1908 return header;
1909}
1910
1911/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001912 * register_sysctl_table_path - register a sysctl table hierarchy
1913 * @path: The path to the directory the sysctl table is in.
1914 * @table: the top-level table structure
1915 *
1916 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1917 * array. A completely 0 filled entry terminates the table.
1918 *
1919 * See __register_sysctl_paths for more details.
1920 */
1921struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1922 struct ctl_table *table)
1923{
1924 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1925 path, table);
1926}
1927
1928/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001929 * register_sysctl_table - register a sysctl table hierarchy
1930 * @table: the top-level table structure
1931 *
1932 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1933 * array. A completely 0 filled entry terminates the table.
1934 *
1935 * See register_sysctl_paths for more details.
1936 */
1937struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1938{
1939 static const struct ctl_path null_path[] = { {} };
1940
1941 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
1944/**
1945 * unregister_sysctl_table - unregister a sysctl table hierarchy
1946 * @header: the header returned from register_sysctl_table
1947 *
1948 * Unregisters the sysctl table and all children. proc entries may not
1949 * actually be removed until they are no longer used by anyone.
1950 */
1951void unregister_sysctl_table(struct ctl_table_header * header)
1952{
Al Viro330d57f2005-11-04 10:18:40 +00001953 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001954
1955 if (header == NULL)
1956 return;
1957
Al Viro330d57f2005-11-04 10:18:40 +00001958 spin_lock(&sysctl_lock);
1959 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001960 if (!--header->parent->count) {
1961 WARN_ON(1);
Al Virodfef6dcd32011-03-08 01:25:28 -05001962 call_rcu(&header->parent->rcu, free_head);
Al Viroae7edec2008-07-15 06:33:31 -04001963 }
Al Virof7e6ced2008-07-15 01:44:23 -04001964 if (!--header->count)
Al Virodfef6dcd32011-03-08 01:25:28 -05001965 call_rcu(&header->rcu, free_head);
Al Viro330d57f2005-11-04 10:18:40 +00001966 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
Al Viro9043476f2008-07-15 08:54:06 -04001969int sysctl_is_seen(struct ctl_table_header *p)
1970{
1971 struct ctl_table_set *set = p->set;
1972 int res;
1973 spin_lock(&sysctl_lock);
1974 if (p->unregistering)
1975 res = 0;
1976 else if (!set->is_seen)
1977 res = 1;
1978 else
1979 res = set->is_seen(set);
1980 spin_unlock(&sysctl_lock);
1981 return res;
1982}
1983
Al Viro73455092008-07-14 21:22:20 -04001984void setup_sysctl_set(struct ctl_table_set *p,
1985 struct ctl_table_set *parent,
1986 int (*is_seen)(struct ctl_table_set *))
1987{
1988 INIT_LIST_HEAD(&p->list);
1989 p->parent = parent ? parent : &sysctl_table_root.default_set;
1990 p->is_seen = is_seen;
1991}
1992
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001993#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001994struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001995{
1996 return NULL;
1997}
1998
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001999struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2000 struct ctl_table *table)
2001{
2002 return NULL;
2003}
2004
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002005void unregister_sysctl_table(struct ctl_table_header * table)
2006{
2007}
2008
Al Viro73455092008-07-14 21:22:20 -04002009void setup_sysctl_set(struct ctl_table_set *p,
2010 struct ctl_table_set *parent,
2011 int (*is_seen)(struct ctl_table_set *))
2012{
2013}
2014
Al Virof7e6ced2008-07-15 01:44:23 -04002015void sysctl_head_put(struct ctl_table_header *head)
2016{
2017}
2018
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002019#endif /* CONFIG_SYSCTL */
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021/*
2022 * /proc/sys support
2023 */
2024
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002025#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002027static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002028 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002029 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002030{
2031 size_t len;
2032 char __user *p;
2033 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002034
2035 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 *lenp = 0;
2037 return 0;
2038 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002039
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002040 if (write) {
2041 len = 0;
2042 p = buffer;
2043 while (len < *lenp) {
2044 if (get_user(c, p++))
2045 return -EFAULT;
2046 if (c == 0 || c == '\n')
2047 break;
2048 len++;
2049 }
2050 if (len >= maxlen)
2051 len = maxlen-1;
2052 if(copy_from_user(data, buffer, len))
2053 return -EFAULT;
2054 ((char *) data)[len] = 0;
2055 *ppos += *lenp;
2056 } else {
2057 len = strlen(data);
2058 if (len > maxlen)
2059 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002060
2061 if (*ppos > len) {
2062 *lenp = 0;
2063 return 0;
2064 }
2065
2066 data += *ppos;
2067 len -= *ppos;
2068
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002069 if (len > *lenp)
2070 len = *lenp;
2071 if (len)
2072 if(copy_to_user(buffer, data, len))
2073 return -EFAULT;
2074 if (len < *lenp) {
2075 if(put_user('\n', ((char __user *) buffer) + len))
2076 return -EFAULT;
2077 len++;
2078 }
2079 *lenp = len;
2080 *ppos += len;
2081 }
2082 return 0;
2083}
2084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085/**
2086 * proc_dostring - read a string sysctl
2087 * @table: the sysctl table
2088 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 * @buffer: the user buffer
2090 * @lenp: the size of the user buffer
2091 * @ppos: file position
2092 *
2093 * Reads/writes a string from/to the user buffer. If the kernel
2094 * buffer provided is not large enough to hold the string, the
2095 * string is truncated. The copied string is %NULL-terminated.
2096 * If the string is being read by the user process, it is copied
2097 * and a newline '\n' is added. It is truncated if the buffer is
2098 * not large enough.
2099 *
2100 * Returns 0 on success.
2101 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002102int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 void __user *buffer, size_t *lenp, loff_t *ppos)
2104{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002105 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002106 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107}
2108
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109static size_t proc_skip_spaces(char **buf)
2110{
2111 size_t ret;
2112 char *tmp = skip_spaces(*buf);
2113 ret = tmp - *buf;
2114 *buf = tmp;
2115 return ret;
2116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002118static void proc_skip_char(char **buf, size_t *size, const char v)
2119{
2120 while (*size) {
2121 if (**buf != v)
2122 break;
2123 (*size)--;
2124 (*buf)++;
2125 }
2126}
2127
Amerigo Wang00b7c332010-05-05 00:26:45 +00002128#define TMPBUFLEN 22
2129/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002130 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002131 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002132 * @buf: a kernel buffer
2133 * @size: size of the kernel buffer
2134 * @val: this is where the number will be stored
2135 * @neg: set to %TRUE if number is negative
2136 * @perm_tr: a vector which contains the allowed trailers
2137 * @perm_tr_len: size of the perm_tr vector
2138 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002139 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002140 * In case of success %0 is returned and @buf and @size are updated with
2141 * the amount of bytes read. If @tr is non-NULL and a trailing
2142 * character exists (size is non-zero after returning from this
2143 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002144 */
2145static int proc_get_long(char **buf, size_t *size,
2146 unsigned long *val, bool *neg,
2147 const char *perm_tr, unsigned perm_tr_len, char *tr)
2148{
2149 int len;
2150 char *p, tmp[TMPBUFLEN];
2151
2152 if (!*size)
2153 return -EINVAL;
2154
2155 len = *size;
2156 if (len > TMPBUFLEN - 1)
2157 len = TMPBUFLEN - 1;
2158
2159 memcpy(tmp, *buf, len);
2160
2161 tmp[len] = 0;
2162 p = tmp;
2163 if (*p == '-' && *size > 1) {
2164 *neg = true;
2165 p++;
2166 } else
2167 *neg = false;
2168 if (!isdigit(*p))
2169 return -EINVAL;
2170
2171 *val = simple_strtoul(p, &p, 0);
2172
2173 len = p - tmp;
2174
2175 /* We don't know if the next char is whitespace thus we may accept
2176 * invalid integers (e.g. 1234...a) or two integers instead of one
2177 * (e.g. 123...1). So lets not allow such large numbers. */
2178 if (len == TMPBUFLEN - 1)
2179 return -EINVAL;
2180
2181 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2182 return -EINVAL;
2183
2184 if (tr && (len < *size))
2185 *tr = *p;
2186
2187 *buf += len;
2188 *size -= len;
2189
2190 return 0;
2191}
2192
2193/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002194 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002195 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002196 * @buf: the user buffer
2197 * @size: the size of the user buffer
2198 * @val: the integer to be converted
2199 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002201 * In case of success %0 is returned and @buf and @size are updated with
2202 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002203 */
2204static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2205 bool neg)
2206{
2207 int len;
2208 char tmp[TMPBUFLEN], *p = tmp;
2209
2210 sprintf(p, "%s%lu", neg ? "-" : "", val);
2211 len = strlen(tmp);
2212 if (len > *size)
2213 len = *size;
2214 if (copy_to_user(*buf, tmp, len))
2215 return -EFAULT;
2216 *size -= len;
2217 *buf += len;
2218 return 0;
2219}
2220#undef TMPBUFLEN
2221
2222static int proc_put_char(void __user **buf, size_t *size, char c)
2223{
2224 if (*size) {
2225 char __user **buffer = (char __user **)buf;
2226 if (put_user(c, *buffer))
2227 return -EFAULT;
2228 (*size)--, (*buffer)++;
2229 *buf = *buffer;
2230 }
2231 return 0;
2232}
2233
2234static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 int *valp,
2236 int write, void *data)
2237{
2238 if (write) {
2239 *valp = *negp ? -*lvalp : *lvalp;
2240 } else {
2241 int val = *valp;
2242 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 *lvalp = (unsigned long)-val;
2245 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 *lvalp = (unsigned long)val;
2248 }
2249 }
2250 return 0;
2251}
2252
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2254
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002255static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002256 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002257 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 int write, void *data),
2260 void *data)
2261{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 int *i, vleft, first = 1, err = 0;
2263 unsigned long page = 0;
2264 size_t left;
2265 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Amerigo Wang00b7c332010-05-05 00:26:45 +00002267 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 *lenp = 0;
2269 return 0;
2270 }
2271
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002272 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 vleft = table->maxlen / sizeof(*i);
2274 left = *lenp;
2275
2276 if (!conv)
2277 conv = do_proc_dointvec_conv;
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002280 if (left > PAGE_SIZE - 1)
2281 left = PAGE_SIZE - 1;
2282 page = __get_free_page(GFP_TEMPORARY);
2283 kbuf = (char *) page;
2284 if (!kbuf)
2285 return -ENOMEM;
2286 if (copy_from_user(kbuf, buffer, left)) {
2287 err = -EFAULT;
2288 goto free;
2289 }
2290 kbuf[left] = 0;
2291 }
2292
2293 for (; left && vleft--; i++, first=0) {
2294 unsigned long lval;
2295 bool neg;
2296
2297 if (write) {
2298 left -= proc_skip_spaces(&kbuf);
2299
J. R. Okajima563b0462010-05-25 16:10:14 -07002300 if (!left)
2301 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302 err = proc_get_long(&kbuf, &left, &lval, &neg,
2303 proc_wspace_sep,
2304 sizeof(proc_wspace_sep), NULL);
2305 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 if (conv(&neg, &lval, i, 1, data)) {
2308 err = -EINVAL;
2309 break;
2310 }
2311 } else {
2312 if (conv(&neg, &lval, i, 0, data)) {
2313 err = -EINVAL;
2314 break;
2315 }
2316 if (!first)
2317 err = proc_put_char(&buffer, &left, '\t');
2318 if (err)
2319 break;
2320 err = proc_put_long(&buffer, &left, lval, neg);
2321 if (err)
2322 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325
2326 if (!write && !first && left && !err)
2327 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002328 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329 left -= proc_skip_spaces(&kbuf);
2330free:
2331 if (write) {
2332 free_page(page);
2333 if (first)
2334 return err ? : -EINVAL;
2335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 *lenp -= left;
2337 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002338 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002341static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002342 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 int write, void *data),
2345 void *data)
2346{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002347 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002348 buffer, lenp, ppos, conv, data);
2349}
2350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351/**
2352 * proc_dointvec - read a vector of integers
2353 * @table: the sysctl table
2354 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 * @buffer: the user buffer
2356 * @lenp: the size of the user buffer
2357 * @ppos: file position
2358 *
2359 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2360 * values from/to the user buffer, treated as an ASCII string.
2361 *
2362 * Returns 0 on success.
2363 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002364int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 void __user *buffer, size_t *lenp, loff_t *ppos)
2366{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002367 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 NULL,NULL);
2369}
2370
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002371/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002372 * Taint values can only be increased
2373 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002374 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002375static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376 void __user *buffer, size_t *lenp, loff_t *ppos)
2377{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002378 struct ctl_table t;
2379 unsigned long tmptaint = get_taint();
2380 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002381
Bastian Blank91fcd412007-04-23 14:41:14 -07002382 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002383 return -EPERM;
2384
Andi Kleen25ddbb12008-10-15 22:01:41 -07002385 t = *table;
2386 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002387 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002388 if (err < 0)
2389 return err;
2390
2391 if (write) {
2392 /*
2393 * Poor man's atomic or. Not worth adding a primitive
2394 * to everyone's atomic.h for this
2395 */
2396 int i;
2397 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2398 if ((tmptaint >> i) & 1)
2399 add_taint(i);
2400 }
2401 }
2402
2403 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002404}
2405
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002406#ifdef CONFIG_PRINTK
2407static int proc_dmesg_restrict(struct ctl_table *table, int write,
2408 void __user *buffer, size_t *lenp, loff_t *ppos)
2409{
2410 if (write && !capable(CAP_SYS_ADMIN))
2411 return -EPERM;
2412
2413 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2414}
2415#endif
2416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417struct do_proc_dointvec_minmax_conv_param {
2418 int *min;
2419 int *max;
2420};
2421
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2423 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 int write, void *data)
2425{
2426 struct do_proc_dointvec_minmax_conv_param *param = data;
2427 if (write) {
2428 int val = *negp ? -*lvalp : *lvalp;
2429 if ((param->min && *param->min > val) ||
2430 (param->max && *param->max < val))
2431 return -EINVAL;
2432 *valp = val;
2433 } else {
2434 int val = *valp;
2435 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002436 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 *lvalp = (unsigned long)-val;
2438 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002439 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 *lvalp = (unsigned long)val;
2441 }
2442 }
2443 return 0;
2444}
2445
2446/**
2447 * proc_dointvec_minmax - read a vector of integers with min/max values
2448 * @table: the sysctl table
2449 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 * @buffer: the user buffer
2451 * @lenp: the size of the user buffer
2452 * @ppos: file position
2453 *
2454 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2455 * values from/to the user buffer, treated as an ASCII string.
2456 *
2457 * This routine will ensure the values are within the range specified by
2458 * table->extra1 (min) and table->extra2 (max).
2459 *
2460 * Returns 0 on success.
2461 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002462int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 void __user *buffer, size_t *lenp, loff_t *ppos)
2464{
2465 struct do_proc_dointvec_minmax_conv_param param = {
2466 .min = (int *) table->extra1,
2467 .max = (int *) table->extra2,
2468 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002469 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 do_proc_dointvec_minmax_conv, &param);
2471}
2472
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002473static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 void __user *buffer,
2475 size_t *lenp, loff_t *ppos,
2476 unsigned long convmul,
2477 unsigned long convdiv)
2478{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002479 unsigned long *i, *min, *max;
2480 int vleft, first = 1, err = 0;
2481 unsigned long page = 0;
2482 size_t left;
2483 char *kbuf;
2484
2485 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 *lenp = 0;
2487 return 0;
2488 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002489
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002490 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 min = (unsigned long *) table->extra1;
2492 max = (unsigned long *) table->extra2;
2493 vleft = table->maxlen / sizeof(unsigned long);
2494 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002495
2496 if (write) {
2497 if (left > PAGE_SIZE - 1)
2498 left = PAGE_SIZE - 1;
2499 page = __get_free_page(GFP_TEMPORARY);
2500 kbuf = (char *) page;
2501 if (!kbuf)
2502 return -ENOMEM;
2503 if (copy_from_user(kbuf, buffer, left)) {
2504 err = -EFAULT;
2505 goto free;
2506 }
2507 kbuf[left] = 0;
2508 }
2509
Eric Dumazet27b3d802010-10-07 12:59:29 -07002510 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002511 unsigned long val;
2512
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002514 bool neg;
2515
2516 left -= proc_skip_spaces(&kbuf);
2517
2518 err = proc_get_long(&kbuf, &left, &val, &neg,
2519 proc_wspace_sep,
2520 sizeof(proc_wspace_sep), NULL);
2521 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 break;
2523 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 continue;
2525 if ((min && val < *min) || (max && val > *max))
2526 continue;
2527 *i = val;
2528 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002529 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002531 err = proc_put_char(&buffer, &left, '\t');
2532 err = proc_put_long(&buffer, &left, val, false);
2533 if (err)
2534 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 }
2536 }
2537
Amerigo Wang00b7c332010-05-05 00:26:45 +00002538 if (!write && !first && left && !err)
2539 err = proc_put_char(&buffer, &left, '\n');
2540 if (write && !err)
2541 left -= proc_skip_spaces(&kbuf);
2542free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002544 free_page(page);
2545 if (first)
2546 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 *lenp -= left;
2549 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002550 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551}
2552
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002553static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002554 void __user *buffer,
2555 size_t *lenp, loff_t *ppos,
2556 unsigned long convmul,
2557 unsigned long convdiv)
2558{
2559 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002560 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002561}
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563/**
2564 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2565 * @table: the sysctl table
2566 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2570 *
2571 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2572 * values from/to the user buffer, treated as an ASCII string.
2573 *
2574 * This routine will ensure the values are within the range specified by
2575 * table->extra1 (min) and table->extra2 (max).
2576 *
2577 * Returns 0 on success.
2578 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002579int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 void __user *buffer, size_t *lenp, loff_t *ppos)
2581{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002582 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583}
2584
2585/**
2586 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2587 * @table: the sysctl table
2588 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2592 *
2593 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2594 * values from/to the user buffer, treated as an ASCII string. The values
2595 * are treated as milliseconds, and converted to jiffies when they are stored.
2596 *
2597 * This routine will ensure the values are within the range specified by
2598 * table->extra1 (min) and table->extra2 (max).
2599 *
2600 * Returns 0 on success.
2601 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002602int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 void __user *buffer,
2604 size_t *lenp, loff_t *ppos)
2605{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002606 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 lenp, ppos, HZ, 1000l);
2608}
2609
2610
Amerigo Wang00b7c332010-05-05 00:26:45 +00002611static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 int *valp,
2613 int write, void *data)
2614{
2615 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002616 if (*lvalp > LONG_MAX / HZ)
2617 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2619 } else {
2620 int val = *valp;
2621 unsigned long lval;
2622 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002623 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 lval = (unsigned long)-val;
2625 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002626 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 lval = (unsigned long)val;
2628 }
2629 *lvalp = lval / HZ;
2630 }
2631 return 0;
2632}
2633
Amerigo Wang00b7c332010-05-05 00:26:45 +00002634static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 int *valp,
2636 int write, void *data)
2637{
2638 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002639 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2640 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2642 } else {
2643 int val = *valp;
2644 unsigned long lval;
2645 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002646 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 lval = (unsigned long)-val;
2648 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002649 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 lval = (unsigned long)val;
2651 }
2652 *lvalp = jiffies_to_clock_t(lval);
2653 }
2654 return 0;
2655}
2656
Amerigo Wang00b7c332010-05-05 00:26:45 +00002657static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 int *valp,
2659 int write, void *data)
2660{
2661 if (write) {
2662 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2663 } else {
2664 int val = *valp;
2665 unsigned long lval;
2666 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002667 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 lval = (unsigned long)-val;
2669 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002670 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 lval = (unsigned long)val;
2672 }
2673 *lvalp = jiffies_to_msecs(lval);
2674 }
2675 return 0;
2676}
2677
2678/**
2679 * proc_dointvec_jiffies - read a vector of integers as seconds
2680 * @table: the sysctl table
2681 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 * @buffer: the user buffer
2683 * @lenp: the size of the user buffer
2684 * @ppos: file position
2685 *
2686 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2687 * values from/to the user buffer, treated as an ASCII string.
2688 * The values read are assumed to be in seconds, and are converted into
2689 * jiffies.
2690 *
2691 * Returns 0 on success.
2692 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002693int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 void __user *buffer, size_t *lenp, loff_t *ppos)
2695{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002696 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 do_proc_dointvec_jiffies_conv,NULL);
2698}
2699
2700/**
2701 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2702 * @table: the sysctl table
2703 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 * @buffer: the user buffer
2705 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002706 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 *
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2710 * The values read are assumed to be in 1/USER_HZ seconds, and
2711 * are converted into jiffies.
2712 *
2713 * Returns 0 on success.
2714 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002715int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 void __user *buffer, size_t *lenp, loff_t *ppos)
2717{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002718 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 do_proc_dointvec_userhz_jiffies_conv,NULL);
2720}
2721
2722/**
2723 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2724 * @table: the sysctl table
2725 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002728 * @ppos: file position
2729 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 *
2731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2732 * values from/to the user buffer, treated as an ASCII string.
2733 * The values read are assumed to be in 1/1000 seconds, and
2734 * are converted into jiffies.
2735 *
2736 * Returns 0 on success.
2737 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002738int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 void __user *buffer, size_t *lenp, loff_t *ppos)
2740{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002741 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 do_proc_dointvec_ms_jiffies_conv, NULL);
2743}
2744
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002745static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002746 void __user *buffer, size_t *lenp, loff_t *ppos)
2747{
2748 struct pid *new_pid;
2749 pid_t tmp;
2750 int r;
2751
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002752 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002753
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002754 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002755 lenp, ppos, NULL, NULL);
2756 if (r || !write)
2757 return r;
2758
2759 new_pid = find_get_pid(tmp);
2760 if (!new_pid)
2761 return -ESRCH;
2762
2763 put_pid(xchg(&cad_pid, new_pid));
2764 return 0;
2765}
2766
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002767/**
2768 * proc_do_large_bitmap - read/write from/to a large bitmap
2769 * @table: the sysctl table
2770 * @write: %TRUE if this is a write to the sysctl file
2771 * @buffer: the user buffer
2772 * @lenp: the size of the user buffer
2773 * @ppos: file position
2774 *
2775 * The bitmap is stored at table->data and the bitmap length (in bits)
2776 * in table->maxlen.
2777 *
2778 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2779 * large bitmaps may be represented in a compact manner. Writing into
2780 * the file will clear the bitmap then update it with the given input.
2781 *
2782 * Returns 0 on success.
2783 */
2784int proc_do_large_bitmap(struct ctl_table *table, int write,
2785 void __user *buffer, size_t *lenp, loff_t *ppos)
2786{
2787 int err = 0;
2788 bool first = 1;
2789 size_t left = *lenp;
2790 unsigned long bitmap_len = table->maxlen;
2791 unsigned long *bitmap = (unsigned long *) table->data;
2792 unsigned long *tmp_bitmap = NULL;
2793 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2794
2795 if (!bitmap_len || !left || (*ppos && !write)) {
2796 *lenp = 0;
2797 return 0;
2798 }
2799
2800 if (write) {
2801 unsigned long page = 0;
2802 char *kbuf;
2803
2804 if (left > PAGE_SIZE - 1)
2805 left = PAGE_SIZE - 1;
2806
2807 page = __get_free_page(GFP_TEMPORARY);
2808 kbuf = (char *) page;
2809 if (!kbuf)
2810 return -ENOMEM;
2811 if (copy_from_user(kbuf, buffer, left)) {
2812 free_page(page);
2813 return -EFAULT;
2814 }
2815 kbuf[left] = 0;
2816
2817 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2818 GFP_KERNEL);
2819 if (!tmp_bitmap) {
2820 free_page(page);
2821 return -ENOMEM;
2822 }
2823 proc_skip_char(&kbuf, &left, '\n');
2824 while (!err && left) {
2825 unsigned long val_a, val_b;
2826 bool neg;
2827
2828 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2829 sizeof(tr_a), &c);
2830 if (err)
2831 break;
2832 if (val_a >= bitmap_len || neg) {
2833 err = -EINVAL;
2834 break;
2835 }
2836
2837 val_b = val_a;
2838 if (left) {
2839 kbuf++;
2840 left--;
2841 }
2842
2843 if (c == '-') {
2844 err = proc_get_long(&kbuf, &left, &val_b,
2845 &neg, tr_b, sizeof(tr_b),
2846 &c);
2847 if (err)
2848 break;
2849 if (val_b >= bitmap_len || neg ||
2850 val_a > val_b) {
2851 err = -EINVAL;
2852 break;
2853 }
2854 if (left) {
2855 kbuf++;
2856 left--;
2857 }
2858 }
2859
2860 while (val_a <= val_b)
2861 set_bit(val_a++, tmp_bitmap);
2862
2863 first = 0;
2864 proc_skip_char(&kbuf, &left, '\n');
2865 }
2866 free_page(page);
2867 } else {
2868 unsigned long bit_a, bit_b = 0;
2869
2870 while (left) {
2871 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2872 if (bit_a >= bitmap_len)
2873 break;
2874 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2875 bit_a + 1) - 1;
2876
2877 if (!first) {
2878 err = proc_put_char(&buffer, &left, ',');
2879 if (err)
2880 break;
2881 }
2882 err = proc_put_long(&buffer, &left, bit_a, false);
2883 if (err)
2884 break;
2885 if (bit_a != bit_b) {
2886 err = proc_put_char(&buffer, &left, '-');
2887 if (err)
2888 break;
2889 err = proc_put_long(&buffer, &left, bit_b, false);
2890 if (err)
2891 break;
2892 }
2893
2894 first = 0; bit_b++;
2895 }
2896 if (!err)
2897 err = proc_put_char(&buffer, &left, '\n');
2898 }
2899
2900 if (!err) {
2901 if (write) {
2902 if (*ppos)
2903 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2904 else
2905 memcpy(bitmap, tmp_bitmap,
2906 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2907 }
2908 kfree(tmp_bitmap);
2909 *lenp -= left;
2910 *ppos += *lenp;
2911 return 0;
2912 } else {
2913 kfree(tmp_bitmap);
2914 return err;
2915 }
2916}
2917
Jovi Zhang55610502011-01-12 17:00:45 -08002918#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002920int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 void __user *buffer, size_t *lenp, loff_t *ppos)
2922{
2923 return -ENOSYS;
2924}
2925
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002926int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
2929 return -ENOSYS;
2930}
2931
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002932int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 void __user *buffer, size_t *lenp, loff_t *ppos)
2934{
2935 return -ENOSYS;
2936}
2937
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002938int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 void __user *buffer, size_t *lenp, loff_t *ppos)
2940{
2941 return -ENOSYS;
2942}
2943
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002944int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 void __user *buffer, size_t *lenp, loff_t *ppos)
2946{
2947 return -ENOSYS;
2948}
2949
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002950int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 void __user *buffer, size_t *lenp, loff_t *ppos)
2952{
2953 return -ENOSYS;
2954}
2955
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002956int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 void __user *buffer, size_t *lenp, loff_t *ppos)
2958{
2959 return -ENOSYS;
2960}
2961
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002962int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 void __user *buffer,
2964 size_t *lenp, loff_t *ppos)
2965{
2966 return -ENOSYS;
2967}
2968
2969
Jovi Zhang55610502011-01-12 17:00:45 -08002970#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972/*
2973 * No sense putting this after each symbol definition, twice,
2974 * exception granted :-)
2975 */
2976EXPORT_SYMBOL(proc_dointvec);
2977EXPORT_SYMBOL(proc_dointvec_jiffies);
2978EXPORT_SYMBOL(proc_dointvec_minmax);
2979EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2980EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2981EXPORT_SYMBOL(proc_dostring);
2982EXPORT_SYMBOL(proc_doulongvec_minmax);
2983EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2984EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002985EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986EXPORT_SYMBOL(unregister_sysctl_table);