Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cgroup/cpuset: Fix wrong check in update_parent_subparts_cpumask()

It was found that the check to see if a partition could use up all
the cpus from the parent cpuset in update_parent_subparts_cpumask()
was incorrect. As a result, it is possible to leave parent with no
effective cpu left even if there are tasks in the parent cpuset. This
can lead to system panic as reported in [1].

Fix this probem by updating the check to fail the enabling the partition
if parent's effective_cpus is a subset of the child's cpus_allowed.

Also record the error code when an error happens in update_prstate()
and add a test case where parent partition and child have the same cpu
list and parent has task. Enabling partition in the child will fail in
this case.

[1] https://www.spinics.net/lists/cgroups/msg36254.html

Fixes: f0af1bfc27b5 ("cgroup/cpuset: Relax constraints to partition & cpus changes")
Cc: stable@vger.kernel.org # v6.1
Reported-by: Srinivas Pandruvada <srinivas.pandruvada@intel.com>
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Waiman Long and committed by
Tejun Heo
e5ae8803 58706f7f

+3 -1
+2 -1
kernel/cgroup/cpuset.c
··· 1346 1346 * A parent can be left with no CPU as long as there is no 1347 1347 * task directly associated with the parent partition. 1348 1348 */ 1349 - if (!cpumask_intersects(cs->cpus_allowed, parent->effective_cpus) && 1349 + if (cpumask_subset(parent->effective_cpus, cs->cpus_allowed) && 1350 1350 partition_is_populated(parent, cs)) 1351 1351 return PERR_NOCPUS; 1352 1352 ··· 2324 2324 new_prs = -new_prs; 2325 2325 spin_lock_irq(&callback_lock); 2326 2326 cs->partition_root_state = new_prs; 2327 + WRITE_ONCE(cs->prs_err, err); 2327 2328 spin_unlock_irq(&callback_lock); 2328 2329 /* 2329 2330 * Update child cpusets, if present.
+1
tools/testing/selftests/cgroup/test_cpuset_prs.sh
··· 268 268 # Taking away all CPUs from parent or itself if there are tasks 269 269 # will make the partition invalid. 270 270 " S+ C2-3:P1:S+ C3:P1 . . T C2-3 . . 0 A1:2-3,A2:2-3 A1:P1,A2:P-1" 271 + " S+ C3:P1:S+ C3 . . T P1 . . 0 A1:3,A2:3 A1:P1,A2:P-1" 271 272 " S+ $SETUP_A123_PARTITIONS . T:C2-3 . . . 0 A1:2-3,A2:2-3,A3:3 A1:P1,A2:P-1,A3:P-1" 272 273 " S+ $SETUP_A123_PARTITIONS . T:C2-3:C1-3 . . . 0 A1:1,A2:2,A3:3 A1:P1,A2:P1,A3:P1" 273 274