cgroup/cpuset: Fix some more bugs in cpuset partition code
Subsystems (3)
Waiman Long
maintainerv2 cover cgroup/cpuset: Fix some more bugs in cpuset partition code
v2:
- Add two fix patches for problems reported by sashiko and Guopeng.
This is another series of 3 fix patches for bugs in cpuset partition code.
Waiman Long (3):
cgroup/cpuset: Fix incorrect CPU accounting with parent's
effective_xcpus expansion
cgroup/cpuset: Recompute effective cpumask in update_cpumasks_hier()
after calling update_parent_effective_cpumask()
cgroup/cpuset: Do housekeeping check when isolated child with root
parent may get more xcpus
kernel/cgroup/cpuset.c | 32 ++++++++++++++++--- .../selftests/cgroup/test_cpuset_prs.sh | 25 +++++++++++++-- 2 files changed, 51 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0
Waiman Long
maintainerPATCH v2 1/3 cgroup/cpuset: Fix incorrect CPU accounting with parent's effective_xcpus expansion
Commit ec0254b9eb49 ("cgroup/cpuset: Release invalid isolated CPUs with a shrunk root partition parent") fixes incorrect isolated_cpus accounting when contraction of a parent's effective_xcpus can cause a child partition to lose isolated CPUs. Expansion of parent's effective_cpus can also allow a child partition to gain more effective_xcpus. However, the current code doesn't handle this case correctly leading to incorrect effective_cpus and isolated_cpus accounting. Fix that by looking for this possible expansion of effective_xcpus and perform the proper accounting action.
New test cases are added to test this effective_xcpus expansion scenarios.
--- kernel/cgroup/cpuset.c | 12 ++++++++++++ tools/testing/selftests/cgroup/test_cpuset_prs.sh | 15 +++++++++++++++ 2 files changed, 27 insertions(+)
kernel/cgroup/cpuset.c +12 -0
@@ -2097,6 +2097,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, parent->effective_xcpus);if (!cpumask_empty (tmp->addmask))isolated_cpus_release (cs, tmp->addmask); +/* Expansion of parent's effective_xcpus is handled below */ }if (nocpu) { part_error =PERR_NOCPUS ;
@@ -2106,11 +2107,22 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, parent->effective_xcpus); }else if ((parent_prs ==PRS_ISOLATED ) && ((old_prs ==PRS_ROOT ) || (old_prs == -PRS_ROOT ))) { +/* Parent partition state changed to PRS_ISOLATED */ part_error =PERR_ISOPARENT ;if (old_prs ==PRS_ROOT ) {cpumask_copy (tmp->addmask, cs->effective_xcpus); adding = true; } + }else if (is_partition_valid (cs) && + !cpumask_equal (tmp->delmask, cs->effective_xcpus)) { +/* +* If there is an expansion of parent's effective_xcpus, +* we may take more xcpus from parent. The parent's +* effective_cpus should still have active CPUs or nocpu +* should have been set. +*/ + deleting =cpumask_andnot (tmp->delmask, tmp->delmask, + cs->effective_xcpus); }else if (is_partition_invalid (cs)) {struct cgroup_subsys_state *css;struct cpuset *child;
tools/testing/selftests/cgroup/test_cpuset_prs.sh +15 -0
@@ -531,6 +531,21 @@ TEST_MATRIX=( " C1-4:P1 C3-4:P2 . . T:C4-6 . . . 0 A1:5-6|A2:4 A1:P1|A2:P2 4" " C1-4:P1 C1-2:P2 . . T:C4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # The extra CPUs gained by a child partition when its parent expands the + # exclusive CPUs have to be taken away from the parent. + " C2-6:X2-5:P1 CX3-6:P1 \ + . . X2-6 . . . 0 A1:2|A2:3-6|XA2:3-6 A1:P1|A2:P1 ." + " C2-6:X2-5:P1 CX3-6:P2 \ + . . X2-6 . . . 0 A1:2|A2:3-6|XA2:3-6 A1:P1|A2:P2 3-6" + + # Both expansion and contraction of parent's effective_xcpus will be + # correctly handled in child partition and the child can be invalidated + # if a populated parent could lose all its effective_cpus. + " C2-6:X2-5:P1 CX3,5-6:P2 \ + . . X4-6 . . . 0 A1:4|A2:5-6|XA2:5-6 A1:P1|A2:P2 5-6" + " C2-6:X2-5:P1 CX3-6:P2 \ + . . T:X4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------
Signature · 1 line
2.56.0
Waiman Long
maintainerPATCH v2 2/3 cgroup/cpuset: Recompute effective cpumask in update_cpumasks_hier() after calling update_parent_effective_cpumask()
In reply to Waiman LongIt is reported by sashiko that calling update_parent_effective_cpumask() may clobber tmp->new_cpus when update_sibling_cpumasks() needs to be called due to possible change in the parent's effective_cpus value. Therefore the new effective cpumask has to be recomputed after calling update_parent_effective_cpumask() to get a correct value back into tmp->new_cpus.
--- kernel/cgroup/cpuset.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/cgroup/cpuset.c +4 -4
@@ -2359,12 +2359,12 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,update_parent_effective_cpumask (cp, partcmd_update,NULL , tmp);/* * Capture current partition_root_state as it may have -* changed. Recompute effective cpumask if changed. +* changed. Always recompute effective cpumask as tmp->new_cpus +* may be clobbered when update_sibling_cpumasks() is called +* within update_parent_effective_cpumask(). */ new_prs = cp->partition_root_state; -if (new_prs != old_prs) { -compute_effective_cpumask (tmp->new_cpus, cp, parent); - } +compute_effective_cpumask (tmp->new_cpus, cp, parent); }spin_lock_irq (&callback_lock);
Signature · 1 line
2.56.0
Waiman Long
maintainerPATCH v2 3/3 cgroup/cpuset: Do housekeeping check when isolated child with root parent may get more xcpus
In reply to Waiman LongIt is reported by sashiko and Guopeng that when an isolated child with root parent gets more isolated CPUs from the expansion of the parent's effective_xcpus, it is possible that all the active housekeeping CPUs may be gone. So a prstate_housekeeping_conflict() should be performed when that happens. Add the check to make sure that we can't exhaust all the active housekeeping CPUs.
Test cases are added to the NOHZ_FULL_TEST_MATRIX of test_cpuset_prs.sh to test that.
--- kernel/cgroup/cpuset.c | 18 +++++++++++++++--- .../selftests/cgroup/test_cpuset_prs.sh | 10 ++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-)
kernel/cgroup/cpuset.c +15 -3
@@ -2119,10 +2119,22 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,* If there is an expansion of parent's effective_xcpus, * we may take more xcpus from parent. The parent's * effective_cpus should still have active CPUs or nocpu -* should have been set. +* should have been set. We also need to do a +* housekeeping check for an isolated child with root +* parent to make sure that it won't exhaust all the +* active housekeeping CPUs. */ - deleting =cpumask_andnot (tmp->delmask, tmp->delmask, - cs->effective_xcpus); +cpumask_andnot (tmp->addmask, cs->effective_xcpus, tmp->delmask); +if ((parent_prs ==PRS_ROOT ) && (old_prs ==PRS_ISOLATED ) && +prstate_housekeeping_conflict (old_prs, parent_prs, + tmp->delmask, tmp->addmask)) { + adding =cpumask_and (tmp->addmask, cs->effective_xcpus, + tmp->delmask); + part_error =PERR_HKEEPING ; + }else { + deleting =cpumask_andnot (tmp->delmask, tmp->delmask, + cs->effective_xcpus); + } }else if (is_partition_invalid (cs)) {struct cgroup_subsys_state *css;struct cpuset *child;
tools/testing/selftests/cgroup/test_cpuset_prs.sh +8 -2
@@ -137,7 +137,8 @@ LAST_PRESENT_CPU=$(cat /sys/devices/system/cpu/present | sed -e "s/.*[,-]//") # If isolated CPUs have been reserved at boot time (as shown in # /sys/devices/system/cpu/isolated), these isolated CPUs should be outside of # CPUs 0-8 that will be used by this script for testing purpose. If not, some -# of the tests may fail incorrectly. +# of the tests may fail incorrectly. The first boot isolated CPU should be +# 10 or above. # # The current set of isolated CPUs (as shown in cpuset.cpus.isolated) should # be the same as the boot value. If not, wait a bit and retry again just in
@@ -156,7 +157,7 @@ TEST_ISOLCPUS= [[ -n "$BOOT_ISOLCPUS" ]] && { FIRST_ISOLCPUS=$(echo $BOOT_ISOLCPUS | sed -e "s/[,-].*//") echo "Boot isolated CPUs: $BOOT_ISOLCPUS" - [[ $FIRST_ISOLCPUS -le 8 ]] && + [[ $FIRST_ISOLCPUS -le 9 ]] && skip_test "Boot isolated CPUs overlap CPUs to be tested" }
@@ -602,6 +603,7 @@ ISOLCPUS_TEST_MATRIX=( ) # Test matrix to be run when boot time nohz_full CPUs cover all CPUs except CPUs 0-7 +# This also means that CPU 8 is available and is a nohz_full CPU. NOHZ_FULL_TEST_MATRIX=( # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------
@@ -610,6 +612,10 @@ NOHZ_FULL_TEST_MATRIX=( " C2-7:P2 . . . C0-4 . . . 0 A1:0-4 A1:P2 0-4" " C1-7:P2 C5-7:P2 . . . . . C0:P2 0 A1:1-4|A2:5-7|B1:0 A1:P2|A2:P2|B1:P-2 1-7" + # An isolated child partition cannot grow to take over the last + # housekeeping CPU when its parent expands the exclusive CPUs. + " C0-8:X1-8:P1 CX0-8:P2 . . X0-7 . . . 0 A1:0-7|A2:0-7 A1:P1|A2:P-2 ." + " C0-8:X0-6:P1 CX0-8:P2 . . X2-8 . . . 0 A1:|A2:2-8 A1:P1|A2:P2 2-8" ) #
Signature · 1 line
2.56.0
Re: [PATCH v2 1/3] cgroup/cpuset: Fix incorrect CPU accounting with parent's effective_xcpus expansion
In reply to Waiman LongQuoted 70 lines · Waiman Long
Commit
ec0254b9eb49("cgroup/cpuset: Release invalid isolated CPUs with a shrunk root partition parent") fixes incorrectisolated_cpusaccounting when contraction of a parent'seffective_xcpuscan cause a child partition to lose isolated CPUs. Expansion of parent'seffective_cpuscan also allow a child partition to gain moreeffective_xcpus. However, the current code doesn't handle this case correctly leading to incorrecteffective_cpusandisolated_cpusaccounting. Fix that by looking for this possible expansion ofeffective_xcpusand perform the proper accounting action.New test cases are added to test this
effective_xcpusexpansion scenarios.Reported-by Guopeng Zhang <[email protected]>Signed-off-by Waiman Long <[email protected]>--- kernel/cgroup/cpuset.c | 12 ++++++++++++ tools/testing/selftests/cgroup/test_cpuset_prs.sh | 15 +++++++++++++++ 2 files changed, 27 insertions(+)kernel/cgroup/cpuset.c +12
-0@@ -2097,6 +2097,7 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, parent->effective_xcpus);if (!cpumask_empty (tmp->addmask))isolated_cpus_release (cs, tmp->addmask); +/* Expansion of parent's effective_xcpus is handled below */ }if (nocpu) { part_error =PERR_NOCPUS ;@@ -2106,11 +2107,22 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd, parent->effective_xcpus); }else if ((parent_prs ==PRS_ISOLATED ) && ((old_prs ==PRS_ROOT ) || (old_prs == -PRS_ROOT ))) { +/* Parent partition state changed to PRS_ISOLATED */ part_error =PERR_ISOPARENT ;if (old_prs ==PRS_ROOT ) {cpumask_copy (tmp->addmask, cs->effective_xcpus); adding = true; } + }else if (is_partition_valid (cs) && + !cpumask_equal (tmp->delmask, cs->effective_xcpus)) { +/* +* If there is an expansion of parent's effective_xcpus, +* we may take more xcpus from parent. The parent's +* effective_cpus should still have active CPUs or nocpu +* should have been set. +*/ + deleting =cpumask_andnot (tmp->delmask, tmp->delmask, + cs->effective_xcpus); }else if (is_partition_invalid (cs)) {struct cgroup_subsys_state *css;struct cpuset *child;tools/testing/selftests/cgroup/test_cpuset_prs.sh +8
-0@@ -531,6 +531,21 @@ TEST_MATRIX=( " C1-4:P1 C3-4:P2 . . T:C4-6 . . . 0 A1:5-6|A2:4 A1:P1|A2:P2 4" " C1-4:P1 C1-2:P2 . . T:C4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # The extra CPUs gained by a child partition when its parent expands the + # exclusive CPUs have to be taken away from the parent. + " C2-6:X2-5:P1 CX3-6:P1 \ + . . X2-6 . . . 0 A1:2|A2:3-6|XA2:3-6 A1:P1|A2:P1 ." + " C2-6:X2-5:P1 CX3-6:P2 \ + . . X2-6 . . . 0 A1:2|A2:3-6|XA2:3-6 A1:P1|A2:P2 3-6" + + # Both expansion and contraction of parent's effective_xcpus will be
tools/testing/selftests/cgroup/test_cpuset_prs.sh TEST_MATRIX=( · line 551
Quoted 10 lines
tools/testing/selftests/cgroup/test_cpuset_prs.sh +7
-0+ # correctly handled in child partition and the child can be invalidated + # if a populated parent could lose all its effective_cpus. + " C2-6:X2-5:P1 CX3,5-6:P2 \ + . . X4-6 . . . 0 A1:4|A2:5-6|XA2:5-6 A1:P1|A2:P2 5-6" + " C2-6:X2-5:P1 CX3-6:P2 \ + . . T:X4-6 . . . 0 A1:4-6|A2:4-6 A1:P1|A2:P-2 ." + # # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------
Thanks,
Guopeng
Re: [PATCH v2 2/3] cgroup/cpuset: Recompute effective cpumask in update_cpumasks_hier() after calling update_parent_effective_cpumask()
In reply to Waiman LongQuoted 24 lines · Waiman Long
It is reported by sashiko that calling
update_parent_effective_cpumask()may clobbertmp->new_cpuswhenupdate_sibling_cpumasks()needs to be called due to possible change in the parent'seffective_cpusvalue. Therefore the new effective cpumask has to be recomputed after callingupdate_parent_effective_cpumask()to get a correct value back intotmp->new_cpus.Fixes f0af1bfc27b5 ("cgroup/cpuset: Relax constraints to partition & cpus changes")Signed-off-by Waiman Long <[email protected]>--- kernel/cgroup/cpuset.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)kernel/cgroup/cpuset.c +2
-1@@ -2359,12 +2359,12 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,update_parent_effective_cpumask (cp, partcmd_update,NULL , tmp);/* * Capture current partition_root_state as it may have -* changed. Recompute effective cpumask if changed. +* changed. Always recompute effective cpumask as tmp->new_cpus +* may be clobbered when update_sibling_cpumasks() is called
kernel/cgroup/cpuset.c static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp, · line 2370
Quoted 10 lines
kernel/cgroup/cpuset.c +2
-3+* within update_parent_effective_cpumask(). */ new_prs = cp->partition_root_state; -if (new_prs != old_prs) { -compute_effective_cpumask (tmp->new_cpus, cp, parent); - } +compute_effective_cpumask (tmp->new_cpus, cp, parent); }spin_lock_irq (&callback_lock);
Thanks,
Guopeng
Re: [PATCH v2 3/3] cgroup/cpuset: Do housekeeping check when isolated child with root parent may get more xcpus
In reply to Waiman LongQuoted 81 lines · Waiman Long
It is reported by sashiko and Guopeng that when an isolated child with root parent gets more isolated CPUs from the expansion of the parent's
effective_xcpus, it is possible that all the active housekeeping CPUs may be gone. So aprstate_housekeeping_conflict()should be performed when that happens. Add the check to make sure that we can't exhaust all the active housekeeping CPUs.Test cases are added to the
NOHZ_FULL_TEST_MATRIXoftest_cpuset_prs.shto test that.Reported-by Guopeng Zhang <[email protected]>Fixes e2ffe502ba45 ("cgroup/cpuset: Add cpuset.cpus.exclusive for v2")Signed-off-by Waiman Long <[email protected]>--- kernel/cgroup/cpuset.c | 18 +++++++++++++++--- .../selftests/cgroup/test_cpuset_prs.sh | 10 ++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-)kernel/cgroup/cpuset.c +15
-3@@ -2119,10 +2119,22 @@ static int update_parent_effective_cpumask(struct cpuset *cs, int cmd,* If there is an expansion of parent's effective_xcpus, * we may take more xcpus from parent. The parent's * effective_cpus should still have active CPUs or nocpu -* should have been set. +* should have been set. We also need to do a +* housekeeping check for an isolated child with root +* parent to make sure that it won't exhaust all the +* active housekeeping CPUs. */ - deleting =cpumask_andnot (tmp->delmask, tmp->delmask, - cs->effective_xcpus); +cpumask_andnot (tmp->addmask, cs->effective_xcpus, tmp->delmask); +if ((parent_prs ==PRS_ROOT ) && (old_prs ==PRS_ISOLATED ) && +prstate_housekeeping_conflict (old_prs, parent_prs, + tmp->delmask, tmp->addmask)) { + adding =cpumask_and (tmp->addmask, cs->effective_xcpus, + tmp->delmask); + part_error =PERR_HKEEPING ; + }else { + deleting =cpumask_andnot (tmp->delmask, tmp->delmask, + cs->effective_xcpus); + } }else if (is_partition_invalid (cs)) {struct cgroup_subsys_state *css;struct cpuset *child;tools/testing/selftests/cgroup/test_cpuset_prs.sh +4
-2@@ -137,7 +137,8 @@ LAST_PRESENT_CPU=$(cat /sys/devices/system/cpu/present | sed -e "s/.*[,-]//") # If isolated CPUs have been reserved at boot time (as shown in # /sys/devices/system/cpu/isolated), these isolated CPUs should be outside of # CPUs 0-8 that will be used by this script for testing purpose. If not, some -# of the tests may fail incorrectly. +# of the tests may fail incorrectly. The first boot isolated CPU should be +# 10 or above. # # The current set of isolated CPUs (as shown in cpuset.cpus.isolated) should # be the same as the boot value. If not, wait a bit and retry again just in@@ -156,7 +157,7 @@ TEST_ISOLCPUS= [[ -n "$BOOT_ISOLCPUS" ]] && { FIRST_ISOLCPUS=$(echo $BOOT_ISOLCPUS | sed -e "s/[,-].*//") echo "Boot isolated CPUs: $BOOT_ISOLCPUS" - [[ $FIRST_ISOLCPUS -le 8 ]] && + [[ $FIRST_ISOLCPUS -le 9 ]] && skip_test "Boot isolated CPUs overlap CPUs to be tested" }@@ -602,6 +603,7 @@ ISOLCPUS_TEST_MATRIX=( ) # Test matrix to be run when boot time nohz_full CPUs cover all CPUs except CPUs 0-7 +# This also means that CPU 8 is available and is a nohz_full CPU. NOHZ_FULL_TEST_MATRIX=( # old-A1 old-A2 old-A3 old-B1 new-A1 new-A2 new-A3 new-B1 fail ECPUs Pstate ISOLCPUS # ------ ------ ------ ------ ------ ------ ------ ------ ---- ----- ------ --------
tools/testing/selftests/cgroup/test_cpuset_prs.sh NOHZ_FULL_TEST_MATRIX=( · line 621
Quoted 10 lines
tools/testing/selftests/cgroup/test_cpuset_prs.sh +4
-0@@ -610,6 +612,10 @@ NOHZ_FULL_TEST_MATRIX=( " C2-7:P2 . . . C0-4 . . . 0 A1:0-4 A1:P2 0-4" " C1-7:P2 C5-7:P2 . . . . . C0:P2 0 A1:1-4|A2:5-7|B1:0 A1:P2|A2:P2|B1:P-2 1-7" + # An isolated child partition cannot grow to take over the last + # housekeeping CPU when its parent expands the exclusive CPUs. + " C0-8:X1-8:P1 CX0-8:P2 . . X0-7 . . . 0 A1:0-7|A2:0-7 A1:P1|A2:P-2 ." + " C0-8:X0-6:P1 CX0-8:P2 . . X2-8 . . . 0 A1:|A2:2-8 A1:P1|A2:P2 2-8" ) #
Thanks,
Guopeng
Quoted 6 lines
cgroup/cpuset: Fix incorrect CPU accounting with parent's
effective_xcpusexpansion
cgroup/cpuset: Recompute effective cpumask inupdate_cpumasks_hier()
after callingupdate_parent_effective_cpumask()
cgroup/cpuset: Do housekeeping check when isolated child with root
parent may get more xcpus
Applied 1-3 to cgroup/for-7.4-fixes with the following tags added:
Two issues I noticed:
- Three of patch 1's new TEST_MATRIX rows end with A1 as a single-CPU root partition, which has no sched domain, so they fail the ISOLCPUS check when the script runs with -v.
- The comment at the end of the "partcmd_update w/o newmask" block in update_parent_effective_cpumask() still says there is no need to adjust the parent's effective_cpus. Patch 1's new expansion branch now does exactly that.
Thanks.
--
tejun
Waiman Long
maintainerQuoted 13 lines · Tejun Heo
Quoted 6 lines
cgroup/cpuset: Fix incorrect CPU accounting with parent's
effective_xcpusexpansion
cgroup/cpuset: Recompute effective cpumask inupdate_cpumasks_hier()
after callingupdate_parent_effective_cpumask()
cgroup/cpuset: Do housekeeping check when isolated child with root
parent may get more xcpusApplied 1-3 to cgroup/for-7.4-fixes with the following tags added:
Reviewed-by Guopeng Zhang <[email protected]>Tested-by Guopeng Zhang <[email protected]>Two issues I noticed:
Quoted 8 lines
- Three of patch 1's new
TEST_MATRIXrows end with A1 as a single-CPU root partition, which has no sched domain, so they fail the ISOLCPUS check when the script runs with -v.- The comment at the end of the "
partcmd_updatew/o newmask" block inupdate_parent_effective_cpumask()still says there is no need to adjust the parent'seffective_cpus. Patch 1's new expansion branch now does exactly that.
Thanks for noticing that. Will fix that in the next set of fixes that I am working on.
Cheers,
Longman