[PATCH] cpu/hotplug: Prevent offlining the last domain housekeeping CPU

From: Guopeng Zhang

Date: Sat Jul 18 2026 - 05:53:17 EST


From: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>

_cpu_down() is supposed to leave at least one HK_TYPE_DOMAIN CPU online.
However, cpumask_any_and() includes the CPU being offlined. The target
therefore satisfies the check when it is the last online CPU in that
housekeeping mask.

Offlining it leaves no online CPU in the HK_TYPE_DOMAIN mask. The next
scheduler-domain rebuild passes an empty span to build_sched_domains()
and triggers its WARN_ON().

Use cpumask_any_and_but() to look for another online HK_TYPE_DOMAIN CPU
and reject the offline request with -EBUSY if none exists.

Testing:
Tested on a 32-vCPU Ubuntu 24.04 guest with:

isolcpus=domain,0,3-31

On the unpatched kernel, offlining the last HK_TYPE_DOMAIN CPU triggered
a kernel panic.

With this patch, the same operation was rejected with -EBUSY (errno 16),
the target CPU remained online, and no scheduler-domain warning was
observed.

Fixes: de715325cc47 ("cpu: Revert "cpu/hotplug: Prevent self deadlock on CPU hot-unplug"")
Signed-off-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>
---
kernel/cpu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index b3c8553d7bd6..81e961964e59 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1418,8 +1418,9 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
* Keep at least one housekeeping cpu onlined to avoid generating
* an empty sched_domain span.
*/
- if (cpumask_any_and(cpu_online_mask,
- housekeeping_cpumask(HK_TYPE_DOMAIN)) >= nr_cpu_ids) {
+ if (cpumask_any_and_but(cpu_online_mask,
+ housekeeping_cpumask(HK_TYPE_DOMAIN),
+ cpu) >= nr_cpu_ids) {
ret = -EBUSY;
goto out;
}
--
2.43.0