cgroup/cpuset: Fix partition recovery with unavailable CPUs
Subsystems (3)
PATCH 1/1 cgroup/cpuset: Fix partition recovery with unavailable CPUs
From: Guopeng Zhang <[email protected]>
An invalid local partition can become valid again even when its exclusive CPUs are no longer available from its parent.
This can be reproduced on a cgroup v2 system with CPUs 0-7 online:
cd /sys/fs/cgroup
echo +cpuset > cgroup.subtree_control
mkdir A
echo 1-4 > A/cpuset.cpus
echo 1-4 > A/cpuset.cpus.exclusive
echo root > A/cpuset.cpus.partition
echo +cpuset > A/cgroup.subtree_control
mkdir A/B
echo 3-4 > A/B/cpuset.cpus
echo 3-4 > A/B/cpuset.cpus.exclusive
echo root > A/B/cpuset.cpus.partition
echo 1-2 > A/cpuset.cpus.exclusive
cat A/B/cpuset.cpus.partition
root
cat A/B/cpuset.cpus.exclusive.effective
cat A/cpuset.cpus.effective
1-2
cat A/B/cpuset.cpus.effective
1-2
B is changed back to a valid root even though its exclusive CPUs are no longer available and cpuset.cpus.exclusive.effective is empty. B should remain invalid until A can provide its exclusive CPUs again.
Shrinking A's exclusive CPUs invalidates B in compute_partition_effective_cpumask(). The subsequent walk in update_cpumasks_hier() tries to recover B, but update_parent_effective_cpumask() skips the recovery checks when xcpus is not a subset of parent->effective_xcpus. Since part_error is still zero, B is changed back to a valid partition.
Set PERR_INVCPUS when the subset check fails so that the partition stays invalid. New test cases are added to test_cpuset_prs.sh for removing and restoring the parent's exclusive CPUs.
--- kernel/cgroup/cpuset.c | 8 ++++++-- tools/testing/selftests/cgroup/test_cpuset_prs.sh | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-)
kernel/cgroup/cpuset.c +6 -2
@@ -1986,12 +1986,16 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,cpumask_copy (tmp->addmask, cs->effective_xcpus); adding = true; } - }else if (is_partition_invalid (cs) && !cpumask_empty (xcpus) && -cpumask_subset (xcpus, parent->effective_xcpus)) { + }else if (is_partition_invalid (cs) && !cpumask_empty (xcpus)) {struct cgroup_subsys_state *css;struct cpuset *child;bool exclusive = true; +if (!cpumask_subset (xcpus, parent->effective_xcpus)) { + part_error =PERR_INVCPUS ; + goto write_error; + } +/* * Convert invalid partition to valid has to pass the * cpu exclusivity test as well as the housekeeping
tools/testing/selftests/cgroup/test_cpuset_prs.sh +4 -0
@@ -427,6 +427,10 @@ TEST_MATRIX=( # cpuset.cpus is allowed, but those extra CPUs are ignored. " C2-3:P1 C3:P1 . . . C2-4 . . 0 A1:|A2:2-3 A1:P1|A2:P1" + # A child cannot recover until its exclusive CPUs are available again. + " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" + " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1" + # Taking away all CPUs from parent or itself if there are tasks # will make the partition invalid. " C2-3:P1 C3:P1 . . T C2-3 . . 0 A1:2-3|A2:2-3 A1:P1|A2:P-1"
Signature · 1 line
2.43.0
Waiman Long
maintainerQuoted 77 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
An invalid local partition can become valid again even when its exclusive CPUs are no longer available from its parent.
This can be reproduced on a cgroup v2 system with CPUs 0-7 online:
cd
/sys/fs/cgroup
echo +cpuset > cgroup.subtree_control
mkdir A
echo 1-4 > A/cpuset.cpus
echo 1-4 > A/cpuset.cpus.exclusive
echo root > A/cpuset.cpus.partition
echo +cpuset > A/cgroup.subtree_control
mkdir A/B
echo 3-4 > A/B/cpuset.cpus
echo 3-4 > A/B/cpuset.cpus.exclusive
echo root > A/B/cpuset.cpus.partition
echo 1-2 > A/cpuset.cpus.exclusive
cat A/B/cpuset.cpus.partition
root
cat A/B/cpuset.cpus.exclusive.effective
cat A/cpuset.cpus.effective
1-2
cat A/B/cpuset.cpus.effective
1-2B is changed back to a valid root even though its exclusive CPUs are no longer available and cpuset.cpus.exclusive.effective is empty. B should remain invalid until A can provide its exclusive CPUs again.
Shrinking A's exclusive CPUs invalidates B in
compute_partition_effective_cpumask(). The subsequent walk inupdate_cpumasks_hier()tries to recover B, butupdate_parent_effective_cpumask()skips the recovery checks when xcpus is not a subset ofparent->effective_xcpus. Sincepart_erroris still zero, B is changed back to a valid partition.Set
PERR_INVCPUSwhen the subset check fails so that the partition stays invalid. New test cases are added totest_cpuset_prs.shfor removing and restoring the parent's exclusive CPUs.Fixes 0c7f293efc87 ("cgroup/cpuset: Add cpuset.cpus.exclusive.effective for v2")Signed-off-by Guopeng Zhang <[email protected]>--- kernel/cgroup/cpuset.c | 8 ++++++-- tools/testing/selftests/cgroup/test_cpuset_prs.sh | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-)kernel/cgroup/cpuset.c +6
-2@@ -1986,12 +1986,16 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,cpumask_copy (tmp->addmask, cs->effective_xcpus); adding = true; } - }else if (is_partition_invalid (cs) && !cpumask_empty (xcpus) && -cpumask_subset (xcpus, parent->effective_xcpus)) { + }else if (is_partition_invalid (cs) && !cpumask_empty (xcpus)) {struct cgroup_subsys_state *css;struct cpuset *child;bool exclusive = true; +if (!cpumask_subset (xcpus, parent->effective_xcpus)) { + part_error =PERR_INVCPUS ; + goto write_error; + } +/* * Convert invalid partition to valid has to pass the * cpu exclusivity test as well as the housekeeping tools/testing/selftests/cgroup/test_cpuset_prs.sh +0
-0
tools/testing/selftests/cgroup/test_cpuset_prs.sh TEST_MATRIX=( · line 436
Quoted 10 lines
tools/testing/selftests/cgroup/test_cpuset_prs.sh +4
-0@@ -427,6 +427,10 @@ TEST_MATRIX=( # cpuset.cpus is allowed, but those extra CPUs are ignored. " C2-3:P1 C3:P1 . . . C2-4 . . 0 A1:|A2:2-3 A1:P1|A2:P1" + # A child cannot recover until its exclusive CPUs are available again. + " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" + " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1" + # Taking away all CPUs from parent or itself if there are tasks # will make the partition invalid. " C2-3:P1 C3:P1 . . T C2-3 . . 0 A1:2-3|A2:2-3 A1:P1|A2:P-1"
Patch 2 of my series should fix this problem too. I do borrow your test cases in my patch. I hope you don't mind about it.
Cheers,
Longman
Quoted 80 lines · Waiman Long
Quoted 79 lines · Guopeng Zhang
From: Guopeng Zhang <[email protected]>
An invalid local partition can become valid again even when its exclusive CPUs are no longer available from its parent.
This can be reproduced on a cgroup v2 system with CPUs 0-7 online:
cd
/sys/fs/cgroup
echo +cpuset > cgroup.subtree_control
mkdir A
echo 1-4 > A/cpuset.cpus
echo 1-4 > A/cpuset.cpus.exclusive
echo root > A/cpuset.cpus.partition
echo +cpuset > A/cgroup.subtree_control
mkdir A/B
echo 3-4 > A/B/cpuset.cpus
echo 3-4 > A/B/cpuset.cpus.exclusive
echo root > A/B/cpuset.cpus.partition
echo 1-2 > A/cpuset.cpus.exclusive
cat A/B/cpuset.cpus.partition
root
cat A/B/cpuset.cpus.exclusive.effective
cat A/cpuset.cpus.effective
1-2
cat A/B/cpuset.cpus.effective
1-2B is changed back to a valid root even though its exclusive CPUs are no longer available and cpuset.cpus.exclusive.effective is empty. B should remain invalid until A can provide its exclusive CPUs again.
Shrinking A's exclusive CPUs invalidates B in
compute_partition_effective_cpumask(). The subsequent walk inupdate_cpumasks_hier()tries to recover B, butupdate_parent_effective_cpumask()skips the recovery checks when xcpus is not a subset ofparent->effective_xcpus. Sincepart_erroris still zero, B is changed back to a valid partition.Set
PERR_INVCPUSwhen the subset check fails so that the partition stays invalid. New test cases are added totest_cpuset_prs.shfor removing and restoring the parent's exclusive CPUs.Fixes 0c7f293efc87 ("cgroup/cpuset: Add cpuset.cpus.exclusive.effective for v2")Signed-off-by Guopeng Zhang <[email protected]>---
kernel/cgroup/cpuset.c | 8 ++++++--tools/testing/selftests/cgroup/test_cpuset_prs.sh| 4 ++++2 files changed, 10 insertions(+), 2 deletions(-)kernel/cgroup/cpuset.c +5
-2@@ -1986,12 +1986,16 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, cpumask_copy(tmp->addmask, cs->effective_xcpus); adding = true; } - } else if (is_partition_invalid(cs) && !cpumask_empty(xcpus) && - cpumask_subset(xcpus, parent->effective_xcpus)) { + } else if (is_partition_invalid(cs) && !cpumask_empty(xcpus)) { struct cgroup_subsys_state *css; struct cpuset *child; bool exclusive = true; + if (!cpumask_subset(xcpus, parent->effective_xcpus)) { + part_error = PERR_INVCPUS; + goto write_error; + } + /** Convert invalid partition to valid has to pass the * cpu exclusivity test as well as the housekeeping tools/testing/selftests/cgroup/test_cpuset_prs.sh +0
-0@@ -427,6 +427,10 @@ TEST_MATRIX=( # cpuset.cpus is allowed, but those extra CPUs are ignored." C2-3:P1 C3:P1 . . . C2-4 . . 0 A1:|A2:2-3 A1:P1|A2:P1" + # A child cannot recover until its exclusive CPUs are available again.
Quoted 9 lines
Quoted 6 lines
+ " CX1-4:P1 CX3-4:P1 . . X1-2 . . . 0 A1:1-2|A2:1-2|XA2: A1:P1|A2:P-1" + " CX1-4:P1 CX3-4:P1 . . X1-2:X1-4 . . . 0 A1:1-2|A2:3-4|XA2:3-4 A1:P1|A2:P1" +
# Taking away all CPUs from parent or itself if there are tasks# will make the partition invalid. " C2-3:P1 C3:P1 . . T C2-3 . . 0 A1:2-3|A2:2-3 A1:P1|A2:P-1"Patch 2 of my series should fix this problem too. I do borrow your test cases in my patch. I hope you don't mind about it.
Thanks for addressing this issue as well.
Of course, I don't mind. Glad the test cases are useful!
Thanks,
Guopeng