[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/3] xen/riscv: use the SBI SRST extension to reboot in machine_restart()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
  • Date: Wed, 2 Dec 2026 08:14:34 +0000
  • Accept-language: en-IN, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=electrifex.com; dmarc=pass action=none header.from=electrifex.com; dkim=pass header.d=electrifex.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XOa0ZivG3+hBbe+rsrYdgf+vX5glOcZvKTGFYqMrlrk=; b=Qx4/+nQD/BluJdPpTkjP0nYFNt5isdydWtVbyk9QXmtr1xFgRnMH5zkGVmmLYvkOlYRxbak86oJWPMxu15W2bIhBtwRIs2i2NsCpyJ5j6oG2/cIdZ8t8XLzLt5v2KemKeTISNbrV4HPf6iTDV5rFi6NYoCRjLMdSdlkU6fhdiNXcD9mi/ni6PLcnDIPfEwxBM9jfb8JbD1Xu148+N1KivLO19/rR+2/HgJPNHDdwboZjBONJC+vUUTtTPbw4/AJiQ9ttYD9u0k+5/H1NWv5ciTDi7lEVJbGEHfv5pBTVhwrpmEhDEZ8HOkNwfvIE5+gWfElPVjyg31+5t02UgMQL1A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RkqyR5hJKdU3oAhTO30e3zXfM78yZN4oepKqibL6ZY2DNZnbAB5ogA50MU1nUyEs/ybSvn7NfqAOb9eNruw6vTbbqwq1z4Pm0C33sA9M96BSgUW8fjn1O2hOJFPTvTDeOvPQ92a0+w2cIUn41WqH7jzZOB2IKSX3MZ4lQ00tvGNywDLn1+CH/hahII9u2mQoHdA7ZKh1KIjMFrKywuJv86PG9G6S+STOyQ6nC4EFzPe/8p35dYSht766OVEwvqwmnMmPirfC0iHmvAGMfan7t+GADpMxsgNceeCcUpxRBY+1A1exS+8/cL2mYyUD/DEvh9X2wc57EoEsYZX6mKUPIg==
  • Authentication-results: eu.smtp.expurgate.cloud; none
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=electrifex.com;
  • Cc: Alistair Francis <alistair.francis@xxxxxxx>, Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>, Connor Davis <connojdavis@xxxxxxxxx>, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, "andrew.cooper3@xxxxxxxxxx" <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, "roger@xxxxxxxxxxxxxx" <roger@xxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>
  • Delivery-date: Wed, 02 Dec 2026 08:14:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdgjUqmr444yFKCUWqT5SQCKR15g==
  • Thread-topic: [PATCH v2 2/3] xen/riscv: use the SBI SRST extension to reboot in machine_restart()

machine_restart() just calls machine_halt(), which uses the legacy SBI
v0.1 SHUTDOWN call, so every reboot request, including the one after a
panic ("Reboot in five seconds..."), powers the system off instead of
rebooting it. Commit 6471badeeec9 ("RISCV/shutdown: Implement
machine_{halt,restart}()") left SRST support for later.

Probe for the SBI System Reset (SRST) extension in sbi_init() and add
sbi_system_reset(). Use it in machine_restart() to request a cold
reboot. If SRST isn't available or the call returns, fall back to
machine_halt() as before. A failed reset request is logged.

Now that udelay() exists, also honour delay_millisecs before resetting
or falling back.

As Arm and x86 do, call console_start_sync() first, so that pending
console output is flushed before the reset. panic() already does this,
but other callers, such as the 'R' debug key, don't.

A panic after sbi_init() but before preinit_xen_time() gets no delay,
so it now reboots straight away, and one that happens on every boot
becomes a reboot loop. With "noreboot", Xen powers off at the panic,
as before.

Assisted-by: Claude
Signed-off-by: Anandu Padinhare <Anandu.Padinhare@xxxxxxxxxxxxxx>
---
Changes in v2:
- Call console_start_sync() first and add comments (Baptiste).

 xen/arch/riscv/include/asm/sbi.h | 11 +++++++++++
 xen/arch/riscv/sbi.c             | 21 +++++++++++++++++++++
 xen/arch/riscv/shutdown.c        | 16 +++++++++++-----
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/xen/arch/riscv/include/asm/sbi.h b/xen/arch/riscv/include/asm/sbi.h
index 2a245d0b42..eda426b623 100644
--- a/xen/arch/riscv/include/asm/sbi.h
+++ b/xen/arch/riscv/include/asm/sbi.h
@@ -29,6 +29,7 @@
 
 #define SBI_EXT_BASE                    0x10
 #define SBI_EXT_RFENCE                  0x52464E43
+#define SBI_EXT_SRST                    0x53525354
 #define SBI_EXT_TIME                    0x54494D45
 
 /* SBI function IDs for BASE extension */
@@ -49,6 +50,13 @@
 #define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA       0x5
 #define SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID  0x6
 
+/* SBI function IDs for SRST extension */
+#define SBI_EXT_SRST_RESET              0x0
+
+/* SBI SRST reset types and reasons */
+#define SBI_SRST_RESET_TYPE_COLD_REBOOT 0x1
+#define SBI_SRST_RESET_REASON_NONE      0x0
+
 /* SBI function IDs for TIME extension */
 #define SBI_EXT_TIME_SET_TIMER          0x0
 
@@ -84,6 +92,9 @@ void sbi_console_putchar(int ch);
 
 void sbi_shutdown(void);
 
+/* Returns only if SRST isn't available or the reset failed. */
+void sbi_system_reset(unsigned int type, unsigned int reason);
+
 /*
  * Check underlying SBI implementation has RFENCE
  *
diff --git a/xen/arch/riscv/sbi.c b/xen/arch/riscv/sbi.c
index 3576e26033..6898dc0dea 100644
--- a/xen/arch/riscv/sbi.c
+++ b/xen/arch/riscv/sbi.c
@@ -25,6 +25,7 @@
 #include <asm/time.h>
 
 static unsigned long __ro_after_init sbi_spec_version = 
SBI_SPEC_VERSION_DEFAULT;
+static bool __ro_after_init sbi_has_srst;
 
 struct sbiret sbi_ecall(unsigned long ext, unsigned long fid,
                         unsigned long arg0, unsigned long arg1,
@@ -82,6 +83,20 @@ void sbi_shutdown(void)
     sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0);
 }
 
+void sbi_system_reset(unsigned int type, unsigned int reason)
+{
+    struct sbiret ret;
+
+    if ( !sbi_has_srst )
+        return;
+
+    ret = sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason,
+                    0, 0, 0, 0);
+
+    printk(XENLOG_ERR "%s: type=%u reason=%u failed (error %ld)\n",
+           __func__, type, reason, ret.error);
+}
+
 static unsigned int sbi_major_version(void)
 {
     return MASK_EXTR(sbi_spec_version, SBI_SPEC_VERSION_MAJOR_MASK);
@@ -381,6 +396,12 @@ int __init sbi_init(void)
             set_xen_timer = sbi_set_timer_v02;
         else
             set_xen_timer = sbi_set_timer_v01;
+
+        if ( sbi_probe_extension(SBI_EXT_SRST) > 0 )
+        {
+            sbi_has_srst = true;
+            dprintk(XENLOG_INFO, "SBI v0.3 SRST extension detected\n");
+        }
     }
     else
         panic("Ooops. SBI spec version 0.1 detected. Need to add support");
diff --git a/xen/arch/riscv/shutdown.c b/xen/arch/riscv/shutdown.c
index 3513d9af47..7047a0df3e 100644
--- a/xen/arch/riscv/shutdown.c
+++ b/xen/arch/riscv/shutdown.c
@@ -1,4 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
+#include <xen/console.h>
+#include <xen/delay.h>
 #include <xen/shutdown.h>
 
 #include <asm/sbi.h>
@@ -17,11 +19,15 @@ void machine_halt(void)
 
 void machine_restart(unsigned int delay_millisecs)
 {
-    /*
-     * TODO: mdelay(delay_millisecs)
-     * TODO: Probe for #SRST support, where sbi_system_reset() has a
-     *       shutdown/reboot parameter.
-     */
+    /* Flush pending console output and make later printk() synchronous. */
+    console_start_sync();
 
+    mdelay(delay_millisecs);
+
+    /* OpenSBI halts the other harts itself before resetting the system. */
+    sbi_system_reset(SBI_SRST_RESET_TYPE_COLD_REBOOT,
+                     SBI_SRST_RESET_REASON_NONE);
+
+    /* Fall back to halting if SRST isn't supported or failed. */
     machine_halt();
 }
-- 
2.53.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.