Skip to content

Commit 605cfa1

Browse files
Paolo Abenikuba-moo
authored andcommitted
net: introduce default_rps_mask netns attribute
If RPS is enabled, this allows configuring a default rps mask, which is effective since receive queue creation time. A default RPS mask allows the system admin to ensure proper isolation, avoiding races at network namespace or device creation time. The default RPS mask is initially empty, and can be modified via a newly added sysctl entry. Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 370ca71 commit 605cfa1

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

Documentation/admin-guide/sysctl/net.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ rmem_max
215215

216216
The maximum receive socket buffer size in bytes.
217217

218+
rps_default_mask
219+
----------------
220+
221+
The default RPS CPU mask used on newly created network devices. An empty
222+
mask means RPS disabled by default.
223+
218224
tstamp_allow_data
219225
-----------------
220226
Allow processes to receive tx timestamps looped together with the original

include/linux/netdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ struct net_device_core_stats {
223223
#include <linux/static_key.h>
224224
extern struct static_key_false rps_needed;
225225
extern struct static_key_false rfs_needed;
226+
extern struct cpumask rps_default_mask;
226227
#endif
227228

228229
struct neighbour;

net/core/net-sysfs.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,13 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
10831083
goto err;
10841084
}
10851085

1086+
#if IS_ENABLED(CONFIG_RPS) && IS_ENABLED(CONFIG_SYSCTL)
1087+
if (!cpumask_empty(&rps_default_mask)) {
1088+
error = netdev_rx_queue_set_rps_mask(queue, &rps_default_mask);
1089+
if (error)
1090+
goto err;
1091+
}
1092+
#endif
10861093
kobject_uevent(kobj, KOBJ_ADD);
10871094

10881095
return error;

net/core/sysctl_net_core.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/vmalloc.h>
1717
#include <linux/init.h>
1818
#include <linux/slab.h>
19+
#include <linux/sched/isolation.h>
1920

2021
#include <net/ip.h>
2122
#include <net/sock.h>
@@ -45,7 +46,7 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
4546
int sysctl_devconf_inherit_init_net __read_mostly;
4647
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
4748

48-
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
49+
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT) || IS_ENABLED(CONFIG_RPS)
4950
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
5051
struct cpumask *mask)
5152
{
@@ -73,6 +74,31 @@ static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
7374
#endif
7475

7576
#ifdef CONFIG_RPS
77+
struct cpumask rps_default_mask;
78+
79+
static int rps_default_mask_sysctl(struct ctl_table *table, int write,
80+
void *buffer, size_t *lenp, loff_t *ppos)
81+
{
82+
int err = 0;
83+
84+
rtnl_lock();
85+
if (write) {
86+
err = cpumask_parse(buffer, &rps_default_mask);
87+
if (err)
88+
goto done;
89+
90+
err = rps_cpumask_housekeeping(&rps_default_mask);
91+
if (err)
92+
goto done;
93+
} else {
94+
dump_cpumask(buffer, lenp, ppos, &rps_default_mask);
95+
}
96+
97+
done:
98+
rtnl_unlock();
99+
return err;
100+
}
101+
76102
static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
77103
void *buffer, size_t *lenp, loff_t *ppos)
78104
{
@@ -482,6 +508,11 @@ static struct ctl_table net_core_table[] = {
482508
.mode = 0644,
483509
.proc_handler = rps_sock_flow_sysctl
484510
},
511+
{
512+
.procname = "rps_default_mask",
513+
.mode = 0644,
514+
.proc_handler = rps_default_mask_sysctl
515+
},
485516
#endif
486517
#ifdef CONFIG_NET_FLOW_LIMIT
487518
{
@@ -685,6 +716,10 @@ static __net_initdata struct pernet_operations sysctl_core_ops = {
685716

686717
static __init int sysctl_core_init(void)
687718
{
719+
#if IS_ENABLED(CONFIG_RPS)
720+
cpumask_copy(&rps_default_mask, cpu_none_mask);
721+
#endif
722+
688723
register_net_sysctl(&init_net, "net/core", net_core_table);
689724
return register_pernet_subsys(&sysctl_core_ops);
690725
}

0 commit comments

Comments
 (0)