qemu-riscv
[Top][All Lists]
Advanced

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

Re: [PATCH v2 2/3] hw/char: riscv_htif: replace exit(0) with proper shut


From: Peter Maydell
Subject: Re: [PATCH v2 2/3] hw/char: riscv_htif: replace exit(0) with proper shutdown
Date: Mon, 4 Sep 2023 10:44:28 +0100

On Wed, 23 Aug 2023 at 08:07, Clément Chigot <chigot@adacore.com> wrote:
>
> This replaces the exit(0) call by a shutdown request, ensuring a proper
> cleanup of Qemu. Otherwise, some connections like gdb could be broken
> without being correctly flushed.
>
> Signed-off-by: Clément Chigot <chigot@adacore.com>
> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
> ---
>  hw/char/riscv_htif.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c
> index 37d3ccc76b..c49d20a221 100644
> --- a/hw/char/riscv_htif.c
> +++ b/hw/char/riscv_htif.c
> @@ -31,6 +31,7 @@
>  #include "qemu/error-report.h"
>  #include "exec/address-spaces.h"
>  #include "sysemu/dma.h"
> +#include "sysemu/runstate.h"
>
>  #define RISCV_DEBUG_HTIF 0
>  #define HTIF_DEBUG(fmt, ...)                                                 
>   \
> @@ -205,7 +206,16 @@ static void htif_handle_tohost_write(HTIFState *s, 
> uint64_t val_written)
>                      g_free(sig_data);
>                  }
>
> -                exit(exit_code);
> +                /*
> +                 * Shutdown request is a clean way to stop the QEMU, compared
> +                 * to a direct call to exit(). But we can't pass the exit 
> code
> +                 * through it so avoid doing that when it can matter.
> +                 */
> +                if (exit_code) {
> +                    exit(exit_code);
> +                } else {
> +                    
> qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> +                }

This is wrong for the same reason that patch 3 is wrong.

Also, does the guest code really expect to handle execution
continuing after this point? qemu_system_shutdown_request()
is asynchronous.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]