The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Guopeng Zhang <guopeng.zhang@linux.dev>
To: tglx@kernel.org, peterz@infradead.org
Cc: frederic@kernel.org, Bradley Morgan <include@grrlz.net>,
	linux-kernel@vger.kernel.org, zhangguopeng@kylinos.cn
Subject: [PATCH v2] cpu/hotplug: Prevent offlining the last domain housekeeping CPU
Date: Tue, 11 Aug 2026 20:13:07 +0800	[thread overview]
Message-ID: <20260811121307.168471-1-guopeng.zhang@linux.dev> (raw)

From: Guopeng Zhang <zhangguopeng@kylinos.cn>

Commit 38685e2a0476 ("cpu/hotplug: Don't offline the last
non-isolated CPU") kept at least one HK_TYPE_DOMAIN CPU online by
selecting a CPU other than the one being offlined. Commit de715325cc47
("cpu: Revert "cpu/hotplug: Prevent self deadlock on CPU hot-unplug"")
moved the check into _cpu_down(), but lost that exclusion.

The replacement cpumask_any_and() check still sees the outgoing CPU in
cpu_online_mask. The target therefore satisfies the check when it is
the last online CPU in the HK_TYPE_DOMAIN mask.

On a system booted with domain isolation, a root-initiated attempt to
offline the last HK_TYPE_DOMAIN CPU leaves scheduler-domain rebuilds
with an empty span. With panic_on_warn=0 and warn_limit=0, this first
triggered the WARN_ON() in build_sched_domains(). The kernel then
crashed with a general protection fault in build_perf_domains():

 WARNING: ... at build_sched_domains+0x443/0xa60
 ...
 Oops: general protection fault ...
 RIP: 0010:build_perf_domains+0x40/0x230
 Call Trace:
  <TASK>
  partition_sched_domains_locked+0x3d9/0x710
  partition_sched_domains+0x30/0x40
  cpuset_reset_sched_domains+0x25/0x40
  sched_cpu_deactivate+0x2f2/0x300
  cpuhp_invoke_callback+0x1a4/0x780
  cpuhp_thread_fun+0x1b4/0x230
  </TASK>

Use cpumask_any_and_but() to exclude the outgoing CPU and return -EBUSY
when no other online HK_TYPE_DOMAIN CPU remains.

Skip this check when tasks_frozen is set because CPU freeze deliberately
takes all non-primary CPUs offline.

The sysfs CPU-offline path was tested on a 32-vCPU Ubuntu 24.04 guest
booted with:

    isolcpus=domain,0,3-31

The unpatched kernel warned in build_sched_domains() and then crashed
with a general protection fault in build_perf_domains(). With this
patch, the request was rejected with -EBUSY, 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"")
Suggested-by: Bradley Morgan <include@grrlz.net>
Signed-off-by: Guopeng Zhang <zhangguopeng@kylinos.cn>
---
Changes in v2:
- Explain that 38685e2a0476 excluded the outgoing CPU and that
  de715325cc47 lost that exclusion when moving the check.
- Report the observed WARN_ON() followed by a GPF in
  build_perf_domains(), and include the relevant splat.
- Skip the regular-hotplug guard while tasks_frozen is set, as suggested
  by Bradley.
- State the root and domain-isolation requirements.
- Retest the frozen path with the same isolcpus setting. The new guard no
  longer returns -EBUSY.

v1: https://lore.kernel.org/all/20260718095249.1271870-1-guopeng.zhang@linux.dev/

 kernel/cpu.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index b3c8553d7bd6..8ffbfc20b8fe 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -1415,11 +1415,13 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen,
 	cpus_write_lock();
 
 	/*
-	 * Keep at least one housekeeping cpu onlined to avoid generating
-	 * an empty sched_domain span.
+	 * Keep at least one HK_TYPE_DOMAIN CPU online during regular hotplug
+	 * to avoid generating an empty sched_domain span.
 	 */
-	if (cpumask_any_and(cpu_online_mask,
-			    housekeeping_cpumask(HK_TYPE_DOMAIN)) >= nr_cpu_ids) {
+	if (!tasks_frozen &&
+	    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-08-11 12:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-11 12:13 Guopeng Zhang [this message]
2026-08-11 12:34 ` [PATCH v2] 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=20260811121307.168471-1-guopeng.zhang@linux.dev \
    --to=guopeng.zhang@linux.dev \
    --cc=frederic@kernel.org \
    --cc=include@grrlz.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox