blob: 5290c437f151c4e2be13afbacc67c0db3de4b989 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050054#include <linux/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#include <asm/uaccess.h>
57#include <asm/processor.h>
58
Andi Kleen29cbc782006-09-30 01:47:55 +020059#ifdef CONFIG_X86
60#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010061#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010062#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020063#endif
Dave Young15485a42010-03-10 15:24:07 -080064#ifdef CONFIG_CHR_DEV_SG
65#include <scsi/sg.h>
66#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020067
Eric W. Biederman7058cb02007-10-18 03:05:58 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#if defined(CONFIG_SYSCTL)
70
71/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int sysctl_overcommit_memory;
73extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070074extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070075extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080076extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070079extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070081extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern int pid_max;
83extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080085extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080086extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020087extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010088extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040089extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000090#ifndef CONFIG_MMU
91extern int sysctl_nr_trim_pages;
92#endif
Jens Axboecb684b52009-09-15 21:53:11 +020093#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020094extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080098#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200100static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101#endif
102
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700104static int __maybe_unused one = 1;
105static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800106static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700107static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700108#ifdef CONFIG_PRINTK
109static int ten_thousand = 10000;
110#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700112/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116static int maxolduid = 65535;
117static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800118static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120static int ngroups_max = NGROUPS_MAX;
121
David S. Miller72c57ed2008-09-11 23:29:54 -0700122#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700123#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif
125
David S. Miller08714202008-11-16 23:49:24 -0800126#ifdef CONFIG_SPARC64
127extern int sysctl_tsb_ratio;
128#endif
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef __hppa__
131extern int pwrsw_enabled;
132extern int unaligned_enabled;
133#endif
134
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800135#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef CONFIG_MATHEMU
137extern int sysctl_ieee_emulation_warnings;
138#endif
139extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700140extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#ifdef CONFIG_BSD_PROCESS_ACCT
144extern int acct_parm[];
145#endif
146
Jes Sorensend2b176e2006-02-28 09:42:23 -0800147#ifdef CONFIG_IA64
148extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800149extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800150#endif
151
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200152extern struct ratelimit_state printk_ratelimit_state;
153
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700154#ifdef CONFIG_RT_MUTEXES
155extern int max_lock_depth;
156#endif
157
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700159static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700161static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800162 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700163#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700164
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700165static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166static struct ctl_table_root sysctl_table_root;
167static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100168 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400170 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400172 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173};
174static struct ctl_table_root sysctl_table_root = {
175 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400176 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100177};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179static struct ctl_table kern_table[];
180static struct ctl_table vm_table[];
181static struct ctl_table fs_table[];
182static struct ctl_table debug_table[];
183static struct ctl_table dev_table[];
184extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700185#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700186extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400187#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800188#ifdef CONFIG_EPOLL
189extern struct ctl_table epoll_table[];
190#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193int sysctl_legacy_va_layout;
194#endif
195
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700196extern int prove_locking;
197extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199/* The default sysctl tables: */
200
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700201static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .procname = "kernel",
204 .mode = 0555,
205 .child = kern_table,
206 },
207 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 .procname = "vm",
209 .mode = 0555,
210 .child = vm_table,
211 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .procname = "fs",
214 .mode = 0555,
215 .child = fs_table,
216 },
217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 .procname = "debug",
219 .mode = 0555,
220 .child = debug_table,
221 },
222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
226 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700227/*
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
230 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700231 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232};
233
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100235static int min_sched_granularity_ns = 100000; /* 100 usecs */
236static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237static int min_wakeup_granularity_ns; /* 0 usecs */
238static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100239static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
240static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100241static int min_sched_shares_ratelimit = 100000; /* 100 usec */
242static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#endif
244
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700245static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200246 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200247 .procname = "sched_child_runs_first",
248 .data = &sysctl_sched_child_runs_first,
249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800251 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200252 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200253#ifdef CONFIG_SCHED_DEBUG
254 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100255 .procname = "sched_min_granularity_ns",
256 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800259 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100260 .extra1 = &min_sched_granularity_ns,
261 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262 },
263 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200264 .procname = "sched_latency_ns",
265 .data = &sysctl_sched_latency,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800268 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200269 .extra1 = &min_sched_granularity_ns,
270 .extra2 = &max_sched_granularity_ns,
271 },
272 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273 .procname = "sched_wakeup_granularity_ns",
274 .data = &sysctl_sched_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800277 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
280 },
281 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800286 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100287 .extra1 = &min_sched_shares_ratelimit,
288 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200289 },
290 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100291 .procname = "sched_tunable_scaling",
292 .data = &sysctl_sched_tunable_scaling,
293 .maxlen = sizeof(enum sched_tunable_scaling),
294 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800295 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100296 .extra1 = &min_sched_tunable_scaling,
297 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200298 },
299 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200300 .procname = "sched_shares_thresh",
301 .data = &sysctl_sched_shares_thresh,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800304 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200305 .extra1 = &zero,
306 },
307 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200308 .procname = "sched_migration_cost",
309 .data = &sysctl_sched_migration_cost,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800312 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200313 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100314 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100315 .procname = "sched_nr_migrate",
316 .data = &sysctl_sched_nr_migrate,
317 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800319 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100320 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530321 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200322 .procname = "sched_time_avg",
323 .data = &sysctl_sched_time_avg,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800326 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200327 },
328 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530329 .procname = "timer_migration",
330 .data = &sysctl_timer_migration,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530334 .extra1 = &zero,
335 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530336 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200337#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200338 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100339 .procname = "sched_rt_period_us",
340 .data = &sysctl_sched_rt_period,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800343 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100344 },
345 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 .procname = "sched_rt_runtime_us",
347 .data = &sysctl_sched_rt_runtime,
348 .maxlen = sizeof(int),
349 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800350 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100351 },
352 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200353 .procname = "sched_compat_yield",
354 .data = &sysctl_sched_compat_yield,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800357 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200358 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700359#ifdef CONFIG_PROVE_LOCKING
360 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700361 .procname = "prove_locking",
362 .data = &prove_locking,
363 .maxlen = sizeof(int),
364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800365 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700366 },
367#endif
368#ifdef CONFIG_LOCK_STAT
369 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700370 .procname = "lock_stat",
371 .data = &lock_stat,
372 .maxlen = sizeof(int),
373 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800374 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700375 },
376#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .procname = "panic",
379 .data = &panic_timeout,
380 .maxlen = sizeof(int),
381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800382 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 },
384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800389 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 },
391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .procname = "core_pattern",
393 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700394 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800396 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 },
Neil Hormana2939802009-09-23 15:56:56 -0700398 {
Neil Hormana2939802009-09-23 15:56:56 -0700399 .procname = "core_pipe_limit",
400 .data = &core_pipe_limit,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700404 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800405#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700408 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100413#ifdef CONFIG_LATENCYTOP
414 {
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800419 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100420 },
421#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#ifdef CONFIG_BLK_DEV_INITRD
423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .procname = "real-root-dev",
425 .data = &real_root_dev,
426 .maxlen = sizeof(int),
427 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800428 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 },
430#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700431 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700432 .procname = "print-fatal-signals",
433 .data = &print_fatal_signals,
434 .maxlen = sizeof(int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700437 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700438#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 .procname = "reboot-cmd",
441 .data = reboot_command,
442 .maxlen = 256,
443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800444 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 },
446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 },
453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460#endif
David S. Miller08714202008-11-16 23:49:24 -0800461#ifdef CONFIG_SPARC64
462 {
David S. Miller08714202008-11-16 23:49:24 -0800463 .procname = "tsb-ratio",
464 .data = &sysctl_tsb_ratio,
465 .maxlen = sizeof (int),
466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800467 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800468 },
469#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#ifdef __hppa__
471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "soft-power",
473 .data = &pwrsw_enabled,
474 .maxlen = sizeof (int),
475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800476 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800483 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 },
485#endif
486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "ctrl-alt-del",
488 .data = &C_A_D,
489 .maxlen = sizeof(int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400493#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200494 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200495 .procname = "ftrace_enabled",
496 .data = &ftrace_enabled,
497 .maxlen = sizeof(int),
498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200500 },
501#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500502#ifdef CONFIG_STACK_TRACER
503 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500504 .procname = "stack_tracer_enabled",
505 .data = &stack_tracer_enabled,
506 .maxlen = sizeof(int),
507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800508 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500509 },
510#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400511#ifdef CONFIG_TRACING
512 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100513 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400514 .data = &ftrace_dump_on_oops,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400518 },
519#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200520#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "modprobe",
523 .data = &modprobe_path,
524 .maxlen = KMOD_PATH_LEN,
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
Kees Cook3d433212009-04-02 15:49:29 -0700528 {
Kees Cook3d433212009-04-02 15:49:29 -0700529 .procname = "modules_disabled",
530 .data = &modules_disabled,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700535 .extra1 = &one,
536 .extra2 = &one,
537 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700539#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100542 .data = &uevent_helper,
543 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800545 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 },
547#endif
548#ifdef CONFIG_CHR_DEV_SG
549 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 .procname = "sg-big-buff",
551 .data = &sg_big_buff,
552 .maxlen = sizeof (int),
553 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800554 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 },
556#endif
557#ifdef CONFIG_BSD_PROCESS_ACCT
558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .procname = "acct",
560 .data = &acct_parm,
561 .maxlen = 3*sizeof(int),
562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800563 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
565#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#ifdef CONFIG_MAGIC_SYSRQ
567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800569 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .maxlen = sizeof (int),
571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800572 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 },
574#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700575#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700578 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .maxlen = sizeof (int),
580 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800581 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700583#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "threads-max",
586 .data = &max_threads,
587 .maxlen = 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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "random",
593 .mode = 0555,
594 .child = random_table,
595 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .procname = "overflowuid",
598 .data = &overflowuid,
599 .maxlen = sizeof(int),
600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800601 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .extra1 = &minolduid,
603 .extra2 = &maxolduid,
604 },
605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "overflowgid",
607 .data = &overflowgid,
608 .maxlen = sizeof(int),
609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800614#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#ifdef CONFIG_MATHEMU
616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .procname = "ieee_emulation_warnings",
618 .data = &sysctl_ieee_emulation_warnings,
619 .maxlen = sizeof(int),
620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800621 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 },
623#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .procname = "userprocess_debug",
626 .data = &sysctl_userprocess_debug,
627 .maxlen = sizeof(int),
628 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800629 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 },
631#endif
632 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .procname = "pid_max",
634 .data = &pid_max,
635 .maxlen = sizeof (int),
636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800637 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 .extra1 = &pid_max_min,
639 .extra2 = &pid_max_max,
640 },
641 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 .procname = "panic_on_oops",
643 .data = &panic_on_oops,
644 .maxlen = sizeof(int),
645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800646 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800648#if defined CONFIG_PRINTK
649 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800650 .procname = "printk",
651 .data = &console_loglevel,
652 .maxlen = 4*sizeof(int),
653 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800655 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700658 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .maxlen = sizeof(int),
660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
663 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700665 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 .maxlen = sizeof(int),
667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
Dave Youngaf913222009-09-22 16:43:33 -0700670 {
Dave Youngaf913222009-09-22 16:43:33 -0700671 .procname = "printk_delay",
672 .data = &printk_delay_msec,
673 .maxlen = sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700676 .extra1 = &zero,
677 .extra2 = &ten_thousand,
678 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800679#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 .procname = "ngroups_max",
682 .data = &ngroups_max,
683 .maxlen = sizeof (int),
684 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800685 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 },
687#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .procname = "unknown_nmi_panic",
690 .data = &unknown_nmi_panic,
691 .maxlen = sizeof (int),
692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800693 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 },
Don Zickus407984f2006-09-26 10:52:27 +0200695 {
Don Zickus407984f2006-09-26 10:52:27 +0200696 .procname = "nmi_watchdog",
697 .data = &nmi_watchdog_enabled,
698 .maxlen = sizeof (int),
699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
702#endif
703#if defined(CONFIG_X86)
704 {
Don Zickus8da5add2006-09-26 10:52:27 +0200705 .procname = "panic_on_unrecovered_nmi",
706 .data = &panic_on_unrecovered_nmi,
707 .maxlen = sizeof(int),
708 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800709 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200710 },
711 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700712 .procname = "panic_on_io_nmi",
713 .data = &panic_on_io_nmi,
714 .maxlen = sizeof(int),
715 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800716 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700717 },
718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .procname = "bootloader_type",
720 .data = &bootloader_type,
721 .maxlen = sizeof (int),
722 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800723 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100725 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700726 .procname = "bootloader_version",
727 .data = &bootloader_version,
728 .maxlen = sizeof (int),
729 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800730 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700731 },
732 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100733 .procname = "kstack_depth_to_print",
734 .data = &kstack_depth_to_print,
735 .maxlen = sizeof(int),
736 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800737 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100738 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100739 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100740 .procname = "io_delay_type",
741 .data = &io_delay_type,
742 .maxlen = sizeof(int),
743 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800744 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100745 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800747#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .procname = "randomize_va_space",
750 .data = &randomize_va_space,
751 .maxlen = sizeof(int),
752 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800753 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800755#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800756#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700757 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700758 .procname = "spin_retry",
759 .data = &spin_retry,
760 .maxlen = sizeof (int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700763 },
764#endif
Len Brown673d5b42007-07-28 03:33:16 -0400765#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800766 {
Pavel Machekc255d842006-02-20 18:27:58 -0800767 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700768 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800769 .maxlen = sizeof (unsigned long),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800772 },
773#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800774#ifdef CONFIG_IA64
775 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800776 .procname = "ignore-unaligned-usertrap",
777 .data = &no_unaligned_warning,
778 .maxlen = sizeof (int),
779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800781 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800782 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800783 .procname = "unaligned-dump-stack",
784 .data = &unaligned_dump_stack,
785 .maxlen = sizeof (int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800788 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800789#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700790#ifdef CONFIG_DETECT_SOFTLOCKUP
791 {
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200792 .procname = "softlockup_panic",
793 .data = &softlockup_panic,
794 .maxlen = sizeof(int),
795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800796 .proc_handler = proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200797 .extra1 = &zero,
798 .extra2 = &one,
799 },
800 {
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700801 .procname = "softlockup_thresh",
802 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200803 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dosoftlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200806 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700807 .extra2 = &sixty,
808 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800809#endif
810#ifdef CONFIG_DETECT_HUNG_TASK
811 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800812 .procname = "hung_task_panic",
813 .data = &sysctl_hung_task_panic,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800816 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800817 .extra1 = &zero,
818 .extra2 = &one,
819 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100820 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100821 .procname = "hung_task_check_count",
822 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100823 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100824 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800825 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100826 },
827 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100828 .procname = "hung_task_timeout_secs",
829 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100830 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100831 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800832 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100833 },
834 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100835 .procname = "hung_task_warnings",
836 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100837 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100838 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800839 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700841#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200842#ifdef CONFIG_COMPAT
843 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200844 .procname = "compat-log",
845 .data = &compat_log,
846 .maxlen = sizeof (int),
847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200849 },
850#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700851#ifdef CONFIG_RT_MUTEXES
852 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700853 .procname = "max_lock_depth",
854 .data = &max_lock_depth,
855 .maxlen = sizeof(int),
856 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800857 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700858 },
859#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700860 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700861 .procname = "poweroff_cmd",
862 .data = &poweroff_cmd,
863 .maxlen = POWEROFF_CMD_PATH_LEN,
864 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700866 },
David Howells0b77f5b2008-04-29 01:01:32 -0700867#ifdef CONFIG_KEYS
868 {
David Howells0b77f5b2008-04-29 01:01:32 -0700869 .procname = "keys",
870 .mode = 0555,
871 .child = key_sysctls,
872 },
873#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700874#ifdef CONFIG_RCU_TORTURE_TEST
875 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700876 .procname = "rcutorture_runnable",
877 .data = &rcutorture_runnable,
878 .maxlen = sizeof(int),
879 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800880 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700881 },
882#endif
David Howells12e22c52009-04-03 16:42:35 +0100883#ifdef CONFIG_SLOW_WORK
884 {
David Howells12e22c52009-04-03 16:42:35 +0100885 .procname = "slow-work",
886 .mode = 0555,
887 .child = slow_work_sysctls,
888 },
889#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200890#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200891 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200892 .procname = "perf_event_paranoid",
893 .data = &sysctl_perf_event_paranoid,
894 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200895 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800896 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200897 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200898 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200899 .procname = "perf_event_mlock_kb",
900 .data = &sysctl_perf_event_mlock,
901 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200902 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800903 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200904 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200905 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200906 .procname = "perf_event_max_sample_rate",
907 .data = &sysctl_perf_event_sample_rate,
908 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200909 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800910 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200911 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200912#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200913#ifdef CONFIG_KMEMCHECK
914 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200915 .procname = "kmemcheck",
916 .data = &kmemcheck_enabled,
917 .maxlen = sizeof(int),
918 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800919 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200920 },
921#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200922#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200923 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200924 .procname = "blk_iopoll",
925 .data = &blk_iopoll_enabled,
926 .maxlen = sizeof(int),
927 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800928 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200929 },
Jens Axboecb684b52009-09-15 21:53:11 +0200930#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700931/*
932 * NOTE: do not add new entries to this table unless you have read
933 * Documentation/sysctl/ctl_unnumbered.txt
934 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700935 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936};
937
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700938static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 .procname = "overcommit_memory",
941 .data = &sysctl_overcommit_memory,
942 .maxlen = sizeof(sysctl_overcommit_memory),
943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 },
946 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700947 .procname = "panic_on_oom",
948 .data = &sysctl_panic_on_oom,
949 .maxlen = sizeof(sysctl_panic_on_oom),
950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700952 },
953 {
David Rientjesfe071d72007-10-16 23:25:56 -0700954 .procname = "oom_kill_allocating_task",
955 .data = &sysctl_oom_kill_allocating_task,
956 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
957 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800958 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700959 },
960 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800961 .procname = "oom_dump_tasks",
962 .data = &sysctl_oom_dump_tasks,
963 .maxlen = sizeof(sysctl_oom_dump_tasks),
964 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800965 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800966 },
967 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 .procname = "overcommit_ratio",
969 .data = &sysctl_overcommit_ratio,
970 .maxlen = sizeof(sysctl_overcommit_ratio),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 },
974 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 .procname = "page-cluster",
976 .data = &page_cluster,
977 .maxlen = sizeof(int),
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 .procname = "dirty_background_ratio",
983 .data = &dirty_background_ratio,
984 .maxlen = sizeof(dirty_background_ratio),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 .extra1 = &zero,
988 .extra2 = &one_hundred,
989 },
990 {
David Rientjes2da02992009-01-06 14:39:31 -0800991 .procname = "dirty_background_bytes",
992 .data = &dirty_background_bytes,
993 .maxlen = sizeof(dirty_background_bytes),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800996 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800997 },
998 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .procname = "dirty_ratio",
1000 .data = &vm_dirty_ratio,
1001 .maxlen = sizeof(vm_dirty_ratio),
1002 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001003 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .extra1 = &zero,
1005 .extra2 = &one_hundred,
1006 },
1007 {
David Rientjes2da02992009-01-06 14:39:31 -08001008 .procname = "dirty_bytes",
1009 .data = &vm_dirty_bytes,
1010 .maxlen = sizeof(vm_dirty_bytes),
1011 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001013 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001014 },
1015 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001017 .data = &dirty_writeback_interval,
1018 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001020 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 },
1022 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001024 .data = &dirty_expire_interval,
1025 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 },
1029 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 .procname = "nr_pdflush_threads",
1031 .data = &nr_pdflush_threads,
1032 .maxlen = sizeof nr_pdflush_threads,
1033 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 },
1036 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 .procname = "swappiness",
1038 .data = &vm_swappiness,
1039 .maxlen = sizeof(vm_swappiness),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .extra1 = &zero,
1043 .extra2 = &one_hundred,
1044 },
1045#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001046 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001048 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .maxlen = sizeof(unsigned long),
1050 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001051 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .extra1 = (void *)&hugetlb_zero,
1053 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001054 },
1055#ifdef CONFIG_NUMA
1056 {
1057 .procname = "nr_hugepages_mempolicy",
1058 .data = NULL,
1059 .maxlen = sizeof(unsigned long),
1060 .mode = 0644,
1061 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1062 .extra1 = (void *)&hugetlb_zero,
1063 .extra2 = (void *)&hugetlb_infinity,
1064 },
1065#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "hugetlb_shm_group",
1068 .data = &sysctl_hugetlb_shm_group,
1069 .maxlen = sizeof(gid_t),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 },
Mel Gorman396faf02007-07-17 04:03:13 -07001073 {
Mel Gorman396faf02007-07-17 04:03:13 -07001074 .procname = "hugepages_treat_as_movable",
1075 .data = &hugepages_treat_as_movable,
1076 .maxlen = sizeof(int),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001079 },
Adam Litke54f9f802007-10-16 01:26:20 -07001080 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001081 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001082 .data = NULL,
1083 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001086 .extra1 = (void *)&hugetlb_zero,
1087 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001088 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089#endif
1090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .procname = "lowmem_reserve_ratio",
1092 .data = &sysctl_lowmem_reserve_ratio,
1093 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1094 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001095 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 },
1097 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001098 .procname = "drop_caches",
1099 .data = &sysctl_drop_caches,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
1102 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001103 },
1104 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 .procname = "min_free_kbytes",
1106 .data = &min_free_kbytes,
1107 .maxlen = sizeof(min_free_kbytes),
1108 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001109 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .extra1 = &zero,
1111 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001112 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001113 .procname = "percpu_pagelist_fraction",
1114 .data = &percpu_pagelist_fraction,
1115 .maxlen = sizeof(percpu_pagelist_fraction),
1116 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001117 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001118 .extra1 = &min_percpu_pagelist_fract,
1119 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120#ifdef CONFIG_MMU
1121 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 .procname = "max_map_count",
1123 .data = &sysctl_max_map_count,
1124 .maxlen = sizeof(sysctl_max_map_count),
1125 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001126 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001127 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001129#else
1130 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001131 .procname = "nr_trim_pages",
1132 .data = &sysctl_nr_trim_pages,
1133 .maxlen = sizeof(sysctl_nr_trim_pages),
1134 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001135 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001136 .extra1 = &zero,
1137 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138#endif
1139 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 .procname = "laptop_mode",
1141 .data = &laptop_mode,
1142 .maxlen = sizeof(laptop_mode),
1143 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001144 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 },
1146 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .procname = "block_dump",
1148 .data = &block_dump,
1149 .maxlen = sizeof(block_dump),
1150 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001151 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 .extra1 = &zero,
1153 },
1154 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 .procname = "vfs_cache_pressure",
1156 .data = &sysctl_vfs_cache_pressure,
1157 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1158 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001159 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .extra1 = &zero,
1161 },
1162#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1163 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 .procname = "legacy_va_layout",
1165 .data = &sysctl_legacy_va_layout,
1166 .maxlen = sizeof(sysctl_legacy_va_layout),
1167 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001168 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 .extra1 = &zero,
1170 },
1171#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001172#ifdef CONFIG_NUMA
1173 {
Christoph Lameter17436602006-01-18 17:42:32 -08001174 .procname = "zone_reclaim_mode",
1175 .data = &zone_reclaim_mode,
1176 .maxlen = sizeof(zone_reclaim_mode),
1177 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001178 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001179 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001180 },
Christoph Lameter96146342006-07-03 00:24:13 -07001181 {
Christoph Lameter96146342006-07-03 00:24:13 -07001182 .procname = "min_unmapped_ratio",
1183 .data = &sysctl_min_unmapped_ratio,
1184 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001187 .extra1 = &zero,
1188 .extra2 = &one_hundred,
1189 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001190 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001191 .procname = "min_slab_ratio",
1192 .data = &sysctl_min_slab_ratio,
1193 .maxlen = sizeof(sysctl_min_slab_ratio),
1194 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001195 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001196 .extra1 = &zero,
1197 .extra2 = &one_hundred,
1198 },
Christoph Lameter17436602006-01-18 17:42:32 -08001199#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001200#ifdef CONFIG_SMP
1201 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001202 .procname = "stat_interval",
1203 .data = &sysctl_stat_interval,
1204 .maxlen = sizeof(sysctl_stat_interval),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001207 },
1208#endif
David Howells6e141542009-12-15 19:27:45 +00001209#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001210 {
Eric Parised032182007-06-28 15:55:21 -04001211 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001212 .data = &dac_mmap_min_addr,
1213 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001214 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001215 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001216 },
David Howells6e141542009-12-15 19:27:45 +00001217#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001218#ifdef CONFIG_NUMA
1219 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001220 .procname = "numa_zonelist_order",
1221 .data = &numa_zonelist_order,
1222 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001224 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001225 },
1226#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001227#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001228 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001229 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001230 .procname = "vdso_enabled",
1231 .data = &vdso_enabled,
1232 .maxlen = sizeof(vdso_enabled),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001235 .extra1 = &zero,
1236 },
1237#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001238#ifdef CONFIG_HIGHMEM
1239 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001240 .procname = "highmem_is_dirtyable",
1241 .data = &vm_highmem_is_dirtyable,
1242 .maxlen = sizeof(vm_highmem_is_dirtyable),
1243 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001244 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001245 .extra1 = &zero,
1246 .extra2 = &one,
1247 },
1248#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001249 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001250 .procname = "scan_unevictable_pages",
1251 .data = &scan_unevictable_pages,
1252 .maxlen = sizeof(scan_unevictable_pages),
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001255 },
Andi Kleen6a460792009-09-16 11:50:15 +02001256#ifdef CONFIG_MEMORY_FAILURE
1257 {
Andi Kleen6a460792009-09-16 11:50:15 +02001258 .procname = "memory_failure_early_kill",
1259 .data = &sysctl_memory_failure_early_kill,
1260 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1261 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001263 .extra1 = &zero,
1264 .extra2 = &one,
1265 },
1266 {
Andi Kleen6a460792009-09-16 11:50:15 +02001267 .procname = "memory_failure_recovery",
1268 .data = &sysctl_memory_failure_recovery,
1269 .maxlen = sizeof(sysctl_memory_failure_recovery),
1270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001271 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001272 .extra1 = &zero,
1273 .extra2 = &one,
1274 },
1275#endif
1276
Andrew Morton2be7fe02007-07-15 23:41:21 -07001277/*
1278 * NOTE: do not add new entries to this table unless you have read
1279 * Documentation/sysctl/ctl_unnumbered.txt
1280 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001281 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282};
1283
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001284#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001285static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001286 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001287};
1288#endif
1289
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001290static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 .procname = "inode-nr",
1293 .data = &inodes_stat,
1294 .maxlen = 2*sizeof(int),
1295 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001296 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 },
1298 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 .procname = "inode-state",
1300 .data = &inodes_stat,
1301 .maxlen = 7*sizeof(int),
1302 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001303 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 },
1305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "file-nr",
1307 .data = &files_stat,
1308 .maxlen = 3*sizeof(int),
1309 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 },
1312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .procname = "file-max",
1314 .data = &files_stat.max_files,
1315 .maxlen = sizeof(int),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 },
1319 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001320 .procname = "nr_open",
1321 .data = &sysctl_nr_open,
1322 .maxlen = sizeof(int),
1323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001324 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001325 .extra1 = &sysctl_nr_open_min,
1326 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001327 },
1328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .procname = "dentry-state",
1330 .data = &dentry_stat,
1331 .maxlen = 6*sizeof(int),
1332 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001333 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 },
1335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .procname = "overflowuid",
1337 .data = &fs_overflowuid,
1338 .maxlen = sizeof(int),
1339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001340 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .extra1 = &minolduid,
1342 .extra2 = &maxolduid,
1343 },
1344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "overflowgid",
1346 .data = &fs_overflowgid,
1347 .maxlen = sizeof(int),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .extra1 = &minolduid,
1351 .extra2 = &maxolduid,
1352 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001353#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "leases-enable",
1356 .data = &leases_enable,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001359 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001361#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362#ifdef CONFIG_DNOTIFY
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "dir-notify-enable",
1365 .data = &dir_notify_enable,
1366 .maxlen = sizeof(int),
1367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001368 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 },
1370#endif
1371#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001372#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "lease-break-time",
1375 .data = &lease_break_time,
1376 .maxlen = sizeof(int),
1377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001380#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001381#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "aio-nr",
1384 .data = &aio_nr,
1385 .maxlen = sizeof(aio_nr),
1386 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "aio-max-nr",
1391 .data = &aio_max_nr,
1392 .maxlen = sizeof(aio_max_nr),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001396#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001397#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001398 {
Robert Love0399cb02005-07-13 12:38:18 -04001399 .procname = "inotify",
1400 .mode = 0555,
1401 .child = inotify_table,
1402 },
1403#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001404#ifdef CONFIG_EPOLL
1405 {
1406 .procname = "epoll",
1407 .mode = 0555,
1408 .child = epoll_table,
1409 },
1410#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001412 {
Alan Coxd6e71142005-06-23 00:09:43 -07001413 .procname = "suid_dumpable",
1414 .data = &suid_dumpable,
1415 .maxlen = sizeof(int),
1416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001417 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001418 .extra1 = &zero,
1419 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001420 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001421#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1422 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001423 .procname = "binfmt_misc",
1424 .mode = 0555,
1425 .child = binfmt_misc_table,
1426 },
1427#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001428/*
1429 * NOTE: do not add new entries to this table unless you have read
1430 * Documentation/sysctl/ctl_unnumbered.txt
1431 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001432 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433};
1434
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001435static struct ctl_table debug_table[] = {
David S. Miller4b177642010-03-01 00:02:23 -08001436#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001437 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001438 .procname = "exception-trace",
1439 .data = &show_unhandled_signals,
1440 .maxlen = sizeof(int),
1441 .mode = 0644,
1442 .proc_handler = proc_dointvec
1443 },
1444#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001445#if defined(CONFIG_OPTPROBES)
1446 {
1447 .procname = "kprobes-optimization",
1448 .data = &sysctl_kprobes_optimization,
1449 .maxlen = sizeof(int),
1450 .mode = 0644,
1451 .proc_handler = proc_kprobes_optimization_handler,
1452 .extra1 = &zero,
1453 .extra2 = &one,
1454 },
1455#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001456 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457};
1458
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001459static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001460 { }
Robert Love0eeca282005-07-12 17:06:03 -04001461};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Al Viro330d57f2005-11-04 10:18:40 +00001463static DEFINE_SPINLOCK(sysctl_lock);
1464
1465/* called under sysctl_lock */
1466static int use_table(struct ctl_table_header *p)
1467{
1468 if (unlikely(p->unregistering))
1469 return 0;
1470 p->used++;
1471 return 1;
1472}
1473
1474/* called under sysctl_lock */
1475static void unuse_table(struct ctl_table_header *p)
1476{
1477 if (!--p->used)
1478 if (unlikely(p->unregistering))
1479 complete(p->unregistering);
1480}
1481
1482/* called under sysctl_lock, will reacquire if has to wait */
1483static void start_unregistering(struct ctl_table_header *p)
1484{
1485 /*
1486 * if p->used is 0, nobody will ever touch that entry again;
1487 * we'll eliminate all paths to it before dropping sysctl_lock
1488 */
1489 if (unlikely(p->used)) {
1490 struct completion wait;
1491 init_completion(&wait);
1492 p->unregistering = &wait;
1493 spin_unlock(&sysctl_lock);
1494 wait_for_completion(&wait);
1495 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001496 } else {
1497 /* anything non-NULL; we'll never dereference it */
1498 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001499 }
1500 /*
1501 * do not remove from the list until nobody holds it; walking the
1502 * list in do_sysctl() relies on that.
1503 */
1504 list_del_init(&p->ctl_entry);
1505}
1506
Al Virof7e6ced2008-07-15 01:44:23 -04001507void sysctl_head_get(struct ctl_table_header *head)
1508{
1509 spin_lock(&sysctl_lock);
1510 head->count++;
1511 spin_unlock(&sysctl_lock);
1512}
1513
1514void sysctl_head_put(struct ctl_table_header *head)
1515{
1516 spin_lock(&sysctl_lock);
1517 if (!--head->count)
1518 kfree(head);
1519 spin_unlock(&sysctl_lock);
1520}
1521
1522struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1523{
1524 if (!head)
1525 BUG();
1526 spin_lock(&sysctl_lock);
1527 if (!use_table(head))
1528 head = ERR_PTR(-ENOENT);
1529 spin_unlock(&sysctl_lock);
1530 return head;
1531}
1532
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001533void sysctl_head_finish(struct ctl_table_header *head)
1534{
1535 if (!head)
1536 return;
1537 spin_lock(&sysctl_lock);
1538 unuse_table(head);
1539 spin_unlock(&sysctl_lock);
1540}
1541
Al Viro73455092008-07-14 21:22:20 -04001542static struct ctl_table_set *
1543lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1544{
1545 struct ctl_table_set *set = &root->default_set;
1546 if (root->lookup)
1547 set = root->lookup(root, namespaces);
1548 return set;
1549}
1550
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001551static struct list_head *
1552lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001553{
Al Viro73455092008-07-14 21:22:20 -04001554 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1555 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001556}
1557
1558struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1559 struct ctl_table_header *prev)
1560{
1561 struct ctl_table_root *root;
1562 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001563 struct ctl_table_header *head;
1564 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001565
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001566 spin_lock(&sysctl_lock);
1567 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001568 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001569 tmp = &prev->ctl_entry;
1570 unuse_table(prev);
1571 goto next;
1572 }
1573 tmp = &root_table_header.ctl_entry;
1574 for (;;) {
1575 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1576
1577 if (!use_table(head))
1578 goto next;
1579 spin_unlock(&sysctl_lock);
1580 return head;
1581 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001582 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001583 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001584 header_list = lookup_header_list(root, namespaces);
1585 if (tmp != header_list)
1586 continue;
1587
1588 do {
1589 root = list_entry(root->root_list.next,
1590 struct ctl_table_root, root_list);
1591 if (root == &sysctl_table_root)
1592 goto out;
1593 header_list = lookup_header_list(root, namespaces);
1594 } while (list_empty(header_list));
1595 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001596 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001597out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001598 spin_unlock(&sysctl_lock);
1599 return NULL;
1600}
1601
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001602struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1603{
1604 return __sysctl_head_next(current->nsproxy, prev);
1605}
1606
1607void register_sysctl_root(struct ctl_table_root *root)
1608{
1609 spin_lock(&sysctl_lock);
1610 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1611 spin_unlock(&sysctl_lock);
1612}
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001615 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 * some sysctl variables are readonly even to root.
1617 */
1618
1619static int test_perm(int mode, int op)
1620{
David Howells76aac0e2008-11-14 10:39:12 +11001621 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 mode >>= 6;
1623 else if (in_egroup_p(0))
1624 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001625 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return 0;
1627 return -EACCES;
1628}
1629
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001630int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
1632 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001633 int mode;
1634
Al Viroe6305c42008-07-15 21:03:57 -04001635 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 if (error)
1637 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001638
1639 if (root->permissions)
1640 mode = root->permissions(root, current->nsproxy, table);
1641 else
1642 mode = table->mode;
1643
1644 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001647static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1648{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001649 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001650 table->parent = parent;
1651 if (table->child)
1652 sysctl_set_parent(table, table->child);
1653 }
1654}
1655
1656static __init int sysctl_init(void)
1657{
1658 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001659#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1660 {
1661 int err;
1662 err = sysctl_check_table(current->nsproxy, root_table);
1663 }
1664#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001665 return 0;
1666}
1667
1668core_initcall(sysctl_init);
1669
Al Virobfbcf032008-07-27 06:31:22 +01001670static struct ctl_table *is_branch_in(struct ctl_table *branch,
1671 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001672{
1673 struct ctl_table *p;
1674 const char *s = branch->procname;
1675
1676 /* branch should have named subdirectory as its first element */
1677 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001678 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001679
1680 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001681 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001682 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001683
1684 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001685 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001686 if (!p->child)
1687 continue;
1688 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001689 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001690 }
Al Virobfbcf032008-07-27 06:31:22 +01001691 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001692}
1693
1694/* see if attaching q to p would be an improvement */
1695static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1696{
1697 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001698 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001699 int is_better = 0;
1700 int not_in_parent = !p->attached_by;
1701
Al Virobfbcf032008-07-27 06:31:22 +01001702 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001703 if (by == q->attached_by)
1704 is_better = 1;
1705 if (to == p->attached_by)
1706 not_in_parent = 1;
1707 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001708 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001709 }
1710
1711 if (is_better && not_in_parent) {
1712 q->attached_by = by;
1713 q->attached_to = to;
1714 q->parent = p;
1715 }
1716}
1717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001719 * __register_sysctl_paths - register a sysctl hierarchy
1720 * @root: List of sysctl headers to register on
1721 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001722 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 *
1725 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001726 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001728 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1731 * enter a sysctl file
1732 *
1733 * data - a pointer to data for use by proc_handler
1734 *
1735 * maxlen - the maximum size in bytes of the data
1736 *
1737 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1738 *
1739 * child - a pointer to the child sysctl table if this entry is a directory, or
1740 * %NULL.
1741 *
1742 * proc_handler - the text handler routine (described below)
1743 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 * de - for internal use by the sysctl routines
1745 *
1746 * extra1, extra2 - extra pointers usable by the proc handler routines
1747 *
1748 * Leaf nodes in the sysctl tree will be represented by a single file
1749 * under /proc; non-leaf nodes will be represented by directories.
1750 *
1751 * sysctl(2) can automatically manage read and write requests through
1752 * the sysctl table. The data and maxlen fields of the ctl_table
1753 * struct enable minimal validation of the values being written to be
1754 * performed, and the mode field allows minimal authentication.
1755 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 * There must be a proc_handler routine for any terminal nodes
1757 * mirrored under /proc/sys (non-terminals are handled by a built-in
1758 * directory handler). Several default handlers are available to
1759 * cover common cases -
1760 *
1761 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1762 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1763 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1764 *
1765 * It is the handler's job to read the input buffer from user memory
1766 * and process it. The handler should return 0 on success.
1767 *
1768 * This routine returns %NULL on a failure to register, and a pointer
1769 * to the table header on success.
1770 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001771struct ctl_table_header *__register_sysctl_paths(
1772 struct ctl_table_root *root,
1773 struct nsproxy *namespaces,
1774 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001776 struct ctl_table_header *header;
1777 struct ctl_table *new, **prevp;
1778 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001779 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001780
1781 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001782 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001783 ;
1784
1785 /*
1786 * For each path component, allocate a 2-element ctl_table array.
1787 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001788 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001789 *
1790 * We allocate everything in one go so that we don't have to
1791 * worry about freeing additional memory in unregister_sysctl_table.
1792 */
1793 header = kzalloc(sizeof(struct ctl_table_header) +
1794 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1795 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001797
1798 new = (struct ctl_table *) (header + 1);
1799
1800 /* Now connect the dots */
1801 prevp = &header->ctl_table;
1802 for (n = 0; n < npath; ++n, ++path) {
1803 /* Copy the procname */
1804 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001805 new->mode = 0555;
1806
1807 *prevp = new;
1808 prevp = &new->child;
1809
1810 new += 2;
1811 }
1812 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001813 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001814
1815 INIT_LIST_HEAD(&header->ctl_entry);
1816 header->used = 0;
1817 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001818 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001819 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001820 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001821#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001822 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001823 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001824 return NULL;
1825 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001826#endif
Al Viro330d57f2005-11-04 10:18:40 +00001827 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001828 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001829 header->attached_by = header->ctl_table;
1830 header->attached_to = root_table;
1831 header->parent = &root_table_header;
1832 for (set = header->set; set; set = set->parent) {
1833 struct ctl_table_header *p;
1834 list_for_each_entry(p, &set->list, ctl_entry) {
1835 if (p->unregistering)
1836 continue;
1837 try_attach(p, header);
1838 }
1839 }
1840 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001841 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001842 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001843
1844 return header;
1845}
1846
1847/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001848 * register_sysctl_table_path - register a sysctl table hierarchy
1849 * @path: The path to the directory the sysctl table is in.
1850 * @table: the top-level table structure
1851 *
1852 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1853 * array. A completely 0 filled entry terminates the table.
1854 *
1855 * See __register_sysctl_paths for more details.
1856 */
1857struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1858 struct ctl_table *table)
1859{
1860 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1861 path, table);
1862}
1863
1864/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001865 * register_sysctl_table - register a sysctl table hierarchy
1866 * @table: the top-level table structure
1867 *
1868 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1869 * array. A completely 0 filled entry terminates the table.
1870 *
1871 * See register_sysctl_paths for more details.
1872 */
1873struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1874{
1875 static const struct ctl_path null_path[] = { {} };
1876
1877 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878}
1879
1880/**
1881 * unregister_sysctl_table - unregister a sysctl table hierarchy
1882 * @header: the header returned from register_sysctl_table
1883 *
1884 * Unregisters the sysctl table and all children. proc entries may not
1885 * actually be removed until they are no longer used by anyone.
1886 */
1887void unregister_sysctl_table(struct ctl_table_header * header)
1888{
Al Viro330d57f2005-11-04 10:18:40 +00001889 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001890
1891 if (header == NULL)
1892 return;
1893
Al Viro330d57f2005-11-04 10:18:40 +00001894 spin_lock(&sysctl_lock);
1895 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001896 if (!--header->parent->count) {
1897 WARN_ON(1);
1898 kfree(header->parent);
1899 }
Al Virof7e6ced2008-07-15 01:44:23 -04001900 if (!--header->count)
1901 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001902 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903}
1904
Al Viro9043476f2008-07-15 08:54:06 -04001905int sysctl_is_seen(struct ctl_table_header *p)
1906{
1907 struct ctl_table_set *set = p->set;
1908 int res;
1909 spin_lock(&sysctl_lock);
1910 if (p->unregistering)
1911 res = 0;
1912 else if (!set->is_seen)
1913 res = 1;
1914 else
1915 res = set->is_seen(set);
1916 spin_unlock(&sysctl_lock);
1917 return res;
1918}
1919
Al Viro73455092008-07-14 21:22:20 -04001920void setup_sysctl_set(struct ctl_table_set *p,
1921 struct ctl_table_set *parent,
1922 int (*is_seen)(struct ctl_table_set *))
1923{
1924 INIT_LIST_HEAD(&p->list);
1925 p->parent = parent ? parent : &sysctl_table_root.default_set;
1926 p->is_seen = is_seen;
1927}
1928
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001929#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001930struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001931{
1932 return NULL;
1933}
1934
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001935struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1936 struct ctl_table *table)
1937{
1938 return NULL;
1939}
1940
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001941void unregister_sysctl_table(struct ctl_table_header * table)
1942{
1943}
1944
Al Viro73455092008-07-14 21:22:20 -04001945void setup_sysctl_set(struct ctl_table_set *p,
1946 struct ctl_table_set *parent,
1947 int (*is_seen)(struct ctl_table_set *))
1948{
1949}
1950
Al Virof7e6ced2008-07-15 01:44:23 -04001951void sysctl_head_put(struct ctl_table_header *head)
1952{
1953}
1954
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001955#endif /* CONFIG_SYSCTL */
1956
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957/*
1958 * /proc/sys support
1959 */
1960
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001961#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001963static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001964 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001965 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001966{
1967 size_t len;
1968 char __user *p;
1969 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001970
1971 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001972 *lenp = 0;
1973 return 0;
1974 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001975
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001976 if (write) {
1977 len = 0;
1978 p = buffer;
1979 while (len < *lenp) {
1980 if (get_user(c, p++))
1981 return -EFAULT;
1982 if (c == 0 || c == '\n')
1983 break;
1984 len++;
1985 }
1986 if (len >= maxlen)
1987 len = maxlen-1;
1988 if(copy_from_user(data, buffer, len))
1989 return -EFAULT;
1990 ((char *) data)[len] = 0;
1991 *ppos += *lenp;
1992 } else {
1993 len = strlen(data);
1994 if (len > maxlen)
1995 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001996
1997 if (*ppos > len) {
1998 *lenp = 0;
1999 return 0;
2000 }
2001
2002 data += *ppos;
2003 len -= *ppos;
2004
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002005 if (len > *lenp)
2006 len = *lenp;
2007 if (len)
2008 if(copy_to_user(buffer, data, len))
2009 return -EFAULT;
2010 if (len < *lenp) {
2011 if(put_user('\n', ((char __user *) buffer) + len))
2012 return -EFAULT;
2013 len++;
2014 }
2015 *lenp = len;
2016 *ppos += len;
2017 }
2018 return 0;
2019}
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021/**
2022 * proc_dostring - read a string sysctl
2023 * @table: the sysctl table
2024 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 * @buffer: the user buffer
2026 * @lenp: the size of the user buffer
2027 * @ppos: file position
2028 *
2029 * Reads/writes a string from/to the user buffer. If the kernel
2030 * buffer provided is not large enough to hold the string, the
2031 * string is truncated. The copied string is %NULL-terminated.
2032 * If the string is being read by the user process, it is copied
2033 * and a newline '\n' is added. It is truncated if the buffer is
2034 * not large enough.
2035 *
2036 * Returns 0 on success.
2037 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002038int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 void __user *buffer, size_t *lenp, loff_t *ppos)
2040{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002041 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002042 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043}
2044
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2047 int *valp,
2048 int write, void *data)
2049{
2050 if (write) {
2051 *valp = *negp ? -*lvalp : *lvalp;
2052 } else {
2053 int val = *valp;
2054 if (val < 0) {
2055 *negp = -1;
2056 *lvalp = (unsigned long)-val;
2057 } else {
2058 *negp = 0;
2059 *lvalp = (unsigned long)val;
2060 }
2061 }
2062 return 0;
2063}
2064
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002065static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002066 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002067 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2069 int write, void *data),
2070 void *data)
2071{
2072#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002073 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 unsigned long lval;
2075 size_t left, len;
2076
2077 char buf[TMPBUFLEN], *p;
2078 char __user *s = buffer;
2079
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002080 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 (*ppos && !write)) {
2082 *lenp = 0;
2083 return 0;
2084 }
2085
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002086 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 vleft = table->maxlen / sizeof(*i);
2088 left = *lenp;
2089
2090 if (!conv)
2091 conv = do_proc_dointvec_conv;
2092
2093 for (; left && vleft--; i++, first=0) {
2094 if (write) {
2095 while (left) {
2096 char c;
2097 if (get_user(c, s))
2098 return -EFAULT;
2099 if (!isspace(c))
2100 break;
2101 left--;
2102 s++;
2103 }
2104 if (!left)
2105 break;
2106 neg = 0;
2107 len = left;
2108 if (len > sizeof(buf) - 1)
2109 len = sizeof(buf) - 1;
2110 if (copy_from_user(buf, s, len))
2111 return -EFAULT;
2112 buf[len] = 0;
2113 p = buf;
2114 if (*p == '-' && left > 1) {
2115 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002116 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118 if (*p < '0' || *p > '9')
2119 break;
2120
2121 lval = simple_strtoul(p, &p, 0);
2122
2123 len = p-buf;
2124 if ((len < left) && *p && !isspace(*p))
2125 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 s += len;
2127 left -= len;
2128
2129 if (conv(&neg, &lval, i, 1, data))
2130 break;
2131 } else {
2132 p = buf;
2133 if (!first)
2134 *p++ = '\t';
2135
2136 if (conv(&neg, &lval, i, 0, data))
2137 break;
2138
2139 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2140 len = strlen(buf);
2141 if (len > left)
2142 len = left;
2143 if(copy_to_user(s, buf, len))
2144 return -EFAULT;
2145 left -= len;
2146 s += len;
2147 }
2148 }
2149
2150 if (!write && !first && left) {
2151 if(put_user('\n', s))
2152 return -EFAULT;
2153 left--, s++;
2154 }
2155 if (write) {
2156 while (left) {
2157 char c;
2158 if (get_user(c, s++))
2159 return -EFAULT;
2160 if (!isspace(c))
2161 break;
2162 left--;
2163 }
2164 }
2165 if (write && first)
2166 return -EINVAL;
2167 *lenp -= left;
2168 *ppos += *lenp;
2169 return 0;
2170#undef TMPBUFLEN
2171}
2172
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002173static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002174 void __user *buffer, size_t *lenp, loff_t *ppos,
2175 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2176 int write, void *data),
2177 void *data)
2178{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002179 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002180 buffer, lenp, ppos, conv, data);
2181}
2182
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183/**
2184 * proc_dointvec - read a vector of integers
2185 * @table: the sysctl table
2186 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 * @buffer: the user buffer
2188 * @lenp: the size of the user buffer
2189 * @ppos: file position
2190 *
2191 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2192 * values from/to the user buffer, treated as an ASCII string.
2193 *
2194 * Returns 0 on success.
2195 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002196int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 void __user *buffer, size_t *lenp, loff_t *ppos)
2198{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002199 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 NULL,NULL);
2201}
2202
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002203/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002204 * Taint values can only be increased
2205 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002206 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002207static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002208 void __user *buffer, size_t *lenp, loff_t *ppos)
2209{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002210 struct ctl_table t;
2211 unsigned long tmptaint = get_taint();
2212 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002213
Bastian Blank91fcd412007-04-23 14:41:14 -07002214 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002215 return -EPERM;
2216
Andi Kleen25ddbb12008-10-15 22:01:41 -07002217 t = *table;
2218 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002219 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002220 if (err < 0)
2221 return err;
2222
2223 if (write) {
2224 /*
2225 * Poor man's atomic or. Not worth adding a primitive
2226 * to everyone's atomic.h for this
2227 */
2228 int i;
2229 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2230 if ((tmptaint >> i) & 1)
2231 add_taint(i);
2232 }
2233 }
2234
2235 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002236}
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238struct do_proc_dointvec_minmax_conv_param {
2239 int *min;
2240 int *max;
2241};
2242
2243static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2244 int *valp,
2245 int write, void *data)
2246{
2247 struct do_proc_dointvec_minmax_conv_param *param = data;
2248 if (write) {
2249 int val = *negp ? -*lvalp : *lvalp;
2250 if ((param->min && *param->min > val) ||
2251 (param->max && *param->max < val))
2252 return -EINVAL;
2253 *valp = val;
2254 } else {
2255 int val = *valp;
2256 if (val < 0) {
2257 *negp = -1;
2258 *lvalp = (unsigned long)-val;
2259 } else {
2260 *negp = 0;
2261 *lvalp = (unsigned long)val;
2262 }
2263 }
2264 return 0;
2265}
2266
2267/**
2268 * proc_dointvec_minmax - read a vector of integers with min/max values
2269 * @table: the sysctl table
2270 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 * @buffer: the user buffer
2272 * @lenp: the size of the user buffer
2273 * @ppos: file position
2274 *
2275 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2276 * values from/to the user buffer, treated as an ASCII string.
2277 *
2278 * This routine will ensure the values are within the range specified by
2279 * table->extra1 (min) and table->extra2 (max).
2280 *
2281 * Returns 0 on success.
2282 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002283int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 void __user *buffer, size_t *lenp, loff_t *ppos)
2285{
2286 struct do_proc_dointvec_minmax_conv_param param = {
2287 .min = (int *) table->extra1,
2288 .max = (int *) table->extra2,
2289 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002290 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 do_proc_dointvec_minmax_conv, &param);
2292}
2293
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002294static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 void __user *buffer,
2296 size_t *lenp, loff_t *ppos,
2297 unsigned long convmul,
2298 unsigned long convdiv)
2299{
2300#define TMPBUFLEN 21
2301 unsigned long *i, *min, *max, val;
2302 int vleft, first=1, neg;
2303 size_t len, left;
2304 char buf[TMPBUFLEN], *p;
2305 char __user *s = buffer;
2306
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002307 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 (*ppos && !write)) {
2309 *lenp = 0;
2310 return 0;
2311 }
2312
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002313 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 min = (unsigned long *) table->extra1;
2315 max = (unsigned long *) table->extra2;
2316 vleft = table->maxlen / sizeof(unsigned long);
2317 left = *lenp;
2318
2319 for (; left && vleft--; i++, min++, max++, first=0) {
2320 if (write) {
2321 while (left) {
2322 char c;
2323 if (get_user(c, s))
2324 return -EFAULT;
2325 if (!isspace(c))
2326 break;
2327 left--;
2328 s++;
2329 }
2330 if (!left)
2331 break;
2332 neg = 0;
2333 len = left;
2334 if (len > TMPBUFLEN-1)
2335 len = TMPBUFLEN-1;
2336 if (copy_from_user(buf, s, len))
2337 return -EFAULT;
2338 buf[len] = 0;
2339 p = buf;
2340 if (*p == '-' && left > 1) {
2341 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002342 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 }
2344 if (*p < '0' || *p > '9')
2345 break;
2346 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2347 len = p-buf;
2348 if ((len < left) && *p && !isspace(*p))
2349 break;
2350 if (neg)
2351 val = -val;
2352 s += len;
2353 left -= len;
2354
2355 if(neg)
2356 continue;
2357 if ((min && val < *min) || (max && val > *max))
2358 continue;
2359 *i = val;
2360 } else {
2361 p = buf;
2362 if (!first)
2363 *p++ = '\t';
2364 sprintf(p, "%lu", convdiv * (*i) / convmul);
2365 len = strlen(buf);
2366 if (len > left)
2367 len = left;
2368 if(copy_to_user(s, buf, len))
2369 return -EFAULT;
2370 left -= len;
2371 s += len;
2372 }
2373 }
2374
2375 if (!write && !first && left) {
2376 if(put_user('\n', s))
2377 return -EFAULT;
2378 left--, s++;
2379 }
2380 if (write) {
2381 while (left) {
2382 char c;
2383 if (get_user(c, s++))
2384 return -EFAULT;
2385 if (!isspace(c))
2386 break;
2387 left--;
2388 }
2389 }
2390 if (write && first)
2391 return -EINVAL;
2392 *lenp -= left;
2393 *ppos += *lenp;
2394 return 0;
2395#undef TMPBUFLEN
2396}
2397
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002398static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002399 void __user *buffer,
2400 size_t *lenp, loff_t *ppos,
2401 unsigned long convmul,
2402 unsigned long convdiv)
2403{
2404 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002405 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002406}
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408/**
2409 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: file position
2415 *
2416 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2417 * values from/to the user buffer, treated as an ASCII string.
2418 *
2419 * This routine will ensure the values are within the range specified by
2420 * table->extra1 (min) and table->extra2 (max).
2421 *
2422 * Returns 0 on success.
2423 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002424int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002427 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428}
2429
2430/**
2431 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 * @buffer: the user buffer
2435 * @lenp: the size of the user buffer
2436 * @ppos: file position
2437 *
2438 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2439 * values from/to the user buffer, treated as an ASCII string. The values
2440 * are treated as milliseconds, and converted to jiffies when they are stored.
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 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002447int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos)
2450{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002451 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 lenp, ppos, HZ, 1000l);
2453}
2454
2455
2456static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2457 int *valp,
2458 int write, void *data)
2459{
2460 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002461 if (*lvalp > LONG_MAX / HZ)
2462 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2464 } else {
2465 int val = *valp;
2466 unsigned long lval;
2467 if (val < 0) {
2468 *negp = -1;
2469 lval = (unsigned long)-val;
2470 } else {
2471 *negp = 0;
2472 lval = (unsigned long)val;
2473 }
2474 *lvalp = lval / HZ;
2475 }
2476 return 0;
2477}
2478
2479static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2480 int *valp,
2481 int write, void *data)
2482{
2483 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002484 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2485 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2487 } else {
2488 int val = *valp;
2489 unsigned long lval;
2490 if (val < 0) {
2491 *negp = -1;
2492 lval = (unsigned long)-val;
2493 } else {
2494 *negp = 0;
2495 lval = (unsigned long)val;
2496 }
2497 *lvalp = jiffies_to_clock_t(lval);
2498 }
2499 return 0;
2500}
2501
2502static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2503 int *valp,
2504 int write, void *data)
2505{
2506 if (write) {
2507 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2508 } else {
2509 int val = *valp;
2510 unsigned long lval;
2511 if (val < 0) {
2512 *negp = -1;
2513 lval = (unsigned long)-val;
2514 } else {
2515 *negp = 0;
2516 lval = (unsigned long)val;
2517 }
2518 *lvalp = jiffies_to_msecs(lval);
2519 }
2520 return 0;
2521}
2522
2523/**
2524 * proc_dointvec_jiffies - read a vector of integers as seconds
2525 * @table: the sysctl table
2526 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 * @buffer: the user buffer
2528 * @lenp: the size of the user buffer
2529 * @ppos: file position
2530 *
2531 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2532 * values from/to the user buffer, treated as an ASCII string.
2533 * The values read are assumed to be in seconds, and are converted into
2534 * jiffies.
2535 *
2536 * Returns 0 on success.
2537 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002538int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 void __user *buffer, size_t *lenp, loff_t *ppos)
2540{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002541 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 do_proc_dointvec_jiffies_conv,NULL);
2543}
2544
2545/**
2546 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2547 * @table: the sysctl table
2548 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 * @buffer: the user buffer
2550 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002551 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 *
2553 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2554 * values from/to the user buffer, treated as an ASCII string.
2555 * The values read are assumed to be in 1/USER_HZ seconds, and
2556 * are converted into jiffies.
2557 *
2558 * Returns 0 on success.
2559 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002560int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 void __user *buffer, size_t *lenp, loff_t *ppos)
2562{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002563 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 do_proc_dointvec_userhz_jiffies_conv,NULL);
2565}
2566
2567/**
2568 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2569 * @table: the sysctl table
2570 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 * @buffer: the user buffer
2572 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002573 * @ppos: file position
2574 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 *
2576 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2577 * values from/to the user buffer, treated as an ASCII string.
2578 * The values read are assumed to be in 1/1000 seconds, and
2579 * are converted into jiffies.
2580 *
2581 * Returns 0 on success.
2582 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002583int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 void __user *buffer, size_t *lenp, loff_t *ppos)
2585{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002586 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 do_proc_dointvec_ms_jiffies_conv, NULL);
2588}
2589
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002590static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002591 void __user *buffer, size_t *lenp, loff_t *ppos)
2592{
2593 struct pid *new_pid;
2594 pid_t tmp;
2595 int r;
2596
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002597 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002598
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002599 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002600 lenp, ppos, NULL, NULL);
2601 if (r || !write)
2602 return r;
2603
2604 new_pid = find_get_pid(tmp);
2605 if (!new_pid)
2606 return -ESRCH;
2607
2608 put_pid(xchg(&cad_pid, new_pid));
2609 return 0;
2610}
2611
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612#else /* CONFIG_PROC_FS */
2613
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002614int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 void __user *buffer, size_t *lenp, loff_t *ppos)
2616{
2617 return -ENOSYS;
2618}
2619
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002620int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 void __user *buffer, size_t *lenp, loff_t *ppos)
2622{
2623 return -ENOSYS;
2624}
2625
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002626int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 void __user *buffer, size_t *lenp, loff_t *ppos)
2628{
2629 return -ENOSYS;
2630}
2631
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002632int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 void __user *buffer, size_t *lenp, loff_t *ppos)
2634{
2635 return -ENOSYS;
2636}
2637
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002638int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 return -ENOSYS;
2642}
2643
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002644int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 void __user *buffer, size_t *lenp, loff_t *ppos)
2646{
2647 return -ENOSYS;
2648}
2649
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002650int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 void __user *buffer, size_t *lenp, loff_t *ppos)
2652{
2653 return -ENOSYS;
2654}
2655
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002656int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 void __user *buffer,
2658 size_t *lenp, loff_t *ppos)
2659{
2660 return -ENOSYS;
2661}
2662
2663
2664#endif /* CONFIG_PROC_FS */
2665
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666/*
2667 * No sense putting this after each symbol definition, twice,
2668 * exception granted :-)
2669 */
2670EXPORT_SYMBOL(proc_dointvec);
2671EXPORT_SYMBOL(proc_dointvec_jiffies);
2672EXPORT_SYMBOL(proc_dointvec_minmax);
2673EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2674EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2675EXPORT_SYMBOL(proc_dostring);
2676EXPORT_SYMBOL(proc_doulongvec_minmax);
2677EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2678EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002679EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680EXPORT_SYMBOL(unregister_sysctl_table);