From: Jimmy Ho <jimmy.ho@sifive.com>
To: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
Hui Wang <hui.wang@canonical.com>,
Ben Dooks <ben.dooks@codethink.co.uk>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Jimmy Ho <jimmy.ho@sifive.com>,
Samuel Holland <samuel.holland@sifive.com>
Subject: [PATCH] riscv: cpu_ops_sbi: retry checking if CPU is stopped
Date: Sat, 8 Aug 2026 14:32:41 +0800 [thread overview]
Message-ID: <20260808063242.20178-1-jimmy.ho@sifive.com> (raw)
Introduce a retry loop with a timeout to wait for the HSM state
of the core being hotplugged down to properly transition to
HSM_STATE_STOPPED.
Suggested-by: Samuel Holland <samuel.holland@sifive.com>
Signed-off-by: Jimmy Ho <jimmy.ho@sifive.com>
---
arch/riscv/kernel/cpu_ops_sbi.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c
index ee6e4b5cc39e..41e577400591 100644
--- a/arch/riscv/kernel/cpu_ops_sbi.c
+++ b/arch/riscv/kernel/cpu_ops_sbi.c
@@ -5,6 +5,7 @@
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
*/
+#include <linux/delay.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/sched/task_stack.h>
@@ -87,8 +88,23 @@ static bool sbi_cpu_is_stopped(unsigned int cpuid)
{
int rc;
unsigned long hartid = cpuid_to_hartid_map(cpuid);
-
- rc = sbi_hsm_hart_get_status(hartid);
+ unsigned long start, end;
+
+ /*
+ * The core that is being hotplugged down might still
+ * be processing SBI ecall hotplug down.
+ * So, try again a few times.
+ */
+
+ start = jiffies;
+ end = start + msecs_to_jiffies(100);
+ do {
+ rc = sbi_hsm_hart_get_status(hartid);
+ if (rc == SBI_HSM_STATE_STOPPED)
+ break;
+
+ usleep_range(100, 1000);
+ } while (time_before(jiffies, end));
if (rc != SBI_HSM_STATE_STOPPED) {
pr_warn("HART%lu isn't stopped; status %d\n", hartid, rc);
--
2.43.7
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2026-08-08 6:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-08 6:32 Jimmy Ho [this message]
2026-08-08 11:47 ` [PATCH] riscv: cpu_ops_sbi: retry checking if CPU is stopped Zhan Xusheng
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=20260808063242.20178-1-jimmy.ho@sifive.com \
--to=jimmy.ho@sifive.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ben.dooks@codethink.co.uk \
--cc=hui.wang@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=samuel.holland@sifive.com \
/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