Skip to contentSkip to conversation

Don't enable a HPET timer if HPET is disabled

PATCH Applied Matt Lupfer 4 participants 9 messages Feb 22, 2014 – Mar 27, 2014

lore
Share & tools
lore
#0 lore raw

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
index 1264dfd..e15d6bc 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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_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 +0 -0
index 1264dfd..e15d6bc 100644

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);
#2 lore raw
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_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 +0 -1
index 1264dfd..e15d6bc 100644
@@ -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);

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

#3 lore raw

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_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 +0 -1
index 1264dfd..e15d6bc 100644
@@ -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);
Quoted 4 lines

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/

Oops. Michael, can you take care of this one?

Paolo

#4 lore raw
In reply to Matt Lupfer
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_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
index 1264dfd..e15d6bc 100644
@@ -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
#5 lore raw

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

#6 lore raw

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_timer would 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
#7 lore raw

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_timer would be a nop if !hpet_enabled(s).

Thanks. I didn't know whether HPET_CFG_ENABLE and HPET_TN_ENABLE were equivalent.

No, they are not, but HPET_CFG_ENABLE is equivalent to hpet_enabled.

Paolo

#8 lore raw
In reply to Matt Lupfer
Quoted 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_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.

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.

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
index 1264dfd..e15d6bc 100644
@@ -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