Commit 6da580ec656a ("cgroup/cpuset: Don't allow creation of local
partition over a remote one") added a check in update_prstate() to reject
creating a top-level local partition whose cs->exclusive_cpus intersects
subpartitions_cpus.

However, if a top-level cgroup A1 is first set to "root" with all CPUs
(CX0-7:P1, becoming "root invalid" because no CPUs would remain in
top_cpuset), has a child A1/A2 enabled as a remote partition on a subset
of those exclusive CPUs (CX2-3:P2), and A1 is then updated to a valid CPU
subset (CX1-3), update_exclusive_cpumask() / update_cpumask() calls
validate_partition() without going through update_prstate(). Because
validate_partition() does not check trialcs->exclusive_cpus against
subpartitions_cpus, A1 transitions from "root invalid" to a valid local
partition over the existing remote partition A1/A2 and triggers:

  WARNING: kernel/cgroup/cpuset.c:1943 at 
update_parent_effective_cpumask+0x189b/0x1fd0

Check trialcs->exclusive_cpus against subpartitions_cpus in
validate_partition() when !is_partition_valid(cs), and add a regression
test case to tools/testing/selftests/cgroup/test_cpuset_prs.sh.

Tested in QEMU on Linux 7.3.0-rc3 using
tools/testing/selftests/cgroup/test_cpuset_prs.sh.

Fixes: 6da580ec656a ("cgroup/cpuset: Don't allow creation of local partition 
over a remote one")
Cc: [email protected]
Assisted-by: LLM
Signed-off-by: Hui Peng <[email protected]>
---
Changes in v3:
- Split the validate_partition() fix (Fixes: 6da580ec656a) and the
  cpus_excl_conflict() fix (Fixes: 2a3602030d80) into separate patches.

 kernel/cgroup/cpuset.c                        | 4 ++++
 tools/testing/selftests/cgroup/test_cpuset_prs.sh | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 7381fa8502e7..7c5b4a8f1f3a 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2415,6 +2415,10 @@ static enum prs_errcode validate_partition(struct cpuset 
*cs, struct cpuset *tri
        if (cpumask_empty(trialcs->effective_xcpus))
                return PERR_INVCPUS;
 
+       if ((parent == &top_cpuset) && !is_partition_valid(cs) &&
+           cpumask_intersects(trialcs->exclusive_cpus, subpartitions_cpus))
+               return PERR_REMOTE;
+
        if (prstate_housekeeping_conflict(trialcs->partition_root_state,
                                          trialcs->effective_xcpus))
                return PERR_HKEEPING;
diff --git a/tools/testing/selftests/cgroup/test_cpuset_prs.sh 
b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
index b732078bf319..f4d1822d4e21 100755
--- a/tools/testing/selftests/cgroup/test_cpuset_prs.sh
+++ b/tools/testing/selftests/cgroup/test_cpuset_prs.sh
@@ -321,6 +321,8 @@ TEST_MATRIX=(
        " C1-3:P2  X4:P2    .      .      .    X3:P2    .      .     0 
A1:1-2|XA1:1-3|A2:3:XA2:3 A1:P2|A2:P2 1-3"
        " C0-3:P2    .      .    C4-6   C0-4     .      .      .     0 
A1:0-4|B1:5-6 A1:P2|B1:P0"
        " C0-3:P2    .      .    C4-6 C0-4:C0-3  .      .      .     0 
A1:0-3|B1:4-6 A1:P2|B1:P0 0-3"
+       " CX0-7:P1 CX2-3:P2 .      .    CX1-3    .      .      .     0 
A1:1|A2:2-3|XA2:2-3 \
+                                                                      
A1:P-1|A2:P2 2-3"
 
        # Local partition invalidation tests
        " C0-3:X1-3:P2 C1-3:X2-3:P2 C2-3:X3:P2 \
-- 
2.49.0

Reply via email to