[PATCH v2 0/7] semihosting: proper QEMU exit on semihosted exit syscall

Luc Michel posted 7 patches 1 year, 10 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220621125916.25257-1-lmichel@kalray.eu
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Laurent Vivier <laurent@vivier.eu>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Max Filippov <jcmvbkbc@gmail.com>
qapi/run-state.json                |  4 +++-
include/semihosting/semihost.h     |  5 +++++
include/sysemu/sysemu.h            |  2 ++
semihosting/arm-compat-semi.c      |  3 +--
semihosting/config.c               | 16 ++++++++++++++++
softmmu/main.c                     |  2 +-
softmmu/runstate.c                 | 13 ++++++++++++-
target/m68k/m68k-semi.c            |  4 ++--
target/mips/tcg/sysemu/mips-semi.c |  2 +-
target/nios2/nios2-semi.c          |  4 ++--
target/xtensa/xtensa-semi.c        |  2 +-
11 files changed, 46 insertions(+), 11 deletions(-)
[PATCH v2 0/7] semihosting: proper QEMU exit on semihosted exit syscall
Posted by Luc Michel 1 year, 10 months ago
v2:
  - fix linux-user compilation. Declare semihosting_exit_request "static
    inline G_NORETURN" on CONFIG_USER_ONLY side. Use
    g_assert_not_reached() to enforce the G_NORETURN since this function
    is unused in linux-user mode.
  - do not call gdb_exit() in semihosting_exit_request() as it is called in
    qemu_cleanup().
  - pass qemu_get_exit_status() to gdb_exit() in qemu_cleanup() instead
    of 0.

Hi,

This series implements a clean way for semihosted exit syscalls to
terminate QEMU with a given return code.

Until now, exit syscalls implementations consisted in calling exit()
with the wanted return code. The problem with this approach is that
other CPUs are not properly stopped, leading to possible crashes in
MTTCG mode, especially when at_exit callbacks have been registered. This
can be the case e.g., when plugins are in use. Plugins can register
at_exit callbacks. Those will be called on the CPU thread the exit
syscall is comming from, while other CPUs can continue to run and thus
call other plugin callbacks.

The semihosting_exit_request function provides a mean to cleanly
terminate QEMU. It introduces an new exit reason
(SHUTDOWN_CAUSE_GUEST_SEMI_EXIT) used in this case. The CPU is stopped
and returns to the main CPU loop so that no more instruction get
executed (the semihosting_exit_request is declared G_NORETURN).

All targets are converted to use this new function.

Thanks,
Luc

Luc Michel (7):
  softmmu: add qemu_[set|get]_exit_status functions
  semihosting: add the semihosting_exit_request function
  semihosting/arm-compat-semi: use semihosting_exit_request
  target/m68k: use semihosting_exit_request on semihosted exit syscall
  target/mips: use semihosting_exit_request on semihosted exit syscall
  target/nios2: use semihosting_exit_request on semihosted exit syscall
  target/xtensa: use semihosting_exit_request on semihosted exit syscall

 qapi/run-state.json                |  4 +++-
 include/semihosting/semihost.h     |  5 +++++
 include/sysemu/sysemu.h            |  2 ++
 semihosting/arm-compat-semi.c      |  3 +--
 semihosting/config.c               | 16 ++++++++++++++++
 softmmu/main.c                     |  2 +-
 softmmu/runstate.c                 | 13 ++++++++++++-
 target/m68k/m68k-semi.c            |  4 ++--
 target/mips/tcg/sysemu/mips-semi.c |  2 +-
 target/nios2/nios2-semi.c          |  4 ++--
 target/xtensa/xtensa-semi.c        |  2 +-
 11 files changed, 46 insertions(+), 11 deletions(-)

-- 
2.17.1
Re: [PATCH v2 0/7] semihosting: proper QEMU exit on semihosted exit syscall
Posted by Richard Henderson 1 year, 10 months ago
On 6/21/22 05:59, Luc Michel wrote:
> v2:
>    - fix linux-user compilation. Declare semihosting_exit_request "static
>      inline G_NORETURN" on CONFIG_USER_ONLY side. Use
>      g_assert_not_reached() to enforce the G_NORETURN since this function
>      is unused in linux-user mode.

Not true.  It *is* used with semihosting linux-user.

Anyway, before you go too far down this road, see

https://patchew.org/QEMU/20220607204557.658541-1-richard.henderson@linaro.org/


r~
Re: [PATCH v2 0/7] semihosting: proper QEMU exit on semihosted exit syscall
Posted by Luc Michel 1 year, 10 months ago
On 07:37 Tue 21 Jun     , Richard Henderson wrote:
> On 6/21/22 05:59, Luc Michel wrote:
> > v2:
> >    - fix linux-user compilation. Declare semihosting_exit_request "static
> >      inline G_NORETURN" on CONFIG_USER_ONLY side. Use
> >      g_assert_not_reached() to enforce the G_NORETURN since this function
> >      is unused in linux-user mode.
> 
> Not true.  It *is* used with semihosting linux-user.
> 
> Anyway, before you go too far down this road, see
> 
> https://patchew.org/QEMU/20220607204557.658541-1-richard.henderson@linaro.org/

aww OK. Let's have your series merged first then.

> 
> 
> r~
> 
> 
> To declare a filtering error, please use the following link : https://www.security-mail.net/reporter.php?mid=16699.62b1d79b.16c49.0&r=lmichel%40kalray.eu&s=richard.henderson%40linaro.org&o=Re%3A+%5BPATCH+v2+0%2F7%5D+semihosting%3A+proper+QEMU+exit+on+semihosted+exit+syscall&verdict=C&c=71759fc2b76b8b9bc7813e449355fa174c40ee7b
> 

--