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

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


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Thu, 2 Oct 2025 16:48:38 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com 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=tMI/5cmdn41E9kTMamZRErFPV8nZGKb41rRXuToIf3E=; b=N/I9RHXHCrPPjh7varTvHTlD03ookoDdbW1hk13cT6H8fZaAbVO/G8PgyM7NYacx9xZBwDaZfyuuPlyKgzS/xlqBmmq/Qfys15VvlJkw3n3FcjPJN+Ou25vbsY1Ai89CuUeJL1sd0QDy9gBJ2KzGBgF8YcMYwRFPvtFUEuFJ0flZg7JASb7C8aEXno8MSnuKuQkzrmbADSS7uV9gvxU8AKB8VPvZ9F3o0vuHS9sZn4mc1mrmxhp1NGat6doUxtjgyy/S4/YJz85/u7bxQsUubBOa7NclaCvZtXItNcUZcoB/2Ex75a4q7Of2uuQPcF3FFwAPPc/RVoYSsjhgcx54lg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=v5+MpVsrSsJhvEw6Wsps/zfJ7msG7XDfOcFOi1eE0OSfbCaAtxCd5vehaG7NCOZTG4fc8XLaBlyvHM8gA1vfDjUJ4JdX7lWuvT+552uqi8oo8TY92BOPsSYoUtLA119laUW6BCf5w8m4yR/hs6P30gypyGfPMsUWa/ZdbDslZSKbvVk7R/p37AWg9jgsVdK86Q62vEM6QRdf8inNHL6nFNAXp0/O6gdV0z7d7/Jl1ImaNnlQnP7aLr7iKVe6r5S0ZloTzDwC4/WhnLOZq0X/mZNk+iE7rohNAx9eU94I7fehEHoTGm+ysSLiioUR/E7+KlpLbQ1dFZrPW3pousxxUw==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 02 Oct 2025 14:49:03 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu Oct 2, 2025 at 4:22 PM CEST, Roger Pau Monné wrote:
> On Thu, Oct 02, 2025 at 03:55:34PM +0200, Alejandro Vallejo wrote:
>> 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);
>
> This relies on the hypercall page being poised with `ret`, which is
> IMO fragile.  I would rather have it poisoned with `int3` and prevent
> such stray accesses in the first place.

I dont' mind caching Xen presence somewhere, but that involves some code motion
from setup.c, which I wanted to avoid.

At the core I just want to speed up testmaking by doing it from WSL rather than
from a Xen host.

>
>> +
>> +    /*
>> +     * 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);
>
> That's kind of weird?  So even if we pass reason == 0, the exit code
> from QEMU will be 1 (and error)?
>
> Isn't there anyway to signal a clean shutdown, and hence QEMU exit
> code being 0?

Nope. It's hardcoded in QEMU itself.

reason=0 => rc=1
reason=1 => rc=3
reason=2 => rc=5

... and so on.

I have something like this in my harness to avoid surprises:

  set +e
  qemu-system-x86_64 <...>
  RC="$?"
  printf "\n[QEMU exit] rc=${RC} reason=$(($RC / 2))\n"

On other test harness I use for personal projects I take the convention that
rc = 1 means success and anything else means failure, but that needs changes
to the runner to integrate the assumptions somewhere, I don't think hardcoding
my conventions is sensible.

Cheers,
Alejandro



 


Rackspace

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