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

[XTF PATCH v2 2/2] x86: Allow exiting QEMU in TCG/QEMU


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Thu, 2 Oct 2025 15:55:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • 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=zrkCPxfsenLoTP5XQkO+LdpiBn8mkFqedF7ORoCKf2s=; b=Uw5Z5gPwDrgw3D5jDdUzRTdPsk5KtacZJ7GSBv/0bLM8Ac7/v72Gkwp3037+5oZhyvcno2rf86NY2xkd8x5cF+ZrMuVHxXytEiFqUmLBt6Bn+5jxFI8XxQiXEFIhdMWbB3dLHwEcKusyOY/Qij33EhBdSOb8TycmcaEqwCObQxb7Zh4OrNqDMAbhtRq6nbXfacEKJTb/WNhBbdr4CLZ1KcQU1tp1GEeEq8NrZjaID5L9dLS+QUnIfqWSnvBy4JZ/ydBGmRK4Q/CZpgbxmJa1PgU/6d6Ud52ZPnEXQ64rbSHOk2slMWjUib/SLfYv8rK1fTSSiuNOEojiAkjSmK7Euw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SNjBg9Jpx4GLSlXc556qp9c3MhlFWqwMsa+JV2lJ4fjm/Sv4Aig/8tDHj7d9hVPz+myrRywKjDn4lV4oqVBcA6vj1RHcZN1HLGR7wmLkbpJsnnxndafLI+w/nXFr8mMXIrxL57L7K7FhkHCnsfzn53v9zaG4EaizBTSoEtUHoMbwFLs1sU2oyDouINtwF/twfCS6IhEdBiNstJeccT4nBhDlVC5I4PuOr/9/1qWZNe9V/9vxmR5ZNkQsBm7HI+eXGU7NCPjltN2PVRr2ck61RzRu86zqJmbmot5pi5JL5d6VMFnwb/n0E9BoLeoZrj/FiQZiiU0LPsPk6I+ZFTGLsA==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 02 Oct 2025 13:56:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

If QEMU has a debug isa-debug-exit device, we can simply write to it
to exit rather than spinning after a failed hypercall.

While at it, reorder an out-of-order include.

Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
 arch/x86/hvm/traps.c    | 16 +++++++++++++++-
 arch/x86/pv/traps.c     |  5 +++++
 common/lib.c            |  2 +-
 common/report.c         |  8 +++++---
 include/xtf/framework.h |  3 +++
 5 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/arch/x86/hvm/traps.c b/arch/x86/hvm/traps.c
index ad7b8cb..b8c4d0c 100644
--- a/arch/x86/hvm/traps.c
+++ b/arch/x86/hvm/traps.c
@@ -1,5 +1,6 @@
-#include <xtf/traps.h>
+#include <xtf/hypercall.h>
 #include <xtf/lib.h>
+#include <xtf/traps.h>
 
 #include <arch/idt.h>
 #include <arch/lib.h>
@@ -139,6 +140,19 @@ void arch_init_traps(void)
                virt_to_gfn(__end_user_bss));
 }
 
+void arch_shutdown(unsigned int reason)
+{
+    hypercall_shutdown(reason);
+
+    /*
+     * Not running under Xen. Attempt exit via the QEMU ISA debug exit device 
on
+     * its default port.
+     *
+     * QEMU's rc is (reason << 1) | 1, if "-device isa-debug-exit" is set.
+     */
+    outb(reason, 0x501);
+}
+
 void __noreturn arch_crash_hard(void)
 {
     /*
diff --git a/arch/x86/pv/traps.c b/arch/x86/pv/traps.c
index 66ef40e..913bab2 100644
--- a/arch/x86/pv/traps.c
+++ b/arch/x86/pv/traps.c
@@ -206,6 +206,11 @@ void arch_init_traps(void)
         panic("Failed to unmap page at NULL: %d\n", rc);
 }
 
+void arch_shutdown(unsigned int reason)
+{
+    hypercall_shutdown(reason);
+}
+
 void __noreturn arch_crash_hard(void)
 {
     /*
diff --git a/common/lib.c b/common/lib.c
index 7f1813f..f4de22e 100644
--- a/common/lib.c
+++ b/common/lib.c
@@ -25,7 +25,7 @@ void __noreturn panic(const char *fmt, ...)
 
     printk("******************************\n");
 
-    hypercall_shutdown(SHUTDOWN_crash);
+    arch_shutdown(SHUTDOWN_crash);
     arch_crash_hard();
 }
 
diff --git a/common/report.c b/common/report.c
index ffdf098..158876e 100644
--- a/common/report.c
+++ b/common/report.c
@@ -1,6 +1,8 @@
+#include <xtf/framework.h>
 #include <xtf/lib.h>
 #include <xtf/report.h>
-#include <xtf/hypercall.h>
+
+#include <xen/sched.h>
 
 enum test_status {
     STATUS_RUNNING, /**< Test not yet completed.       */
@@ -124,8 +126,8 @@ bool xtf_status_reported(void)
 void xtf_exit(void)
 {
     xtf_report_status();
-    hypercall_shutdown(SHUTDOWN_poweroff);
-    panic("xtf_exit(): hypercall_shutdown(SHUTDOWN_poweroff) returned\n");
+    arch_shutdown(SHUTDOWN_poweroff);
+    panic("xtf_exit(): arch_shutdown(SHUTDOWN_poweroff) returned\n");
 }
 
 /*
diff --git a/include/xtf/framework.h b/include/xtf/framework.h
index 95de195..e852882 100644
--- a/include/xtf/framework.h
+++ b/include/xtf/framework.h
@@ -16,6 +16,9 @@ void arch_setup(void);
 /* Set up test-specific configuration. */
 void test_setup(void);
 
+/* Stop the machine. See SHUTDOWN_poweroff et al for reasons */
+void arch_shutdown(unsigned int reason);
+
 /*
  * In the case that normal shutdown actions have failed, contain execution as
  * best as possible.
-- 
2.43.0




 


Rackspace

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