Skip to contentSkip to conversation

qemu-timer: properly arm alarm timer for timers set by device initialization

PATCH In review Paolo Bonzini 4 participants 5 messages Sep 3, 2012 – Sep 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-timer: properly arm alarm timer for timers set by device initialization

QEMU will hang when fed the following command-line

qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none

The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line:

  [    0.000000] NR_IRQS:256

Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop.

The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10).

But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag.

---
 qemu-timer.c | 3 ---

1 file modificato, 3 rimozioni(-)

qemu-timer.c +0 -3
index 5aea94e..c7a1551 100644
@@ -759,11 +759,8 @@ int init_timer_alarm(void)
         goto fail;
     }
 
-    /* first event is at time 0 */
     atexit(quit_timers);
-    t->pending = true;
     alarm_timer = t;
-
     return 0;
 
 fail:
Signature · 1 line
1.7.11.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Paolo Bonzini

QEMU will hang when fed the following command-line

qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none

The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line:

  [    0.000000] NR_IRQS:256

Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop.

The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10).

But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag.

---
 qemu-timer.c | 3 ---

1 file modificato, 3 rimozioni(-)

qemu-timer.c +0 -0
index 5aea94e..c7a1551 100644
@@ -759,11 +759,8 @@ int init_timer_alarm(void)
         goto fail;

qemu-timer.c int init_timer_alarm(void) · line 766

Quoted 10 lines
qemu-timer.c +0 -3
     }
 
-    /* first event is at time 0 */
     atexit(quit_timers);
-    t->pending = true;
     alarm_timer = t;
-
     return 0;
 
 fail:

Funnily, I just create the same problem with my "run timer handlers in signal handler" patch (*). Same solution there.

Jan

(*) I will go for select-based timers once I have time for the necessary refactorings.

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux
Tested-by on v1 1/1
#2 lore raw
In reply to Paolo Bonzini
Quoted 37 lines · Paolo Bonzini

QEMU will hang when fed the following command-line

qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none

The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line:

  [    0.000000] NR_IRQS:256

Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop.

The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10).

But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag.

---
 qemu-timer.c | 3 ---

1 file modificato, 3 rimozioni(-)

qemu-timer.c +0 -0
index 5aea94e..c7a1551 100644
@@ -759,11 +759,8 @@ int init_timer_alarm(void)
         goto fail;

qemu-timer.c int init_timer_alarm(void) · line 766

Quoted 10 lines
qemu-timer.c +0 -3
     }
 
-    /* first event is at time 0 */
     atexit(quit_timers);
-    t->pending = true;
     alarm_timer = t;
-
     return 0;
 
 fail:

Thanks a lot that was quite fast!

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
Tested-by on v1 1/1
#3 lore raw
In reply to Paolo Bonzini
Quoted 36 lines · Paolo Bonzini

QEMU will hang when fed the following command-line

qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none

The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line:

  [    0.000000] NR_IRQS:256

Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop.

The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10).

But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag.

---
 qemu-timer.c | 3 ---

1 file modificato, 3 rimozioni(-)

qemu-timer.c +0 -0
index 5aea94e..c7a1551 100644
@@ -759,11 +759,8 @@ int init_timer_alarm(void)
         goto fail;

qemu-timer.c int init_timer_alarm(void) · line 766

Quoted 10 lines
qemu-timer.c +0 -3
     }
 
-    /* first event is at time 0 */
     atexit(quit_timers);
-    t->pending = true;
     alarm_timer = t;
-
     return 0;
 
 fail:

This also fixes the pty-char hang I reported yesterday in thread "apparently missing yet another notify_event()".

This should go to 1.1-stable too, as this problem exists there, with both -net none and -serial pty being reproducers. Cc'ing -stable.

Thanks!

/mjt

#4 lore raw
In reply to Paolo Bonzini
Quoted 36 lines · Paolo Bonzini

QEMU will hang when fed the following command-line

qemu-system-mips -kernel vmlinux-2.6.32-5-4kc-malta -append "console=ttyS0" -nographic -net none

The -net none is important otherwise it seems some events are generated causing the things to work. When it doesn't work, the guest hangs when measuring the CPU frequency, after the following line:

  [    0.000000] NR_IRQS:256

Pressing a key on the serial port unblocks it, hinting that the problem is due to the recent elimination of the 1 second timeout in the main loop.

The problem is that because init_timer_alarm sets the timer's pending flag to true, the alarm timer is never armed until after the first time through the main loop. Thus the bug started when QEMU started testing the pending flag in qemu_mod_timer (commit 1828be3, more alarm timer cleanup, 2010-03-10).

But actually, it isn't true at all that a timer is pending when the alarm timer is created, and the real bug has been latent forever: the fix is to remove the bogus setting of pending flag.

---
 qemu-timer.c | 3 ---

1 file modificato, 3 rimozioni(-)

qemu-timer.c +0 -0
index 5aea94e..c7a1551 100644
@@ -759,11 +759,8 @@ int init_timer_alarm(void)
         goto fail;

qemu-timer.c int init_timer_alarm(void) · line 766

Quoted 10 lines
qemu-timer.c +0 -3
     }
 
-    /* first event is at time 0 */
     atexit(quit_timers);
-    t->pending = true;
     alarm_timer = t;
-
     return 0;
 
 fail:

Thanks, I have applied it.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net