[PATCH] net: don't let user assign task isolation CPUs for RPS

From: Yury Norov
Date: Sat Jul 07 2018 - 17:40:46 EST


Receive Packet Steering (RPS) subsystem distributes network traffic
handling to CPUs defined by user in
/sys/class/net/<dev>/queues/rx-<n>/rps_cpus.

If rps_cpus intersects with task_isolation_map, RPS may break task
isolation by assigning RPS work to CPU that runs isolated task.

In this patch user-provided rps_cpus map filtered to avoid that.

Signed-off-by: Yury Norov <ynorov@xxxxxxxxxxxxxxxxxx>
---
include/linux/isolation.h | 2 ++
net/core/net-sysfs.c | 13 +++++++++++++
2 files changed, 15 insertions(+)

diff --git a/include/linux/isolation.h b/include/linux/isolation.h
index f467545ad37d..b7f0a9085b13 100644
--- a/include/linux/isolation.h
+++ b/include/linux/isolation.h
@@ -14,6 +14,8 @@ struct task_struct;

#ifdef CONFIG_TASK_ISOLATION

+extern cpumask_var_t task_isolation_map;
+
/**
* task_isolation_request() - prctl hook to request task isolation
* @flags: Flags from <linux/prctl.h> PR_TASK_ISOLATION_xxx.
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 927a6dcbad96..18e576893984 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -11,6 +11,7 @@

#include <linux/capability.h>
#include <linux/kernel.h>
+#include <linux/isolation.h>
#include <linux/netdevice.h>
#include <net/switchdev.h>
#include <linux/if_arp.h>
@@ -727,6 +728,18 @@ static ssize_t store_rps_map(struct netdev_rx_queue *queue,
return err;
}

+#ifdef CONFIG_TASK_ISOLATION
+ if (cpumask_intersects(mask, task_isolation_map)) {
+ char tmp[256];
+
+ pr_warn("RPS is not allowed on CPUs allocated for isolated tasks\n");
+
+ cpumask_andnot(mask, mask, task_isolation_map);
+ cpumap_print_to_pagebuf(1, tmp, mask);
+ pr_warn("RPS CPUs list is reduced to: %s\n", tmp);
+ }
+#endif
+
map = kzalloc(max_t(unsigned int,
RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
GFP_KERNEL);
--
2.17.1