sysctl.c 74.6 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * sysctl.c: General linux system control interface
 *
 * Begun 24 March 1995, Stephen Tweedie
 * Added /proc support, Dec 1995
 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
 * Dynamic registration fixes, Stephen Tweedie.
 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
 *  Horn.
 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
 *  Wendling.
 * The list_for_each() macro wasn't appropriate for the sysctl loop.
 *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
 */

#include <linux/module.h>
#include <linux/mm.h>
#include <linux/swap.h>
#include <linux/slab.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
27
#include <linux/security.h>
Linus Torvalds's avatar
Linus Torvalds committed
28 29 30
#include <linux/ctype.h>
#include <linux/utsname.h>
#include <linux/smp_lock.h>
31
#include <linux/fs.h>
Linus Torvalds's avatar
Linus Torvalds committed
32 33
#include <linux/init.h>
#include <linux/kernel.h>
34
#include <linux/kobject.h>
35
#include <linux/net.h>
Linus Torvalds's avatar
Linus Torvalds committed
36 37 38 39 40
#include <linux/sysrq.h>
#include <linux/highuid.h>
#include <linux/writeback.h>
#include <linux/hugetlb.h>
#include <linux/initrd.h>
41
#include <linux/key.h>
Linus Torvalds's avatar
Linus Torvalds committed
42 43 44 45
#include <linux/times.h>
#include <linux/limits.h>
#include <linux/dcache.h>
#include <linux/syscalls.h>
Adrian Bunk's avatar
Adrian Bunk committed
46
#include <linux/vmstat.h>
47 48
#include <linux/nfs_fs.h>
#include <linux/acpi.h>
49
#include <linux/reboot.h>
50
#include <linux/ftrace.h>
51
#include <linux/slow-work.h>
52
#include <linux/perf_counter.h>
Linus Torvalds's avatar
Linus Torvalds committed
53 54 55 56

#include <asm/uaccess.h>
#include <asm/processor.h>

57 58
#ifdef CONFIG_X86
#include <asm/nmi.h>
59
#include <asm/stacktrace.h>
60
#include <asm/io.h>
61 62
#endif

63 64
static int deprecated_sysctl_warning(struct __sysctl_args *args);

Linus Torvalds's avatar
Linus Torvalds committed
65 66 67 68
#if defined(CONFIG_SYSCTL)

/* External variables not in a header file. */
extern int C_A_D;
Ingo Molnar's avatar
Ingo Molnar committed
69
extern int print_fatal_signals;
Linus Torvalds's avatar
Linus Torvalds committed
70 71
extern int sysctl_overcommit_memory;
extern int sysctl_overcommit_ratio;
72
extern int sysctl_panic_on_oom;
73
extern int sysctl_oom_kill_allocating_task;
74
extern int sysctl_oom_dump_tasks;
Linus Torvalds's avatar
Linus Torvalds committed
75 76
extern int max_threads;
extern int core_uses_pid;
Alan Cox's avatar
Alan Cox committed
77
extern int suid_dumpable;
Linus Torvalds's avatar
Linus Torvalds committed
78 79 80 81
extern char core_pattern[];
extern int pid_max;
extern int min_free_kbytes;
extern int pid_max_min, pid_max_max;
Andrew Morton's avatar
Andrew Morton committed
82
extern int sysctl_drop_caches;
83
extern int percpu_pagelist_fraction;
84
extern int compat_log;
Arjan van de Ven's avatar
Arjan van de Ven committed
85
extern int latencytop_enabled;
86
extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 88 89
#ifndef CONFIG_MMU
extern int sysctl_nr_trim_pages;
#endif
90 91 92
#ifdef CONFIG_RCU_TORTURE_TEST
extern int rcutorture_runnable;
#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds's avatar
Linus Torvalds committed
93

94
/* Constants used for minimum and  maximum */
95
#ifdef CONFIG_DETECT_SOFTLOCKUP
96
static int sixty = 60;
97
static int neg_one = -1;
98 99 100
#endif

static int zero;
101 102
static int __maybe_unused one = 1;
static int __maybe_unused two = 2;
103
static unsigned long one_ul = 1;
104 105
static int one_hundred = 100;

106 107 108
/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;

Linus Torvalds's avatar
Linus Torvalds committed
109 110 111
/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
static int maxolduid = 65535;
static int minolduid;
112
static int min_percpu_pagelist_fract = 8;
Linus Torvalds's avatar
Linus Torvalds committed
113 114 115

static int ngroups_max = NGROUPS_MAX;

116
#ifdef CONFIG_MODULES
Linus Torvalds's avatar
Linus Torvalds committed
117
extern char modprobe_path[];
118
extern int modules_disabled;
Linus Torvalds's avatar
Linus Torvalds committed
119 120 121 122 123
#endif
#ifdef CONFIG_CHR_DEV_SG
extern int sg_big_buff;
#endif

124
#ifdef CONFIG_SPARC
125
#include <asm/system.h>
Linus Torvalds's avatar
Linus Torvalds committed
126 127
#endif

128 129 130 131
#ifdef CONFIG_SPARC64
extern int sysctl_tsb_ratio;
#endif

Linus Torvalds's avatar
Linus Torvalds committed
132 133 134 135 136
#ifdef __hppa__
extern int pwrsw_enabled;
extern int unaligned_enabled;
#endif

137
#ifdef CONFIG_S390
Linus Torvalds's avatar
Linus Torvalds committed
138 139 140 141
#ifdef CONFIG_MATHEMU
extern int sysctl_ieee_emulation_warnings;
#endif
extern int sysctl_userprocess_debug;
142
extern int spin_retry;
Linus Torvalds's avatar
Linus Torvalds committed
143 144 145 146 147 148
#endif

#ifdef CONFIG_BSD_PROCESS_ACCT
extern int acct_parm[];
#endif

149 150
#ifdef CONFIG_IA64
extern int no_unaligned_warning;
151
extern int unaligned_dump_stack;
152 153
#endif

Ingo Molnar's avatar
Ingo Molnar committed
154 155 156 157
#ifdef CONFIG_RT_MUTEXES
extern int max_lock_depth;
#endif

158
#ifdef CONFIG_PROC_SYSCTL
159
static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
160
		  void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen's avatar
Andi Kleen committed
161
static int proc_taint(struct ctl_table *table, int write, struct file *filp,
162
			       void __user *buffer, size_t *lenp, loff_t *ppos);
163
#endif
164

165
static struct ctl_table root_table[];
166 167
static struct ctl_table_root sysctl_table_root;
static struct ctl_table_header root_table_header = {
168
	.count = 1,
169
	.ctl_table = root_table,
170
	.ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
171
	.root = &sysctl_table_root,
172
	.set = &sysctl_table_root.default_set,
173 174 175
};
static struct ctl_table_root sysctl_table_root = {
	.root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
176
	.default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
177
};
Linus Torvalds's avatar
Linus Torvalds committed
178

179 180 181 182 183 184
static struct ctl_table kern_table[];
static struct ctl_table vm_table[];
static struct ctl_table fs_table[];
static struct ctl_table debug_table[];
static struct ctl_table dev_table[];
extern struct ctl_table random_table[];
185
#ifdef CONFIG_INOTIFY_USER
186
extern struct ctl_table inotify_table[];
Robert Love's avatar
Robert Love committed
187
#endif
188 189 190
#ifdef CONFIG_EPOLL
extern struct ctl_table epoll_table[];
#endif
Linus Torvalds's avatar
Linus Torvalds committed
191 192 193 194 195

#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
int sysctl_legacy_va_layout;
#endif

Peter Zijlstra's avatar
Peter Zijlstra committed
196 197
extern int prove_locking;
extern int lock_stat;
198

Linus Torvalds's avatar
Linus Torvalds committed
199 200
/* The default sysctl tables: */

201
static struct ctl_table root_table[] = {
Linus Torvalds's avatar
Linus Torvalds committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
	{
		.ctl_name	= CTL_KERN,
		.procname	= "kernel",
		.mode		= 0555,
		.child		= kern_table,
	},
	{
		.ctl_name	= CTL_VM,
		.procname	= "vm",
		.mode		= 0555,
		.child		= vm_table,
	},
	{
		.ctl_name	= CTL_FS,
		.procname	= "fs",
		.mode		= 0555,
		.child		= fs_table,
	},
	{
		.ctl_name	= CTL_DEBUG,
		.procname	= "debug",
		.mode		= 0555,
		.child		= debug_table,
	},
	{
		.ctl_name	= CTL_DEV,
		.procname	= "dev",
		.mode		= 0555,
		.child		= dev_table,
	},
232 233 234 235
/*
 * NOTE: do not add new entries to this table unless you have read
 * Documentation/sysctl/ctl_unnumbered.txt
 */
Linus Torvalds's avatar
Linus Torvalds committed
236 237 238
	{ .ctl_name = 0 }
};

Ingo Molnar's avatar
Ingo Molnar committed
239
#ifdef CONFIG_SCHED_DEBUG
240 241 242 243
static int min_sched_granularity_ns = 100000;		/* 100 usecs */
static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
static int min_wakeup_granularity_ns;			/* 0 usecs */
static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
Ingo Molnar's avatar
Ingo Molnar committed
244 245
#endif

246
static struct ctl_table kern_table[] = {
Ingo Molnar's avatar
Ingo Molnar committed
247 248 249
#ifdef CONFIG_SCHED_DEBUG
	{
		.ctl_name	= CTL_UNNUMBERED,
250 251
		.procname	= "sched_min_granularity_ns",
		.data		= &sysctl_sched_min_granularity,
Ingo Molnar's avatar
Ingo Molnar committed
252 253
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
254 255 256 257
		.proc_handler	= &sched_nr_latency_handler,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_sched_granularity_ns,
		.extra2		= &max_sched_granularity_ns,
Ingo Molnar's avatar
Ingo Molnar committed
258
	},
259 260 261 262 263 264
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_latency_ns",
		.data		= &sysctl_sched_latency,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
265
		.proc_handler	= &sched_nr_latency_handler,
266 267 268 269
		.strategy	= &sysctl_intvec,
		.extra1		= &min_sched_granularity_ns,
		.extra2		= &max_sched_granularity_ns,
	},
Ingo Molnar's avatar
Ingo Molnar committed
270 271 272 273 274 275 276 277 278 279 280
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_wakeup_granularity_ns",
		.data		= &sysctl_sched_wakeup_granularity,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_wakeup_granularity_ns,
		.extra2		= &max_wakeup_granularity_ns,
	},
281 282 283 284 285 286 287 288
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_shares_ratelimit",
		.data		= &sysctl_sched_shares_ratelimit,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
289 290 291 292 293 294 295 296 297 298
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_shares_thresh",
		.data		= &sysctl_sched_shares_thresh,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
Ingo Molnar's avatar
Ingo Molnar committed
299 300 301 302 303 304 305 306
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_child_runs_first",
		.data		= &sysctl_sched_child_runs_first,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
307 308 309 310 311 312 313 314
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_features",
		.data		= &sysctl_sched_features,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
315 316 317 318 319 320 321 322
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_migration_cost",
		.data		= &sysctl_sched_migration_cost,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
323 324 325 326 327
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_nr_migrate",
		.data		= &sysctl_sched_nr_migrate,
		.maxlen		= sizeof(unsigned int),
Peter Zijlstra's avatar
Peter Zijlstra committed
328 329 330
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
331 332 333 334 335 336 337
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "timer_migration",
		.data		= &sysctl_timer_migration,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
Peter Zijlstra's avatar
Peter Zijlstra committed
338
	},
339
#endif
Peter Zijlstra's avatar
Peter Zijlstra committed
340 341 342 343 344 345
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_rt_period_us",
		.data		= &sysctl_sched_rt_period,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
346
		.proc_handler	= &sched_rt_handler,
Peter Zijlstra's avatar
Peter Zijlstra committed
347 348 349 350 351 352 353
	},
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_rt_runtime_us",
		.data		= &sysctl_sched_rt_runtime,
		.maxlen		= sizeof(int),
		.mode		= 0644,
354
		.proc_handler	= &sched_rt_handler,
Peter Zijlstra's avatar
Peter Zijlstra committed
355
	},
356 357 358 359 360 361 362 363
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "sched_compat_yield",
		.data		= &sysctl_sched_compat_yield,
		.maxlen		= sizeof(unsigned int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Peter Zijlstra's avatar
Peter Zijlstra committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
#ifdef CONFIG_PROVE_LOCKING
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "prove_locking",
		.data		= &prove_locking,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
#ifdef CONFIG_LOCK_STAT
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "lock_stat",
		.data		= &lock_stat,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Ingo Molnar's avatar
Ingo Molnar committed
383
#endif
Linus Torvalds's avatar
Linus Torvalds committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
	{
		.ctl_name	= KERN_PANIC,
		.procname	= "panic",
		.data		= &panic_timeout,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= KERN_CORE_USES_PID,
		.procname	= "core_uses_pid",
		.data		= &core_uses_pid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= KERN_CORE_PATTERN,
		.procname	= "core_pattern",
		.data		= core_pattern,
404
		.maxlen		= CORENAME_MAX_SIZE,
Linus Torvalds's avatar
Linus Torvalds committed
405 406 407 408
		.mode		= 0644,
		.proc_handler	= &proc_dostring,
		.strategy	= &sysctl_string,
	},
409
#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds's avatar
Linus Torvalds committed
410 411
	{
		.procname	= "tainted",
Andi Kleen's avatar
Andi Kleen committed
412
		.maxlen 	= sizeof(long),
413
		.mode		= 0644,
Andi Kleen's avatar
Andi Kleen committed
414
		.proc_handler	= &proc_taint,
Linus Torvalds's avatar
Linus Torvalds committed
415
	},
416
#endif
Arjan van de Ven's avatar
Arjan van de Ven committed
417 418 419 420 421 422 423 424 425
#ifdef CONFIG_LATENCYTOP
	{
		.procname	= "latencytop",
		.data		= &latencytop_enabled,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
Linus Torvalds's avatar
Linus Torvalds committed
426 427 428 429 430 431 432 433 434 435
#ifdef CONFIG_BLK_DEV_INITRD
	{
		.ctl_name	= KERN_REALROOTDEV,
		.procname	= "real-root-dev",
		.data		= &real_root_dev,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
Ingo Molnar's avatar
Ingo Molnar committed
436 437 438 439 440 441 442 443
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "print-fatal-signals",
		.data		= &print_fatal_signals,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
444
#ifdef CONFIG_SPARC
Linus Torvalds's avatar
Linus Torvalds committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
	{
		.ctl_name	= KERN_SPARC_REBOOT,
		.procname	= "reboot-cmd",
		.data		= reboot_command,
		.maxlen		= 256,
		.mode		= 0644,
		.proc_handler	= &proc_dostring,
		.strategy	= &sysctl_string,
	},
	{
		.ctl_name	= KERN_SPARC_STOP_A,
		.procname	= "stop-a",
		.data		= &stop_a_enabled,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= KERN_SPARC_SCONS_PWROFF,
		.procname	= "scons-poweroff",
		.data		= &scons_pwroff,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
471 472 473 474 475 476 477 478 479 480
#ifdef CONFIG_SPARC64
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "tsb-ratio",
		.data		= &sysctl_tsb_ratio,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
Linus Torvalds's avatar
Linus Torvalds committed
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
#ifdef __hppa__
	{
		.ctl_name	= KERN_HPPA_PWRSW,
		.procname	= "soft-power",
		.data		= &pwrsw_enabled,
		.maxlen		= sizeof (int),
	 	.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= KERN_HPPA_UNALIGNED,
		.procname	= "unaligned-trap",
		.data		= &unaligned_enabled,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
	{
		.ctl_name	= KERN_CTLALTDEL,
		.procname	= "ctrl-alt-del",
		.data		= &C_A_D,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
507
#ifdef CONFIG_FUNCTION_TRACER
508 509 510 511 512 513 514 515 516
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "ftrace_enabled",
		.data		= &ftrace_enabled,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &ftrace_enable_sysctl,
	},
#endif
517 518 519 520 521 522 523 524 525 526
#ifdef CONFIG_STACK_TRACER
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "stack_tracer_enabled",
		.data		= &stack_tracer_enabled,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &stack_trace_sysctl,
	},
#endif
527 528 529
#ifdef CONFIG_TRACING
	{
		.ctl_name	= CTL_UNNUMBERED,
Peter Zijlstra's avatar
Peter Zijlstra committed
530
		.procname	= "ftrace_dump_on_oops",
531 532 533 534 535 536
		.data		= &ftrace_dump_on_oops,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
537
#ifdef CONFIG_MODULES
Linus Torvalds's avatar
Linus Torvalds committed
538 539 540 541 542 543 544 545 546
	{
		.ctl_name	= KERN_MODPROBE,
		.procname	= "modprobe",
		.data		= &modprobe_path,
		.maxlen		= KMOD_PATH_LEN,
		.mode		= 0644,
		.proc_handler	= &proc_dostring,
		.strategy	= &sysctl_string,
	},
547 548 549 550 551 552 553 554 555 556 557
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "modules_disabled",
		.data		= &modules_disabled,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		/* only handle a transition from default "0" to "1" */
		.proc_handler	= &proc_dointvec_minmax,
		.extra1		= &one,
		.extra2		= &one,
	},
Linus Torvalds's avatar
Linus Torvalds committed
558
#endif
Andrew Morton's avatar
Andrew Morton committed
559
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds's avatar
Linus Torvalds committed
560 561 562
	{
		.ctl_name	= KERN_HOTPLUG,
		.procname	= "hotplug",
563 564
		.data		= &uevent_helper,
		.maxlen		= UEVENT_HELPER_PATH_LEN,
Linus Torvalds's avatar
Linus Torvalds committed
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
		.mode		= 0644,
		.proc_handler	= &proc_dostring,
		.strategy	= &sysctl_string,
	},
#endif
#ifdef CONFIG_CHR_DEV_SG
	{
		.ctl_name	= KERN_SG_BIG_BUFF,
		.procname	= "sg-big-buff",
		.data		= &sg_big_buff,
		.maxlen		= sizeof (int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
#endif
#ifdef CONFIG_BSD_PROCESS_ACCT
	{
		.ctl_name	= KERN_ACCT,
		.procname	= "acct",
		.data		= &acct_parm,
		.maxlen		= 3*sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
#ifdef CONFIG_MAGIC_SYSRQ
	{
		.ctl_name	= KERN_SYSRQ,
		.procname	= "sysrq",
594
		.data		= &__sysrq_enabled,
Linus Torvalds's avatar
Linus Torvalds committed
595 596 597 598 599
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
600
#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds's avatar
Linus Torvalds committed
601 602
	{
		.procname	= "cad_pid",
603
		.data		= NULL,
Linus Torvalds's avatar
Linus Torvalds committed
604 605
		.maxlen		= sizeof (int),
		.mode		= 0600,
606
		.proc_handler	= &proc_do_cad_pid,
Linus Torvalds's avatar
Linus Torvalds committed
607
	},
608
#endif
Linus Torvalds's avatar
Linus Torvalds committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
	{
		.ctl_name	= KERN_MAX_THREADS,
		.procname	= "threads-max",
		.data		= &max_threads,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= KERN_RANDOM,
		.procname	= "random",
		.mode		= 0555,
		.child		= random_table,
	},
	{
		.ctl_name	= KERN_OVERFLOWUID,
		.procname	= "overflowuid",
		.data		= &overflowuid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &minolduid,
		.extra2		= &maxolduid,
	},
	{
		.ctl_name	= KERN_OVERFLOWGID,
		.procname	= "overflowgid",
		.data		= &overflowgid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &minolduid,
		.extra2		= &maxolduid,
	},
645
#ifdef CONFIG_S390
Linus Torvalds's avatar
Linus Torvalds committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
#ifdef CONFIG_MATHEMU
	{
		.ctl_name	= KERN_IEEE_EMULATION_WARNINGS,
		.procname	= "ieee_emulation_warnings",
		.data		= &sysctl_ieee_emulation_warnings,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
	{
		.ctl_name	= KERN_S390_USER_DEBUG_LOGGING,
		.procname	= "userprocess_debug",
		.data		= &sysctl_userprocess_debug,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
	{
		.ctl_name	= KERN_PIDMAX,
		.procname	= "pid_max",
		.data		= &pid_max,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= sysctl_intvec,
		.extra1		= &pid_max_min,
		.extra2		= &pid_max_max,
	},
	{
		.ctl_name	= KERN_PANIC_ON_OOPS,
		.procname	= "panic_on_oops",
		.data		= &panic_on_oops,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
684 685 686 687 688 689 690 691 692
#if defined CONFIG_PRINTK
	{
		.ctl_name	= KERN_PRINTK,
		.procname	= "printk",
		.data		= &console_loglevel,
		.maxlen		= 4*sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Linus Torvalds's avatar
Linus Torvalds committed
693 694 695
	{
		.ctl_name	= KERN_PRINTK_RATELIMIT,
		.procname	= "printk_ratelimit",
Dave Young's avatar
Dave Young committed
696
		.data		= &printk_ratelimit_state.interval,
Linus Torvalds's avatar
Linus Torvalds committed
697 698 699 700 701 702 703 704
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_jiffies,
		.strategy	= &sysctl_jiffies,
	},
	{
		.ctl_name	= KERN_PRINTK_RATELIMIT_BURST,
		.procname	= "printk_ratelimit_burst",
Dave Young's avatar
Dave Young committed
705
		.data		= &printk_ratelimit_state.burst,
Linus Torvalds's avatar
Linus Torvalds committed
706 707 708 709
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
710
#endif
Linus Torvalds's avatar
Linus Torvalds committed
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
	{
		.ctl_name	= KERN_NGROUPS_MAX,
		.procname	= "ngroups_max",
		.data		= &ngroups_max,
		.maxlen		= sizeof (int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
	{
		.ctl_name       = KERN_UNKNOWN_NMI_PANIC,
		.procname       = "unknown_nmi_panic",
		.data           = &unknown_nmi_panic,
		.maxlen         = sizeof (int),
		.mode           = 0644,
726
		.proc_handler   = &proc_dointvec,
Linus Torvalds's avatar
Linus Torvalds committed
727
	},
728 729 730 731 732 733
	{
		.procname       = "nmi_watchdog",
		.data           = &nmi_watchdog_enabled,
		.maxlen         = sizeof (int),
		.mode           = 0644,
		.proc_handler   = &proc_nmi_enabled,
Linus Torvalds's avatar
Linus Torvalds committed
734 735 736
	},
#endif
#if defined(CONFIG_X86)
737 738 739 740 741 742 743 744
	{
		.ctl_name	= KERN_PANIC_ON_NMI,
		.procname	= "panic_on_unrecovered_nmi",
		.data		= &panic_on_unrecovered_nmi,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Linus Torvalds's avatar
Linus Torvalds committed
745 746 747 748 749 750 751 752
	{
		.ctl_name	= KERN_BOOTLOADER_TYPE,
		.procname	= "bootloader_type",
		.data		= &bootloader_type,
		.maxlen		= sizeof (int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
753 754 755 756 757 758 759 760
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "bootloader_version",
		.data		= &bootloader_version,
		.maxlen		= sizeof (int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
761 762 763 764 765 766 767 768
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "kstack_depth_to_print",
		.data		= &kstack_depth_to_print,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
769 770 771 772 773 774 775 776
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "io_delay_type",
		.data		= &io_delay_type,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Linus Torvalds's avatar
Linus Torvalds committed
777
#endif
778
#if defined(CONFIG_MMU)
Linus Torvalds's avatar
Linus Torvalds committed
779 780 781 782 783 784 785 786
	{
		.ctl_name	= KERN_RANDOMIZE,
		.procname	= "randomize_va_space",
		.data		= &randomize_va_space,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
787
#endif
788
#if defined(CONFIG_S390) && defined(CONFIG_SMP)
789 790 791 792 793 794 795 796
	{
		.ctl_name	= KERN_SPIN_RETRY,
		.procname	= "spin_retry",
		.data		= &spin_retry,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
797
#endif
Len Brown's avatar
Len Brown committed
798
#if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
799 800
	{
		.procname	= "acpi_video_flags",
801
		.data		= &acpi_realmode_flags,
802 803
		.maxlen		= sizeof (unsigned long),
		.mode		= 0644,
804
		.proc_handler	= &proc_doulongvec_minmax,
805
	},
806 807 808 809 810 811 812 813 814 815
#endif
#ifdef CONFIG_IA64
	{
		.ctl_name	= KERN_IA64_UNALIGNED,
		.procname	= "ignore-unaligned-usertrap",
		.data		= &no_unaligned_warning,
		.maxlen		= sizeof (int),
	 	.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
816 817 818 819 820 821 822 823
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "unaligned-dump-stack",
		.data		= &unaligned_dump_stack,
		.maxlen		= sizeof (int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
824
#endif
825
#ifdef CONFIG_DETECT_SOFTLOCKUP
826 827 828 829 830 831
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "softlockup_panic",
		.data		= &softlockup_panic,
		.maxlen		= sizeof(int),
		.mode		= 0644,
832
		.proc_handler	= &proc_dointvec_minmax,
833 834 835 836
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one,
	},
837 838 839 840
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "softlockup_thresh",
		.data		= &softlockup_thresh,
841
		.maxlen		= sizeof(int),
842
		.mode		= 0644,
843
		.proc_handler	= &proc_dosoftlockup_thresh,
844
		.strategy	= &sysctl_intvec,
845
		.extra1		= &neg_one,
846 847
		.extra2		= &sixty,
	},
848 849 850 851 852 853 854 855 856 857 858 859 860
#endif
#ifdef CONFIG_DETECT_HUNG_TASK
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "hung_task_panic",
		.data		= &sysctl_hung_task_panic,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one,
	},
861 862 863 864
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "hung_task_check_count",
		.data		= &sysctl_hung_task_check_count,
Ingo Molnar's avatar
Ingo Molnar committed
865
		.maxlen		= sizeof(unsigned long),
866
		.mode		= 0644,
Ingo Molnar's avatar
Ingo Molnar committed
867
		.proc_handler	= &proc_doulongvec_minmax,
868 869 870 871 872 873
		.strategy	= &sysctl_intvec,
	},
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "hung_task_timeout_secs",
		.data		= &sysctl_hung_task_timeout_secs,
Ingo Molnar's avatar
Ingo Molnar committed
874
		.maxlen		= sizeof(unsigned long),
875
		.mode		= 0644,
876
		.proc_handler	= &proc_dohung_task_timeout_secs,
877 878 879 880 881 882
		.strategy	= &sysctl_intvec,
	},
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "hung_task_warnings",
		.data		= &sysctl_hung_task_warnings,
Ingo Molnar's avatar
Ingo Molnar committed
883
		.maxlen		= sizeof(unsigned long),
884
		.mode		= 0644,
Ingo Molnar's avatar
Ingo Molnar committed
885
		.proc_handler	= &proc_doulongvec_minmax,
886 887
		.strategy	= &sysctl_intvec,
	},
888
#endif
889 890 891 892 893 894 895 896 897
#ifdef CONFIG_COMPAT
	{
		.ctl_name	= KERN_COMPAT_LOG,
		.procname	= "compat-log",
		.data		= &compat_log,
		.maxlen		= sizeof (int),
	 	.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
898
#endif
Ingo Molnar's avatar
Ingo Molnar committed
899 900 901 902 903 904 905 906 907
#ifdef CONFIG_RT_MUTEXES
	{
		.ctl_name	= KERN_MAX_LOCK_DEPTH,
		.procname	= "max_lock_depth",
		.data		= &max_lock_depth,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Kees Cook's avatar
Kees Cook committed
908
#endif
909 910 911 912 913 914 915 916 917
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "poweroff_cmd",
		.data		= &poweroff_cmd,
		.maxlen		= POWEROFF_CMD_PATH_LEN,
		.mode		= 0644,
		.proc_handler	= &proc_dostring,
		.strategy	= &sysctl_string,
	},
918 919 920 921 922 923 924 925
#ifdef CONFIG_KEYS
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "keys",
		.mode		= 0555,
		.child		= key_sysctls,
	},
#endif
926 927 928 929 930 931 932 933 934 935
#ifdef CONFIG_RCU_TORTURE_TEST
	{
		.ctl_name       = CTL_UNNUMBERED,
		.procname       = "rcutorture_runnable",
		.data           = &rcutorture_runnable,
		.maxlen         = sizeof(int),
		.mode           = 0644,
		.proc_handler   = &proc_dointvec,
	},
#endif
936 937 938 939 940 941 942 943
#ifdef CONFIG_SLOW_WORK
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "slow-work",
		.mode		= 0555,
		.child		= slow_work_sysctls,
	},
#endif
944 945 946
#ifdef CONFIG_PERF_COUNTERS
	{
		.ctl_name	= CTL_UNNUMBERED,
947 948 949
		.procname	= "perf_counter_paranoid",
		.data		= &sysctl_perf_counter_paranoid,
		.maxlen		= sizeof(sysctl_perf_counter_paranoid),
950 951 952
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
953 954 955 956 957 958 959 960
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "perf_counter_mlock_kb",
		.data		= &sysctl_perf_counter_mlock,
		.maxlen		= sizeof(sysctl_perf_counter_mlock),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
961 962
	{
		.ctl_name	= CTL_UNNUMBERED,
963 964 965
		.procname	= "perf_counter_max_sample_rate",
		.data		= &sysctl_perf_counter_sample_rate,
		.maxlen		= sizeof(sysctl_perf_counter_sample_rate),
966 967 968
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
969
#endif
970 971 972 973
/*
 * NOTE: do not add new entries to this table unless you have read
 * Documentation/sysctl/ctl_unnumbered.txt
 */
Linus Torvalds's avatar
Linus Torvalds committed
974 975 976
	{ .ctl_name = 0 }
};

977
static struct ctl_table vm_table[] = {
Linus Torvalds's avatar
Linus Torvalds committed
978 979 980 981 982 983 984 985
	{
		.ctl_name	= VM_OVERCOMMIT_MEMORY,
		.procname	= "overcommit_memory",
		.data		= &sysctl_overcommit_memory,
		.maxlen		= sizeof(sysctl_overcommit_memory),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
986 987 988 989 990 991 992 993
	{
		.ctl_name	= VM_PANIC_ON_OOM,
		.procname	= "panic_on_oom",
		.data		= &sysctl_panic_on_oom,
		.maxlen		= sizeof(sysctl_panic_on_oom),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
994 995 996 997 998 999 1000 1001
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "oom_kill_allocating_task",
		.data		= &sysctl_oom_kill_allocating_task,
		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
1002 1003 1004 1005 1006 1007 1008 1009
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "oom_dump_tasks",
		.data		= &sysctl_oom_dump_tasks,
		.maxlen		= sizeof(sysctl_oom_dump_tasks),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
Linus Torvalds's avatar
Linus Torvalds committed
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
	{
		.ctl_name	= VM_OVERCOMMIT_RATIO,
		.procname	= "overcommit_ratio",
		.data		= &sysctl_overcommit_ratio,
		.maxlen		= sizeof(sysctl_overcommit_ratio),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= VM_PAGE_CLUSTER,
		.procname	= "page-cluster", 
		.data		= &page_cluster,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= VM_DIRTY_BACKGROUND,
		.procname	= "dirty_background_ratio",
		.data		= &dirty_background_ratio,
		.maxlen		= sizeof(dirty_background_ratio),
		.mode		= 0644,
1032
		.proc_handler	= &dirty_background_ratio_handler,
Linus Torvalds's avatar
Linus Torvalds committed
1033 1034 1035 1036
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one_hundred,
	},
1037 1038 1039 1040 1041 1042 1043 1044
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "dirty_background_bytes",
		.data		= &dirty_background_bytes,
		.maxlen		= sizeof(dirty_background_bytes),
		.mode		= 0644,
		.proc_handler	= &dirty_background_bytes_handler,
		.strategy	= &sysctl_intvec,
1045
		.extra1		= &one_ul,
1046
	},
Linus Torvalds's avatar
Linus Torvalds committed
1047 1048 1049 1050 1051 1052
	{
		.ctl_name	= VM_DIRTY_RATIO,
		.procname	= "dirty_ratio",
		.data		= &vm_dirty_ratio,
		.maxlen		= sizeof(vm_dirty_ratio),
		.mode		= 0644,
1053
		.proc_handler	= &dirty_ratio_handler,
Linus Torvalds's avatar
Linus Torvalds committed
1054 1055 1056 1057
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one_hundred,
	},
1058 1059 1060 1061 1062 1063 1064 1065
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "dirty_bytes",
		.data		= &vm_dirty_bytes,
		.maxlen		= sizeof(vm_dirty_bytes),
		.mode		= 0644,
		.proc_handler	= &dirty_bytes_handler,
		.strategy	= &sysctl_intvec,
1066
		.extra1		= &dirty_bytes_min,
1067
	},
Linus Torvalds's avatar
Linus Torvalds committed
1068 1069
	{
		.procname	= "dirty_writeback_centisecs",
1070 1071
		.data		= &dirty_writeback_interval,
		.maxlen		= sizeof(dirty_writeback_interval),
Linus Torvalds's avatar
Linus Torvalds committed
1072 1073 1074 1075 1076
		.mode		= 0644,
		.proc_handler	= &dirty_writeback_centisecs_handler,
	},
	{
		.procname	= "dirty_expire_centisecs",
1077 1078
		.data		= &dirty_expire_interval,
		.maxlen		= sizeof(dirty_expire_interval),
Linus Torvalds's avatar
Linus Torvalds committed
1079
		.mode		= 0644,
1080
		.proc_handler	= &proc_dointvec,
Linus Torvalds's avatar
Linus Torvalds committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
	},
	{
		.ctl_name	= VM_NR_PDFLUSH_THREADS,
		.procname	= "nr_pdflush_threads",
		.data		= &nr_pdflush_threads,
		.maxlen		= sizeof nr_pdflush_threads,
		.mode		= 0444 /* read-only*/,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= VM_SWAPPINESS,
		.procname	= "swappiness",
		.data		= &vm_swappiness,
		.maxlen		= sizeof(vm_swappiness),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one_hundred,
	},
#ifdef CONFIG_HUGETLB_PAGE
	 {
		.procname	= "nr_hugepages",
1104
		.data		= NULL,
Linus Torvalds's avatar
Linus Torvalds committed
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118
		.maxlen		= sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= &hugetlb_sysctl_handler,
		.extra1		= (void *)&hugetlb_zero,
		.extra2		= (void *)&hugetlb_infinity,
	 },
	 {
		.ctl_name	= VM_HUGETLB_GROUP,
		.procname	= "hugetlb_shm_group",
		.data		= &sysctl_hugetlb_shm_group,
		.maxlen		= sizeof(gid_t),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	 },
1119 1120 1121 1122 1123 1124 1125 1126
	 {
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "hugepages_treat_as_movable",
		.data		= &hugepages_treat_as_movable,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &hugetlb_treat_movable_handler,
	},
1127 1128 1129
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "nr_overcommit_hugepages",
1130 1131
		.data		= NULL,
		.maxlen		= sizeof(unsigned long),
1132
		.mode		= 0644,
1133
		.proc_handler	= &hugetlb_overcommit_handler,
1134 1135
		.extra1		= (void *)&hugetlb_zero,
		.extra2		= (void *)&hugetlb_infinity,
1136
	},
Linus Torvalds's avatar
Linus Torvalds committed
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
#endif
	{
		.ctl_name	= VM_LOWMEM_RESERVE_RATIO,
		.procname	= "lowmem_reserve_ratio",
		.data		= &sysctl_lowmem_reserve_ratio,
		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
		.mode		= 0644,
		.proc_handler	= &lowmem_reserve_ratio_sysctl_handler,
		.strategy	= &sysctl_intvec,
	},
Andrew Morton's avatar
Andrew Morton committed
1147 1148 1149 1150 1151 1152 1153 1154 1155
	{
		.ctl_name	= VM_DROP_PAGECACHE,
		.procname	= "drop_caches",
		.data		= &sysctl_drop_caches,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= drop_caches_sysctl_handler,
		.strategy	= &sysctl_intvec,
	},
Linus Torvalds's avatar
Linus Torvalds committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
	{
		.ctl_name	= VM_MIN_FREE_KBYTES,
		.procname	= "min_free_kbytes",
		.data		= &min_free_kbytes,
		.maxlen		= sizeof(min_free_kbytes),
		.mode		= 0644,
		.proc_handler	= &min_free_kbytes_sysctl_handler,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
	{
		.ctl_name	= VM_PERCPU_PAGELIST_FRACTION,
		.procname	= "percpu_pagelist_fraction",
		.data		= &percpu_pagelist_fraction,
		.maxlen		= sizeof(percpu_pagelist_fraction),
		.mode		= 0644,
		.proc_handler	= &percpu_pagelist_fraction_sysctl_handler,
		.strategy	= &sysctl_intvec,
		.extra1		= &min_percpu_pagelist_fract,
	},
Linus Torvalds's avatar
Linus Torvalds committed
1176 1177 1178 1179 1180 1181 1182 1183 1184
#ifdef CONFIG_MMU
	{
		.ctl_name	= VM_MAX_MAP_COUNT,
		.procname	= "max_map_count",
		.data		= &sysctl_max_map_count,
		.maxlen		= sizeof(sysctl_max_map_count),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec
	},
1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
#else
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "nr_trim_pages",
		.data		= &sysctl_nr_trim_pages,
		.maxlen		= sizeof(sysctl_nr_trim_pages),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
Linus Torvalds's avatar
Linus Torvalds committed
1196 1197 1198 1199 1200 1201 1202
#endif
	{
		.ctl_name	= VM_LAPTOP_MODE,
		.procname	= "laptop_mode",
		.data		= &laptop_mode,
		.maxlen		= sizeof(laptop_mode),
		.mode		= 0644,
1203 1204
		.proc_handler	= &proc_dointvec_jiffies,
		.strategy	= &sysctl_jiffies,
Linus Torvalds's avatar
Linus Torvalds committed
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237
	},
	{
		.ctl_name	= VM_BLOCK_DUMP,
		.procname	= "block_dump",
		.data		= &block_dump,
		.maxlen		= sizeof(block_dump),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
	{
		.ctl_name	= VM_VFS_CACHE_PRESSURE,
		.procname	= "vfs_cache_pressure",
		.data		= &sysctl_vfs_cache_pressure,
		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
	{
		.ctl_name	= VM_LEGACY_VA_LAYOUT,
		.procname	= "legacy_va_layout",
		.data		= &sysctl_legacy_va_layout,
		.maxlen		= sizeof(sysctl_legacy_va_layout),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
#endif
1238 1239 1240 1241 1242 1243 1244 1245
#ifdef CONFIG_NUMA
	{
		.ctl_name	= VM_ZONE_RECLAIM_MODE,
		.procname	= "zone_reclaim_mode",
		.data		= &zone_reclaim_mode,
		.maxlen		= sizeof(zone_reclaim_mode),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
1246 1247
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
1248
	},
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
	{
		.ctl_name	= VM_MIN_UNMAPPED,
		.procname	= "min_unmapped_ratio",
		.data		= &sysctl_min_unmapped_ratio,
		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
		.mode		= 0644,
		.proc_handler	= &sysctl_min_unmapped_ratio_sysctl_handler,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one_hundred,
	},
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
	{
		.ctl_name	= VM_MIN_SLAB,
		.procname	= "min_slab_ratio",
		.data		= &sysctl_min_slab_ratio,
		.maxlen		= sizeof(sysctl_min_slab_ratio),
		.mode		= 0644,
		.proc_handler	= &sysctl_min_slab_ratio_sysctl_handler,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one_hundred,
	},
1271
#endif
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
#ifdef CONFIG_SMP
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "stat_interval",
		.data		= &sysctl_stat_interval,
		.maxlen		= sizeof(sysctl_stat_interval),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_jiffies,
		.strategy	= &sysctl_jiffies,
	},
#endif
1283 1284 1285 1286 1287 1288 1289 1290
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "mmap_min_addr",
		.data		= &mmap_min_addr,
		.maxlen         = sizeof(unsigned long),
		.mode		= 0644,
		.proc_handler	= &proc_doulongvec_minmax,
	},
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
#ifdef CONFIG_NUMA
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "numa_zonelist_order",
		.data		= &numa_zonelist_order,
		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
		.mode		= 0644,
		.proc_handler	= &numa_zonelist_order_handler,
		.strategy	= &sysctl_string,
	},
#endif
1302
#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1303
   (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
	{
		.ctl_name	= VM_VDSO_ENABLED,
		.procname	= "vdso_enabled",
		.data		= &vdso_enabled,
		.maxlen		= sizeof(vdso_enabled),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
	},
Linus Torvalds's avatar
Linus Torvalds committed
1314
#endif
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
#ifdef CONFIG_HIGHMEM
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "highmem_is_dirtyable",
		.data		= &vm_highmem_is_dirtyable,
		.maxlen		= sizeof(vm_highmem_is_dirtyable),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &one,
	},
#endif
1328 1329 1330 1331 1332 1333 1334 1335
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "scan_unevictable_pages",
		.data		= &scan_unevictable_pages,
		.maxlen		= sizeof(scan_unevictable_pages),
		.mode		= 0644,
		.proc_handler	= &scan_unevictable_handler,
	},
1336 1337 1338 1339
/*
 * NOTE: do not add new entries to this table unless you have read
 * Documentation/sysctl/ctl_unnumbered.txt
 */
Linus Torvalds's avatar
Linus Torvalds committed
1340 1341 1342
	{ .ctl_name = 0 }
};

1343
#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1344
static struct ctl_table binfmt_misc_table[] = {
1345 1346 1347 1348
	{ .ctl_name = 0 }
};
#endif

1349
static struct ctl_table fs_table[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
	{
		.ctl_name	= FS_NRINODE,
		.procname	= "inode-nr",
		.data		= &inodes_stat,
		.maxlen		= 2*sizeof(int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= FS_STATINODE,
		.procname	= "inode-state",
		.data		= &inodes_stat,
		.maxlen		= 7*sizeof(int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
	{
		.procname	= "file-nr",
		.data		= &files_stat,
		.maxlen		= 3*sizeof(int),
		.mode		= 0444,
Dipankar Sarma's avatar
Dipankar Sarma committed
1371
		.proc_handler	= &proc_nr_files,
Linus Torvalds's avatar
Linus Torvalds committed
1372 1373 1374 1375 1376 1377 1378 1379 1380
	},
	{
		.ctl_name	= FS_MAXFILE,
		.procname	= "file-max",
		.data		= &files_stat.max_files,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
1381 1382 1383 1384 1385 1386
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "nr_open",
		.data		= &sysctl_nr_open,
		.maxlen		= sizeof(int),
		.mode		= 0644,
1387 1388 1389
		.proc_handler	= &proc_dointvec_minmax,
		.extra1		= &sysctl_nr_open_min,
		.extra2		= &sysctl_nr_open_max,
1390
	},
Linus Torvalds's avatar
Linus Torvalds committed
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
	{
		.ctl_name	= FS_DENTRY,
		.procname	= "dentry-state",
		.data		= &dentry_stat,
		.maxlen		= 6*sizeof(int),
		.mode		= 0444,
		.proc_handler	= &proc_dointvec,
	},
	{
		.ctl_name	= FS_OVERFLOWUID,
		.procname	= "overflowuid",
		.data		= &fs_overflowuid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &minolduid,
		.extra2		= &maxolduid,
	},
	{
		.ctl_name	= FS_OVERFLOWGID,
		.procname	= "overflowgid",
		.data		= &fs_overflowgid,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &minolduid,
		.extra2		= &maxolduid,
	},
1421
#ifdef CONFIG_FILE_LOCKING
Linus Torvalds's avatar
Linus Torvalds committed
1422 1423 1424 1425 1426 1427 1428 1429
	{
		.ctl_name	= FS_LEASES,
		.procname	= "leases-enable",
		.data		= &leases_enable,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
1430
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
#ifdef CONFIG_DNOTIFY
	{
		.ctl_name	= FS_DIR_NOTIFY,
		.procname	= "dir-notify-enable",
		.data		= &dir_notify_enable,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
#endif
#ifdef CONFIG_MMU
1442
#ifdef CONFIG_FILE_LOCKING
Linus Torvalds's avatar
Linus Torvalds committed
1443 1444 1445 1446 1447 1448
	{
		.ctl_name	= FS_LEASE_TIME,
		.procname	= "lease-break-time",
		.data		= &lease_break_time,
		.maxlen		= sizeof(int),
		.mode		= 0644,
1449
		.proc_handler	= &proc_dointvec,
Linus Torvalds's avatar
Linus Torvalds committed
1450
	},
1451
#endif
Thomas Petazzoni's avatar
Thomas Petazzoni committed
1452
#ifdef CONFIG_AIO
Linus Torvalds's avatar
Linus Torvalds committed
1453 1454 1455 1456 1457
	{
		.procname	= "aio-nr",
		.data		= &aio_nr,
		.maxlen		= sizeof(aio_nr),
		.mode		= 0444,
1458
		.proc_handler	= &proc_doulongvec_minmax,
Linus Torvalds's avatar
Linus Torvalds committed
1459 1460 1461 1462 1463 1464
	},
	{
		.procname	= "aio-max-nr",
		.data		= &aio_max_nr,
		.maxlen		= sizeof(aio_max_nr),
		.mode		= 0644,
1465
		.proc_handler	= &proc_doulongvec_minmax,
Linus Torvalds's avatar
Linus Torvalds committed
1466
	},
Thomas Petazzoni's avatar
Thomas Petazzoni committed
1467
#endif /* CONFIG_AIO */
1468
#ifdef CONFIG_INOTIFY_USER
Robert Love's avatar
Robert Love committed
1469 1470 1471 1472 1473 1474 1475
	{
		.ctl_name	= FS_INOTIFY,
		.procname	= "inotify",
		.mode		= 0555,
		.child		= inotify_table,
	},
#endif	
1476 1477 1478 1479 1480 1481 1482
#ifdef CONFIG_EPOLL
	{
		.procname	= "epoll",
		.mode		= 0555,
		.child		= epoll_table,
	},
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1483
#endif
Alan Cox's avatar
Alan Cox committed
1484 1485 1486 1487 1488 1489
	{
		.ctl_name	= KERN_SETUID_DUMPABLE,
		.procname	= "suid_dumpable",
		.data		= &suid_dumpable,
		.maxlen		= sizeof(int),
		.mode		= 0644,
1490 1491 1492 1493
		.proc_handler	= &proc_dointvec_minmax,
		.strategy	= &sysctl_intvec,
		.extra1		= &zero,
		.extra2		= &two,
Alan Cox's avatar
Alan Cox committed
1494
	},
1495 1496 1497 1498 1499 1500 1501 1502
#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "binfmt_misc",
		.mode		= 0555,
		.child		= binfmt_misc_table,
	},
#endif
1503 1504 1505 1506
/*
 * NOTE: do not add new entries to this table unless you have read
 * Documentation/sysctl/ctl_unnumbered.txt
 */
Linus Torvalds's avatar
Linus Torvalds committed
1507 1508 1509
	{ .ctl_name = 0 }
};

1510
static struct ctl_table debug_table[] = {
1511
#if defined(CONFIG_X86) || defined(CONFIG_PPC)
1512 1513 1514 1515 1516 1517 1518 1519 1520
	{
		.ctl_name	= CTL_UNNUMBERED,
		.procname	= "exception-trace",
		.data		= &show_unhandled_signals,
		.maxlen		= sizeof(int),
		.mode		= 0644,
		.proc_handler	= proc_dointvec
	},
#endif
Linus Torvalds's avatar
Linus Torvalds committed
1521 1522 1523
	{ .ctl_name = 0 }
};

1524
static struct ctl_table dev_table[] = {
Linus Torvalds's avatar
Linus Torvalds committed
1525
	{ .ctl_name = 0 }
Robert Love's avatar
Robert Love committed
1526
};
Linus Torvalds's avatar
Linus Torvalds committed
1527

1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
static DEFINE_SPINLOCK(sysctl_lock);

/* called under sysctl_lock */
static int use_table(struct ctl_table_header *p)
{
	if (unlikely(p->unregistering))
		return 0;
	p->used++;
	return 1;
}

/* called under sysctl_lock */
static void unuse_table(struct ctl_table_header *p)
{
	if (!--p->used)
		if (unlikely(p->unregistering))
			complete(p->unregistering);
}

/* called under sysctl_lock, will reacquire if has to wait */
static void start_unregistering(struct ctl_table_header *p)
{
	/*
	 * if p->used is 0, nobody will ever touch that entry again;
	 * we'll eliminate all paths to it before dropping sysctl_lock
	 */
	if (unlikely(p->used)) {
		struct completion wait;
		init_completion(&wait);
		p->unregistering = &wait;
		spin_unlock(&sysctl_lock);
		wait_for_completion(&wait);
		spin_lock(&sysctl_lock);
1561 1562 1563
	} else {
		/* anything non-NULL; we'll never dereference it */
		p->unregistering = ERR_PTR(-EINVAL);
1564 1565 1566 1567 1568 1569 1570 1571
	}
	/*
	 * do not remove from the list until nobody holds it; walking the
	 * list in do_sysctl() relies on that.
	 */
	list_del_init(&p->ctl_entry);
}

1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
void sysctl_head_get(struct ctl_table_header *head)
{
	spin_lock(&sysctl_lock);
	head->count++;
	spin_unlock(&sysctl_lock);
}

void sysctl_head_put(struct ctl_table_header *head)
{
	spin_lock(&sysctl_lock);
	if (!--head->count)
		kfree(head);
	spin_unlock(&sysctl_lock);
}

struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
{
	if (!head)
		BUG();
	spin_lock(&sysctl_lock);
	if (!use_table(head))
		head = ERR_PTR(-ENOENT);
	spin_unlock(&sysctl_lock);
	return head;
}

1598 1599 1600 1601 1602 1603 1604 1605 1606
void sysctl_head_finish(struct ctl_table_header *head)
{
	if (!head)
		return;
	spin_lock(&sysctl_lock);
	unuse_table(head);
	spin_unlock(&sysctl_lock);
}

1607 1608 1609 1610 1611 1612 1613 1614 1615
static struct ctl_table_set *
lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
{
	struct ctl_table_set *set = &root->default_set;
	if (root->lookup)
		set = root->lookup(root, namespaces);
	return set;
}

1616 1617
static struct list_head *
lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1618
{
1619 1620
	struct ctl_table_set *set = lookup_header_set(root, namespaces);
	return &set->list;
1621 1622 1623 1624 1625 1626 1627
}

struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
					    struct ctl_table_header *prev)
{
	struct ctl_table_root *root;
	struct list_head *header_list;
1628 1629
	struct ctl_table_header *head;
	struct list_head *tmp;
1630

1631 1632
	spin_lock(&sysctl_lock);
	if (prev) {
1633
		head = prev;
1634 1635 1636 1637 1638 1639 1640 1641