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

Configure Feed

Select the types of activity you want to include in your feed.

cpuset: Remove unnecessary checks in rebuild_sched_domains_locked

Commit 406100f3da08 ("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 2125c0034c5d ("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>

authored by

Chen Ridong and committed by
Tejun Heo
6ee43047 82d7e59e

+16 -36
+16 -36
kernel/cgroup/cpuset.c
··· 1103 1103 */ 1104 1104 void rebuild_sched_domains_locked(void) 1105 1105 { 1106 - struct cgroup_subsys_state *pos_css; 1107 1106 struct sched_domain_attr *attr; 1108 1107 cpumask_var_t *doms; 1109 - struct cpuset *cs; 1110 1108 int ndoms; 1109 + int i; 1111 1110 1112 1111 lockdep_assert_cpus_held(); 1113 1112 lockdep_assert_held(&cpuset_mutex); 1114 1113 force_sd_rebuild = false; 1115 1114 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; 1128 - 1129 - /* 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(); 1148 - } 1149 - 1150 1115 /* Generate domain masks and attrs */ 1151 1116 ndoms = generate_sched_domains(&doms, &attr); 1117 + 1118 + /* 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; 1131 + } 1152 1132 1153 1133 /* Have scheduler rebuild the domains */ 1154 1134 partition_sched_domains(ndoms, doms, attr);