From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A8693B4EB7 for ; Tue, 11 Aug 2026 12:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450440; cv=none; b=d3DNiv2bPNwcipYid90ev/pgedO8SaWucq7hst9rIxy3JkfIVHmU96pI25T/b+qUya7RyFQVVIhSI401ALck/guyCV34Y+VjMo0/P6ZCtNRKx99NOTvxd7vaF/xLOGdbv1lOXQpaKan6PyEFqiSHy9ReNZrA6m1PbT87Oa8Au/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786450440; c=relaxed/simple; bh=8gNsbZTp2393UHCPQvipYZGnlLLBatkS4HAPaRdRiYA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DQYum2xRiUW3+zG8YrfIDUYS3kQNYfLWaOzjasFWZ83t+Ld06iMunABVSLqarGbCycGxT0pna+H5aBD9GV2GtjplRfkn6wEhYyTffhNLMoJXNAU01VEUjMAat4iMKgYIUJBY+jh6CQBEzEvFrHg5nymWXd6qw+ZRXz7A92yDDCk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=v+54H0lB; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="v+54H0lB" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786450435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DTFNYdGIuD0bwClS3/6+oejAUvzwAyp6bNBqHhNmMoY=; b=v+54H0lBeQN2xaUHnd9W50l2QUM8+a9qkOHsA7Pe/QV2A6moinIKpStjDLUFD3bBZvNpw/ KO4iBWO/Vp+y06znrTpuwzEhvWpAd8okgpuK3zRyWgP68mjcTzvKmTjkvg9v+x+j3G5l/i 6xRI8G/8Rw/4b6eqNETguZ3yTtSxGbQ= From: Guopeng Zhang To: tglx@kernel.org, peterz@infradead.org Cc: frederic@kernel.org, Bradley Morgan , 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 Message-ID: <20260811121307.168471-1-guopeng.zhang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Guopeng Zhang 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: 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 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 Signed-off-by: Guopeng Zhang --- 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