Skip to contentSkip to conversation

bogus HPET initialization order on x86

DISCUSSION Jan Beulich 4 participants 7 messages Mar 9, 2011 – Mar 11, 2011

lore
Share & tools
lore
#0 lore raw
Quoted 1 line

From looking at the code I cannot deduce why it wouldn't be possible

for hpet_interrupt_handler() or hpet_legacy_irq_tick() to be called while hpet_broadcast_init() is still executing. If that's indeed possible, then the setting of .event_handler clearly has to happen *after* initializing the channel's spinlock and rwlock.

Further, with the channel getting enabled (down the hpet_fsb_cap_lookup() call tree) before hpet_events[] gets fully initialized, I'd also think it should be possible to hit the spurious warning in hpet_interrupt_handler() just because of improper initialization order.

If that's all impossible in practice, adding some meaningful comments to the code to describe why this is so would be much appreciated.

Thanks, Jan

#1 lore raw
Quoted 13 lines
Quoted 2 lines
Quoted 1 line · Jan Beulich

From looking at the code I cannot deduce why it wouldn't be possible

for hpet_interrupt_handler() or hpet_legacy_irq_tick() to be called while hpet_broadcast_init() is still executing. If that's indeed possible, then the setting of .event_handler clearly has to happen *after* initializing the channel's spinlock and rwlock.

Further, with the channel getting enabled (down the hpet_fsb_cap_lookup() call tree) before hpet_events[] gets fully initialized, I'd also think it should be possible to hit the spurious warning in hpet_interrupt_handler() just because of improper initialization order.

Quoted 3 lines

If that's all impossible in practice, adding some meaningful comments to the code to describe why this is so would be much appreciated.

Also, what's the point of decrementing the per-CPU irq_count in hpet_legacy_irq_tick()?

Thanks, Jan

#2 lore raw

Jan Beulich wrote on 2011-03-09:

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

From looking at the code I cannot deduce why it wouldn't be possible

for hpet_interrupt_handler() or hpet_legacy_irq_tick() to be called while hpet_broadcast_init() is still executing. If that's indeed possible, then the setting of .event_handler clearly has to happen *after* initializing the channel's spinlock and rwlock.

First of all, pulling the code initializing the channel's spinlock & rwlock before the setting of .event_handler should be a cleaner way anyway.

Quoted 8 lines
Quoted 8 lines

Further, with the channel getting enabled (down the hpet_fsb_cap_lookup() call tree) before hpet_events[] gets fully initialized, I'd also think it should be possible to hit the spurious warning in hpet_interrupt_handler() just because of improper initialization order.

If that's all impossible in practice, adding some meaningful comments to the code to describe why this is so would be much appreciated.

For normal booting case, hpet interrupts should not come before dom0 start booting and pass ACPI tables to hypervisor, so that's impossible in practice in this case.

For S3 resume case, the hpet_broadcast_init() is called in device_power_up()->time_resume()->disable_pit_irq(), when the irq was disabled and all non-boot cpus not enabled. So that's also impossible.

Do I miss any other cases? If not, I will cook a patch to add the required comments along with pulling spinlock/rwlock initialization before .event_handler settings.

Quoted 2 lines

Also, what's the point of decrementing the per-CPU irq_count in hpet_legacy_irq_tick()?

The per-CPU irq_count are used for calculate the total irq number excluding hpet irqs in a past period to give a estimation of IO frequence. The hpet irq was counted in do_IRQ, so need to reduce it while handling it. You can see another one in hpet_interrupt_handler().

Jimmy

#3 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Gang

Jan Beulich wrote on 2011-03-09:

Quoted 2 lines

Also, what's the point of decrementing the per-CPU irq_count in hpet_legacy_irq_tick()?

The per-CPU irq_count are used for calculate the total irq number excluding hpet irqs in a past period to give a estimation of IO frequence. The hpet irq was counted in do_IRQ, so need to reduce it while handling it. You can see another one in hpet_interrupt_handler().

I can understand the latter, but the one I was asking about decrements irq_count even if not calling the event handler (i.e. when returning zero from the function). In other words, I would have understood what this is for if it was sitting after the initial if().

Jan

#4 lore raw

Jan Beulich wrote on 2011-03-11:

Quoted 10 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line · Gang

Jan Beulich wrote on 2011-03-09:

Quoted 2 lines

Also, what's the point of decrementing the per-CPU irq_count in hpet_legacy_irq_tick()?

The per-CPU irq_count are used for calculate the total irq number excluding hpet irqs in a past period to give a estimation of IO frequence. The hpet irq was counted in do_IRQ, so need to reduce it while handling it. You can see another one in hpet_interrupt_handler().

Quoted 4 lines

I can understand the latter, but the one I was asking about decrements irq_count even if not calling the event handler (i.e.
when returning zero from the function). In other words, I would have understood what this is for if it was sitting after the initial if().

The irq_count is added to count the total irq number excluding hpet/pit irqs, so even the real event handler was not called, the adjustment should still be done.

Jimmy

#5 lore raw
In reply to Jan Beulich
Quoted 12 lines · Jan Beulich
Quoted 1 line

From looking at the code I cannot deduce why it wouldn't be possible

for hpet_interrupt_handler() or hpet_legacy_irq_tick() to be called while hpet_broadcast_init() is still executing. If that's indeed possible, then the setting of .event_handler clearly has to happen *after* initializing the channel's spinlock and rwlock.

Further, with the channel getting enabled (down the hpet_fsb_cap_lookup() call tree) before hpet_events[] gets fully initialized, I'd also think it should be possible to hit the spurious warning in hpet_interrupt_handler() just because of improper initialization order.

Quoted 3 lines

If that's all impossible in practice, adding some meaningful comments to the code to describe why this is so would be much appreciated.

Only someone at Intel could answer these questions. Cc'ing Yu Ke, who seems most involved in this aspect.

-- Keir

Quoted 7 lines

Thanks, Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#6 lore raw

CC the author Wei Gang

Regards
Ke

Quoted 37 lines

-----Original Message-----
From: Keir Fraser [mailto:[email protected]]
Sent: Thursday, March 10, 2011 12:12 AM
To: Jan Beulich; [email protected]
Cc: Yu, Ke
Subject: Re: [Xen-devel] bogus HPET initialization order on x86

Quoted 6 lines · Jan Beulich
Quoted 1 line

From looking at the code I cannot deduce why it wouldn't be possible

for hpet_interrupt_handler() or hpet_legacy_irq_tick() to be called while hpet_broadcast_init() is still executing. If that's indeed possible, then the setting of .event_handler clearly has to happen *after* initializing the channel's spinlock and rwlock.

Quoted 8 lines

Further, with the channel getting enabled (down the hpet_fsb_cap_lookup() call tree) before hpet_events[] gets fully initialized, I'd also think it should be possible to hit the spurious warning in hpet_interrupt_handler() just because of improper initialization order.

If that's all impossible in practice, adding some meaningful comments to the code to describe why this is so would be much appreciated.

Only someone at Intel could answer these questions. Cc'ing Yu Ke, who seems most involved in this aspect.

-- Keir

Quoted 7 lines

Thanks, Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel