Don't enable a HPET timer if HPET is disabled
PATCH 1/1 Don't enable a HPET timer if HPET is disabled
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a hpet_offset of 0 (uninitialized). When HPET is enabled, hpet_set_timer() is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initialized hpet_offset) and the timer's comparator (which was generated before hpet_offset was initialized). This results in a long period of no HPET timer ticks.
When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
--- hw/timer/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/timer/hpet.c +2 -1
@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) { +if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);
Signature · 1 line
1.8.5.3
Il 22/02/2014 05:37, Matt Lupfer ha scritto:
Quoted 31 lines
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a
hpet_offsetof 0 (uninitialized). When HPET is enabled,hpet_set_timer()is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initializedhpet_offset) and the timer's comparator (which was generated beforehpet_offsetwas initialized). This results in a long period of no HPET timer ticks.When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
Signed-off-by Matt Lupfer <[email protected]>--- hw/timer/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/timer/hpet.c +0
-0
hw/timer/hpet.c static void hpet_ram_write(void *opaque, hwaddr addr, · line 513
Quoted 9 lines
hw/timer/hpet.c +2
-1@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) { +if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);
Quoted 35 lines · Paolo Bonzini
Il 22/02/2014 05:37, Matt Lupfer ha scritto:
Quoted 34 lines
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a
hpet_offsetof 0 (uninitialized). When HPET is enabled,hpet_set_timer()is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initializedhpet_offset) and the timer's comparator (which was generated beforehpet_offsetwas initialized). This results in a long period of no HPET timer ticks.When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
Signed-off-by Matt Lupfer <[email protected]>--- hw/timer/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/timer/hpet.c +0
-1@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) {
Quoted 8 lines
hw/timer/hpet.c static void hpet_ram_write(void *opaque, hwaddr addr, · line 513
Quoted 6 lines
hw/timer/hpet.c +2
-0+if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);Reviewed-by Paolo Bonzini <[email protected]>
Ping? Now that 1.7.1 is out, I hope this small patch will be considered for the 2.0 release.
http://patchwork.ozlabs.org/patch/323121/
Matt
Il 26/03/2014 21:20, Matt Lupfer ha scritto:
Quoted 45 lines · Paolo Bonzini
Quoted 35 lines
Il 22/02/2014 05:37, Matt Lupfer ha scritto:
Quoted 34 lines
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a
hpet_offsetof 0 (uninitialized). When HPET is enabled,hpet_set_timer()is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initializedhpet_offset) and the timer's comparator (which was generated beforehpet_offsetwas initialized). This results in a long period of no HPET timer ticks.When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
Signed-off-by Matt Lupfer <[email protected]>--- hw/timer/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/timer/hpet.c +0
-1@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) {Quoted 8 lines
hw/timer/hpet.c static void hpet_ram_write(void *opaque, hwaddr addr, · line 513
Quoted 6 lines
hw/timer/hpet.c +2
-0+if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);Reviewed-by Paolo Bonzini <[email protected]>
Quoted 4 lines
Ping? Now that 1.7.1 is out, I hope this small patch will be considered for the 2.0 release.
Oops. Michael, can you take care of this one?
Paolo
Quoted 43 lines · Matt Lupfer
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a
hpet_offsetof 0 (uninitialized). When HPET is enabled,hpet_set_timer()is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initializedhpet_offset) and the timer's comparator (which was generated beforehpet_offsetwas initialized). This results in a long period of no HPET timer ticks.When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
Signed-off-by Matt Lupfer <[email protected]>---
hw/timer/hpet.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/timer/hpet.c +2
-1@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) { +if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);Signature · 1 line
1.8.5.3
Thanks
I am unfamiliar with the HPET code but symmetry suggests perhaps the 'else' condition should be changed too:
} else if (deactivating_bit(old_val, new_val, HPET_TN_ENABLE) ||
!hpet_enabled(s)) {
hpet_del_timer(timer);
}Signature · 1 line
Alex Bligh
Il 22/02/2014 10:03, Alex Bligh ha scritto:
Quoted 9 lines
I am unfamiliar with the HPET code but symmetry suggests perhaps the 'else' condition should be changed too:
} else if (deactivating_bit(old_val, new_val, HPET_TN_ENABLE) || !hpet_enabled(s)) { hpet_del_timer(timer); }
I thought the same, but there is no need for that. When the enabled bit goes from set to clear, all timers are disabled:
} else if (deactivating_bit(old_val, new_val, HPET_CFG_ENABLE)) {
/* Halt main counter and disable interrupt generation. */
s->hpet_counter = hpet_get_ticks(s);
for (i = 0; i < s->num_timers; i++) {
hpet_del_timer(&s->timer[i]);
}
}So hpet_del_timer would be a nop if !hpet_enabled(s).
Paolo
Paolo,
Quoted 22 lines · Paolo Bonzini
Il 22/02/2014 10:03, Alex Bligh ha scritto:
Quoted 9 lines
I am unfamiliar with the HPET code but symmetry suggests perhaps the 'else' condition should be changed too:
} else if (deactivating_bit(old_val, new_val, HPET_TN_ENABLE) || !hpet_enabled(s)) { hpet_del_timer(timer); }I thought the same, but there is no need for that. When the enabled bit goes from set to clear, all timers are disabled:
} else if (deactivating_bit(old_val, new_val, HPET_CFG_ENABLE)) { /* Halt main counter and disable interrupt generation. */ s->hpet_counter = hpet_get_ticks(s); for (i = 0; i < s->num_timers; i++) { hpet_del_timer(&s->timer[i]); } }
Quoted 1 line
So
hpet_del_timerwould be a nop if !hpet_enabled(s).
Thanks. I didn't know whether HPET_CFG_ENABLE and HPET_TN_ENABLE were equivalent.
Signature · 1 line
Alex Bligh
Il 22/02/2014 13:25, Alex Bligh ha scritto:
Quoted 26 lines
Paolo,
Quoted 22 lines · Paolo Bonzini
Il 22/02/2014 10:03, Alex Bligh ha scritto:
Quoted 9 lines
I am unfamiliar with the HPET code but symmetry suggests perhaps the 'else' condition should be changed too:
} else if (deactivating_bit(old_val, new_val, HPET_TN_ENABLE) || !hpet_enabled(s)) { hpet_del_timer(timer); }--
I thought the same, but there is no need for that. When the enabled bit goes from set to clear, all timers are disabled:
} else if (deactivating_bit(old_val, new_val, HPET_CFG_ENABLE)) { /* Halt main counter and disable interrupt generation. */ s->hpet_counter = hpet_get_ticks(s); for (i = 0; i < s->num_timers; i++) { hpet_del_timer(&s->timer[i]); } }
Quoted 3 lines
Quoted 1 line
So
hpet_del_timerwould be a nop if !hpet_enabled(s).Thanks. I didn't know whether
HPET_CFG_ENABLEandHPET_TN_ENABLEwere equivalent.
No, they are not, but HPET_CFG_ENABLE is equivalent to hpet_enabled.
Paolo
Michael S. Tsirkin
AppliedQuoted 16 lines · Matt Lupfer
A HPET timer can be started when HPET is not yet enabled. This will not generate an interrupt to the guest, but causes problems when HPET is later enabled.
A timer that is created and expires at least once before HPET is enabled will have an initialized comparator based on a
hpet_offsetof 0 (uninitialized). When HPET is enabled,hpet_set_timer()is called a second time, which modifies the timer expiry to a time based on the difference between current ticks (measured with the newly initializedhpet_offset) and the timer's comparator (which was generated beforehpet_offsetwas initialized). This results in a long period of no HPET timer ticks.
Quoted 5 lines
When this occurs with a CentOS 5.x guest, the guest may not receive timer interrupts during its narrow timer check window and panic on boot.
Signed-off-by Matt Lupfer <[email protected]>
Queued for 2.0, thanks everyone.
Quoted 20 lines
--- hw/timer/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/timer/hpet.c +2
-1@@ -506,7 +506,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr, timer->cmp = (uint32_t )timer->cmp; timer->period = (uint32_t )timer->period; } -if (activating_bit (old_val, new_val,HPET_TN_ENABLE )) { +if (activating_bit (old_val, new_val,HPET_TN_ENABLE ) && +hpet_enabled (s)) {hpet_set_timer (timer); }else if (deactivating_bit (old_val, new_val,HPET_TN_ENABLE )) {hpet_del_timer (timer);Signature · 1 line
1.8.5.3