Skip to content

Commit 5e01671

Browse files
committed
net: make default_rps_mask a per netns attribute
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author Paolo Abeni <[email protected]> commit 50bcfe8 That really was meant to be a per netns attribute from the beginning. The idea is that once proper isolation is in place in the main namespace, additional demux in the child namespaces will be redundant. Let's make child netns default rps mask empty by default. To avoid bloating the netns with a possibly large cpumask, allocate it on-demand during the first write operation. Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]> (cherry picked from commit 50bcfe8) Signed-off-by: Jonathan Maple <[email protected]>
1 parent d93732f commit 5e01671

File tree

4 files changed

+59
-21
lines changed

4 files changed

+59
-21
lines changed

include/linux/netdevice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ 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;
217216
#endif
218217

219218
struct neighbour;

include/net/netns/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
struct ctl_table_header;
66
struct prot_inuse;
7+
struct cpumask;
78

89
struct netns_core {
910
/* core sysctls */
@@ -15,6 +16,10 @@ struct netns_core {
1516
#ifdef CONFIG_PROC_FS
1617
struct prot_inuse __percpu *prot_inuse;
1718
#endif
19+
20+
#if IS_ENABLED(CONFIG_RPS) && IS_ENABLED(CONFIG_SYSCTL)
21+
struct cpumask *rps_default_mask;
22+
#endif
1823
};
1924

2025
#endif

net/core/net-sysfs.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,18 @@ static struct kobj_type rx_queue_ktype __ro_after_init = {
10481048
.get_ownership = rx_queue_get_ownership,
10491049
};
10501050

1051+
static int rx_queue_default_mask(struct net_device *dev,
1052+
struct netdev_rx_queue *queue)
1053+
{
1054+
#if IS_ENABLED(CONFIG_RPS) && IS_ENABLED(CONFIG_SYSCTL)
1055+
struct cpumask *rps_default_mask = READ_ONCE(dev_net(dev)->core.rps_default_mask);
1056+
1057+
if (rps_default_mask && !cpumask_empty(rps_default_mask))
1058+
return netdev_rx_queue_set_rps_mask(queue, rps_default_mask);
1059+
#endif
1060+
return 0;
1061+
}
1062+
10511063
static int rx_queue_add_kobject(struct net_device *dev, int index)
10521064
{
10531065
struct netdev_rx_queue *queue = dev->_rx + index;
@@ -1071,13 +1083,10 @@ static int rx_queue_add_kobject(struct net_device *dev, int index)
10711083
goto err;
10721084
}
10731085

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
1086+
error = rx_queue_default_mask(dev, queue);
1087+
if (error)
1088+
goto err;
1089+
10811090
kobject_uevent(kobj, KOBJ_ADD);
10821091

10831092
return error;

net/core/sysctl_net_core.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,47 @@ static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
7878
#endif
7979

8080
#ifdef CONFIG_RPS
81-
struct cpumask rps_default_mask;
81+
82+
static struct cpumask *rps_default_mask_cow_alloc(struct net *net)
83+
{
84+
struct cpumask *rps_default_mask;
85+
86+
if (net->core.rps_default_mask)
87+
return net->core.rps_default_mask;
88+
89+
rps_default_mask = kzalloc(cpumask_size(), GFP_KERNEL);
90+
if (!rps_default_mask)
91+
return NULL;
92+
93+
/* pairs with READ_ONCE in rx_queue_default_mask() */
94+
WRITE_ONCE(net->core.rps_default_mask, rps_default_mask);
95+
return rps_default_mask;
96+
}
8297

8398
static int rps_default_mask_sysctl(struct ctl_table *table, int write,
8499
void *buffer, size_t *lenp, loff_t *ppos)
85100
{
101+
struct net *net = (struct net *)table->data;
86102
int err = 0;
87103

88104
rtnl_lock();
89105
if (write) {
90-
err = cpumask_parse(buffer, &rps_default_mask);
106+
struct cpumask *rps_default_mask = rps_default_mask_cow_alloc(net);
107+
108+
err = -ENOMEM;
109+
if (!rps_default_mask)
110+
goto done;
111+
112+
err = cpumask_parse(buffer, rps_default_mask);
91113
if (err)
92114
goto done;
93115

94-
err = rps_cpumask_housekeeping(&rps_default_mask);
116+
err = rps_cpumask_housekeeping(rps_default_mask);
95117
if (err)
96118
goto done;
97119
} else {
98-
dump_cpumask(buffer, lenp, ppos, &rps_default_mask);
120+
dump_cpumask(buffer, lenp, ppos,
121+
net->core.rps_default_mask ? : cpu_none_mask);
99122
}
100123

101124
done:
@@ -514,11 +537,6 @@ static struct ctl_table net_core_table[] = {
514537
.mode = 0644,
515538
.proc_handler = rps_sock_flow_sysctl
516539
},
517-
{
518-
.procname = "rps_default_mask",
519-
.mode = 0644,
520-
.proc_handler = rps_default_mask_sysctl
521-
},
522540
#endif
523541
#ifdef CONFIG_NET_FLOW_LIMIT
524542
{
@@ -637,6 +655,14 @@ static struct ctl_table net_core_table[] = {
637655
};
638656

639657
static struct ctl_table netns_core_table[] = {
658+
#if IS_ENABLED(CONFIG_RPS)
659+
{
660+
.procname = "rps_default_mask",
661+
.data = &init_net,
662+
.mode = 0644,
663+
.proc_handler = rps_default_mask_sysctl
664+
},
665+
#endif
640666
{
641667
.procname = "somaxconn",
642668
.data = &init_net.core.sysctl_somaxconn,
@@ -709,6 +735,9 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
709735
tbl = net->core.sysctl_hdr->ctl_table_arg;
710736
unregister_net_sysctl_table(net->core.sysctl_hdr);
711737
BUG_ON(tbl == netns_core_table);
738+
#if IS_ENABLED(CONFIG_RPS)
739+
kfree(net->core.rps_default_mask);
740+
#endif
712741
kfree(tbl);
713742
}
714743

@@ -719,10 +748,6 @@ static __net_initdata struct pernet_operations sysctl_core_ops = {
719748

720749
static __init int sysctl_core_init(void)
721750
{
722-
#if IS_ENABLED(CONFIG_RPS)
723-
cpumask_copy(&rps_default_mask, cpu_none_mask);
724-
#endif
725-
726751
register_net_sysctl(&init_net, "net/core", net_core_table);
727752
return register_pernet_subsys(&sysctl_core_ops);
728753
}

0 commit comments

Comments
 (0)