blob: 5abfa151855493735a91fd45a255a45727c8ba97 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070028#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070040#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070043#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/times.h>
45#include <linux/limits.h>
46#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020047#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070049#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080050#include <linux/nfs_fs.h>
51#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070052#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020053#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020054#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050055#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020056#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070057#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/uaccess.h>
60#include <asm/processor.h>
61
Andi Kleen29cbc782006-09-30 01:47:55 +020062#ifdef CONFIG_X86
63#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010064#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010065#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020066#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080067#ifdef CONFIG_BSD_PROCESS_ACCT
68#include <linux/acct.h>
69#endif
Dave Young4f0e0562010-03-10 15:24:09 -080070#ifdef CONFIG_RT_MUTEXES
71#include <linux/rtmutex.h>
72#endif
Dave Young2edf5e42010-03-10 15:24:10 -080073#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74#include <linux/lockdep.h>
75#endif
Dave Young15485a42010-03-10 15:24:07 -080076#ifdef CONFIG_CHR_DEV_SG
77#include <scsi/sg.h>
78#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020079
Don Zickus58687ac2010-05-07 17:11:44 -040080#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050081#include <linux/nmi.h>
82#endif
83
Eric W. Biederman7058cb02007-10-18 03:05:58 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#if defined(CONFIG_SYSCTL)
86
87/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int sysctl_overcommit_memory;
89extern int sysctl_overcommit_ratio;
90extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070092extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070094extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern int pid_max;
96extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080098extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080099extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200100extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100101extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400102extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000103#ifndef CONFIG_MMU
104extern int sysctl_nr_trim_pages;
105#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200106#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200107extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700110/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400111#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200113static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114#endif
115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700117static int __maybe_unused one = 1;
118static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800119static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700121#ifdef CONFIG_PRINTK
122static int ten_thousand = 10000;
123#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700125/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129static int maxolduid = 65535;
130static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800131static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133static int ngroups_max = NGROUPS_MAX;
134
Dave Youngd14f1722010-02-25 20:28:57 -0500135#ifdef CONFIG_INOTIFY_USER
136#include <linux/inotify.h>
137#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700138#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700139#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif
141
David S. Miller08714202008-11-16 23:49:24 -0800142#ifdef CONFIG_SPARC64
143extern int sysctl_tsb_ratio;
144#endif
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef __hppa__
147extern int pwrsw_enabled;
148extern int unaligned_enabled;
149#endif
150
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800151#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#ifdef CONFIG_MATHEMU
153extern int sysctl_ieee_emulation_warnings;
154#endif
155extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700156extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#ifdef CONFIG_IA64
160extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800161extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#endif
163
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700165static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800168 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700171#ifdef CONFIG_MAGIC_SYSRQ
172static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
173
174static int sysrq_sysctl_handler(ctl_table *table, int write,
175 void __user *buffer, size_t *lenp,
176 loff_t *ppos)
177{
178 int error;
179
180 error = proc_dointvec(table, write, buffer, lenp, ppos);
181 if (error)
182 return error;
183
184 if (write)
185 sysrq_toggle_support(__sysrq_enabled);
186
187 return 0;
188}
189
190#endif
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100193static struct ctl_table_root sysctl_table_root;
194static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100195 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400197 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100198 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400199 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200};
201static struct ctl_table_root sysctl_table_root = {
202 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400203 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700206static struct ctl_table kern_table[];
207static struct ctl_table vm_table[];
208static struct ctl_table fs_table[];
209static struct ctl_table debug_table[];
210static struct ctl_table dev_table[];
211extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800212#ifdef CONFIG_EPOLL
213extern struct ctl_table epoll_table[];
214#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217int sysctl_legacy_va_layout;
218#endif
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/* The default sysctl tables: */
221
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700222static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .procname = "kernel",
225 .mode = 0555,
226 .child = kern_table,
227 },
228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .procname = "vm",
230 .mode = 0555,
231 .child = vm_table,
232 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .procname = "fs",
235 .mode = 0555,
236 .child = fs_table,
237 },
238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .procname = "debug",
240 .mode = 0555,
241 .child = debug_table,
242 },
243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "dev",
245 .mode = 0555,
246 .child = dev_table,
247 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700248/*
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
251 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700252 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100256static int min_sched_granularity_ns = 100000; /* 100 usecs */
257static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258static int min_wakeup_granularity_ns; /* 0 usecs */
259static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100262static int min_sched_shares_ratelimit = 100000; /* 100 usec */
263static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264#endif
265
Mel Gorman5e771902010-05-24 14:32:31 -0700266#ifdef CONFIG_COMPACTION
267static int min_extfrag_threshold;
268static int max_extfrag_threshold = 1000;
269#endif
270
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700271static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200272 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800277 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200278 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279#ifdef CONFIG_SCHED_DEBUG
280 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100281 .procname = "sched_min_granularity_ns",
282 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800285 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200288 },
289 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200290 .procname = "sched_latency_ns",
291 .data = &sysctl_sched_latency,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800294 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
297 },
298 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .procname = "sched_wakeup_granularity_ns",
300 .data = &sysctl_sched_wakeup_granularity,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800303 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200304 .extra1 = &min_wakeup_granularity_ns,
305 .extra2 = &max_wakeup_granularity_ns,
306 },
307 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200308 .procname = "sched_shares_ratelimit",
309 .data = &sysctl_sched_shares_ratelimit,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800312 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100313 .extra1 = &min_sched_shares_ratelimit,
314 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200315 },
316 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200324 },
325 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200326 .procname = "sched_shares_thresh",
327 .data = &sysctl_sched_shares_thresh,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200331 .extra1 = &zero,
332 },
333 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200334 .procname = "sched_migration_cost",
335 .data = &sysctl_sched_migration_cost,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800338 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200339 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100340 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100341 .procname = "sched_nr_migrate",
342 .data = &sysctl_sched_nr_migrate,
343 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800345 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100346 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200348 .procname = "sched_time_avg",
349 .data = &sysctl_sched_time_avg,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800352 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200353 },
354 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800359 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530360 .extra1 = &zero,
361 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530362 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200363#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200364 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 .procname = "sched_rt_period_us",
366 .data = &sysctl_sched_rt_period,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100370 },
371 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100372 .procname = "sched_rt_runtime_us",
373 .data = &sysctl_sched_rt_runtime,
374 .maxlen = sizeof(int),
375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800376 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100377 },
378 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200379 .procname = "sched_compat_yield",
380 .data = &sysctl_sched_compat_yield,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800383 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200384 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700385#ifdef CONFIG_PROVE_LOCKING
386 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700387 .procname = "prove_locking",
388 .data = &prove_locking,
389 .maxlen = sizeof(int),
390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800391 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392 },
393#endif
394#ifdef CONFIG_LOCK_STAT
395 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700396 .procname = "lock_stat",
397 .data = &lock_stat,
398 .maxlen = sizeof(int),
399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800400 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700401 },
402#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .procname = "panic",
405 .data = &panic_timeout,
406 .maxlen = sizeof(int),
407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800408 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 },
410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
414 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800415 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 },
417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .procname = "core_pattern",
419 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700420 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800422 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 },
Neil Hormana2939802009-09-23 15:56:56 -0700424 {
Neil Hormana2939802009-09-23 15:56:56 -0700425 .procname = "core_pipe_limit",
426 .data = &core_pipe_limit,
427 .maxlen = sizeof(unsigned int),
428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800429 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700430 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800431#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700434 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800438#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100439#ifdef CONFIG_LATENCYTOP
440 {
441 .procname = "latencytop",
442 .data = &latencytop_enabled,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800445 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100446 },
447#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448#ifdef CONFIG_BLK_DEV_INITRD
449 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .procname = "real-root-dev",
451 .data = &real_root_dev,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800454 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 },
456#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700457 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700458 .procname = "print-fatal-signals",
459 .data = &print_fatal_signals,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800462 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700463 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700464#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .procname = "reboot-cmd",
467 .data = reboot_command,
468 .maxlen = 256,
469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800470 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 },
472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "scons-poweroff",
481 .data = &scons_pwroff,
482 .maxlen = sizeof (int),
483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800484 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
486#endif
David S. Miller08714202008-11-16 23:49:24 -0800487#ifdef CONFIG_SPARC64
488 {
David S. Miller08714202008-11-16 23:49:24 -0800489 .procname = "tsb-ratio",
490 .data = &sysctl_tsb_ratio,
491 .maxlen = sizeof (int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800494 },
495#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#ifdef __hppa__
497 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .procname = "soft-power",
499 .data = &pwrsw_enabled,
500 .maxlen = sizeof (int),
501 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800502 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .procname = "unaligned-trap",
506 .data = &unaligned_enabled,
507 .maxlen = sizeof (int),
508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800509 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 },
511#endif
512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "ctrl-alt-del",
514 .data = &C_A_D,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400519#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200520 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 .procname = "ftrace_enabled",
522 .data = &ftrace_enabled,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800525 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200526 },
527#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500528#ifdef CONFIG_STACK_TRACER
529 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500530 .procname = "stack_tracer_enabled",
531 .data = &stack_tracer_enabled,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500535 },
536#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400537#ifdef CONFIG_TRACING
538 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100539 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400540 .data = &ftrace_dump_on_oops,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400544 },
545#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200546#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .procname = "modprobe",
549 .data = &modprobe_path,
550 .maxlen = KMOD_PATH_LEN,
551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800552 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 },
Kees Cook3d433212009-04-02 15:49:29 -0700554 {
Kees Cook3d433212009-04-02 15:49:29 -0700555 .procname = "modules_disabled",
556 .data = &modules_disabled,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800560 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700561 .extra1 = &one,
562 .extra2 = &one,
563 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100565#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100568 .data = &uevent_helper,
569 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800571 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573#endif
574#ifdef CONFIG_CHR_DEV_SG
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "sg-big-buff",
577 .data = &sg_big_buff,
578 .maxlen = sizeof (int),
579 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800580 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582#endif
583#ifdef CONFIG_BSD_PROCESS_ACCT
584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "acct",
586 .data = &acct_parm,
587 .maxlen = 3*sizeof(int),
588 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800589 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 },
591#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#ifdef CONFIG_MAGIC_SYSRQ
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800595 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 .maxlen = sizeof (int),
597 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700598 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
600#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700601#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700604 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 .maxlen = sizeof (int),
606 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "threads-max",
612 .data = &max_threads,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "random",
619 .mode = 0555,
620 .child = random_table,
621 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .procname = "overflowuid",
624 .data = &overflowuid,
625 .maxlen = sizeof(int),
626 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800627 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
630 },
631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .procname = "overflowgid",
633 .data = &overflowgid,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .extra1 = &minolduid,
638 .extra2 = &maxolduid,
639 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800640#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#ifdef CONFIG_MATHEMU
642 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .procname = "ieee_emulation_warnings",
644 .data = &sysctl_ieee_emulation_warnings,
645 .maxlen = sizeof(int),
646 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800647 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 },
649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200652 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .maxlen = sizeof(int),
654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800655 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 },
657#endif
658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "pid_max",
660 .data = &pid_max,
661 .maxlen = sizeof (int),
662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
666 },
667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
671 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800674#if defined CONFIG_PRINTK
675 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800676 .procname = "printk",
677 .data = &console_loglevel,
678 .maxlen = 4*sizeof(int),
679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800681 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700684 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .maxlen = sizeof(int),
686 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800687 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 },
689 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700691 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 .maxlen = sizeof(int),
693 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800694 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 },
Dave Youngaf913222009-09-22 16:43:33 -0700696 {
Dave Youngaf913222009-09-22 16:43:33 -0700697 .procname = "printk_delay",
698 .data = &printk_delay_msec,
699 .maxlen = sizeof(int),
700 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700702 .extra1 = &zero,
703 .extra2 = &ten_thousand,
704 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800706 .procname = "dmesg_restrict",
707 .data = &dmesg_restrict,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = proc_dointvec_minmax,
711 .extra1 = &zero,
712 .extra2 = &one,
713 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800714#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .procname = "ngroups_max",
717 .data = &ngroups_max,
718 .maxlen = sizeof (int),
719 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800720 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
Don Zickus58687ac2010-05-07 17:11:44 -0400722#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500723 {
Don Zickus58687ac2010-05-07 17:11:44 -0400724 .procname = "watchdog",
725 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500726 .maxlen = sizeof (int),
727 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400728 .proc_handler = proc_dowatchdog_enabled,
729 },
730 {
731 .procname = "watchdog_thresh",
732 .data = &softlockup_thresh,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = proc_dowatchdog_thresh,
736 .extra1 = &neg_one,
737 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500738 },
Don Zickus2508ce12010-05-07 17:11:46 -0400739 {
740 .procname = "softlockup_panic",
741 .data = &softlockup_panic,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = proc_dointvec_minmax,
745 .extra1 = &zero,
746 .extra2 = &one,
747 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500748#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400749#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 .procname = "unknown_nmi_panic",
752 .data = &unknown_nmi_panic,
753 .maxlen = sizeof (int),
754 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800755 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 },
Don Zickus407984f2006-09-26 10:52:27 +0200757 {
Don Zickus407984f2006-09-26 10:52:27 +0200758 .procname = "nmi_watchdog",
759 .data = &nmi_watchdog_enabled,
760 .maxlen = sizeof (int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 },
764#endif
765#if defined(CONFIG_X86)
766 {
Don Zickus8da5add2006-09-26 10:52:27 +0200767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200772 },
773 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700774 .procname = "panic_on_io_nmi",
775 .data = &panic_on_io_nmi,
776 .maxlen = sizeof(int),
777 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800778 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700779 },
780 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 .procname = "bootloader_type",
782 .data = &bootloader_type,
783 .maxlen = sizeof (int),
784 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800785 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100787 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700788 .procname = "bootloader_version",
789 .data = &bootloader_version,
790 .maxlen = sizeof (int),
791 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700793 },
794 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100795 .procname = "kstack_depth_to_print",
796 .data = &kstack_depth_to_print,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100800 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100801 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100802 .procname = "io_delay_type",
803 .data = &io_delay_type,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100807 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800809#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .procname = "randomize_va_space",
812 .data = &randomize_va_space,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800817#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800818#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700819 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700820 .procname = "spin_retry",
821 .data = &spin_retry,
822 .maxlen = sizeof (int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700825 },
826#endif
Len Brown673d5b42007-07-28 03:33:16 -0400827#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800828 {
Pavel Machekc255d842006-02-20 18:27:58 -0800829 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700830 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800831 .maxlen = sizeof (unsigned long),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800834 },
835#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800836#ifdef CONFIG_IA64
837 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800838 .procname = "ignore-unaligned-usertrap",
839 .data = &no_unaligned_warning,
840 .maxlen = sizeof (int),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800843 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800844 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800845 .procname = "unaligned-dump-stack",
846 .data = &unaligned_dump_stack,
847 .maxlen = sizeof (int),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800850 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800851#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800852#ifdef CONFIG_DETECT_HUNG_TASK
853 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800854 .procname = "hung_task_panic",
855 .data = &sysctl_hung_task_panic,
856 .maxlen = sizeof(int),
857 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800858 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800859 .extra1 = &zero,
860 .extra2 = &one,
861 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100862 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 .procname = "hung_task_check_count",
864 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100865 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 },
869 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100870 .procname = "hung_task_timeout_secs",
871 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100872 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 },
876 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 .procname = "hung_task_warnings",
878 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100879 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100880 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800881 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700883#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200884#ifdef CONFIG_COMPAT
885 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200886 .procname = "compat-log",
887 .data = &compat_log,
888 .maxlen = sizeof (int),
889 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800890 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200891 },
892#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700893#ifdef CONFIG_RT_MUTEXES
894 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700895 .procname = "max_lock_depth",
896 .data = &max_lock_depth,
897 .maxlen = sizeof(int),
898 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800899 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700900 },
901#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700902 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700903 .procname = "poweroff_cmd",
904 .data = &poweroff_cmd,
905 .maxlen = POWEROFF_CMD_PATH_LEN,
906 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800907 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700908 },
David Howells0b77f5b2008-04-29 01:01:32 -0700909#ifdef CONFIG_KEYS
910 {
David Howells0b77f5b2008-04-29 01:01:32 -0700911 .procname = "keys",
912 .mode = 0555,
913 .child = key_sysctls,
914 },
915#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700916#ifdef CONFIG_RCU_TORTURE_TEST
917 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700918 .procname = "rcutorture_runnable",
919 .data = &rcutorture_runnable,
920 .maxlen = sizeof(int),
921 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800922 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700923 },
924#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200925#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200926 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200927 .procname = "perf_event_paranoid",
928 .data = &sysctl_perf_event_paranoid,
929 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200930 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800931 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200932 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200933 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200934 .procname = "perf_event_mlock_kb",
935 .data = &sysctl_perf_event_mlock,
936 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200937 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800938 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200939 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200940 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200941 .procname = "perf_event_max_sample_rate",
942 .data = &sysctl_perf_event_sample_rate,
943 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200944 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800945 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200946 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200947#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200948#ifdef CONFIG_KMEMCHECK
949 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200950 .procname = "kmemcheck",
951 .data = &kmemcheck_enabled,
952 .maxlen = sizeof(int),
953 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800954 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200955 },
956#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200957#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200958 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200959 .procname = "blk_iopoll",
960 .data = &blk_iopoll_enabled,
961 .maxlen = sizeof(int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200964 },
Jens Axboecb684b52009-09-15 21:53:11 +0200965#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700966/*
967 * NOTE: do not add new entries to this table unless you have read
968 * Documentation/sysctl/ctl_unnumbered.txt
969 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700970 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971};
972
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700973static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 .procname = "overcommit_memory",
976 .data = &sysctl_overcommit_memory,
977 .maxlen = sizeof(sysctl_overcommit_memory),
978 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800979 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 },
981 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700982 .procname = "panic_on_oom",
983 .data = &sysctl_panic_on_oom,
984 .maxlen = sizeof(sysctl_panic_on_oom),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700987 },
988 {
David Rientjesfe071d72007-10-16 23:25:56 -0700989 .procname = "oom_kill_allocating_task",
990 .data = &sysctl_oom_kill_allocating_task,
991 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
992 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800993 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700994 },
995 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800996 .procname = "oom_dump_tasks",
997 .data = &sysctl_oom_dump_tasks,
998 .maxlen = sizeof(sysctl_oom_dump_tasks),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001001 },
1002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .procname = "overcommit_ratio",
1004 .data = &sysctl_overcommit_ratio,
1005 .maxlen = sizeof(sysctl_overcommit_ratio),
1006 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001007 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 },
1009 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 .procname = "page-cluster",
1011 .data = &page_cluster,
1012 .maxlen = sizeof(int),
1013 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001014 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 },
1016 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .procname = "dirty_background_ratio",
1018 .data = &dirty_background_ratio,
1019 .maxlen = sizeof(dirty_background_ratio),
1020 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001021 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .extra1 = &zero,
1023 .extra2 = &one_hundred,
1024 },
1025 {
David Rientjes2da02992009-01-06 14:39:31 -08001026 .procname = "dirty_background_bytes",
1027 .data = &dirty_background_bytes,
1028 .maxlen = sizeof(dirty_background_bytes),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001031 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001032 },
1033 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 .procname = "dirty_ratio",
1035 .data = &vm_dirty_ratio,
1036 .maxlen = sizeof(vm_dirty_ratio),
1037 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001038 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .extra1 = &zero,
1040 .extra2 = &one_hundred,
1041 },
1042 {
David Rientjes2da02992009-01-06 14:39:31 -08001043 .procname = "dirty_bytes",
1044 .data = &vm_dirty_bytes,
1045 .maxlen = sizeof(vm_dirty_bytes),
1046 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001047 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001048 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001049 },
1050 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001052 .data = &dirty_writeback_interval,
1053 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001055 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 },
1057 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001059 .data = &dirty_expire_interval,
1060 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 },
1064 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 .procname = "nr_pdflush_threads",
1066 .data = &nr_pdflush_threads,
1067 .maxlen = sizeof nr_pdflush_threads,
1068 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 },
1071 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .procname = "swappiness",
1073 .data = &vm_swappiness,
1074 .maxlen = sizeof(vm_swappiness),
1075 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001076 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1079 },
1080#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001081 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001083 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .maxlen = sizeof(unsigned long),
1085 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001086 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 .extra1 = (void *)&hugetlb_zero,
1088 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001089 },
1090#ifdef CONFIG_NUMA
1091 {
1092 .procname = "nr_hugepages_mempolicy",
1093 .data = NULL,
1094 .maxlen = sizeof(unsigned long),
1095 .mode = 0644,
1096 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1097 .extra1 = (void *)&hugetlb_zero,
1098 .extra2 = (void *)&hugetlb_infinity,
1099 },
1100#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .procname = "hugetlb_shm_group",
1103 .data = &sysctl_hugetlb_shm_group,
1104 .maxlen = sizeof(gid_t),
1105 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001106 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 },
Mel Gorman396faf02007-07-17 04:03:13 -07001108 {
Mel Gorman396faf02007-07-17 04:03:13 -07001109 .procname = "hugepages_treat_as_movable",
1110 .data = &hugepages_treat_as_movable,
1111 .maxlen = sizeof(int),
1112 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001113 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001114 },
Adam Litke54f9f802007-10-16 01:26:20 -07001115 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001116 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001117 .data = NULL,
1118 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001121 .extra1 = (void *)&hugetlb_zero,
1122 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001123 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124#endif
1125 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 .procname = "lowmem_reserve_ratio",
1127 .data = &sysctl_lowmem_reserve_ratio,
1128 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1129 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001130 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 },
1132 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001133 .procname = "drop_caches",
1134 .data = &sysctl_drop_caches,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001138 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001139#ifdef CONFIG_COMPACTION
1140 {
1141 .procname = "compact_memory",
1142 .data = &sysctl_compact_memory,
1143 .maxlen = sizeof(int),
1144 .mode = 0200,
1145 .proc_handler = sysctl_compaction_handler,
1146 },
Mel Gorman5e771902010-05-24 14:32:31 -07001147 {
1148 .procname = "extfrag_threshold",
1149 .data = &sysctl_extfrag_threshold,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
1152 .proc_handler = sysctl_extfrag_handler,
1153 .extra1 = &min_extfrag_threshold,
1154 .extra2 = &max_extfrag_threshold,
1155 },
1156
Mel Gorman76ab0f52010-05-24 14:32:28 -07001157#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001158 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 .procname = "min_free_kbytes",
1160 .data = &min_free_kbytes,
1161 .maxlen = sizeof(min_free_kbytes),
1162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001163 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 .extra1 = &zero,
1165 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001166 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001167 .procname = "percpu_pagelist_fraction",
1168 .data = &percpu_pagelist_fraction,
1169 .maxlen = sizeof(percpu_pagelist_fraction),
1170 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001171 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001172 .extra1 = &min_percpu_pagelist_fract,
1173 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#ifdef CONFIG_MMU
1175 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 .procname = "max_map_count",
1177 .data = &sysctl_max_map_count,
1178 .maxlen = sizeof(sysctl_max_map_count),
1179 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001180 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001181 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001183#else
1184 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001185 .procname = "nr_trim_pages",
1186 .data = &sysctl_nr_trim_pages,
1187 .maxlen = sizeof(sysctl_nr_trim_pages),
1188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001190 .extra1 = &zero,
1191 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192#endif
1193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .procname = "laptop_mode",
1195 .data = &laptop_mode,
1196 .maxlen = sizeof(laptop_mode),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 },
1200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 .procname = "block_dump",
1202 .data = &block_dump,
1203 .maxlen = sizeof(block_dump),
1204 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001205 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 .extra1 = &zero,
1207 },
1208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "vfs_cache_pressure",
1210 .data = &sysctl_vfs_cache_pressure,
1211 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 .extra1 = &zero,
1215 },
1216#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .procname = "legacy_va_layout",
1219 .data = &sysctl_legacy_va_layout,
1220 .maxlen = sizeof(sysctl_legacy_va_layout),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .extra1 = &zero,
1224 },
1225#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001226#ifdef CONFIG_NUMA
1227 {
Christoph Lameter17436602006-01-18 17:42:32 -08001228 .procname = "zone_reclaim_mode",
1229 .data = &zone_reclaim_mode,
1230 .maxlen = sizeof(zone_reclaim_mode),
1231 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001232 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001233 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001234 },
Christoph Lameter96146342006-07-03 00:24:13 -07001235 {
Christoph Lameter96146342006-07-03 00:24:13 -07001236 .procname = "min_unmapped_ratio",
1237 .data = &sysctl_min_unmapped_ratio,
1238 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1239 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001240 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001241 .extra1 = &zero,
1242 .extra2 = &one_hundred,
1243 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001244 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001245 .procname = "min_slab_ratio",
1246 .data = &sysctl_min_slab_ratio,
1247 .maxlen = sizeof(sysctl_min_slab_ratio),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001250 .extra1 = &zero,
1251 .extra2 = &one_hundred,
1252 },
Christoph Lameter17436602006-01-18 17:42:32 -08001253#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001254#ifdef CONFIG_SMP
1255 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001256 .procname = "stat_interval",
1257 .data = &sysctl_stat_interval,
1258 .maxlen = sizeof(sysctl_stat_interval),
1259 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001260 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001261 },
1262#endif
David Howells6e141542009-12-15 19:27:45 +00001263#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001264 {
Eric Parised032182007-06-28 15:55:21 -04001265 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001266 .data = &dac_mmap_min_addr,
1267 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001268 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001269 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001270 },
David Howells6e141542009-12-15 19:27:45 +00001271#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001272#ifdef CONFIG_NUMA
1273 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001274 .procname = "numa_zonelist_order",
1275 .data = &numa_zonelist_order,
1276 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1277 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001278 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001279 },
1280#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001281#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001282 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001283 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001284 .procname = "vdso_enabled",
1285 .data = &vdso_enabled,
1286 .maxlen = sizeof(vdso_enabled),
1287 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001288 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001289 .extra1 = &zero,
1290 },
1291#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001292#ifdef CONFIG_HIGHMEM
1293 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001294 .procname = "highmem_is_dirtyable",
1295 .data = &vm_highmem_is_dirtyable,
1296 .maxlen = sizeof(vm_highmem_is_dirtyable),
1297 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001298 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001299 .extra1 = &zero,
1300 .extra2 = &one,
1301 },
1302#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001303 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001304 .procname = "scan_unevictable_pages",
1305 .data = &scan_unevictable_pages,
1306 .maxlen = sizeof(scan_unevictable_pages),
1307 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001308 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001309 },
Andi Kleen6a460792009-09-16 11:50:15 +02001310#ifdef CONFIG_MEMORY_FAILURE
1311 {
Andi Kleen6a460792009-09-16 11:50:15 +02001312 .procname = "memory_failure_early_kill",
1313 .data = &sysctl_memory_failure_early_kill,
1314 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1315 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001316 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001317 .extra1 = &zero,
1318 .extra2 = &one,
1319 },
1320 {
Andi Kleen6a460792009-09-16 11:50:15 +02001321 .procname = "memory_failure_recovery",
1322 .data = &sysctl_memory_failure_recovery,
1323 .maxlen = sizeof(sysctl_memory_failure_recovery),
1324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001325 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001326 .extra1 = &zero,
1327 .extra2 = &one,
1328 },
1329#endif
1330
Andrew Morton2be7fe02007-07-15 23:41:21 -07001331/*
1332 * NOTE: do not add new entries to this table unless you have read
1333 * Documentation/sysctl/ctl_unnumbered.txt
1334 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001335 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336};
1337
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001338#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001339static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001340 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001341};
1342#endif
1343
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001344static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .procname = "inode-nr",
1347 .data = &inodes_stat,
1348 .maxlen = 2*sizeof(int),
1349 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001350 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 },
1352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .procname = "inode-state",
1354 .data = &inodes_stat,
1355 .maxlen = 7*sizeof(int),
1356 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001357 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 },
1359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 .procname = "file-nr",
1361 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001362 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001364 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 },
1366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .procname = "file-max",
1368 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001369 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001371 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 },
1373 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001374 .procname = "nr_open",
1375 .data = &sysctl_nr_open,
1376 .maxlen = sizeof(int),
1377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001379 .extra1 = &sysctl_nr_open_min,
1380 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "dentry-state",
1384 .data = &dentry_stat,
1385 .maxlen = 6*sizeof(int),
1386 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001387 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "overflowuid",
1391 .data = &fs_overflowuid,
1392 .maxlen = sizeof(int),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .extra1 = &minolduid,
1396 .extra2 = &maxolduid,
1397 },
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "overflowgid",
1400 .data = &fs_overflowgid,
1401 .maxlen = sizeof(int),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .extra1 = &minolduid,
1405 .extra2 = &maxolduid,
1406 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001407#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 .procname = "leases-enable",
1410 .data = &leases_enable,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416#ifdef CONFIG_DNOTIFY
1417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "dir-notify-enable",
1419 .data = &dir_notify_enable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
1424#endif
1425#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001426#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 .procname = "lease-break-time",
1429 .data = &lease_break_time,
1430 .maxlen = sizeof(int),
1431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001432 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001434#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001435#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .procname = "aio-nr",
1438 .data = &aio_nr,
1439 .maxlen = sizeof(aio_nr),
1440 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 },
1443 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .procname = "aio-max-nr",
1445 .data = &aio_max_nr,
1446 .maxlen = sizeof(aio_max_nr),
1447 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001448 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001450#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001451#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001452 {
Robert Love0399cb02005-07-13 12:38:18 -04001453 .procname = "inotify",
1454 .mode = 0555,
1455 .child = inotify_table,
1456 },
1457#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001458#ifdef CONFIG_EPOLL
1459 {
1460 .procname = "epoll",
1461 .mode = 0555,
1462 .child = epoll_table,
1463 },
1464#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001466 {
Alan Coxd6e71142005-06-23 00:09:43 -07001467 .procname = "suid_dumpable",
1468 .data = &suid_dumpable,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001471 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001472 .extra1 = &zero,
1473 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001474 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001475#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1476 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001477 .procname = "binfmt_misc",
1478 .mode = 0555,
1479 .child = binfmt_misc_table,
1480 },
1481#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001482 {
Jens Axboeff9da692010-06-03 14:54:39 +02001483 .procname = "pipe-max-size",
1484 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001485 .maxlen = sizeof(int),
1486 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001487 .proc_handler = &pipe_proc_fn,
1488 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001489 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001490/*
1491 * NOTE: do not add new entries to this table unless you have read
1492 * Documentation/sysctl/ctl_unnumbered.txt
1493 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001494 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495};
1496
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001497static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001498#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1499 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001500 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001501 .procname = "exception-trace",
1502 .data = &show_unhandled_signals,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = proc_dointvec
1506 },
1507#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001508#if defined(CONFIG_OPTPROBES)
1509 {
1510 .procname = "kprobes-optimization",
1511 .data = &sysctl_kprobes_optimization,
1512 .maxlen = sizeof(int),
1513 .mode = 0644,
1514 .proc_handler = proc_kprobes_optimization_handler,
1515 .extra1 = &zero,
1516 .extra2 = &one,
1517 },
1518#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001519 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520};
1521
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001522static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001523 { }
Robert Love0eeca282005-07-12 17:06:03 -04001524};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Al Viro330d57f2005-11-04 10:18:40 +00001526static DEFINE_SPINLOCK(sysctl_lock);
1527
1528/* called under sysctl_lock */
1529static int use_table(struct ctl_table_header *p)
1530{
1531 if (unlikely(p->unregistering))
1532 return 0;
1533 p->used++;
1534 return 1;
1535}
1536
1537/* called under sysctl_lock */
1538static void unuse_table(struct ctl_table_header *p)
1539{
1540 if (!--p->used)
1541 if (unlikely(p->unregistering))
1542 complete(p->unregistering);
1543}
1544
1545/* called under sysctl_lock, will reacquire if has to wait */
1546static void start_unregistering(struct ctl_table_header *p)
1547{
1548 /*
1549 * if p->used is 0, nobody will ever touch that entry again;
1550 * we'll eliminate all paths to it before dropping sysctl_lock
1551 */
1552 if (unlikely(p->used)) {
1553 struct completion wait;
1554 init_completion(&wait);
1555 p->unregistering = &wait;
1556 spin_unlock(&sysctl_lock);
1557 wait_for_completion(&wait);
1558 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001559 } else {
1560 /* anything non-NULL; we'll never dereference it */
1561 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001562 }
1563 /*
1564 * do not remove from the list until nobody holds it; walking the
1565 * list in do_sysctl() relies on that.
1566 */
1567 list_del_init(&p->ctl_entry);
1568}
1569
Al Virof7e6ced2008-07-15 01:44:23 -04001570void sysctl_head_get(struct ctl_table_header *head)
1571{
1572 spin_lock(&sysctl_lock);
1573 head->count++;
1574 spin_unlock(&sysctl_lock);
1575}
1576
1577void sysctl_head_put(struct ctl_table_header *head)
1578{
1579 spin_lock(&sysctl_lock);
1580 if (!--head->count)
1581 kfree(head);
1582 spin_unlock(&sysctl_lock);
1583}
1584
1585struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1586{
1587 if (!head)
1588 BUG();
1589 spin_lock(&sysctl_lock);
1590 if (!use_table(head))
1591 head = ERR_PTR(-ENOENT);
1592 spin_unlock(&sysctl_lock);
1593 return head;
1594}
1595
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001596void sysctl_head_finish(struct ctl_table_header *head)
1597{
1598 if (!head)
1599 return;
1600 spin_lock(&sysctl_lock);
1601 unuse_table(head);
1602 spin_unlock(&sysctl_lock);
1603}
1604
Al Viro73455092008-07-14 21:22:20 -04001605static struct ctl_table_set *
1606lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1607{
1608 struct ctl_table_set *set = &root->default_set;
1609 if (root->lookup)
1610 set = root->lookup(root, namespaces);
1611 return set;
1612}
1613
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001614static struct list_head *
1615lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616{
Al Viro73455092008-07-14 21:22:20 -04001617 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1618 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619}
1620
1621struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1622 struct ctl_table_header *prev)
1623{
1624 struct ctl_table_root *root;
1625 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001626 struct ctl_table_header *head;
1627 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001629 spin_lock(&sysctl_lock);
1630 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632 tmp = &prev->ctl_entry;
1633 unuse_table(prev);
1634 goto next;
1635 }
1636 tmp = &root_table_header.ctl_entry;
1637 for (;;) {
1638 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1639
1640 if (!use_table(head))
1641 goto next;
1642 spin_unlock(&sysctl_lock);
1643 return head;
1644 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001645 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001646 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001647 header_list = lookup_header_list(root, namespaces);
1648 if (tmp != header_list)
1649 continue;
1650
1651 do {
1652 root = list_entry(root->root_list.next,
1653 struct ctl_table_root, root_list);
1654 if (root == &sysctl_table_root)
1655 goto out;
1656 header_list = lookup_header_list(root, namespaces);
1657 } while (list_empty(header_list));
1658 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001659 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001660out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001661 spin_unlock(&sysctl_lock);
1662 return NULL;
1663}
1664
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001665struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1666{
1667 return __sysctl_head_next(current->nsproxy, prev);
1668}
1669
1670void register_sysctl_root(struct ctl_table_root *root)
1671{
1672 spin_lock(&sysctl_lock);
1673 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1674 spin_unlock(&sysctl_lock);
1675}
1676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001678 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 * some sysctl variables are readonly even to root.
1680 */
1681
1682static int test_perm(int mode, int op)
1683{
David Howells76aac0e2008-11-14 10:39:12 +11001684 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 mode >>= 6;
1686 else if (in_egroup_p(0))
1687 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001688 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 return 0;
1690 return -EACCES;
1691}
1692
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001693int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694{
1695 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001696 int mode;
1697
Al Viroe6305c42008-07-15 21:03:57 -04001698 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 if (error)
1700 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001701
1702 if (root->permissions)
1703 mode = root->permissions(root, current->nsproxy, table);
1704 else
1705 mode = table->mode;
1706
1707 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001710static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1711{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001712 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001713 table->parent = parent;
1714 if (table->child)
1715 sysctl_set_parent(table, table->child);
1716 }
1717}
1718
1719static __init int sysctl_init(void)
1720{
1721 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001722#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001723 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001724#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001725 return 0;
1726}
1727
1728core_initcall(sysctl_init);
1729
Al Virobfbcf032008-07-27 06:31:22 +01001730static struct ctl_table *is_branch_in(struct ctl_table *branch,
1731 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001732{
1733 struct ctl_table *p;
1734 const char *s = branch->procname;
1735
1736 /* branch should have named subdirectory as its first element */
1737 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001738 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001739
1740 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001741 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001742 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001743
1744 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001745 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001746 if (!p->child)
1747 continue;
1748 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001749 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001750 }
Al Virobfbcf032008-07-27 06:31:22 +01001751 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001752}
1753
1754/* see if attaching q to p would be an improvement */
1755static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1756{
1757 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001758 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001759 int is_better = 0;
1760 int not_in_parent = !p->attached_by;
1761
Al Virobfbcf032008-07-27 06:31:22 +01001762 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001763 if (by == q->attached_by)
1764 is_better = 1;
1765 if (to == p->attached_by)
1766 not_in_parent = 1;
1767 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001768 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001769 }
1770
1771 if (is_better && not_in_parent) {
1772 q->attached_by = by;
1773 q->attached_to = to;
1774 q->parent = p;
1775 }
1776}
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001779 * __register_sysctl_paths - register a sysctl hierarchy
1780 * @root: List of sysctl headers to register on
1781 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001782 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 *
1785 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001786 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001788 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1791 * enter a sysctl file
1792 *
1793 * data - a pointer to data for use by proc_handler
1794 *
1795 * maxlen - the maximum size in bytes of the data
1796 *
1797 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1798 *
1799 * child - a pointer to the child sysctl table if this entry is a directory, or
1800 * %NULL.
1801 *
1802 * proc_handler - the text handler routine (described below)
1803 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 * de - for internal use by the sysctl routines
1805 *
1806 * extra1, extra2 - extra pointers usable by the proc handler routines
1807 *
1808 * Leaf nodes in the sysctl tree will be represented by a single file
1809 * under /proc; non-leaf nodes will be represented by directories.
1810 *
1811 * sysctl(2) can automatically manage read and write requests through
1812 * the sysctl table. The data and maxlen fields of the ctl_table
1813 * struct enable minimal validation of the values being written to be
1814 * performed, and the mode field allows minimal authentication.
1815 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 * There must be a proc_handler routine for any terminal nodes
1817 * mirrored under /proc/sys (non-terminals are handled by a built-in
1818 * directory handler). Several default handlers are available to
1819 * cover common cases -
1820 *
1821 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1822 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1823 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1824 *
1825 * It is the handler's job to read the input buffer from user memory
1826 * and process it. The handler should return 0 on success.
1827 *
1828 * This routine returns %NULL on a failure to register, and a pointer
1829 * to the table header on success.
1830 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001831struct ctl_table_header *__register_sysctl_paths(
1832 struct ctl_table_root *root,
1833 struct nsproxy *namespaces,
1834 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001836 struct ctl_table_header *header;
1837 struct ctl_table *new, **prevp;
1838 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001839 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001840
1841 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001842 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001843 ;
1844
1845 /*
1846 * For each path component, allocate a 2-element ctl_table array.
1847 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001848 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 *
1850 * We allocate everything in one go so that we don't have to
1851 * worry about freeing additional memory in unregister_sysctl_table.
1852 */
1853 header = kzalloc(sizeof(struct ctl_table_header) +
1854 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1855 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001857
1858 new = (struct ctl_table *) (header + 1);
1859
1860 /* Now connect the dots */
1861 prevp = &header->ctl_table;
1862 for (n = 0; n < npath; ++n, ++path) {
1863 /* Copy the procname */
1864 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001865 new->mode = 0555;
1866
1867 *prevp = new;
1868 prevp = &new->child;
1869
1870 new += 2;
1871 }
1872 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001873 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001874
1875 INIT_LIST_HEAD(&header->ctl_entry);
1876 header->used = 0;
1877 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001878 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001880 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001881#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001882 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001883 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001884 return NULL;
1885 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001886#endif
Al Viro330d57f2005-11-04 10:18:40 +00001887 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001888 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001889 header->attached_by = header->ctl_table;
1890 header->attached_to = root_table;
1891 header->parent = &root_table_header;
1892 for (set = header->set; set; set = set->parent) {
1893 struct ctl_table_header *p;
1894 list_for_each_entry(p, &set->list, ctl_entry) {
1895 if (p->unregistering)
1896 continue;
1897 try_attach(p, header);
1898 }
1899 }
1900 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001901 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001902 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001903
1904 return header;
1905}
1906
1907/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001908 * register_sysctl_table_path - register a sysctl table hierarchy
1909 * @path: The path to the directory the sysctl table is in.
1910 * @table: the top-level table structure
1911 *
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1914 *
1915 * See __register_sysctl_paths for more details.
1916 */
1917struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1918 struct ctl_table *table)
1919{
1920 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1921 path, table);
1922}
1923
1924/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001925 * register_sysctl_table - register a sysctl table hierarchy
1926 * @table: the top-level table structure
1927 *
1928 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1929 * array. A completely 0 filled entry terminates the table.
1930 *
1931 * See register_sysctl_paths for more details.
1932 */
1933struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1934{
1935 static const struct ctl_path null_path[] = { {} };
1936
1937 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
1940/**
1941 * unregister_sysctl_table - unregister a sysctl table hierarchy
1942 * @header: the header returned from register_sysctl_table
1943 *
1944 * Unregisters the sysctl table and all children. proc entries may not
1945 * actually be removed until they are no longer used by anyone.
1946 */
1947void unregister_sysctl_table(struct ctl_table_header * header)
1948{
Al Viro330d57f2005-11-04 10:18:40 +00001949 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001950
1951 if (header == NULL)
1952 return;
1953
Al Viro330d57f2005-11-04 10:18:40 +00001954 spin_lock(&sysctl_lock);
1955 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001956 if (!--header->parent->count) {
1957 WARN_ON(1);
1958 kfree(header->parent);
1959 }
Al Virof7e6ced2008-07-15 01:44:23 -04001960 if (!--header->count)
1961 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001962 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
Al Viro9043476f2008-07-15 08:54:06 -04001965int sysctl_is_seen(struct ctl_table_header *p)
1966{
1967 struct ctl_table_set *set = p->set;
1968 int res;
1969 spin_lock(&sysctl_lock);
1970 if (p->unregistering)
1971 res = 0;
1972 else if (!set->is_seen)
1973 res = 1;
1974 else
1975 res = set->is_seen(set);
1976 spin_unlock(&sysctl_lock);
1977 return res;
1978}
1979
Al Viro73455092008-07-14 21:22:20 -04001980void setup_sysctl_set(struct ctl_table_set *p,
1981 struct ctl_table_set *parent,
1982 int (*is_seen)(struct ctl_table_set *))
1983{
1984 INIT_LIST_HEAD(&p->list);
1985 p->parent = parent ? parent : &sysctl_table_root.default_set;
1986 p->is_seen = is_seen;
1987}
1988
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001989#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001990struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001991{
1992 return NULL;
1993}
1994
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001995struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1996 struct ctl_table *table)
1997{
1998 return NULL;
1999}
2000
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002001void unregister_sysctl_table(struct ctl_table_header * table)
2002{
2003}
2004
Al Viro73455092008-07-14 21:22:20 -04002005void setup_sysctl_set(struct ctl_table_set *p,
2006 struct ctl_table_set *parent,
2007 int (*is_seen)(struct ctl_table_set *))
2008{
2009}
2010
Al Virof7e6ced2008-07-15 01:44:23 -04002011void sysctl_head_put(struct ctl_table_header *head)
2012{
2013}
2014
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002015#endif /* CONFIG_SYSCTL */
2016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017/*
2018 * /proc/sys support
2019 */
2020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002021#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002023static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002024 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002025 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002026{
2027 size_t len;
2028 char __user *p;
2029 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002030
2031 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002032 *lenp = 0;
2033 return 0;
2034 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002035
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 if (write) {
2037 len = 0;
2038 p = buffer;
2039 while (len < *lenp) {
2040 if (get_user(c, p++))
2041 return -EFAULT;
2042 if (c == 0 || c == '\n')
2043 break;
2044 len++;
2045 }
2046 if (len >= maxlen)
2047 len = maxlen-1;
2048 if(copy_from_user(data, buffer, len))
2049 return -EFAULT;
2050 ((char *) data)[len] = 0;
2051 *ppos += *lenp;
2052 } else {
2053 len = strlen(data);
2054 if (len > maxlen)
2055 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002056
2057 if (*ppos > len) {
2058 *lenp = 0;
2059 return 0;
2060 }
2061
2062 data += *ppos;
2063 len -= *ppos;
2064
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002065 if (len > *lenp)
2066 len = *lenp;
2067 if (len)
2068 if(copy_to_user(buffer, data, len))
2069 return -EFAULT;
2070 if (len < *lenp) {
2071 if(put_user('\n', ((char __user *) buffer) + len))
2072 return -EFAULT;
2073 len++;
2074 }
2075 *lenp = len;
2076 *ppos += len;
2077 }
2078 return 0;
2079}
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/**
2082 * proc_dostring - read a string sysctl
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2088 *
2089 * Reads/writes a string from/to the user buffer. If the kernel
2090 * buffer provided is not large enough to hold the string, the
2091 * string is truncated. The copied string is %NULL-terminated.
2092 * If the string is being read by the user process, it is copied
2093 * and a newline '\n' is added. It is truncated if the buffer is
2094 * not large enough.
2095 *
2096 * Returns 0 on success.
2097 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002098int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 void __user *buffer, size_t *lenp, loff_t *ppos)
2100{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002101 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002102 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
Amerigo Wang00b7c332010-05-05 00:26:45 +00002105static size_t proc_skip_spaces(char **buf)
2106{
2107 size_t ret;
2108 char *tmp = skip_spaces(*buf);
2109 ret = tmp - *buf;
2110 *buf = tmp;
2111 return ret;
2112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002114static void proc_skip_char(char **buf, size_t *size, const char v)
2115{
2116 while (*size) {
2117 if (**buf != v)
2118 break;
2119 (*size)--;
2120 (*buf)++;
2121 }
2122}
2123
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124#define TMPBUFLEN 22
2125/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002126 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002127 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002128 * @buf: a kernel buffer
2129 * @size: size of the kernel buffer
2130 * @val: this is where the number will be stored
2131 * @neg: set to %TRUE if number is negative
2132 * @perm_tr: a vector which contains the allowed trailers
2133 * @perm_tr_len: size of the perm_tr vector
2134 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002136 * In case of success %0 is returned and @buf and @size are updated with
2137 * the amount of bytes read. If @tr is non-NULL and a trailing
2138 * character exists (size is non-zero after returning from this
2139 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 */
2141static int proc_get_long(char **buf, size_t *size,
2142 unsigned long *val, bool *neg,
2143 const char *perm_tr, unsigned perm_tr_len, char *tr)
2144{
2145 int len;
2146 char *p, tmp[TMPBUFLEN];
2147
2148 if (!*size)
2149 return -EINVAL;
2150
2151 len = *size;
2152 if (len > TMPBUFLEN - 1)
2153 len = TMPBUFLEN - 1;
2154
2155 memcpy(tmp, *buf, len);
2156
2157 tmp[len] = 0;
2158 p = tmp;
2159 if (*p == '-' && *size > 1) {
2160 *neg = true;
2161 p++;
2162 } else
2163 *neg = false;
2164 if (!isdigit(*p))
2165 return -EINVAL;
2166
2167 *val = simple_strtoul(p, &p, 0);
2168
2169 len = p - tmp;
2170
2171 /* We don't know if the next char is whitespace thus we may accept
2172 * invalid integers (e.g. 1234...a) or two integers instead of one
2173 * (e.g. 123...1). So lets not allow such large numbers. */
2174 if (len == TMPBUFLEN - 1)
2175 return -EINVAL;
2176
2177 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2178 return -EINVAL;
2179
2180 if (tr && (len < *size))
2181 *tr = *p;
2182
2183 *buf += len;
2184 *size -= len;
2185
2186 return 0;
2187}
2188
2189/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002190 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002192 * @buf: the user buffer
2193 * @size: the size of the user buffer
2194 * @val: the integer to be converted
2195 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002197 * In case of success %0 is returned and @buf and @size are updated with
2198 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 */
2200static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2201 bool neg)
2202{
2203 int len;
2204 char tmp[TMPBUFLEN], *p = tmp;
2205
2206 sprintf(p, "%s%lu", neg ? "-" : "", val);
2207 len = strlen(tmp);
2208 if (len > *size)
2209 len = *size;
2210 if (copy_to_user(*buf, tmp, len))
2211 return -EFAULT;
2212 *size -= len;
2213 *buf += len;
2214 return 0;
2215}
2216#undef TMPBUFLEN
2217
2218static int proc_put_char(void __user **buf, size_t *size, char c)
2219{
2220 if (*size) {
2221 char __user **buffer = (char __user **)buf;
2222 if (put_user(c, *buffer))
2223 return -EFAULT;
2224 (*size)--, (*buffer)++;
2225 *buf = *buffer;
2226 }
2227 return 0;
2228}
2229
2230static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 int *valp,
2232 int write, void *data)
2233{
2234 if (write) {
2235 *valp = *negp ? -*lvalp : *lvalp;
2236 } else {
2237 int val = *valp;
2238 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 *lvalp = (unsigned long)-val;
2241 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *lvalp = (unsigned long)val;
2244 }
2245 }
2246 return 0;
2247}
2248
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2250
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002251static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002252 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002253 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002254 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 int write, void *data),
2256 void *data)
2257{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258 int *i, vleft, first = 1, err = 0;
2259 unsigned long page = 0;
2260 size_t left;
2261 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *lenp = 0;
2265 return 0;
2266 }
2267
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002268 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 vleft = table->maxlen / sizeof(*i);
2270 left = *lenp;
2271
2272 if (!conv)
2273 conv = do_proc_dointvec_conv;
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 if (left > PAGE_SIZE - 1)
2277 left = PAGE_SIZE - 1;
2278 page = __get_free_page(GFP_TEMPORARY);
2279 kbuf = (char *) page;
2280 if (!kbuf)
2281 return -ENOMEM;
2282 if (copy_from_user(kbuf, buffer, left)) {
2283 err = -EFAULT;
2284 goto free;
2285 }
2286 kbuf[left] = 0;
2287 }
2288
2289 for (; left && vleft--; i++, first=0) {
2290 unsigned long lval;
2291 bool neg;
2292
2293 if (write) {
2294 left -= proc_skip_spaces(&kbuf);
2295
J. R. Okajima563b0462010-05-25 16:10:14 -07002296 if (!left)
2297 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298 err = proc_get_long(&kbuf, &left, &lval, &neg,
2299 proc_wspace_sep,
2300 sizeof(proc_wspace_sep), NULL);
2301 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 if (conv(&neg, &lval, i, 1, data)) {
2304 err = -EINVAL;
2305 break;
2306 }
2307 } else {
2308 if (conv(&neg, &lval, i, 0, data)) {
2309 err = -EINVAL;
2310 break;
2311 }
2312 if (!first)
2313 err = proc_put_char(&buffer, &left, '\t');
2314 if (err)
2315 break;
2316 err = proc_put_long(&buffer, &left, lval, neg);
2317 if (err)
2318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002321
2322 if (!write && !first && left && !err)
2323 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002324 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 left -= proc_skip_spaces(&kbuf);
2326free:
2327 if (write) {
2328 free_page(page);
2329 if (first)
2330 return err ? : -EINVAL;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 *lenp -= left;
2333 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002337static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002340 int write, void *data),
2341 void *data)
2342{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002343 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 buffer, lenp, ppos, conv, data);
2345}
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347/**
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: file position
2354 *
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 *
2358 * Returns 0 on success.
2359 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002360int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 void __user *buffer, size_t *lenp, loff_t *ppos)
2362{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002363 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 NULL,NULL);
2365}
2366
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002368 * Taint values can only be increased
2369 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002370 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002371static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372 void __user *buffer, size_t *lenp, loff_t *ppos)
2373{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002374 struct ctl_table t;
2375 unsigned long tmptaint = get_taint();
2376 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377
Bastian Blank91fcd412007-04-23 14:41:14 -07002378 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379 return -EPERM;
2380
Andi Kleen25ddbb12008-10-15 22:01:41 -07002381 t = *table;
2382 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002383 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002384 if (err < 0)
2385 return err;
2386
2387 if (write) {
2388 /*
2389 * Poor man's atomic or. Not worth adding a primitive
2390 * to everyone's atomic.h for this
2391 */
2392 int i;
2393 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2394 if ((tmptaint >> i) & 1)
2395 add_taint(i);
2396 }
2397 }
2398
2399 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002400}
2401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402struct do_proc_dointvec_minmax_conv_param {
2403 int *min;
2404 int *max;
2405};
2406
Amerigo Wang00b7c332010-05-05 00:26:45 +00002407static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2408 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 int write, void *data)
2410{
2411 struct do_proc_dointvec_minmax_conv_param *param = data;
2412 if (write) {
2413 int val = *negp ? -*lvalp : *lvalp;
2414 if ((param->min && *param->min > val) ||
2415 (param->max && *param->max < val))
2416 return -EINVAL;
2417 *valp = val;
2418 } else {
2419 int val = *valp;
2420 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002421 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 *lvalp = (unsigned long)-val;
2423 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002424 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 *lvalp = (unsigned long)val;
2426 }
2427 }
2428 return 0;
2429}
2430
2431/**
2432 * proc_dointvec_minmax - read a vector of integers with min/max values
2433 * @table: the sysctl table
2434 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2438 *
2439 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2440 * values from/to the user buffer, treated as an ASCII string.
2441 *
2442 * This routine will ensure the values are within the range specified by
2443 * table->extra1 (min) and table->extra2 (max).
2444 *
2445 * Returns 0 on success.
2446 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002447int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 void __user *buffer, size_t *lenp, loff_t *ppos)
2449{
2450 struct do_proc_dointvec_minmax_conv_param param = {
2451 .min = (int *) table->extra1,
2452 .max = (int *) table->extra2,
2453 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002454 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 do_proc_dointvec_minmax_conv, &param);
2456}
2457
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002458static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer,
2460 size_t *lenp, loff_t *ppos,
2461 unsigned long convmul,
2462 unsigned long convdiv)
2463{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002464 unsigned long *i, *min, *max;
2465 int vleft, first = 1, err = 0;
2466 unsigned long page = 0;
2467 size_t left;
2468 char *kbuf;
2469
2470 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 *lenp = 0;
2472 return 0;
2473 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002474
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002475 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 min = (unsigned long *) table->extra1;
2477 max = (unsigned long *) table->extra2;
2478 vleft = table->maxlen / sizeof(unsigned long);
2479 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002480
2481 if (write) {
2482 if (left > PAGE_SIZE - 1)
2483 left = PAGE_SIZE - 1;
2484 page = __get_free_page(GFP_TEMPORARY);
2485 kbuf = (char *) page;
2486 if (!kbuf)
2487 return -ENOMEM;
2488 if (copy_from_user(kbuf, buffer, left)) {
2489 err = -EFAULT;
2490 goto free;
2491 }
2492 kbuf[left] = 0;
2493 }
2494
Eric Dumazet27b3d802010-10-07 12:59:29 -07002495 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002496 unsigned long val;
2497
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002499 bool neg;
2500
2501 left -= proc_skip_spaces(&kbuf);
2502
2503 err = proc_get_long(&kbuf, &left, &val, &neg,
2504 proc_wspace_sep,
2505 sizeof(proc_wspace_sep), NULL);
2506 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 break;
2508 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 continue;
2510 if ((min && val < *min) || (max && val > *max))
2511 continue;
2512 *i = val;
2513 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002514 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002516 err = proc_put_char(&buffer, &left, '\t');
2517 err = proc_put_long(&buffer, &left, val, false);
2518 if (err)
2519 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
2521 }
2522
Amerigo Wang00b7c332010-05-05 00:26:45 +00002523 if (!write && !first && left && !err)
2524 err = proc_put_char(&buffer, &left, '\n');
2525 if (write && !err)
2526 left -= proc_skip_spaces(&kbuf);
2527free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002529 free_page(page);
2530 if (first)
2531 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 *lenp -= left;
2534 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002535 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002538static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002539 void __user *buffer,
2540 size_t *lenp, loff_t *ppos,
2541 unsigned long convmul,
2542 unsigned long convdiv)
2543{
2544 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002545 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002546}
2547
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548/**
2549 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2555 *
2556 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2557 * values from/to the user buffer, treated as an ASCII string.
2558 *
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2561 *
2562 * Returns 0 on success.
2563 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002564int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 void __user *buffer, size_t *lenp, loff_t *ppos)
2566{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002567 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568}
2569
2570/**
2571 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2572 * @table: the sysctl table
2573 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 * @buffer: the user buffer
2575 * @lenp: the size of the user buffer
2576 * @ppos: file position
2577 *
2578 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2579 * values from/to the user buffer, treated as an ASCII string. The values
2580 * are treated as milliseconds, and converted to jiffies when they are stored.
2581 *
2582 * This routine will ensure the values are within the range specified by
2583 * table->extra1 (min) and table->extra2 (max).
2584 *
2585 * Returns 0 on success.
2586 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002587int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 void __user *buffer,
2589 size_t *lenp, loff_t *ppos)
2590{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002591 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 lenp, ppos, HZ, 1000l);
2593}
2594
2595
Amerigo Wang00b7c332010-05-05 00:26:45 +00002596static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 int *valp,
2598 int write, void *data)
2599{
2600 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002601 if (*lvalp > LONG_MAX / HZ)
2602 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2604 } else {
2605 int val = *valp;
2606 unsigned long lval;
2607 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002608 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 lval = (unsigned long)-val;
2610 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002611 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 lval = (unsigned long)val;
2613 }
2614 *lvalp = lval / HZ;
2615 }
2616 return 0;
2617}
2618
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 int *valp,
2621 int write, void *data)
2622{
2623 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002624 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2625 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2627 } else {
2628 int val = *valp;
2629 unsigned long lval;
2630 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002631 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 lval = (unsigned long)-val;
2633 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002634 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 lval = (unsigned long)val;
2636 }
2637 *lvalp = jiffies_to_clock_t(lval);
2638 }
2639 return 0;
2640}
2641
Amerigo Wang00b7c332010-05-05 00:26:45 +00002642static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 int *valp,
2644 int write, void *data)
2645{
2646 if (write) {
2647 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2648 } else {
2649 int val = *valp;
2650 unsigned long lval;
2651 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002652 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 lval = (unsigned long)-val;
2654 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002655 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 lval = (unsigned long)val;
2657 }
2658 *lvalp = jiffies_to_msecs(lval);
2659 }
2660 return 0;
2661}
2662
2663/**
2664 * proc_dointvec_jiffies - read a vector of integers as seconds
2665 * @table: the sysctl table
2666 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 * @buffer: the user buffer
2668 * @lenp: the size of the user buffer
2669 * @ppos: file position
2670 *
2671 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2672 * values from/to the user buffer, treated as an ASCII string.
2673 * The values read are assumed to be in seconds, and are converted into
2674 * jiffies.
2675 *
2676 * Returns 0 on success.
2677 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002678int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 void __user *buffer, size_t *lenp, loff_t *ppos)
2680{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002681 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 do_proc_dointvec_jiffies_conv,NULL);
2683}
2684
2685/**
2686 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2687 * @table: the sysctl table
2688 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 * @buffer: the user buffer
2690 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002691 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 *
2693 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2694 * values from/to the user buffer, treated as an ASCII string.
2695 * The values read are assumed to be in 1/USER_HZ seconds, and
2696 * are converted into jiffies.
2697 *
2698 * Returns 0 on success.
2699 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002700int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 void __user *buffer, size_t *lenp, loff_t *ppos)
2702{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002703 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 do_proc_dointvec_userhz_jiffies_conv,NULL);
2705}
2706
2707/**
2708 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2709 * @table: the sysctl table
2710 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 * @buffer: the user buffer
2712 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002713 * @ppos: file position
2714 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 *
2716 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2717 * values from/to the user buffer, treated as an ASCII string.
2718 * The values read are assumed to be in 1/1000 seconds, and
2719 * are converted into jiffies.
2720 *
2721 * Returns 0 on success.
2722 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 void __user *buffer, size_t *lenp, loff_t *ppos)
2725{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002726 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 do_proc_dointvec_ms_jiffies_conv, NULL);
2728}
2729
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002730static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002731 void __user *buffer, size_t *lenp, loff_t *ppos)
2732{
2733 struct pid *new_pid;
2734 pid_t tmp;
2735 int r;
2736
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002737 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002738
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002739 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002740 lenp, ppos, NULL, NULL);
2741 if (r || !write)
2742 return r;
2743
2744 new_pid = find_get_pid(tmp);
2745 if (!new_pid)
2746 return -ESRCH;
2747
2748 put_pid(xchg(&cad_pid, new_pid));
2749 return 0;
2750}
2751
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002752/**
2753 * proc_do_large_bitmap - read/write from/to a large bitmap
2754 * @table: the sysctl table
2755 * @write: %TRUE if this is a write to the sysctl file
2756 * @buffer: the user buffer
2757 * @lenp: the size of the user buffer
2758 * @ppos: file position
2759 *
2760 * The bitmap is stored at table->data and the bitmap length (in bits)
2761 * in table->maxlen.
2762 *
2763 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2764 * large bitmaps may be represented in a compact manner. Writing into
2765 * the file will clear the bitmap then update it with the given input.
2766 *
2767 * Returns 0 on success.
2768 */
2769int proc_do_large_bitmap(struct ctl_table *table, int write,
2770 void __user *buffer, size_t *lenp, loff_t *ppos)
2771{
2772 int err = 0;
2773 bool first = 1;
2774 size_t left = *lenp;
2775 unsigned long bitmap_len = table->maxlen;
2776 unsigned long *bitmap = (unsigned long *) table->data;
2777 unsigned long *tmp_bitmap = NULL;
2778 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2779
2780 if (!bitmap_len || !left || (*ppos && !write)) {
2781 *lenp = 0;
2782 return 0;
2783 }
2784
2785 if (write) {
2786 unsigned long page = 0;
2787 char *kbuf;
2788
2789 if (left > PAGE_SIZE - 1)
2790 left = PAGE_SIZE - 1;
2791
2792 page = __get_free_page(GFP_TEMPORARY);
2793 kbuf = (char *) page;
2794 if (!kbuf)
2795 return -ENOMEM;
2796 if (copy_from_user(kbuf, buffer, left)) {
2797 free_page(page);
2798 return -EFAULT;
2799 }
2800 kbuf[left] = 0;
2801
2802 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2803 GFP_KERNEL);
2804 if (!tmp_bitmap) {
2805 free_page(page);
2806 return -ENOMEM;
2807 }
2808 proc_skip_char(&kbuf, &left, '\n');
2809 while (!err && left) {
2810 unsigned long val_a, val_b;
2811 bool neg;
2812
2813 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2814 sizeof(tr_a), &c);
2815 if (err)
2816 break;
2817 if (val_a >= bitmap_len || neg) {
2818 err = -EINVAL;
2819 break;
2820 }
2821
2822 val_b = val_a;
2823 if (left) {
2824 kbuf++;
2825 left--;
2826 }
2827
2828 if (c == '-') {
2829 err = proc_get_long(&kbuf, &left, &val_b,
2830 &neg, tr_b, sizeof(tr_b),
2831 &c);
2832 if (err)
2833 break;
2834 if (val_b >= bitmap_len || neg ||
2835 val_a > val_b) {
2836 err = -EINVAL;
2837 break;
2838 }
2839 if (left) {
2840 kbuf++;
2841 left--;
2842 }
2843 }
2844
2845 while (val_a <= val_b)
2846 set_bit(val_a++, tmp_bitmap);
2847
2848 first = 0;
2849 proc_skip_char(&kbuf, &left, '\n');
2850 }
2851 free_page(page);
2852 } else {
2853 unsigned long bit_a, bit_b = 0;
2854
2855 while (left) {
2856 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2857 if (bit_a >= bitmap_len)
2858 break;
2859 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2860 bit_a + 1) - 1;
2861
2862 if (!first) {
2863 err = proc_put_char(&buffer, &left, ',');
2864 if (err)
2865 break;
2866 }
2867 err = proc_put_long(&buffer, &left, bit_a, false);
2868 if (err)
2869 break;
2870 if (bit_a != bit_b) {
2871 err = proc_put_char(&buffer, &left, '-');
2872 if (err)
2873 break;
2874 err = proc_put_long(&buffer, &left, bit_b, false);
2875 if (err)
2876 break;
2877 }
2878
2879 first = 0; bit_b++;
2880 }
2881 if (!err)
2882 err = proc_put_char(&buffer, &left, '\n');
2883 }
2884
2885 if (!err) {
2886 if (write) {
2887 if (*ppos)
2888 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2889 else
2890 memcpy(bitmap, tmp_bitmap,
2891 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2892 }
2893 kfree(tmp_bitmap);
2894 *lenp -= left;
2895 *ppos += *lenp;
2896 return 0;
2897 } else {
2898 kfree(tmp_bitmap);
2899 return err;
2900 }
2901}
2902
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903#else /* CONFIG_PROC_FS */
2904
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002905int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *buffer, size_t *lenp, loff_t *ppos)
2907{
2908 return -ENOSYS;
2909}
2910
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002911int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 void __user *buffer, size_t *lenp, loff_t *ppos)
2913{
2914 return -ENOSYS;
2915}
2916
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 void __user *buffer, size_t *lenp, loff_t *ppos)
2919{
2920 return -ENOSYS;
2921}
2922
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002923int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *buffer, size_t *lenp, loff_t *ppos)
2925{
2926 return -ENOSYS;
2927}
2928
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 void __user *buffer, size_t *lenp, loff_t *ppos)
2931{
2932 return -ENOSYS;
2933}
2934
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002935int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 void __user *buffer, size_t *lenp, loff_t *ppos)
2937{
2938 return -ENOSYS;
2939}
2940
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002941int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 void __user *buffer, size_t *lenp, loff_t *ppos)
2943{
2944 return -ENOSYS;
2945}
2946
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002947int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 void __user *buffer,
2949 size_t *lenp, loff_t *ppos)
2950{
2951 return -ENOSYS;
2952}
2953
2954
2955#endif /* CONFIG_PROC_FS */
2956
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957/*
2958 * No sense putting this after each symbol definition, twice,
2959 * exception granted :-)
2960 */
2961EXPORT_SYMBOL(proc_dointvec);
2962EXPORT_SYMBOL(proc_dointvec_jiffies);
2963EXPORT_SYMBOL(proc_dointvec_minmax);
2964EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2965EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2966EXPORT_SYMBOL(proc_dostring);
2967EXPORT_SYMBOL(proc_doulongvec_minmax);
2968EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2969EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002970EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971EXPORT_SYMBOL(unregister_sysctl_table);