.. | .. |
---|
22 | 22 | #include <net/busy_poll.h> |
---|
23 | 23 | #include <net/pkt_sched.h> |
---|
24 | 24 | |
---|
25 | | -static int zero = 0; |
---|
26 | | -static int one = 1; |
---|
27 | | -static int two __maybe_unused = 2; |
---|
| 25 | +static int two = 2; |
---|
| 26 | +static int three = 3; |
---|
28 | 27 | static int min_sndbuf = SOCK_MIN_SNDBUF; |
---|
29 | 28 | static int min_rcvbuf = SOCK_MIN_RCVBUF; |
---|
30 | 29 | static int max_skb_frags = MAX_SKB_FRAGS; |
---|
.. | .. |
---|
36 | 35 | int sysctl_fb_tunnels_only_for_init_net __read_mostly = 0; |
---|
37 | 36 | EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net); |
---|
38 | 37 | |
---|
| 38 | +/* 0 - Keep current behavior: |
---|
| 39 | + * IPv4: inherit all current settings from init_net |
---|
| 40 | + * IPv6: reset all settings to default |
---|
| 41 | + * 1 - Both inherit all current settings from init_net |
---|
| 42 | + * 2 - Both reset all settings to default |
---|
| 43 | + * 3 - Both inherit all settings from current netns |
---|
| 44 | + */ |
---|
| 45 | +int sysctl_devconf_inherit_init_net __read_mostly; |
---|
| 46 | +EXPORT_SYMBOL(sysctl_devconf_inherit_init_net); |
---|
| 47 | + |
---|
39 | 48 | #ifdef CONFIG_RPS |
---|
40 | 49 | static int rps_sock_flow_sysctl(struct ctl_table *table, int write, |
---|
41 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 50 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
42 | 51 | { |
---|
43 | 52 | unsigned int orig_size, size; |
---|
44 | 53 | int ret, i; |
---|
.. | .. |
---|
86 | 95 | if (sock_table != orig_sock_table) { |
---|
87 | 96 | rcu_assign_pointer(rps_sock_flow_table, sock_table); |
---|
88 | 97 | if (sock_table) { |
---|
89 | | - static_key_slow_inc(&rps_needed); |
---|
90 | | - static_key_slow_inc(&rfs_needed); |
---|
| 98 | + static_branch_inc(&rps_needed); |
---|
| 99 | + static_branch_inc(&rfs_needed); |
---|
91 | 100 | } |
---|
92 | 101 | if (orig_sock_table) { |
---|
93 | | - static_key_slow_dec(&rps_needed); |
---|
94 | | - static_key_slow_dec(&rfs_needed); |
---|
| 102 | + static_branch_dec(&rps_needed); |
---|
| 103 | + static_branch_dec(&rfs_needed); |
---|
95 | 104 | synchronize_rcu(); |
---|
96 | 105 | vfree(orig_sock_table); |
---|
97 | 106 | } |
---|
.. | .. |
---|
108 | 117 | static DEFINE_MUTEX(flow_limit_update_mutex); |
---|
109 | 118 | |
---|
110 | 119 | static int flow_limit_cpu_sysctl(struct ctl_table *table, int write, |
---|
111 | | - void __user *buffer, size_t *lenp, |
---|
112 | | - loff_t *ppos) |
---|
| 120 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
113 | 121 | { |
---|
114 | 122 | struct sd_flow_limit *cur; |
---|
115 | 123 | struct softnet_data *sd; |
---|
.. | .. |
---|
120 | 128 | return -ENOMEM; |
---|
121 | 129 | |
---|
122 | 130 | if (write) { |
---|
123 | | - ret = cpumask_parse_user(buffer, *lenp, mask); |
---|
| 131 | + ret = cpumask_parse(buffer, mask); |
---|
124 | 132 | if (ret) |
---|
125 | 133 | goto done; |
---|
126 | 134 | |
---|
.. | .. |
---|
173 | 181 | } |
---|
174 | 182 | if (len < *lenp) |
---|
175 | 183 | kbuf[len++] = '\n'; |
---|
176 | | - if (copy_to_user(buffer, kbuf, len)) { |
---|
177 | | - ret = -EFAULT; |
---|
178 | | - goto done; |
---|
179 | | - } |
---|
| 184 | + memcpy(buffer, kbuf, len); |
---|
180 | 185 | *lenp = len; |
---|
181 | 186 | *ppos += len; |
---|
182 | 187 | } |
---|
.. | .. |
---|
187 | 192 | } |
---|
188 | 193 | |
---|
189 | 194 | static int flow_limit_table_len_sysctl(struct ctl_table *table, int write, |
---|
190 | | - void __user *buffer, size_t *lenp, |
---|
191 | | - loff_t *ppos) |
---|
| 195 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
192 | 196 | { |
---|
193 | 197 | unsigned int old, *ptr; |
---|
194 | 198 | int ret; |
---|
.. | .. |
---|
210 | 214 | |
---|
211 | 215 | #ifdef CONFIG_NET_SCHED |
---|
212 | 216 | static int set_default_qdisc(struct ctl_table *table, int write, |
---|
213 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 217 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
214 | 218 | { |
---|
215 | 219 | char id[IFNAMSIZ]; |
---|
216 | 220 | struct ctl_table tbl = { |
---|
.. | .. |
---|
229 | 233 | #endif |
---|
230 | 234 | |
---|
231 | 235 | static int proc_do_dev_weight(struct ctl_table *table, int write, |
---|
232 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 236 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
233 | 237 | { |
---|
234 | | - int ret; |
---|
| 238 | + static DEFINE_MUTEX(dev_weight_mutex); |
---|
| 239 | + int ret, weight; |
---|
235 | 240 | |
---|
| 241 | + mutex_lock(&dev_weight_mutex); |
---|
236 | 242 | ret = proc_dointvec(table, write, buffer, lenp, ppos); |
---|
237 | | - if (ret != 0) |
---|
238 | | - return ret; |
---|
239 | | - |
---|
240 | | - dev_rx_weight = weight_p * dev_weight_rx_bias; |
---|
241 | | - dev_tx_weight = weight_p * dev_weight_tx_bias; |
---|
| 243 | + if (!ret && write) { |
---|
| 244 | + weight = READ_ONCE(weight_p); |
---|
| 245 | + WRITE_ONCE(dev_rx_weight, weight * dev_weight_rx_bias); |
---|
| 246 | + WRITE_ONCE(dev_tx_weight, weight * dev_weight_tx_bias); |
---|
| 247 | + } |
---|
| 248 | + mutex_unlock(&dev_weight_mutex); |
---|
242 | 249 | |
---|
243 | 250 | return ret; |
---|
244 | 251 | } |
---|
245 | 252 | |
---|
246 | | -#ifdef CONFIG_ETHTOOL |
---|
247 | 253 | static int proc_do_rss_key(struct ctl_table *table, int write, |
---|
248 | | - void __user *buffer, size_t *lenp, loff_t *ppos) |
---|
| 254 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
249 | 255 | { |
---|
250 | 256 | struct ctl_table fake_table; |
---|
251 | 257 | char buf[NETDEV_RSS_KEY_LEN * 3]; |
---|
.. | .. |
---|
255 | 261 | fake_table.maxlen = sizeof(buf); |
---|
256 | 262 | return proc_dostring(&fake_table, write, buffer, lenp, ppos); |
---|
257 | 263 | } |
---|
258 | | -#endif |
---|
259 | 264 | |
---|
260 | 265 | #ifdef CONFIG_BPF_JIT |
---|
261 | 266 | static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write, |
---|
262 | | - void __user *buffer, size_t *lenp, |
---|
| 267 | + void *buffer, size_t *lenp, |
---|
263 | 268 | loff_t *ppos) |
---|
264 | 269 | { |
---|
265 | 270 | int ret, jit_enable = *(int *)table->data; |
---|
.. | .. |
---|
286 | 291 | # ifdef CONFIG_HAVE_EBPF_JIT |
---|
287 | 292 | static int |
---|
288 | 293 | proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write, |
---|
289 | | - void __user *buffer, size_t *lenp, |
---|
290 | | - loff_t *ppos) |
---|
| 294 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
291 | 295 | { |
---|
292 | 296 | if (!capable(CAP_SYS_ADMIN)) |
---|
293 | 297 | return -EPERM; |
---|
.. | .. |
---|
298 | 302 | |
---|
299 | 303 | static int |
---|
300 | 304 | proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write, |
---|
301 | | - void __user *buffer, size_t *lenp, |
---|
302 | | - loff_t *ppos) |
---|
| 305 | + void *buffer, size_t *lenp, loff_t *ppos) |
---|
303 | 306 | { |
---|
304 | 307 | if (!capable(CAP_SYS_ADMIN)) |
---|
305 | 308 | return -EPERM; |
---|
.. | .. |
---|
370 | 373 | .mode = 0644, |
---|
371 | 374 | .proc_handler = proc_dointvec |
---|
372 | 375 | }, |
---|
373 | | -#ifdef CONFIG_ETHTOOL |
---|
374 | 376 | { |
---|
375 | 377 | .procname = "netdev_rss_key", |
---|
376 | 378 | .data = &netdev_rss_key, |
---|
.. | .. |
---|
378 | 380 | .mode = 0444, |
---|
379 | 381 | .proc_handler = proc_do_rss_key, |
---|
380 | 382 | }, |
---|
381 | | -#endif |
---|
382 | 383 | #ifdef CONFIG_BPF_JIT |
---|
383 | 384 | { |
---|
384 | 385 | .procname = "bpf_jit_enable", |
---|
.. | .. |
---|
387 | 388 | .mode = 0644, |
---|
388 | 389 | .proc_handler = proc_dointvec_minmax_bpf_enable, |
---|
389 | 390 | # ifdef CONFIG_BPF_JIT_ALWAYS_ON |
---|
390 | | - .extra1 = &one, |
---|
391 | | - .extra2 = &one, |
---|
| 391 | + .extra1 = SYSCTL_ONE, |
---|
| 392 | + .extra2 = SYSCTL_ONE, |
---|
392 | 393 | # else |
---|
393 | | - .extra1 = &zero, |
---|
| 394 | + .extra1 = SYSCTL_ZERO, |
---|
394 | 395 | .extra2 = &two, |
---|
395 | 396 | # endif |
---|
396 | 397 | }, |
---|
.. | .. |
---|
401 | 402 | .maxlen = sizeof(int), |
---|
402 | 403 | .mode = 0600, |
---|
403 | 404 | .proc_handler = proc_dointvec_minmax_bpf_restricted, |
---|
404 | | - .extra1 = &zero, |
---|
| 405 | + .extra1 = SYSCTL_ZERO, |
---|
405 | 406 | .extra2 = &two, |
---|
406 | 407 | }, |
---|
407 | 408 | { |
---|
.. | .. |
---|
410 | 411 | .maxlen = sizeof(int), |
---|
411 | 412 | .mode = 0600, |
---|
412 | 413 | .proc_handler = proc_dointvec_minmax_bpf_restricted, |
---|
413 | | - .extra1 = &zero, |
---|
414 | | - .extra2 = &one, |
---|
| 414 | + .extra1 = SYSCTL_ZERO, |
---|
| 415 | + .extra2 = SYSCTL_ONE, |
---|
415 | 416 | }, |
---|
416 | 417 | # endif |
---|
417 | 418 | { |
---|
.. | .. |
---|
458 | 459 | .maxlen = sizeof(int), |
---|
459 | 460 | .mode = 0644, |
---|
460 | 461 | .proc_handler = proc_dointvec_minmax, |
---|
461 | | - .extra1 = &zero, |
---|
462 | | - .extra2 = &one |
---|
| 462 | + .extra1 = SYSCTL_ZERO, |
---|
| 463 | + .extra2 = SYSCTL_ONE |
---|
463 | 464 | }, |
---|
464 | 465 | #ifdef CONFIG_RPS |
---|
465 | 466 | { |
---|
.. | .. |
---|
490 | 491 | .maxlen = sizeof(unsigned int), |
---|
491 | 492 | .mode = 0644, |
---|
492 | 493 | .proc_handler = proc_dointvec_minmax, |
---|
493 | | - .extra1 = &zero, |
---|
| 494 | + .extra1 = SYSCTL_ZERO, |
---|
494 | 495 | }, |
---|
495 | 496 | { |
---|
496 | 497 | .procname = "busy_read", |
---|
.. | .. |
---|
498 | 499 | .maxlen = sizeof(unsigned int), |
---|
499 | 500 | .mode = 0644, |
---|
500 | 501 | .proc_handler = proc_dointvec_minmax, |
---|
501 | | - .extra1 = &zero, |
---|
| 502 | + .extra1 = SYSCTL_ZERO, |
---|
502 | 503 | }, |
---|
503 | 504 | #endif |
---|
504 | 505 | #ifdef CONFIG_NET_SCHED |
---|
.. | .. |
---|
530 | 531 | .maxlen = sizeof(int), |
---|
531 | 532 | .mode = 0644, |
---|
532 | 533 | .proc_handler = proc_dointvec_minmax, |
---|
533 | | - .extra1 = &one, |
---|
| 534 | + .extra1 = SYSCTL_ONE, |
---|
534 | 535 | .extra2 = &max_skb_frags, |
---|
535 | 536 | }, |
---|
536 | 537 | { |
---|
.. | .. |
---|
539 | 540 | .maxlen = sizeof(unsigned int), |
---|
540 | 541 | .mode = 0644, |
---|
541 | 542 | .proc_handler = proc_dointvec_minmax, |
---|
542 | | - .extra1 = &zero, |
---|
| 543 | + .extra1 = SYSCTL_ZERO, |
---|
543 | 544 | }, |
---|
544 | 545 | { |
---|
545 | 546 | .procname = "fb_tunnels_only_for_init_net", |
---|
.. | .. |
---|
547 | 548 | .maxlen = sizeof(int), |
---|
548 | 549 | .mode = 0644, |
---|
549 | 550 | .proc_handler = proc_dointvec_minmax, |
---|
550 | | - .extra1 = &zero, |
---|
551 | | - .extra2 = &one, |
---|
| 551 | + .extra1 = SYSCTL_ZERO, |
---|
| 552 | + .extra2 = &two, |
---|
| 553 | + }, |
---|
| 554 | + { |
---|
| 555 | + .procname = "devconf_inherit_init_net", |
---|
| 556 | + .data = &sysctl_devconf_inherit_init_net, |
---|
| 557 | + .maxlen = sizeof(int), |
---|
| 558 | + .mode = 0644, |
---|
| 559 | + .proc_handler = proc_dointvec_minmax, |
---|
| 560 | + .extra1 = SYSCTL_ZERO, |
---|
| 561 | + .extra2 = &three, |
---|
| 562 | + }, |
---|
| 563 | + { |
---|
| 564 | + .procname = "high_order_alloc_disable", |
---|
| 565 | + .data = &net_high_order_alloc_disable_key.key, |
---|
| 566 | + .maxlen = sizeof(net_high_order_alloc_disable_key), |
---|
| 567 | + .mode = 0644, |
---|
| 568 | + .proc_handler = proc_do_static_key, |
---|
| 569 | + }, |
---|
| 570 | + { |
---|
| 571 | + .procname = "gro_normal_batch", |
---|
| 572 | + .data = &gro_normal_batch, |
---|
| 573 | + .maxlen = sizeof(unsigned int), |
---|
| 574 | + .mode = 0644, |
---|
| 575 | + .proc_handler = proc_dointvec_minmax, |
---|
| 576 | + .extra1 = SYSCTL_ONE, |
---|
552 | 577 | }, |
---|
553 | 578 | { } |
---|
554 | 579 | }; |
---|
.. | .. |
---|
559 | 584 | .data = &init_net.core.sysctl_somaxconn, |
---|
560 | 585 | .maxlen = sizeof(int), |
---|
561 | 586 | .mode = 0644, |
---|
562 | | - .extra1 = &zero, |
---|
| 587 | + .extra1 = SYSCTL_ZERO, |
---|
563 | 588 | .proc_handler = proc_dointvec_minmax |
---|
564 | 589 | }, |
---|
565 | 590 | { } |
---|
566 | 591 | }; |
---|
567 | 592 | |
---|
| 593 | +static int __init fb_tunnels_only_for_init_net_sysctl_setup(char *str) |
---|
| 594 | +{ |
---|
| 595 | + /* fallback tunnels for initns only */ |
---|
| 596 | + if (!strncmp(str, "initns", 6)) |
---|
| 597 | + sysctl_fb_tunnels_only_for_init_net = 1; |
---|
| 598 | + /* no fallback tunnels anywhere */ |
---|
| 599 | + else if (!strncmp(str, "none", 4)) |
---|
| 600 | + sysctl_fb_tunnels_only_for_init_net = 2; |
---|
| 601 | + |
---|
| 602 | + return 1; |
---|
| 603 | +} |
---|
| 604 | +__setup("fb_tunnels=", fb_tunnels_only_for_init_net_sysctl_setup); |
---|
| 605 | + |
---|
568 | 606 | static __net_init int sysctl_core_net_init(struct net *net) |
---|
569 | 607 | { |
---|
570 | 608 | struct ctl_table *tbl; |
---|