diff mbox

Make qemu_shutdown_requested signal-safe

Message ID 544CBFA1.1090108@web.de
State New
Headers show

Commit Message

Jan Kiszka Oct. 26, 2014, 9:32 a.m. UTC
From: Jan Kiszka <jan.kiszka@siemens.com>

qemu_shutdown_requested may be interrupted by qemu_system_killed. If the
latter sets shutdown_requested after qemu_shutdown_requested has read it
but before it was cleared, the shutdown event is lost. Fix this by using
atomic_xchg.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 vl.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Gonglei (Arei) Oct. 26, 2014, 9:43 a.m. UTC | #1
On 2014/10/26 17:32, Jan Kiszka wrote:

> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> qemu_shutdown_requested may be interrupted by qemu_system_killed. If the
> latter sets shutdown_requested after qemu_shutdown_requested has read it
> but before it was cleared, the shutdown event is lost. Fix this by using
> atomic_xchg.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>  vl.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index 2f81384..f6b3546 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1609,9 +1609,7 @@ int qemu_reset_requested_get(void)
>  
>  static int qemu_shutdown_requested(void)
>  {
> -    int r = shutdown_requested;
> -    shutdown_requested = 0;
> -    return r;
> +    return atomic_xchg(&shutdown_requested, 0);
>  }
>  
>  static void qemu_kill_report(void)


Looks good to me, so

Reviewed-by: Gonglei <arei.gonglei@huawei.com>

Best regards,
-Gonglei
Paolo Bonzini Oct. 27, 2014, 9:09 a.m. UTC | #2
On 10/26/2014 10:32 AM, Jan Kiszka wrote:
> From: Jan Kiszka <jan.kiszka@siemens.com>
> 
> qemu_shutdown_requested may be interrupted by qemu_system_killed. 
> If the latter sets shutdown_requested after qemu_shutdown_requested
> has read it but before it was cleared, the shutdown event is lost.
> Fix this by using atomic_xchg.
> 
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> --- vl.c | 4 
> +--- 1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/vl.c b/vl.c index 2f81384..f6b3546 100644 --- a/vl.c 
> +++ b/vl.c @@ -1609,9 +1609,7 @@ int 
> qemu_reset_requested_get(void)
> 
> static int qemu_shutdown_requested(void) { -    int r = 
> shutdown_requested; -    shutdown_requested = 0; -    return r; + 
> return atomic_xchg(&shutdown_requested, 0); }
> 
> static void qemu_kill_report(void)
> 

Cc: qemu-stable@nongnu.org
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Are you going to send a pull request yourself?
Jan Kiszka Oct. 27, 2014, 9:11 a.m. UTC | #3
On 2014-10-27 10:09, Paolo Bonzini wrote:
> On 10/26/2014 10:32 AM, Jan Kiszka wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> qemu_shutdown_requested may be interrupted by qemu_system_killed. 
>> If the latter sets shutdown_requested after qemu_shutdown_requested
>> has read it but before it was cleared, the shutdown event is lost.
>> Fix this by using atomic_xchg.
>>
>> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> --- vl.c | 4 
>> +--- 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/vl.c b/vl.c index 2f81384..f6b3546 100644 --- a/vl.c 
>> +++ b/vl.c @@ -1609,9 +1609,7 @@ int 
>> qemu_reset_requested_get(void)
>>
>> static int qemu_shutdown_requested(void) { -    int r = 
>> shutdown_requested; -    shutdown_requested = 0; -    return r; + 
>> return atomic_xchg(&shutdown_requested, 0); }
>>
>> static void qemu_kill_report(void)
>>
> 
> Cc: qemu-stable@nongnu.org
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Are you going to send a pull request yourself?
> 

I was assuming Peter would merge (and decide about the ordering).

Jan
diff mbox

Patch

diff --git a/vl.c b/vl.c
index 2f81384..f6b3546 100644
--- a/vl.c
+++ b/vl.c
@@ -1609,9 +1609,7 @@  int qemu_reset_requested_get(void)
 
 static int qemu_shutdown_requested(void)
 {
-    int r = shutdown_requested;
-    shutdown_requested = 0;
-    return r;
+    return atomic_xchg(&shutdown_requested, 0);
 }
 
 static void qemu_kill_report(void)