Skip to content

Commit 9b496a8

Browse files
Waiman-Longhtejun
authored andcommitted
cgroup/cpuset: Prevent leakage of isolated CPUs into sched domains
Isolated CPUs are not allowed to be used in a non-isolated partition. The only exception is the top cpuset which is allowed to contain boot time isolated CPUs. Commit ccac8e8 ("cgroup/cpuset: Fix remote root partition creation problem") introduces a simplified scheme of including only partition roots in sched domain generation. However, it does not properly account for this exception case. This can result in leakage of isolated CPUs into a sched domain. Fix it by making sure that isolated CPUs are excluded from the top cpuset before generating sched domains. Also update the way the boot time isolated CPUs are handled in test_cpuset_prs.sh to make sure that those isolated CPUs are really isolated instead of just skipping them in the tests. Fixes: ccac8e8 ("cgroup/cpuset: Fix remote root partition creation problem") Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent eb1dd15 commit 9b496a8

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

kernel/cgroup/cpuset.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,15 @@ static int generate_sched_domains(cpumask_var_t **domains,
885885
*/
886886
if (cgrpv2) {
887887
for (i = 0; i < ndoms; i++) {
888-
cpumask_copy(doms[i], csa[i]->effective_cpus);
888+
/*
889+
* The top cpuset may contain some boot time isolated
890+
* CPUs that need to be excluded from the sched domain.
891+
*/
892+
if (csa[i] == &top_cpuset)
893+
cpumask_and(doms[i], csa[i]->effective_cpus,
894+
housekeeping_cpumask(HK_TYPE_DOMAIN));
895+
else
896+
cpumask_copy(doms[i], csa[i]->effective_cpus);
889897
if (dattr)
890898
dattr[i] = SD_ATTR_INIT;
891899
}

tools/testing/selftests/cgroup/test_cpuset_prs.sh

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ echo "" > test/cpuset.cpus
8686

8787
#
8888
# If isolated CPUs have been reserved at boot time (as shown in
89-
# cpuset.cpus.isolated), these isolated CPUs should be outside of CPUs 0-7
89+
# cpuset.cpus.isolated), these isolated CPUs should be outside of CPUs 0-8
9090
# that will be used by this script for testing purpose. If not, some of
91-
# the tests may fail incorrectly. These isolated CPUs will also be removed
92-
# before being compared with the expected results.
91+
# the tests may fail incorrectly. These pre-isolated CPUs should stay in
92+
# an isolated state throughout the testing process for now.
9393
#
9494
BOOT_ISOLCPUS=$(cat $CGROUP2/cpuset.cpus.isolated)
9595
if [[ -n "$BOOT_ISOLCPUS" ]]
9696
then
97-
[[ $(echo $BOOT_ISOLCPUS | sed -e "s/[,-].*//") -le 7 ]] &&
97+
[[ $(echo $BOOT_ISOLCPUS | sed -e "s/[,-].*//") -le 8 ]] &&
9898
skip_test "Pre-isolated CPUs ($BOOT_ISOLCPUS) overlap CPUs to be tested"
9999
echo "Pre-isolated CPUs: $BOOT_ISOLCPUS"
100100
fi
@@ -683,15 +683,19 @@ check_isolcpus()
683683
EXPECT_VAL2=$EXPECT_VAL
684684
fi
685685
686+
#
687+
# Appending pre-isolated CPUs
688+
# Even though CPU #8 isn't used for testing, it can't be pre-isolated
689+
# to make appending those CPUs easier.
690+
#
691+
[[ -n "$BOOT_ISOLCPUS" ]] && {
692+
EXPECT_VAL=${EXPECT_VAL:+${EXPECT_VAL},}${BOOT_ISOLCPUS}
693+
EXPECT_VAL2=${EXPECT_VAL2:+${EXPECT_VAL2},}${BOOT_ISOLCPUS}
694+
}
695+
686696
#
687697
# Check cpuset.cpus.isolated cpumask
688698
#
689-
if [[ -z "$BOOT_ISOLCPUS" ]]
690-
then
691-
ISOLCPUS=$(cat $ISCPUS)
692-
else
693-
ISOLCPUS=$(cat $ISCPUS | sed -e "s/,*$BOOT_ISOLCPUS//")
694-
fi
695699
[[ "$EXPECT_VAL2" != "$ISOLCPUS" ]] && {
696700
# Take a 50ms pause and try again
697701
pause 0.05
@@ -731,8 +735,6 @@ check_isolcpus()
731735
fi
732736
done
733737
[[ "$ISOLCPUS" = *- ]] && ISOLCPUS=${ISOLCPUS}$LASTISOLCPU
734-
[[ -n "BOOT_ISOLCPUS" ]] &&
735-
ISOLCPUS=$(echo $ISOLCPUS | sed -e "s/,*$BOOT_ISOLCPUS//")
736738

737739
[[ "$EXPECT_VAL" = "$ISOLCPUS" ]]
738740
}
@@ -836,8 +838,11 @@ run_state_test()
836838
# if available
837839
[[ -n "$ICPUS" ]] && {
838840
check_isolcpus $ICPUS
839-
[[ $? -ne 0 ]] && test_fail $I "isolated CPU" \
840-
"Expect $ICPUS, get $ISOLCPUS instead"
841+
[[ $? -ne 0 ]] && {
842+
[[ -n "$BOOT_ISOLCPUS" ]] && ICPUS=${ICPUS},${BOOT_ISOLCPUS}
843+
test_fail $I "isolated CPU" \
844+
"Expect $ICPUS, get $ISOLCPUS instead"
845+
}
841846
}
842847
reset_cgroup_states
843848
#

0 commit comments

Comments
 (0)