Skip to content

Commit b561cfe

Browse files
committed
net: introduce default_rps_mask netns attribute
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author Paolo Abeni <pabeni@redhat.com> commit 605cfa1 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 <pabeni@redhat.com> Reviewed-by: Simon Horman <simon.horman@corigine.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 605cfa1) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 7777eab commit b561cfe

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
@@ -214,6 +214,12 @@ rmem_max
214214

215215
The maximum receive socket buffer size in bytes.
216216

217+
rps_default_mask
218+
----------------
219+
220+
The default RPS CPU mask used on newly created network devices. An empty
221+
mask means RPS disabled by default.
222+
217223
tstamp_allow_data
218224
-----------------
219225
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
@@ -213,6 +213,7 @@ struct net_device_core_stats {
213213
#include <linux/static_key.h>
214214
extern struct static_key_false rps_needed;
215215
extern struct static_key_false rfs_needed;
216+
extern struct cpumask rps_default_mask;
216217
#endif
217218

218219
struct neighbour;

net/core/net-sysfs.c

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

1074+
#if IS_ENABLED(CONFIG_RPS) && IS_ENABLED(CONFIG_SYSCTL)
1075+
if (!cpumask_empty(&rps_default_mask)) {
1076+
error = netdev_rx_queue_set_rps_mask(queue, &rps_default_mask);
1077+
if (error)
1078+
goto err;
1079+
}
1080+
#endif
10741081
kobject_uevent(kobj, KOBJ_ADD);
10751082

10761083
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>
@@ -49,7 +50,7 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
4950
int sysctl_devconf_inherit_init_net __read_mostly;
5051
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
5152

52-
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
53+
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT) || IS_ENABLED(CONFIG_RPS)
5354
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
5455
struct cpumask *mask)
5556
{
@@ -77,6 +78,31 @@ static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
7778
#endif
7879

7980
#ifdef CONFIG_RPS
81+
struct cpumask rps_default_mask;
82+
83+
static int rps_default_mask_sysctl(struct ctl_table *table, int write,
84+
void *buffer, size_t *lenp, loff_t *ppos)
85+
{
86+
int err = 0;
87+
88+
rtnl_lock();
89+
if (write) {
90+
err = cpumask_parse(buffer, &rps_default_mask);
91+
if (err)
92+
goto done;
93+
94+
err = rps_cpumask_housekeeping(&rps_default_mask);
95+
if (err)
96+
goto done;
97+
} else {
98+
dump_cpumask(buffer, lenp, ppos, &rps_default_mask);
99+
}
100+
101+
done:
102+
rtnl_unlock();
103+
return err;
104+
}
105+
80106
static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
81107
void *buffer, size_t *lenp, loff_t *ppos)
82108
{
@@ -488,6 +514,11 @@ static struct ctl_table net_core_table[] = {
488514
.mode = 0644,
489515
.proc_handler = rps_sock_flow_sysctl
490516
},
517+
{
518+
.procname = "rps_default_mask",
519+
.mode = 0644,
520+
.proc_handler = rps_default_mask_sysctl
521+
},
491522
#endif
492523
#ifdef CONFIG_NET_FLOW_LIMIT
493524
{
@@ -688,6 +719,10 @@ static __net_initdata struct pernet_operations sysctl_core_ops = {
688719

689720
static __init int sysctl_core_init(void)
690721
{
722+
#if IS_ENABLED(CONFIG_RPS)
723+
cpumask_copy(&rps_default_mask, cpu_none_mask);
724+
#endif
725+
691726
register_net_sysctl(&init_net, "net/core", net_core_table);
692727
return register_pernet_subsys(&sysctl_core_ops);
693728
}

0 commit comments

Comments
 (0)