All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: Thomas Gleixner <tglx@kernel.org>, Peter Zijlstra <peterz@infradead.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
	linux-kernel@vger.kernel.org,
	Guopeng Zhang <zhangguopeng@kylinos.cn>
Subject: [PATCH] cpu/hotplug: Prevent offlining the last domain housekeeping CPU
Date: Sat, 18 Jul 2026 17:52:49 +0800	[thread overview]
Message-ID: <20260718095249.1271870-1-guopeng.zhang@linux.dev> (raw)

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


             reply	other threads:[~2026-07-18  9:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18  9:52 Guopeng Zhang [this message]
2026-07-18 14:53 ` [PATCH] cpu/hotplug: Prevent offlining the last domain housekeeping CPU Bradley Morgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260718095249.1271870-1-guopeng.zhang@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@kernel.org \
    --cc=zhangguopeng@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.