Patchwork fix race between timer firing vs. alarm_timer->pending = 0

login
register
mail settings
Submitter Paolo Bonzini
Date March 19, 2010, 10:30 a.m.
Message ID <1268994635-5788-1-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/48132/
State New
Headers show

Comments

Paolo Bonzini - March 19, 2010, 10:30 a.m.
The period for Win32 timers is very short and always the same
independent of dynticks, so it's possible that the timer fires
before qemu_run_all_timers has reset alarm_timer->pending to zero.
Reset alarm_timer->pending before rearming.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qemu-timer.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
Aurelien Jarno - March 27, 2010, 1:05 p.m.
On Fri, Mar 19, 2010 at 11:30:35AM +0100, Paolo Bonzini wrote:
> The period for Win32 timers is very short and always the same
> independent of dynticks, so it's possible that the timer fires
> before qemu_run_all_timers has reset alarm_timer->pending to zero.
> Reset alarm_timer->pending before rearming.

Thanks, applied.

> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  qemu-timer.c |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-timer.c b/qemu-timer.c
> index 329d3a4..49eac86 100644
> --- a/qemu-timer.c
> +++ b/qemu-timer.c
> @@ -706,14 +706,14 @@ void configure_icount(const char *option)
>  
>  void qemu_run_all_timers(void)
>  {
> +    alarm_timer->pending = 0;
> +
>      /* rearm timer, if not periodic */
>      if (alarm_timer->expired) {
>          alarm_timer->expired = 0;
>          qemu_rearm_alarm_timer(alarm_timer);
>      }
>  
> -    alarm_timer->pending = 0;
> -
>      /* vm time timers */
>      if (vm_running) {
>          qemu_run_timers(vm_clock);
> -- 
> 1.6.6.1
> 
> 
> 
>

Patch

diff --git a/qemu-timer.c b/qemu-timer.c
index 329d3a4..49eac86 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -706,14 +706,14 @@  void configure_icount(const char *option)
 
 void qemu_run_all_timers(void)
 {
+    alarm_timer->pending = 0;
+
     /* rearm timer, if not periodic */
     if (alarm_timer->expired) {
         alarm_timer->expired = 0;
         qemu_rearm_alarm_timer(alarm_timer);
     }
 
-    alarm_timer->pending = 0;
-
     /* vm time timers */
     if (vm_running) {
         qemu_run_timers(vm_clock);