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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Mon, 6 Oct 2025 12:25:57 +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=DSMzU7bE9Ybv33ngMzEle9ovbrOIGUbmOQRWhev2j/E=; b=W24zH/ouXqpeCu1L2X1YyWtXZFnsnq2i5T7v6EyidsPXNUVkNgx6lT3kKU9ogKFn8hqDyvuY3nE+pSKPkBY1hLqYASmrxSNiqrqLw6uEVyddb4BJX7XVDC+fVqyCmY5KUUTf6hXYZjhuwa/n3q59RKdNcsxZD4gQt496cpdlB9pZ1IKiaLfbEDAMj/jQpmYbDqJpPX+lJoDoTN2nEkR/GZecj9Ixg1UVccDvR6+/Gvlu5MscsHPP56MORoDc4d0o/xGZIjjU2qFB6LqoLAdWmj0vmpOT2bkPV/6sHKZWuNgIeodKnS0R77wmSRxps7CUt6fPvj6+GyilHEao+HRQCg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lmqMdHAebE65e2OZo9Mp0GK4Wp8qf63mIsVuXqvigxjnHsGOdKo9Xyqf+H0zgk4KPvGfGCRVZGCTH2vNBf55su9Yl66fCmfqHrHr+ttmn33RH/iarXFoACyVAtGbtf5BsUAijf5RWJWLMeuhS5tjYfdYevlIjCXC6ZSU6PLSbQDBtUMPeQN+bJcuedomh4nOfJXkqr97xpVGp+taIevXD3ytwRWLF7DAIZ9qkNF1xCmvTcIXtxCCOnhHn51Dvp3IInjqxOsKinJrc5Y2W4jPbiikGaECNoPxb+jttnaLvB3m+qPzFnTrzpjbNcbvlFTj7+0se4o7XaBAKxLi8h8puw==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 06 Oct 2025 10:28:34 +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.

There's nothing to signal its existence, so it's a best-effort write
after a shutdown attempt via hypercall.

Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
v3:
  * Moved arch_shutdown() from HVM/PV folders to arch/x86/traps.c
    There's nothing terribly specific about it.
  * Gated calling hypercall_shutdown() on cpu_has_xen being set
---
 arch/x86/traps.c        | 15 +++++++++++++++
 common/lib.c            |  2 +-
 common/report.c         |  8 +++++---
 include/xtf/framework.h |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 1f82752..b530719 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -80,6 +80,21 @@ void __weak do_evtchn(struct cpu_regs *regs)
     panic("Unhandled evtchn upcall\n");
 }
 
+void arch_shutdown(unsigned int reason)
+{
+    if ( cpu_has_xen )
+        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.
+     */
+    if ( IS_DEFINED(CONFIG_HVM) )
+        outb(reason, 0x501);
+}
+
 /*
  * Local variables:
  * mode: C
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®.