From nobody Wed Sep 30 03:45:56 2026 Received: from va-1-112.ptr.blmpb.com (va-1-112.ptr.blmpb.com [209.127.230.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08EF447B41C for ; Thu, 13 Aug 2026 13:04:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786626275; cv=none; b=UAN78+TewWPLDqPkfIcXtnd4qYRZAMYgL1i18fq9sBKKLMt/EcXLQ+X5ZsccmDAu87/R7lXbi5Cp1Bh3nqCJ6KYxgKdeiPVIH0j8qIGimtJPKhK2iEgGlsBNGH3KnHyBWWKoqQYgtqUxdkbnfseu1ZResjkEfnQ+Pwcm2+5FYMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786626275; c=relaxed/simple; bh=sco2+XTyFFmQ6r+Z36OgomRmEpoPBJ1NcsANevO1k90=; h=From:Mime-Version:To:Subject:Date:Message-Id:References:Cc: In-Reply-To:Content-Type; b=t1RIx/TMQE6aV6HMlC2fllHSe8uHKbEKEhLtsyA0I7+uaBMhqyKzTsFiCCUG/ybizoGK8wGBWaucqVDfVZtUr+bddDb1ZPvUSqxRzaSoUzvPw6B4oSZYDZLTj5QpnvK8f49YAycVQhRDmXw+KhMfHtiZD1h/3ofOJmgq5UIXeZ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=UmZ7ZrEx; arc=none smtp.client-ip=209.127.230.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="UmZ7ZrEx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1786626263; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=REzDDvgcolRGWcU+mrb7PUOYaUqrGGQBSl0cuWRGrqg=; b=UmZ7ZrExZ615q9czAXYQyygQS/Y1yyCrd1XRsOb08YhtSOG+SMCp7nJYSsW/aW7HLeyA6h bS70QEoZ6TepWKUyQ7K3MPLHATL8B67M68jvwTiCGL2kBk4cMtMDmSZa1DBnkTchVRfWau W1V2Zxa3hnnh6sxc7ieyt1KmD+FU7qwPDGV6tE0lUEnRYhsIeIuy0TKBySERFf2fBu9/P/ R/+3NtctagA71cACYYfSQ6wLXfwR6Xpjro1yOEPFckyMy/pFBrvClNv9qGIy3Z2JQEWQOE ea802XjcmnYjMqxZu4dI2jHz65AuZRJLrv7oLdBEh9E6UKBxERuZ1PMFEPdT5Q== From: "Rui Qi" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Original-From: Rui Qi To: Subject: [PATCH 1/2] riscv: Fix spurious warning when cpu_is_stopped callback is absent Date: Thu, 13 Aug 2026 21:03:56 +0800 Message-Id: <20260813130357.1144775-2-qirui.001@bytedance.com> References: <20260813130357.1144775-1-qirui.001@bytedance.com> Content-Transfer-Encoding: quoted-printable Cc: , , , , , "Rui Qi" X-Lms-Return-Path: X-Mailer: git-send-email 2.20.1 In-Reply-To: <20260813130357.1144775-1-qirui.001@bytedance.com> Content-Type: text/plain; charset="utf-8" Commit 2b2b207e1162 ("riscv: cpu_ops: Change return value type of cpu_is_stopped() to bool") inverted the warning condition from if (ret) to if (!ret) to match the new bool semantics where false means "not stopped". However, ret is initialized to 0, so when the cpu_is_stopped callback is NULL (the callback is optional), ret remains 0 and if (!ret) evaluates to true, causing a spurious "CPU%u may not have stopped" warning on every CPU offlining. Move the warning inside the callback existence check so that the firmware verification only happens when the backend actually provides the callback. This also eliminates the now-unneeded ret variable. Fixes: 2b2b207e1162 ("riscv: cpu_ops: Change return value type of cpu_is_st= opped() to bool") Signed-off-by: Rui Qi --- arch/riscv/kernel/cpu-hotplug.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/riscv/kernel/cpu-hotplug.c b/arch/riscv/kernel/cpu-hotplu= g.c index 0bc56d8381b6..4c3dfc0efbee 100644 --- a/arch/riscv/kernel/cpu-hotplug.c +++ b/arch/riscv/kernel/cpu-hotplug.c @@ -49,15 +49,11 @@ int __cpu_disable(void) */ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu) { - int ret =3D 0; - pr_notice("CPU%u: off\n", cpu); =20 clear_tasks_mm_cpumask(cpu); /* Verify from the firmware if the cpu is really stopped*/ - if (cpu_ops->cpu_is_stopped) - ret =3D cpu_ops->cpu_is_stopped(cpu); - if (!ret) + if (cpu_ops->cpu_is_stopped && !cpu_ops->cpu_is_stopped(cpu)) pr_warn("CPU%u may not have stopped\n", cpu); } =20 --=20 2.20.1 From nobody Wed Sep 30 03:45:56 2026 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC85D47CA92 for ; Thu, 13 Aug 2026 13:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.114 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786626279; cv=none; b=MlAokBdWAPfc1ykQGCBNmAv1roqyVTinEaURB3MRFWTB8p5ZJkC51rNGgkZAOm2L7llx5bZLQVYqomp83IUVMGAFzs28Ccjdgj9JErQvEyzeouPNKBPwo+Fx6LJ4pnn8Ub90TDFAnkqnaAdUZ4gbcnqBw2rZXS/SVLV9NyZj3NY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786626279; c=relaxed/simple; bh=0dsZvTW4rsDMEU42bDyiMYx5AP74gxdMhYauMVv7kbo=; h=To:Message-Id:Content-Type:Cc:Subject:In-Reply-To:Date:From: Mime-Version:References; b=LcMnplcCK/IwgAEVO4JhRVyOcwjbhV0KFWylfM/HfNJF8FYO9RSJkh5Tu1hopcrs6j9K5+r9CM5e4Vd4OAz6ng+uytOzsc1fq+e63oiGYop9VbkYj0XIYkgrnsBa3NxF+mGM4ft+9fOfqJ2icruTlKgFIMTjndAZB+9RPj01zpA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=NG/h1ubR; arc=none smtp.client-ip=209.127.230.114 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="NG/h1ubR" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1786626272; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=g4QWpVDt+BGsuhwdwrmcwuQnEyaPLYAMiaqo4m0h4wk=; b=NG/h1ubRG0Qu4QTaIQx8a5jNTwPNOD4M5l6griB9ewDWhC5DqnePBTeCbLRR6iWcBJr1Mj GCDlxkcKKVglQgNnRLVpnoc5GZcLwZV7CzUfxyYrYSH/iEw5wnoXkooWoS+qZd+KhlNM+H ClfQvyWbsN6LvE2g1oWXyGkU3iQ3hdOcE2OlYlbkA+7AyJFPSuIu/SLxTVPhrlGyasNtX1 KtZgn18RuxiEuXwVUOK2FV4i5I56SvrPjU9ynsgtoPdzLjedFVvtMxSdo9IDXzATCxvzHh G818eD/7kMTknwyItxOLhN8QbwkXvMEACCsKxfw4ZGN89q+sIMRe2nTlFPFY5Q== To: Message-Id: <20260813130357.1144775-3-qirui.001@bytedance.com> X-Lms-Return-Path: Cc: , , , , , "Rui Qi" Subject: [PATCH 2/2] riscv: Poll for SBI_HSM_STATE_STOPPED in sbi_cpu_is_stopped() In-Reply-To: <20260813130357.1144775-1-qirui.001@bytedance.com> Date: Thu, 13 Aug 2026 21:03:57 +0800 Content-Transfer-Encoding: quoted-printable X-Mailer: git-send-email 2.20.1 X-Original-From: Rui Qi From: "Rui Qi" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260813130357.1144775-1-qirui.001@bytedance.com> Content-Type: text/plain; charset="utf-8" When offlining a CPU, the dying CPU (AP) and the controlling CPU (BP) have a race: AP: cpuhp_ap_report_dead() -> cpu_ops->cpu_stop() ^^^ BP: sees DEAD -> cpu_is_stopped() -> sbi_hsm_hart_get_status() The AP reports itself dead before it actually invokes cpu_stop(), so the BP can read the SBI HSM state while the AP is still in STARTED state, not yet STOPPED. This race was previously masked: the old sbi_cpu_is_stopped() returned the raw SBI status code, and SBI_HSM_STATE_STARTED happens to be 0, which the caller treated as success. The recent bool conversion made the check strict (rc !=3D STOPPED is failure), exposing the race as a spurious warning. Fix by replacing the single sbi_hsm_hart_get_status() call with read_poll_timeout(), giving the AP time to complete the transition to STOPPED. This follows the same approach as arm64's cpu_psci_cpu_kill(), which polls psci_ops.affinity_info() for the same reason. The first SBI query is issued immediately (sleep_before_read=3Dfalse), so the common case where the CPU has already stopped incurs no extra delay. If the state is not yet STOPPED, the code retries every 100us with usleep_range() for up to 100ms. Signed-off-by: Rui Qi --- arch/riscv/kernel/cpu_ops_sbi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sb= i.c index ee6e4b5cc39e..607d386db5f7 100644 --- a/arch/riscv/kernel/cpu_ops_sbi.c +++ b/arch/riscv/kernel/cpu_ops_sbi.c @@ -6,6 +6,7 @@ */ =20 #include +#include #include #include #include @@ -13,6 +14,9 @@ #include #include =20 +#define SBI_HSM_STOP_POLL_US 100 +#define SBI_HSM_STOP_TIMEOUT_US (100 * USEC_PER_MSEC) + extern char secondary_start_sbi[]; const struct cpu_operations cpu_ops_sbi; =20 @@ -85,12 +89,15 @@ static void sbi_cpu_stop(void) =20 static bool sbi_cpu_is_stopped(unsigned int cpuid) { - int rc; + int rc, ret; unsigned long hartid =3D cpuid_to_hartid_map(cpuid); =20 - rc =3D sbi_hsm_hart_get_status(hartid); + ret =3D read_poll_timeout(sbi_hsm_hart_get_status, rc, + rc < 0 || rc =3D=3D SBI_HSM_STATE_STOPPED, + SBI_HSM_STOP_POLL_US, SBI_HSM_STOP_TIMEOUT_US, + false, hartid); =20 - if (rc !=3D SBI_HSM_STATE_STOPPED) { + if (ret || rc !=3D SBI_HSM_STATE_STOPPED) { pr_warn("HART%lu isn't stopped; status %d\n", hartid, rc); return false; } --=20 2.20.1