Skip to content

Commit 6ee4304

Browse files
Chen Ridonghtejun
authored andcommitted
cpuset: Remove unnecessary checks in rebuild_sched_domains_locked
Commit 406100f ("cpuset: fix race between hotplug work and later CPU offline") added a check for empty effective_cpus in partitions for cgroup v2. However, this check did not account for remote partitions, which were introduced later. After commit 2125c00 ("cgroup/cpuset: Make cpuset hotplug processing synchronous"), cpuset hotplug handling is now synchronous. This eliminates the race condition with subsequent CPU offline operations that the original check aimed to fix. Instead of extending the check to support remote partitions, this patch removes all the redundant effective_cpus check. Additionally, it adds a check and warning to verify that all generated sched domains consist of active CPUs, preventing partition_sched_domains from being invoked with offline CPUs. Signed-off-by: Chen Ridong <chenridong@huawei.com> Reviewed-by: Waiman Long <longman@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 82d7e59 commit 6ee4304

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

kernel/cgroup/cpuset.c

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,53 +1103,33 @@ void dl_rebuild_rd_accounting(void)
11031103
*/
11041104
void rebuild_sched_domains_locked(void)
11051105
{
1106-
struct cgroup_subsys_state *pos_css;
11071106
struct sched_domain_attr *attr;
11081107
cpumask_var_t *doms;
1109-
struct cpuset *cs;
11101108
int ndoms;
1109+
int i;
11111110

11121111
lockdep_assert_cpus_held();
11131112
lockdep_assert_held(&cpuset_mutex);
11141113
force_sd_rebuild = false;
11151114

1116-
/*
1117-
* If we have raced with CPU hotplug, return early to avoid
1118-
* passing doms with offlined cpu to partition_sched_domains().
1119-
* Anyways, cpuset_handle_hotplug() will rebuild sched domains.
1120-
*
1121-
* With no CPUs in any subpartitions, top_cpuset's effective CPUs
1122-
* should be the same as the active CPUs, so checking only top_cpuset
1123-
* is enough to detect racing CPU offlines.
1124-
*/
1125-
if (cpumask_empty(subpartitions_cpus) &&
1126-
!cpumask_equal(top_cpuset.effective_cpus, cpu_active_mask))
1127-
return;
1115+
/* Generate domain masks and attrs */
1116+
ndoms = generate_sched_domains(&doms, &attr);
11281117

11291118
/*
1130-
* With subpartition CPUs, however, the effective CPUs of a partition
1131-
* root should be only a subset of the active CPUs. Since a CPU in any
1132-
* partition root could be offlined, all must be checked.
1133-
*/
1134-
if (!cpumask_empty(subpartitions_cpus)) {
1135-
rcu_read_lock();
1136-
cpuset_for_each_descendant_pre(cs, pos_css, &top_cpuset) {
1137-
if (!is_partition_valid(cs)) {
1138-
pos_css = css_rightmost_descendant(pos_css);
1139-
continue;
1140-
}
1141-
if (!cpumask_subset(cs->effective_cpus,
1142-
cpu_active_mask)) {
1143-
rcu_read_unlock();
1144-
return;
1145-
}
1146-
}
1147-
rcu_read_unlock();
1119+
* cpuset_hotplug_workfn is invoked synchronously now, thus this
1120+
* function should not race with CPU hotplug. And the effective CPUs
1121+
* must not include any offline CPUs. Passing an offline CPU in the
1122+
* doms to partition_sched_domains() will trigger a kernel panic.
1123+
*
1124+
* We perform a final check here: if the doms contains any
1125+
* offline CPUs, a warning is emitted and we return directly to
1126+
* prevent the panic.
1127+
*/
1128+
for (i = 0; i < ndoms; ++i) {
1129+
if (WARN_ON_ONCE(!cpumask_subset(doms[i], cpu_active_mask)))
1130+
return;
11481131
}
11491132

1150-
/* Generate domain masks and attrs */
1151-
ndoms = generate_sched_domains(&doms, &attr);
1152-
11531133
/* Have scheduler rebuild the domains */
11541134
partition_sched_domains(ndoms, doms, attr);
11551135
}

0 commit comments

Comments
 (0)