* [RFC PATCH] chardev: don't exit() straight away on C-a x
@ 2021-10-18 14:02 Alex Bennée
2021-10-18 14:20 ` Marc-André Lureau
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Alex Bennée @ 2021-10-18 14:02 UTC (permalink / raw)
To: qemu-devel
Cc: Marc-André Lureau, Lukas Jünger, Alex Bennée,
Paolo Bonzini
While there are a number of uses in the code-base of the exit(0)
pattern it gets in the way of clean exit which can do all of it's
house-keeping. In particular it was reported that you can crash
plugins this way because TCG can still be running on other threads
when the atexit callback is called.
Use qemu_system_shutdown_request() instead. I did a gentle rename of
the runstate stub seeing as it now contains two functions.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
---
chardev/char-mux.c | 3 ++-
stubs/{runstate-check.c => runstate.c} | 5 +++++
stubs/meson.build | 2 +-
3 files changed, 8 insertions(+), 2 deletions(-)
rename stubs/{runstate-check.c => runstate.c} (64%)
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index ada0c6866f..a46897fcd5 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -28,6 +28,7 @@
#include "qemu/option.h"
#include "chardev/char.h"
#include "sysemu/block-backend.h"
+#include "sysemu/runstate.h"
#include "chardev-internal.h"
/* MUX driver for serial I/O splitting */
@@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
{
const char *term = "QEMU: Terminated\n\r";
qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
- exit(0);
+ qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
break;
}
case 's':
diff --git a/stubs/runstate-check.c b/stubs/runstate.c
similarity index 64%
rename from stubs/runstate-check.c
rename to stubs/runstate.c
index 2ccda2b70f..f47dbcd3e0 100644
--- a/stubs/runstate-check.c
+++ b/stubs/runstate.c
@@ -5,3 +5,8 @@ bool runstate_check(RunState state)
{
return state == RUN_STATE_PRELAUNCH;
}
+
+void qemu_system_shutdown_request(ShutdownCause reason)
+{
+ return;
+}
diff --git a/stubs/meson.build b/stubs/meson.build
index f6aa3aa94f..8f6a9f17e5 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
stub_ss.add(files('ram-block.c'))
stub_ss.add(files('ramfb.c'))
stub_ss.add(files('replay.c'))
-stub_ss.add(files('runstate-check.c'))
+stub_ss.add(files('runstate.c'))
stub_ss.add(files('sysbus.c'))
stub_ss.add(files('target-get-monitor-def.c'))
stub_ss.add(files('target-monitor-defs.c'))
--
2.30.2
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:02 [RFC PATCH] chardev: don't exit() straight away on C-a x Alex Bennée
@ 2021-10-18 14:20 ` Marc-André Lureau
2021-10-18 14:37 ` Paolo Bonzini
2021-10-18 15:04 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 10+ messages in thread
From: Marc-André Lureau @ 2021-10-18 14:20 UTC (permalink / raw)
To: Alex Bennée; +Cc: Paolo Bonzini, Lukas Jünger, QEMU
[-- Attachment #1: Type: text/plain, Size: 2815 bytes --]
On Mon, Oct 18, 2021 at 6:06 PM Alex Bennée <alex.bennee@linaro.org> wrote:
> While there are a number of uses in the code-base of the exit(0)
> pattern it gets in the way of clean exit which can do all of it's
> house-keeping. In particular it was reported that you can crash
> plugins this way because TCG can still be running on other threads
> when the atexit callback is called.
>
> Use qemu_system_shutdown_request() instead. I did a gentle rename of
> the runstate stub seeing as it now contains two functions.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
> chardev/char-mux.c | 3 ++-
> stubs/{runstate-check.c => runstate.c} | 5 +++++
> stubs/meson.build | 2 +-
> 3 files changed, 8 insertions(+), 2 deletions(-)
> rename stubs/{runstate-check.c => runstate.c} (64%)
>
> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> index ada0c6866f..a46897fcd5 100644
> --- a/chardev/char-mux.c
> +++ b/chardev/char-mux.c
> @@ -28,6 +28,7 @@
> #include "qemu/option.h"
> #include "chardev/char.h"
> #include "sysemu/block-backend.h"
> +#include "sysemu/runstate.h"
> #include "chardev-internal.h"
>
> /* MUX driver for serial I/O splitting */
> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d,
> int ch)
> {
> const char *term = "QEMU: Terminated\n\r";
> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
> - exit(0);
> +
> qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> break;
> }
> case 's':
> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
> similarity index 64%
> rename from stubs/runstate-check.c
> rename to stubs/runstate.c
> index 2ccda2b70f..f47dbcd3e0 100644
> --- a/stubs/runstate-check.c
> +++ b/stubs/runstate.c
> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
> {
> return state == RUN_STATE_PRELAUNCH;
> }
> +
> +void qemu_system_shutdown_request(ShutdownCause reason)
> +{
> + return;
> +}
> diff --git a/stubs/meson.build b/stubs/meson.build
> index f6aa3aa94f..8f6a9f17e5 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
> stub_ss.add(files('ram-block.c'))
> stub_ss.add(files('ramfb.c'))
> stub_ss.add(files('replay.c'))
> -stub_ss.add(files('runstate-check.c'))
> +stub_ss.add(files('runstate.c'))
> stub_ss.add(files('sysbus.c'))
> stub_ss.add(files('target-get-monitor-def.c'))
> stub_ss.add(files('target-monitor-defs.c'))
> --
> 2.30.2
>
>
>
--
Marc-André Lureau
[-- Attachment #2: Type: text/html, Size: 3953 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:02 [RFC PATCH] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-18 14:20 ` Marc-André Lureau
@ 2021-10-18 14:37 ` Paolo Bonzini
2021-10-18 14:53 ` Alex Bennée
2021-10-18 15:04 ` Philippe Mathieu-Daudé
2 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2021-10-18 14:37 UTC (permalink / raw)
To: Alex Bennée, qemu-devel; +Cc: Marc-André Lureau, Lukas Jünger
On 18/10/21 16:02, Alex Bennée wrote:
> While there are a number of uses in the code-base of the exit(0)
> pattern it gets in the way of clean exit which can do all of it's
> house-keeping. In particular it was reported that you can crash
> plugins this way because TCG can still be running on other threads
> when the atexit callback is called.
>
> Use qemu_system_shutdown_request() instead. I did a gentle rename of
> the runstate stub seeing as it now contains two functions.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
That won't work with -no-shutdown, but you can just call qmp_quit() instead.
Paolo
> ---
> chardev/char-mux.c | 3 ++-
> stubs/{runstate-check.c => runstate.c} | 5 +++++
> stubs/meson.build | 2 +-
> 3 files changed, 8 insertions(+), 2 deletions(-)
> rename stubs/{runstate-check.c => runstate.c} (64%)
>
> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> index ada0c6866f..a46897fcd5 100644
> --- a/chardev/char-mux.c
> +++ b/chardev/char-mux.c
> @@ -28,6 +28,7 @@
> #include "qemu/option.h"
> #include "chardev/char.h"
> #include "sysemu/block-backend.h"
> +#include "sysemu/runstate.h"
> #include "chardev-internal.h"
>
> /* MUX driver for serial I/O splitting */
> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
> {
> const char *term = "QEMU: Terminated\n\r";
> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
> - exit(0);
> + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> break;
> }
> case 's':
> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
> similarity index 64%
> rename from stubs/runstate-check.c
> rename to stubs/runstate.c
> index 2ccda2b70f..f47dbcd3e0 100644
> --- a/stubs/runstate-check.c
> +++ b/stubs/runstate.c
> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
> {
> return state == RUN_STATE_PRELAUNCH;
> }
> +
> +void qemu_system_shutdown_request(ShutdownCause reason)
> +{
> + return;
> +}
> diff --git a/stubs/meson.build b/stubs/meson.build
> index f6aa3aa94f..8f6a9f17e5 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
> stub_ss.add(files('ram-block.c'))
> stub_ss.add(files('ramfb.c'))
> stub_ss.add(files('replay.c'))
> -stub_ss.add(files('runstate-check.c'))
> +stub_ss.add(files('runstate.c'))
> stub_ss.add(files('sysbus.c'))
> stub_ss.add(files('target-get-monitor-def.c'))
> stub_ss.add(files('target-monitor-defs.c'))
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:37 ` Paolo Bonzini
@ 2021-10-18 14:53 ` Alex Bennée
2021-10-18 14:59 ` Paolo Bonzini
0 siblings, 1 reply; 10+ messages in thread
From: Alex Bennée @ 2021-10-18 14:53 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Marc-André Lureau, Lukas Jünger, qemu-devel
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 18/10/21 16:02, Alex Bennée wrote:
>> While there are a number of uses in the code-base of the exit(0)
>> pattern it gets in the way of clean exit which can do all of it's
>> house-keeping. In particular it was reported that you can crash
>> plugins this way because TCG can still be running on other threads
>> when the atexit callback is called.
>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>> the runstate stub seeing as it now contains two functions.
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>
> That won't work with -no-shutdown, but you can just call qmp_quit()
> instead.
How does calling qmp_quit() fix --no-shutdown? Isn't it just a thin
wrapper around the qemu_system_shutdown_request()?
>
> Paolo
>
>> ---
>> chardev/char-mux.c | 3 ++-
>> stubs/{runstate-check.c => runstate.c} | 5 +++++
>> stubs/meson.build | 2 +-
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>> rename stubs/{runstate-check.c => runstate.c} (64%)
>> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
>> index ada0c6866f..a46897fcd5 100644
>> --- a/chardev/char-mux.c
>> +++ b/chardev/char-mux.c
>> @@ -28,6 +28,7 @@
>> #include "qemu/option.h"
>> #include "chardev/char.h"
>> #include "sysemu/block-backend.h"
>> +#include "sysemu/runstate.h"
>> #include "chardev-internal.h"
>> /* MUX driver for serial I/O splitting */
>> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
>> {
>> const char *term = "QEMU: Terminated\n\r";
>> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
>> - exit(0);
>> + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
>> break;
>> }
>> case 's':
>> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
>> similarity index 64%
>> rename from stubs/runstate-check.c
>> rename to stubs/runstate.c
>> index 2ccda2b70f..f47dbcd3e0 100644
>> --- a/stubs/runstate-check.c
>> +++ b/stubs/runstate.c
>> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
>> {
>> return state == RUN_STATE_PRELAUNCH;
>> }
>> +
>> +void qemu_system_shutdown_request(ShutdownCause reason)
>> +{
>> + return;
>> +}
>> diff --git a/stubs/meson.build b/stubs/meson.build
>> index f6aa3aa94f..8f6a9f17e5 100644
>> --- a/stubs/meson.build
>> +++ b/stubs/meson.build
>> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
>> stub_ss.add(files('ram-block.c'))
>> stub_ss.add(files('ramfb.c'))
>> stub_ss.add(files('replay.c'))
>> -stub_ss.add(files('runstate-check.c'))
>> +stub_ss.add(files('runstate.c'))
>> stub_ss.add(files('sysbus.c'))
>> stub_ss.add(files('target-get-monitor-def.c'))
>> stub_ss.add(files('target-monitor-defs.c'))
>>
--
Alex Bennée
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:53 ` Alex Bennée
@ 2021-10-18 14:59 ` Paolo Bonzini
2021-10-18 17:20 ` Alex Bennée
0 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2021-10-18 14:59 UTC (permalink / raw)
To: Alex Bennée; +Cc: Marc-André Lureau, Lukas Jünger, qemu-devel
On 18/10/21 16:53, Alex Bennée wrote:
>
> Paolo Bonzini <pbonzini@redhat.com> writes:
>
>> On 18/10/21 16:02, Alex Bennée wrote:
>>> While there are a number of uses in the code-base of the exit(0)
>>> pattern it gets in the way of clean exit which can do all of it's
>>> house-keeping. In particular it was reported that you can crash
>>> plugins this way because TCG can still be running on other threads
>>> when the atexit callback is called.
>>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>>> the runstate stub seeing as it now contains two functions.
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>>
>> That won't work with -no-shutdown, but you can just call qmp_quit()
>> instead.
>
> How does calling qmp_quit() fix --no-shutdown? Isn't it just a thin
> wrapper around the qemu_system_shutdown_request()?
It first undoes the effect of -no-shutdown:
void qmp_quit(Error **errp)
{
shutdown_action = SHUTDOWN_ACTION_POWEROFF;
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
}
Paolo
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:02 [RFC PATCH] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-18 14:20 ` Marc-André Lureau
2021-10-18 14:37 ` Paolo Bonzini
@ 2021-10-18 15:04 ` Philippe Mathieu-Daudé
2021-10-18 16:14 ` Alex Bennée
2 siblings, 1 reply; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-18 15:04 UTC (permalink / raw)
To: Alex Bennée, qemu-devel, Warner Losh, Richard Henderson
Cc: Marc-André Lureau, Lukas Jünger, Paolo Bonzini
On 10/18/21 16:02, Alex Bennée wrote:
> While there are a number of uses in the code-base of the exit(0)
> pattern it gets in the way of clean exit which can do all of it's
> house-keeping. In particular it was reported that you can crash
> plugins this way because TCG can still be running on other threads
> when the atexit callback is called.
>
> Use qemu_system_shutdown_request() instead. I did a gentle rename of
> the runstate stub seeing as it now contains two functions.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
> ---
> chardev/char-mux.c | 3 ++-
> stubs/{runstate-check.c => runstate.c} | 5 +++++
> stubs/meson.build | 2 +-
> 3 files changed, 8 insertions(+), 2 deletions(-)
> rename stubs/{runstate-check.c => runstate.c} (64%)
>
> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> index ada0c6866f..a46897fcd5 100644
> --- a/chardev/char-mux.c
> +++ b/chardev/char-mux.c
> @@ -28,6 +28,7 @@
> #include "qemu/option.h"
> #include "chardev/char.h"
> #include "sysemu/block-backend.h"
> +#include "sysemu/runstate.h"
> #include "chardev-internal.h"
>
> /* MUX driver for serial I/O splitting */
> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
> {
> const char *term = "QEMU: Terminated\n\r";
> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
> - exit(0);
> + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
> break;
> }
> case 's':
> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
> similarity index 64%
> rename from stubs/runstate-check.c
> rename to stubs/runstate.c
> index 2ccda2b70f..f47dbcd3e0 100644
> --- a/stubs/runstate-check.c
> +++ b/stubs/runstate.c
> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
> {
> return state == RUN_STATE_PRELAUNCH;
> }
> +
> +void qemu_system_shutdown_request(ShutdownCause reason)
> +{
> + return;
> +}
Hmm this isn't a stub anymore, this is the user-mode implementation.
I'd rather have some shared user/ or meanwhile duplicate it in
both bsd-user/linux-user (even if the implementation is empty)
instead of a stub.
> diff --git a/stubs/meson.build b/stubs/meson.build
> index f6aa3aa94f..8f6a9f17e5 100644
> --- a/stubs/meson.build
> +++ b/stubs/meson.build
> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
> stub_ss.add(files('ram-block.c'))
> stub_ss.add(files('ramfb.c'))
> stub_ss.add(files('replay.c'))
> -stub_ss.add(files('runstate-check.c'))
> +stub_ss.add(files('runstate.c'))
> stub_ss.add(files('sysbus.c'))
> stub_ss.add(files('target-get-monitor-def.c'))
> stub_ss.add(files('target-monitor-defs.c'))
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 15:04 ` Philippe Mathieu-Daudé
@ 2021-10-18 16:14 ` Alex Bennée
2021-10-18 17:30 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 10+ messages in thread
From: Alex Bennée @ 2021-10-18 16:14 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Richard Henderson, qemu-devel, Lukas Jünger, Paolo Bonzini,
Marc-André Lureau, Warner Losh
Philippe Mathieu-Daudé <philmd@redhat.com> writes:
> On 10/18/21 16:02, Alex Bennée wrote:
>> While there are a number of uses in the code-base of the exit(0)
>> pattern it gets in the way of clean exit which can do all of it's
>> house-keeping. In particular it was reported that you can crash
>> plugins this way because TCG can still be running on other threads
>> when the atexit callback is called.
>>
>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>> the runstate stub seeing as it now contains two functions.
>>
>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>> ---
>> chardev/char-mux.c | 3 ++-
>> stubs/{runstate-check.c => runstate.c} | 5 +++++
>> stubs/meson.build | 2 +-
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>> rename stubs/{runstate-check.c => runstate.c} (64%)
>>
>> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
>> index ada0c6866f..a46897fcd5 100644
>> --- a/chardev/char-mux.c
>> +++ b/chardev/char-mux.c
>> @@ -28,6 +28,7 @@
>> #include "qemu/option.h"
>> #include "chardev/char.h"
>> #include "sysemu/block-backend.h"
>> +#include "sysemu/runstate.h"
>> #include "chardev-internal.h"
>>
>> /* MUX driver for serial I/O splitting */
>> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
>> {
>> const char *term = "QEMU: Terminated\n\r";
>> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
>> - exit(0);
>> + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
>> break;
>> }
>> case 's':
>> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
>> similarity index 64%
>> rename from stubs/runstate-check.c
>> rename to stubs/runstate.c
>> index 2ccda2b70f..f47dbcd3e0 100644
>> --- a/stubs/runstate-check.c
>> +++ b/stubs/runstate.c
>> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
>> {
>> return state == RUN_STATE_PRELAUNCH;
>> }
>> +
>> +void qemu_system_shutdown_request(ShutdownCause reason)
>> +{
>> + return;
>> +}
>
> Hmm this isn't a stub anymore, this is the user-mode implementation.
It is? I don't think any of the chardev code touches user-mode, I had to
add this because apparently other binaries link the libchardev code.
> I'd rather have some shared user/ or meanwhile duplicate it in
> both bsd-user/linux-user (even if the implementation is empty)
> instead of a stub.
>
>> diff --git a/stubs/meson.build b/stubs/meson.build
>> index f6aa3aa94f..8f6a9f17e5 100644
>> --- a/stubs/meson.build
>> +++ b/stubs/meson.build
>> @@ -35,7 +35,7 @@ stub_ss.add(files('qtest.c'))
>> stub_ss.add(files('ram-block.c'))
>> stub_ss.add(files('ramfb.c'))
>> stub_ss.add(files('replay.c'))
>> -stub_ss.add(files('runstate-check.c'))
>> +stub_ss.add(files('runstate.c'))
>> stub_ss.add(files('sysbus.c'))
>> stub_ss.add(files('target-get-monitor-def.c'))
>> stub_ss.add(files('target-monitor-defs.c'))
>>
--
Alex Bennée
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 14:59 ` Paolo Bonzini
@ 2021-10-18 17:20 ` Alex Bennée
2021-10-19 10:49 ` Paolo Bonzini
0 siblings, 1 reply; 10+ messages in thread
From: Alex Bennée @ 2021-10-18 17:20 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Marc-André Lureau, Lukas Jünger, qemu-devel
Paolo Bonzini <pbonzini@redhat.com> writes:
> On 18/10/21 16:53, Alex Bennée wrote:
>> Paolo Bonzini <pbonzini@redhat.com> writes:
>>
>>> On 18/10/21 16:02, Alex Bennée wrote:
>>>> While there are a number of uses in the code-base of the exit(0)
>>>> pattern it gets in the way of clean exit which can do all of it's
>>>> house-keeping. In particular it was reported that you can crash
>>>> plugins this way because TCG can still be running on other threads
>>>> when the atexit callback is called.
>>>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>>>> the runstate stub seeing as it now contains two functions.
>>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>>>
>>> That won't work with -no-shutdown, but you can just call qmp_quit()
>>> instead.
>> How does calling qmp_quit() fix --no-shutdown? Isn't it just a thin
>> wrapper around the qemu_system_shutdown_request()?
>
> It first undoes the effect of -no-shutdown:
>
> void qmp_quit(Error **errp)
> {
> shutdown_action = SHUTDOWN_ACTION_POWEROFF;
I guess this is it? I couldn't follow the chain of qemu_opts to find
what sort of change -no-shutdown made to the shutdown_action.
> qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_QMP_QUIT);
> }
>
> Paolo
--
Alex Bennée
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 16:14 ` Alex Bennée
@ 2021-10-18 17:30 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-10-18 17:30 UTC (permalink / raw)
To: Alex Bennée
Cc: Richard Henderson, qemu-devel, Lukas Jünger, Paolo Bonzini,
Marc-André Lureau, Warner Losh
On 10/18/21 18:14, Alex Bennée wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> writes:
>> On 10/18/21 16:02, Alex Bennée wrote:
>>> While there are a number of uses in the code-base of the exit(0)
>>> pattern it gets in the way of clean exit which can do all of it's
>>> house-keeping. In particular it was reported that you can crash
>>> plugins this way because TCG can still be running on other threads
>>> when the atexit callback is called.
>>>
>>> Use qemu_system_shutdown_request() instead. I did a gentle rename of
>>> the runstate stub seeing as it now contains two functions.
>>>
>>> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
>>> Reported-by: Lukas Jünger <lukas.junger@greensocs.com>
>>> ---
>>> chardev/char-mux.c | 3 ++-
>>> stubs/{runstate-check.c => runstate.c} | 5 +++++
>>> stubs/meson.build | 2 +-
>>> 3 files changed, 8 insertions(+), 2 deletions(-)
>>> rename stubs/{runstate-check.c => runstate.c} (64%)
>>>
>>> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
>>> index ada0c6866f..a46897fcd5 100644
>>> --- a/chardev/char-mux.c
>>> +++ b/chardev/char-mux.c
>>> @@ -28,6 +28,7 @@
>>> #include "qemu/option.h"
>>> #include "chardev/char.h"
>>> #include "sysemu/block-backend.h"
>>> +#include "sysemu/runstate.h"
>>> #include "chardev-internal.h"
>>>
>>> /* MUX driver for serial I/O splitting */
>>> @@ -157,7 +158,7 @@ static int mux_proc_byte(Chardev *chr, MuxChardev *d, int ch)
>>> {
>>> const char *term = "QEMU: Terminated\n\r";
>>> qemu_chr_write_all(chr, (uint8_t *)term, strlen(term));
>>> - exit(0);
>>> + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
>>> break;
>>> }
>>> case 's':
>>> diff --git a/stubs/runstate-check.c b/stubs/runstate.c
>>> similarity index 64%
>>> rename from stubs/runstate-check.c
>>> rename to stubs/runstate.c
>>> index 2ccda2b70f..f47dbcd3e0 100644
>>> --- a/stubs/runstate-check.c
>>> +++ b/stubs/runstate.c
>>> @@ -5,3 +5,8 @@ bool runstate_check(RunState state)
>>> {
>>> return state == RUN_STATE_PRELAUNCH;
>>> }
>>> +
>>> +void qemu_system_shutdown_request(ShutdownCause reason)
>>> +{
>>> + return;
>>> +}
>>
>> Hmm this isn't a stub anymore, this is the user-mode implementation.
>
> It is? I don't think any of the chardev code touches user-mode, I had to
> add this because apparently other binaries link the libchardev code.
If it isn't then is should call g_assert_not_reached().
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC PATCH] chardev: don't exit() straight away on C-a x
2021-10-18 17:20 ` Alex Bennée
@ 2021-10-19 10:49 ` Paolo Bonzini
0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2021-10-19 10:49 UTC (permalink / raw)
To: Alex Bennée; +Cc: Marc-André Lureau, Lukas Jünger, qemu-devel
On 18/10/21 19:20, Alex Bennée wrote:
>> shutdown_action = SHUTDOWN_ACTION_POWEROFF;
> I guess this is it? I couldn't follow the chain of qemu_opts to find
> what sort of change -no-shutdown made to the shutdown_action.
>
Yes, "-no-shutdown" is short for "-action shutdown=pause". From there
it goes process_runstate_actions -> qmp_marshal_set_action ->
qmp_set_action, where it sets "shutdown_action = SHUTDOWN_ACTION_PAUSE".
Paolo
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2021-10-19 10:51 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 14:02 [RFC PATCH] chardev: don't exit() straight away on C-a x Alex Bennée
2021-10-18 14:20 ` Marc-André Lureau
2021-10-18 14:37 ` Paolo Bonzini
2021-10-18 14:53 ` Alex Bennée
2021-10-18 14:59 ` Paolo Bonzini
2021-10-18 17:20 ` Alex Bennée
2021-10-19 10:49 ` Paolo Bonzini
2021-10-18 15:04 ` Philippe Mathieu-Daudé
2021-10-18 16:14 ` Alex Bennée
2021-10-18 17:30 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.