All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpu/hotplug: Prevent offlining the last domain housekeeping CPU
@ 2026-07-18  9:52 Guopeng Zhang
  2026-07-18 14:53 ` Bradley Morgan
  0 siblings, 1 reply; 2+ messages in thread
From: Guopeng Zhang @ 2026-07-18  9:52 UTC (permalink / raw)
  To: Thomas Gleixner, Peter Zijlstra
  Cc: Frederic Weisbecker, linux-kernel, Guopeng Zhang

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

_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@kylinos.cn>
---
 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-18 14:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-18  9:52 [PATCH] cpu/hotplug: Prevent offlining the last domain housekeeping CPU Guopeng Zhang
2026-07-18 14:53 ` Bradley Morgan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.