cgroup/cpuset: Don't allow creation of local partition over a remote one
authorWaiman Long <longman@redhat.com>
Sun, 30 Mar 2025 21:52:43 +0000 (17:52 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:59:21 +0000 (07:59 +0200)
[ Upstream commit 6da580ec656a5ed135db2cdf574b47635611a4d7 ]

Currently, we don't allow the creation of a remote partition underneath
another local or remote partition. However, it is currently possible to
create a new local partition with an existing remote partition underneath
it if top_cpuset is the parent. However, the current cpuset code does
not set the effective exclusive CPUs correctly to account for those
that are taken by the remote partition.

Changing the code to properly account for those remote partition CPUs
under all possible circumstances can be complex. It is much easier to
not allow such a configuration which is not that useful. So forbid
that by making sure that exclusive_cpus mask doesn't overlap with
subpartitions_cpus and invalidate the partition if that happens.

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/cgroup/cpuset-internal.h
kernel/cgroup/cpuset.c

index 976a8bc3ff60318b67526c67f125823496cd9cb5..383963e28ac69c8937a84f5b176de2ce99d55564 100644 (file)
@@ -33,6 +33,7 @@ enum prs_errcode {
        PERR_CPUSEMPTY,
        PERR_HKEEPING,
        PERR_ACCESS,
+       PERR_REMOTE,
 };
 
 /* bits in struct cpuset flags field */
index 839f88ba17f7d3950a974be3bb4dcd03a405b073..c709a05023cd990e8239ec36799aa9de28036071 100644 (file)
@@ -62,6 +62,7 @@ static const char * const perr_strings[] = {
        [PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are empty",
        [PERR_HKEEPING]  = "partition config conflicts with housekeeping setup",
        [PERR_ACCESS]    = "Enable partition not permitted",
+       [PERR_REMOTE]    = "Have remote partition underneath",
 };
 
 /*
@@ -2824,6 +2825,19 @@ static int update_prstate(struct cpuset *cs, int new_prs)
                        goto out;
                }
 
+               /*
+                * We don't support the creation of a new local partition with
+                * a remote partition underneath it. This unsupported
+                * setting can happen only if parent is the top_cpuset because
+                * a remote partition cannot be created underneath an existing
+                * local or remote partition.
+                */
+               if ((parent == &top_cpuset) &&
+                   cpumask_intersects(cs->exclusive_cpus, subpartitions_cpus)) {
+                       err = PERR_REMOTE;
+                       goto out;
+               }
+
                /*
                 * If parent is valid partition, enable local partiion.
                 * Otherwise, enable a remote partition.