aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sysctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r--kernel/sysctl.c613
1 files changed, 450 insertions, 163 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8686b0f5fc12..997080f00e0b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -37,6 +37,7 @@
37#include <linux/highuid.h> 37#include <linux/highuid.h>
38#include <linux/writeback.h> 38#include <linux/writeback.h>
39#include <linux/ratelimit.h> 39#include <linux/ratelimit.h>
40#include <linux/compaction.h>
40#include <linux/hugetlb.h> 41#include <linux/hugetlb.h>
41#include <linux/initrd.h> 42#include <linux/initrd.h>
42#include <linux/key.h> 43#include <linux/key.h>
@@ -52,6 +53,7 @@
52#include <linux/slow-work.h> 53#include <linux/slow-work.h>
53#include <linux/perf_event.h> 54#include <linux/perf_event.h>
54#include <linux/kprobes.h> 55#include <linux/kprobes.h>
56#include <linux/pipe_fs_i.h>
55 57
56#include <asm/uaccess.h> 58#include <asm/uaccess.h>
57#include <asm/processor.h> 59#include <asm/processor.h>
@@ -163,6 +165,27 @@ static int proc_taint(struct ctl_table *table, int write,
163 void __user *buffer, size_t *lenp, loff_t *ppos); 165 void __user *buffer, size_t *lenp, loff_t *ppos);
164#endif 166#endif
165 167
168#ifdef CONFIG_MAGIC_SYSRQ
169static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
170
171static int sysrq_sysctl_handler(ctl_table *table, int write,
172 void __user *buffer, size_t *lenp,
173 loff_t *ppos)
174{
175 int error;
176
177 error = proc_dointvec(table, write, buffer, lenp, ppos);
178 if (error)
179 return error;
180
181 if (write)
182 sysrq_toggle_support(__sysrq_enabled);
183
184 return 0;
185}
186
187#endif
188
166static struct ctl_table root_table[]; 189static struct ctl_table root_table[];
167static struct ctl_table_root sysctl_table_root; 190static struct ctl_table_root sysctl_table_root;
168static struct ctl_table_header root_table_header = { 191static struct ctl_table_header root_table_header = {
@@ -240,6 +263,11 @@ static int min_sched_shares_ratelimit = 100000; /* 100 usec */
240static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */ 263static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
241#endif 264#endif
242 265
266#ifdef CONFIG_COMPACTION
267static int min_extfrag_threshold;
268static int max_extfrag_threshold = 1000;
269#endif
270
243static struct ctl_table kern_table[] = { 271static struct ctl_table kern_table[] = {
244 { 272 {
245 .procname = "sched_child_runs_first", 273 .procname = "sched_child_runs_first",
@@ -567,7 +595,7 @@ static struct ctl_table kern_table[] = {
567 .data = &__sysrq_enabled, 595 .data = &__sysrq_enabled,
568 .maxlen = sizeof (int), 596 .maxlen = sizeof (int),
569 .mode = 0644, 597 .mode = 0644,
570 .proc_handler = proc_dointvec, 598 .proc_handler = sysrq_sysctl_handler,
571 }, 599 },
572#endif 600#endif
573#ifdef CONFIG_PROC_SYSCTL 601#ifdef CONFIG_PROC_SYSCTL
@@ -621,7 +649,7 @@ static struct ctl_table kern_table[] = {
621#endif 649#endif
622 { 650 {
623 .procname = "userprocess_debug", 651 .procname = "userprocess_debug",
624 .data = &sysctl_userprocess_debug, 652 .data = &show_unhandled_signals,
625 .maxlen = sizeof(int), 653 .maxlen = sizeof(int),
626 .mode = 0644, 654 .mode = 0644,
627 .proc_handler = proc_dointvec, 655 .proc_handler = proc_dointvec,
@@ -1099,6 +1127,25 @@ static struct ctl_table vm_table[] = {
1099 .mode = 0644, 1127 .mode = 0644,
1100 .proc_handler = drop_caches_sysctl_handler, 1128 .proc_handler = drop_caches_sysctl_handler,
1101 }, 1129 },
1130#ifdef CONFIG_COMPACTION
1131 {
1132 .procname = "compact_memory",
1133 .data = &sysctl_compact_memory,
1134 .maxlen = sizeof(int),
1135 .mode = 0200,
1136 .proc_handler = sysctl_compaction_handler,
1137 },
1138 {
1139 .procname = "extfrag_threshold",
1140 .data = &sysctl_extfrag_threshold,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = sysctl_extfrag_handler,
1144 .extra1 = &min_extfrag_threshold,
1145 .extra2 = &max_extfrag_threshold,
1146 },
1147
1148#endif /* CONFIG_COMPACTION */
1102 { 1149 {
1103 .procname = "min_free_kbytes", 1150 .procname = "min_free_kbytes",
1104 .data = &min_free_kbytes, 1151 .data = &min_free_kbytes,
@@ -1423,6 +1470,14 @@ static struct ctl_table fs_table[] = {
1423 .child = binfmt_misc_table, 1470 .child = binfmt_misc_table,
1424 }, 1471 },
1425#endif 1472#endif
1473 {
1474 .procname = "pipe-max-pages",
1475 .data = &pipe_max_pages,
1476 .maxlen = sizeof(int),
1477 .mode = 0644,
1478 .proc_handler = &proc_dointvec_minmax,
1479 .extra1 = &two,
1480 },
1426/* 1481/*
1427 * NOTE: do not add new entries to this table unless you have read 1482 * NOTE: do not add new entries to this table unless you have read
1428 * Documentation/sysctl/ctl_unnumbered.txt 1483 * Documentation/sysctl/ctl_unnumbered.txt
@@ -1431,7 +1486,8 @@ static struct ctl_table fs_table[] = {
1431}; 1486};
1432 1487
1433static struct ctl_table debug_table[] = { 1488static struct ctl_table debug_table[] = {
1434#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) 1489#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1490 defined(CONFIG_S390)
1435 { 1491 {
1436 .procname = "exception-trace", 1492 .procname = "exception-trace",
1437 .data = &show_unhandled_signals, 1493 .data = &show_unhandled_signals,
@@ -2040,8 +2096,132 @@ int proc_dostring(struct ctl_table *table, int write,
2040 buffer, lenp, ppos); 2096 buffer, lenp, ppos);
2041} 2097}
2042 2098
2099static size_t proc_skip_spaces(char **buf)
2100{
2101 size_t ret;
2102 char *tmp = skip_spaces(*buf);
2103 ret = tmp - *buf;
2104 *buf = tmp;
2105 return ret;
2106}
2107
2108static void proc_skip_char(char **buf, size_t *size, const char v)
2109{
2110 while (*size) {
2111 if (**buf != v)
2112 break;
2113 (*size)--;
2114 (*buf)++;
2115 }
2116}
2117
2118#define TMPBUFLEN 22
2119/**
2120 * proc_get_long - reads an ASCII formatted integer from a user buffer
2121 *
2122 * @buf: a kernel buffer
2123 * @size: size of the kernel buffer
2124 * @val: this is where the number will be stored
2125 * @neg: set to %TRUE if number is negative
2126 * @perm_tr: a vector which contains the allowed trailers
2127 * @perm_tr_len: size of the perm_tr vector
2128 * @tr: pointer to store the trailer character
2129 *
2130 * In case of success %0 is returned and @buf and @size are updated with
2131 * the amount of bytes read. If @tr is non-NULL and a trailing
2132 * character exists (size is non-zero after returning from this
2133 * function), @tr is updated with the trailing character.
2134 */
2135static int proc_get_long(char **buf, size_t *size,
2136 unsigned long *val, bool *neg,
2137 const char *perm_tr, unsigned perm_tr_len, char *tr)
2138{
2139 int len;
2140 char *p, tmp[TMPBUFLEN];
2141
2142 if (!*size)
2143 return -EINVAL;
2144
2145 len = *size;
2146 if (len > TMPBUFLEN - 1)
2147 len = TMPBUFLEN - 1;
2148
2149 memcpy(tmp, *buf, len);
2150
2151 tmp[len] = 0;
2152 p = tmp;
2153 if (*p == '-' && *size > 1) {
2154 *neg = true;
2155 p++;
2156 } else
2157 *neg = false;
2158 if (!isdigit(*p))
2159 return -EINVAL;
2160
2161 *val = simple_strtoul(p, &p, 0);
2162
2163 len = p - tmp;
2164
2165 /* We don't know if the next char is whitespace thus we may accept
2166 * invalid integers (e.g. 1234...a) or two integers instead of one
2167 * (e.g. 123...1). So lets not allow such large numbers. */
2168 if (len == TMPBUFLEN - 1)
2169 return -EINVAL;
2170
2171 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2172 return -EINVAL;
2173
2174 if (tr && (len < *size))
2175 *tr = *p;
2176
2177 *buf += len;
2178 *size -= len;
2179
2180 return 0;
2181}
2182
2183/**
2184 * proc_put_long - converts an integer to a decimal ASCII formatted string
2185 *
2186 * @buf: the user buffer
2187 * @size: the size of the user buffer
2188 * @val: the integer to be converted
2189 * @neg: sign of the number, %TRUE for negative
2190 *
2191 * In case of success %0 is returned and @buf and @size are updated with
2192 * the amount of bytes written.
2193 */
2194static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2195 bool neg)
2196{
2197 int len;
2198 char tmp[TMPBUFLEN], *p = tmp;
2199
2200 sprintf(p, "%s%lu", neg ? "-" : "", val);
2201 len = strlen(tmp);
2202 if (len > *size)
2203 len = *size;
2204 if (copy_to_user(*buf, tmp, len))
2205 return -EFAULT;
2206 *size -= len;
2207 *buf += len;
2208 return 0;
2209}
2210#undef TMPBUFLEN
2211
2212static int proc_put_char(void __user **buf, size_t *size, char c)
2213{
2214 if (*size) {
2215 char __user **buffer = (char __user **)buf;
2216 if (put_user(c, *buffer))
2217 return -EFAULT;
2218 (*size)--, (*buffer)++;
2219 *buf = *buffer;
2220 }
2221 return 0;
2222}
2043 2223
2044static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 2224static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2045 int *valp, 2225 int *valp,
2046 int write, void *data) 2226 int write, void *data)
2047{ 2227{
@@ -2050,33 +2230,31 @@ static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2050 } else { 2230 } else {
2051 int val = *valp; 2231 int val = *valp;
2052 if (val < 0) { 2232 if (val < 0) {
2053 *negp = -1; 2233 *negp = true;
2054 *lvalp = (unsigned long)-val; 2234 *lvalp = (unsigned long)-val;
2055 } else { 2235 } else {
2056 *negp = 0; 2236 *negp = false;
2057 *lvalp = (unsigned long)val; 2237 *lvalp = (unsigned long)val;
2058 } 2238 }
2059 } 2239 }
2060 return 0; 2240 return 0;
2061} 2241}
2062 2242
2243static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2244
2063static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 2245static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2064 int write, void __user *buffer, 2246 int write, void __user *buffer,
2065 size_t *lenp, loff_t *ppos, 2247 size_t *lenp, loff_t *ppos,
2066 int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2248 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2067 int write, void *data), 2249 int write, void *data),
2068 void *data) 2250 void *data)
2069{ 2251{
2070#define TMPBUFLEN 21 2252 int *i, vleft, first = 1, err = 0;
2071 int *i, vleft, first = 1, neg; 2253 unsigned long page = 0;
2072 unsigned long lval; 2254 size_t left;
2073 size_t left, len; 2255 char *kbuf;
2074 2256
2075 char buf[TMPBUFLEN], *p; 2257 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2076 char __user *s = buffer;
2077
2078 if (!tbl_data || !table->maxlen || !*lenp ||
2079 (*ppos && !write)) {
2080 *lenp = 0; 2258 *lenp = 0;
2081 return 0; 2259 return 0;
2082 } 2260 }
@@ -2088,89 +2266,71 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2088 if (!conv) 2266 if (!conv)
2089 conv = do_proc_dointvec_conv; 2267 conv = do_proc_dointvec_conv;
2090 2268
2269 if (write) {
2270 if (left > PAGE_SIZE - 1)
2271 left = PAGE_SIZE - 1;
2272 page = __get_free_page(GFP_TEMPORARY);
2273 kbuf = (char *) page;
2274 if (!kbuf)
2275 return -ENOMEM;
2276 if (copy_from_user(kbuf, buffer, left)) {
2277 err = -EFAULT;
2278 goto free;
2279 }
2280 kbuf[left] = 0;
2281 }
2282
2091 for (; left && vleft--; i++, first=0) { 2283 for (; left && vleft--; i++, first=0) {
2284 unsigned long lval;
2285 bool neg;
2286
2092 if (write) { 2287 if (write) {
2093 while (left) { 2288 left -= proc_skip_spaces(&kbuf);
2094 char c; 2289
2095 if (get_user(c, s))
2096 return -EFAULT;
2097 if (!isspace(c))
2098 break;
2099 left--;
2100 s++;
2101 }
2102 if (!left) 2290 if (!left)
2103 break; 2291 break;
2104 neg = 0; 2292 err = proc_get_long(&kbuf, &left, &lval, &neg,
2105 len = left; 2293 proc_wspace_sep,
2106 if (len > sizeof(buf) - 1) 2294 sizeof(proc_wspace_sep), NULL);
2107 len = sizeof(buf) - 1; 2295 if (err)
2108 if (copy_from_user(buf, s, len))
2109 return -EFAULT;
2110 buf[len] = 0;
2111 p = buf;
2112 if (*p == '-' && left > 1) {
2113 neg = 1;
2114 p++;
2115 }
2116 if (*p < '0' || *p > '9')
2117 break; 2296 break;
2118 2297 if (conv(&neg, &lval, i, 1, data)) {
2119 lval = simple_strtoul(p, &p, 0); 2298 err = -EINVAL;
2120
2121 len = p-buf;
2122 if ((len < left) && *p && !isspace(*p))
2123 break;
2124 s += len;
2125 left -= len;
2126
2127 if (conv(&neg, &lval, i, 1, data))
2128 break; 2299 break;
2300 }
2129 } else { 2301 } else {
2130 p = buf; 2302 if (conv(&neg, &lval, i, 0, data)) {
2303 err = -EINVAL;
2304 break;
2305 }
2131 if (!first) 2306 if (!first)
2132 *p++ = '\t'; 2307 err = proc_put_char(&buffer, &left, '\t');
2133 2308 if (err)
2134 if (conv(&neg, &lval, i, 0, data)) 2309 break;
2310 err = proc_put_long(&buffer, &left, lval, neg);
2311 if (err)
2135 break; 2312 break;
2136
2137 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2138 len = strlen(buf);
2139 if (len > left)
2140 len = left;
2141 if(copy_to_user(s, buf, len))
2142 return -EFAULT;
2143 left -= len;
2144 s += len;
2145 } 2313 }
2146 } 2314 }
2147 2315
2148 if (!write && !first && left) { 2316 if (!write && !first && left && !err)
2149 if(put_user('\n', s)) 2317 err = proc_put_char(&buffer, &left, '\n');
2150 return -EFAULT; 2318 if (write && !err && left)
2151 left--, s++; 2319 left -= proc_skip_spaces(&kbuf);
2152 } 2320free:
2153 if (write) { 2321 if (write) {
2154 while (left) { 2322 free_page(page);
2155 char c; 2323 if (first)
2156 if (get_user(c, s++)) 2324 return err ? : -EINVAL;
2157 return -EFAULT;
2158 if (!isspace(c))
2159 break;
2160 left--;
2161 }
2162 } 2325 }
2163 if (write && first)
2164 return -EINVAL;
2165 *lenp -= left; 2326 *lenp -= left;
2166 *ppos += *lenp; 2327 *ppos += *lenp;
2167 return 0; 2328 return err;
2168#undef TMPBUFLEN
2169} 2329}
2170 2330
2171static int do_proc_dointvec(struct ctl_table *table, int write, 2331static int do_proc_dointvec(struct ctl_table *table, int write,
2172 void __user *buffer, size_t *lenp, loff_t *ppos, 2332 void __user *buffer, size_t *lenp, loff_t *ppos,
2173 int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2333 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2174 int write, void *data), 2334 int write, void *data),
2175 void *data) 2335 void *data)
2176{ 2336{
@@ -2238,8 +2398,8 @@ struct do_proc_dointvec_minmax_conv_param {
2238 int *max; 2398 int *max;
2239}; 2399};
2240 2400
2241static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 2401static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2242 int *valp, 2402 int *valp,
2243 int write, void *data) 2403 int write, void *data)
2244{ 2404{
2245 struct do_proc_dointvec_minmax_conv_param *param = data; 2405 struct do_proc_dointvec_minmax_conv_param *param = data;
@@ -2252,10 +2412,10 @@ static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2252 } else { 2412 } else {
2253 int val = *valp; 2413 int val = *valp;
2254 if (val < 0) { 2414 if (val < 0) {
2255 *negp = -1; 2415 *negp = true;
2256 *lvalp = (unsigned long)-val; 2416 *lvalp = (unsigned long)-val;
2257 } else { 2417 } else {
2258 *negp = 0; 2418 *negp = false;
2259 *lvalp = (unsigned long)val; 2419 *lvalp = (unsigned long)val;
2260 } 2420 }
2261 } 2421 }
@@ -2295,102 +2455,78 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
2295 unsigned long convmul, 2455 unsigned long convmul,
2296 unsigned long convdiv) 2456 unsigned long convdiv)
2297{ 2457{
2298#define TMPBUFLEN 21 2458 unsigned long *i, *min, *max;
2299 unsigned long *i, *min, *max, val; 2459 int vleft, first = 1, err = 0;
2300 int vleft, first=1, neg; 2460 unsigned long page = 0;
2301 size_t len, left; 2461 size_t left;
2302 char buf[TMPBUFLEN], *p; 2462 char *kbuf;
2303 char __user *s = buffer; 2463
2304 2464 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2305 if (!data || !table->maxlen || !*lenp ||
2306 (*ppos && !write)) {
2307 *lenp = 0; 2465 *lenp = 0;
2308 return 0; 2466 return 0;
2309 } 2467 }
2310 2468
2311 i = (unsigned long *) data; 2469 i = (unsigned long *) data;
2312 min = (unsigned long *) table->extra1; 2470 min = (unsigned long *) table->extra1;
2313 max = (unsigned long *) table->extra2; 2471 max = (unsigned long *) table->extra2;
2314 vleft = table->maxlen / sizeof(unsigned long); 2472 vleft = table->maxlen / sizeof(unsigned long);
2315 left = *lenp; 2473 left = *lenp;
2316 2474
2475 if (write) {
2476 if (left > PAGE_SIZE - 1)
2477 left = PAGE_SIZE - 1;
2478 page = __get_free_page(GFP_TEMPORARY);
2479 kbuf = (char *) page;
2480 if (!kbuf)
2481 return -ENOMEM;
2482 if (copy_from_user(kbuf, buffer, left)) {
2483 err = -EFAULT;
2484 goto free;
2485 }
2486 kbuf[left] = 0;
2487 }
2488
2317 for (; left && vleft--; i++, min++, max++, first=0) { 2489 for (; left && vleft--; i++, min++, max++, first=0) {
2490 unsigned long val;
2491
2318 if (write) { 2492 if (write) {
2319 while (left) { 2493 bool neg;
2320 char c; 2494
2321 if (get_user(c, s)) 2495 left -= proc_skip_spaces(&kbuf);
2322 return -EFAULT; 2496
2323 if (!isspace(c)) 2497 err = proc_get_long(&kbuf, &left, &val, &neg,
2324 break; 2498 proc_wspace_sep,
2325 left--; 2499 sizeof(proc_wspace_sep), NULL);
2326 s++; 2500 if (err)
2327 }
2328 if (!left)
2329 break;
2330 neg = 0;
2331 len = left;
2332 if (len > TMPBUFLEN-1)
2333 len = TMPBUFLEN-1;
2334 if (copy_from_user(buf, s, len))
2335 return -EFAULT;
2336 buf[len] = 0;
2337 p = buf;
2338 if (*p == '-' && left > 1) {
2339 neg = 1;
2340 p++;
2341 }
2342 if (*p < '0' || *p > '9')
2343 break;
2344 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2345 len = p-buf;
2346 if ((len < left) && *p && !isspace(*p))
2347 break; 2501 break;
2348 if (neg) 2502 if (neg)
2349 val = -val;
2350 s += len;
2351 left -= len;
2352
2353 if(neg)
2354 continue; 2503 continue;
2355 if ((min && val < *min) || (max && val > *max)) 2504 if ((min && val < *min) || (max && val > *max))
2356 continue; 2505 continue;
2357 *i = val; 2506 *i = val;
2358 } else { 2507 } else {
2359 p = buf; 2508 val = convdiv * (*i) / convmul;
2360 if (!first) 2509 if (!first)
2361 *p++ = '\t'; 2510 err = proc_put_char(&buffer, &left, '\t');
2362 sprintf(p, "%lu", convdiv * (*i) / convmul); 2511 err = proc_put_long(&buffer, &left, val, false);
2363 len = strlen(buf); 2512 if (err)
2364 if (len > left) 2513 break;
2365 len = left;
2366 if(copy_to_user(s, buf, len))
2367 return -EFAULT;
2368 left -= len;
2369 s += len;
2370 } 2514 }
2371 } 2515 }
2372 2516
2373 if (!write && !first && left) { 2517 if (!write && !first && left && !err)
2374 if(put_user('\n', s)) 2518 err = proc_put_char(&buffer, &left, '\n');
2375 return -EFAULT; 2519 if (write && !err)
2376 left--, s++; 2520 left -= proc_skip_spaces(&kbuf);
2377 } 2521free:
2378 if (write) { 2522 if (write) {
2379 while (left) { 2523 free_page(page);
2380 char c; 2524 if (first)
2381 if (get_user(c, s++)) 2525 return err ? : -EINVAL;
2382 return -EFAULT;
2383 if (!isspace(c))
2384 break;
2385 left--;
2386 }
2387 } 2526 }
2388 if (write && first)
2389 return -EINVAL;
2390 *lenp -= left; 2527 *lenp -= left;
2391 *ppos += *lenp; 2528 *ppos += *lenp;
2392 return 0; 2529 return err;
2393#undef TMPBUFLEN
2394} 2530}
2395 2531
2396static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2532static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
@@ -2451,7 +2587,7 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2451} 2587}
2452 2588
2453 2589
2454static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, 2590static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2455 int *valp, 2591 int *valp,
2456 int write, void *data) 2592 int write, void *data)
2457{ 2593{
@@ -2463,10 +2599,10 @@ static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2463 int val = *valp; 2599 int val = *valp;
2464 unsigned long lval; 2600 unsigned long lval;
2465 if (val < 0) { 2601 if (val < 0) {
2466 *negp = -1; 2602 *negp = true;
2467 lval = (unsigned long)-val; 2603 lval = (unsigned long)-val;
2468 } else { 2604 } else {
2469 *negp = 0; 2605 *negp = false;
2470 lval = (unsigned long)val; 2606 lval = (unsigned long)val;
2471 } 2607 }
2472 *lvalp = lval / HZ; 2608 *lvalp = lval / HZ;
@@ -2474,7 +2610,7 @@ static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2474 return 0; 2610 return 0;
2475} 2611}
2476 2612
2477static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, 2613static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2478 int *valp, 2614 int *valp,
2479 int write, void *data) 2615 int write, void *data)
2480{ 2616{
@@ -2486,10 +2622,10 @@ static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2486 int val = *valp; 2622 int val = *valp;
2487 unsigned long lval; 2623 unsigned long lval;
2488 if (val < 0) { 2624 if (val < 0) {
2489 *negp = -1; 2625 *negp = true;
2490 lval = (unsigned long)-val; 2626 lval = (unsigned long)-val;
2491 } else { 2627 } else {
2492 *negp = 0; 2628 *negp = false;
2493 lval = (unsigned long)val; 2629 lval = (unsigned long)val;
2494 } 2630 }
2495 *lvalp = jiffies_to_clock_t(lval); 2631 *lvalp = jiffies_to_clock_t(lval);
@@ -2497,7 +2633,7 @@ static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2497 return 0; 2633 return 0;
2498} 2634}
2499 2635
2500static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, 2636static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2501 int *valp, 2637 int *valp,
2502 int write, void *data) 2638 int write, void *data)
2503{ 2639{
@@ -2507,10 +2643,10 @@ static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2507 int val = *valp; 2643 int val = *valp;
2508 unsigned long lval; 2644 unsigned long lval;
2509 if (val < 0) { 2645 if (val < 0) {
2510 *negp = -1; 2646 *negp = true;
2511 lval = (unsigned long)-val; 2647 lval = (unsigned long)-val;
2512 } else { 2648 } else {
2513 *negp = 0; 2649 *negp = false;
2514 lval = (unsigned long)val; 2650 lval = (unsigned long)val;
2515 } 2651 }
2516 *lvalp = jiffies_to_msecs(lval); 2652 *lvalp = jiffies_to_msecs(lval);
@@ -2607,6 +2743,157 @@ static int proc_do_cad_pid(struct ctl_table *table, int write,
2607 return 0; 2743 return 0;
2608} 2744}
2609 2745
2746/**
2747 * proc_do_large_bitmap - read/write from/to a large bitmap
2748 * @table: the sysctl table
2749 * @write: %TRUE if this is a write to the sysctl file
2750 * @buffer: the user buffer
2751 * @lenp: the size of the user buffer
2752 * @ppos: file position
2753 *
2754 * The bitmap is stored at table->data and the bitmap length (in bits)
2755 * in table->maxlen.
2756 *
2757 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2758 * large bitmaps may be represented in a compact manner. Writing into
2759 * the file will clear the bitmap then update it with the given input.
2760 *
2761 * Returns 0 on success.
2762 */
2763int proc_do_large_bitmap(struct ctl_table *table, int write,
2764 void __user *buffer, size_t *lenp, loff_t *ppos)
2765{
2766 int err = 0;
2767 bool first = 1;
2768 size_t left = *lenp;
2769 unsigned long bitmap_len = table->maxlen;
2770 unsigned long *bitmap = (unsigned long *) table->data;
2771 unsigned long *tmp_bitmap = NULL;
2772 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2773
2774 if (!bitmap_len || !left || (*ppos && !write)) {
2775 *lenp = 0;
2776 return 0;
2777 }
2778
2779 if (write) {
2780 unsigned long page = 0;
2781 char *kbuf;
2782
2783 if (left > PAGE_SIZE - 1)
2784 left = PAGE_SIZE - 1;
2785
2786 page = __get_free_page(GFP_TEMPORARY);
2787 kbuf = (char *) page;
2788 if (!kbuf)
2789 return -ENOMEM;
2790 if (copy_from_user(kbuf, buffer, left)) {
2791 free_page(page);
2792 return -EFAULT;
2793 }
2794 kbuf[left] = 0;
2795
2796 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2797 GFP_KERNEL);
2798 if (!tmp_bitmap) {
2799 free_page(page);
2800 return -ENOMEM;
2801 }
2802 proc_skip_char(&kbuf, &left, '\n');
2803 while (!err && left) {
2804 unsigned long val_a, val_b;
2805 bool neg;
2806
2807 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2808 sizeof(tr_a), &c);
2809 if (err)
2810 break;
2811 if (val_a >= bitmap_len || neg) {
2812 err = -EINVAL;
2813 break;
2814 }
2815
2816 val_b = val_a;
2817 if (left) {
2818 kbuf++;
2819 left--;
2820 }
2821
2822 if (c == '-') {
2823 err = proc_get_long(&kbuf, &left, &val_b,
2824 &neg, tr_b, sizeof(tr_b),
2825 &c);
2826 if (err)
2827 break;
2828 if (val_b >= bitmap_len || neg ||
2829 val_a > val_b) {
2830 err = -EINVAL;
2831 break;
2832 }
2833 if (left) {
2834 kbuf++;
2835 left--;
2836 }
2837 }
2838
2839 while (val_a <= val_b)
2840 set_bit(val_a++, tmp_bitmap);
2841
2842 first = 0;
2843 proc_skip_char(&kbuf, &left, '\n');
2844 }
2845 free_page(page);
2846 } else {
2847 unsigned long bit_a, bit_b = 0;
2848
2849 while (left) {
2850 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2851 if (bit_a >= bitmap_len)
2852 break;
2853 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2854 bit_a + 1) - 1;
2855
2856 if (!first) {
2857 err = proc_put_char(&buffer, &left, ',');
2858 if (err)
2859 break;
2860 }
2861 err = proc_put_long(&buffer, &left, bit_a, false);
2862 if (err)
2863 break;
2864 if (bit_a != bit_b) {
2865 err = proc_put_char(&buffer, &left, '-');
2866 if (err)
2867 break;
2868 err = proc_put_long(&buffer, &left, bit_b, false);
2869 if (err)
2870 break;
2871 }
2872
2873 first = 0; bit_b++;
2874 }
2875 if (!err)
2876 err = proc_put_char(&buffer, &left, '\n');
2877 }
2878
2879 if (!err) {
2880 if (write) {
2881 if (*ppos)
2882 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2883 else
2884 memcpy(bitmap, tmp_bitmap,
2885 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2886 }
2887 kfree(tmp_bitmap);
2888 *lenp -= left;
2889 *ppos += *lenp;
2890 return 0;
2891 } else {
2892 kfree(tmp_bitmap);
2893 return err;
2894 }
2895}
2896
2610#else /* CONFIG_PROC_FS */ 2897#else /* CONFIG_PROC_FS */
2611 2898
2612int proc_dostring(struct ctl_table *table, int write, 2899int proc_dostring(struct ctl_table *table, int write,