Search the LAPIC's for one that will accept a PIC interrupt.
PATCH 1/1 Search the LAPIC's for one that will accept a PIC interrupt.
Older versions of 32-bit linux have a "Checking 'hlt' instruction" test where they repeatedly call the 'hlt' instruction, and then expect a timer interrupt to kick the CPU out of halt. This happens before any LAPIC or IOAPIC setup happens, which means that all of the APIC's are in virtual wire mode at this point. Unfortunately, the current implementation of virtual wire mode is hardcoded to only kick the BSP, so if a crash+kexec occurs on a different vcpu, it will never get kicked.
This patch makes pic_unlock() do the equivalent of kvm_irq_delivery_to_apic() for the IOAPIC code. That is, it runs through all of the vcpus looking for one that is in virtual wire mode. In the normal case where LAPICs and IOAPICs are configured, this won't be used at all. In the bootstrap phase of a modern OS, before the LAPICs and IOAPICs are configured, this will have exactly the same behavior as today; VCPU0 is always looked at first, so it will always get out of the loop after the first iteration. This will only go through the loop more than once during a kexec/kdump, in which case it will only do it a few times until the kexec'ed kernel programs the LAPIC and IOAPIC.
--- arch/x86/kvm/i8259.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
arch/x86/kvm/i8259.c +13 -4
@@ -44,16 +44,25 @@ static void pic_unlock(struct kvm_pic *s) __releases(&s->lock) {bool wakeup = s->wakeup_needed; -struct kvm_vcpu *vcpu; +struct kvm_vcpu *vcpu, *found =NULL ; +int i; s->wakeup_needed = false;raw_spin_unlock (&s->lock);if (wakeup) { - vcpu = s->kvm->bsp_vcpu; -if (vcpu) -kvm_vcpu_kick (vcpu); +kvm_for_each_vcpu (i, vcpu, s->kvm) { +if (kvm_apic_accept_pic_intr (vcpu)) { + found = vcpu; +break ; + } + } + +if (!found) + found = s->kvm->bsp_vcpu; + +kvm_vcpu_kick (found); } }
Signature · 1 line
1.6.6.1
Quoted 42 lines · Chris Lalancette
Older versions of 32-bit linux have a "Checking 'hlt' instruction" test where they repeatedly call the 'hlt' instruction, and then expect a timer interrupt to kick the CPU out of halt. This happens before any LAPIC or IOAPIC setup happens, which means that all of the APIC's are in virtual wire mode at this point. Unfortunately, the current implementation of virtual wire mode is hardcoded to only kick the BSP, so if a crash+kexec occurs on a different vcpu, it will never get kicked.
This patch makes
pic_unlock()do the equivalent ofkvm_irq_delivery_to_apic()for the IOAPIC code. That is, it runs through all of the vcpus looking for one that is in virtual wire mode. In the normal case where LAPICs and IOAPICs are configured, this won't be used at all. In the bootstrap phase of a modern OS, before the LAPICs and IOAPICs are configured, this will have exactly the same behavior as today; VCPU0 is always looked at first, so it will always get out of the loop after the first iteration. This will only go through the loop more than once during a kexec/kdump, in which case it will only do it a few times until the kexec'ed kernel programs the LAPIC and IOAPIC.Signed-off-by Chris Lalancette <[email protected]>--- arch/x86/kvm/i8259.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)arch/x86/kvm/i8259.c +2
-1@@ -44,16 +44,25 @@ static void pic_unlock(struct kvm_pic *s) __releases(&s->lock) {bool wakeup = s->wakeup_needed; -struct kvm_vcpu *vcpu; +struct kvm_vcpu *vcpu, *found =NULL ; +int i; s->wakeup_needed = false;raw_spin_unlock (&s->lock);
arch/x86/kvm/i8259.c static void pic_unlock(struct kvm_pic *s) · line 60
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3if (wakeup) { - vcpu = s->kvm->bsp_vcpu; -if (vcpu) -kvm_vcpu_kick (vcpu); +kvm_for_each_vcpu (i, vcpu, s->kvm) { +if (kvm_apic_accept_pic_intr (vcpu)) { + found = vcpu; +break ; + } + }
Shouldn't we kick all vcpus that are in virtual write mode, not just first one found?
Quoted 15 lines
arch/x86/kvm/i8259.c +5
-0+ +if (!found) + found = s->kvm->bsp_vcpu; + +kvm_vcpu_kick (found); } }Signature · 6 lines
1.6.6.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Gleb.
Quoted 44 lines · Gleb Natapov
Quoted 42 lines · Chris Lalancette
Older versions of 32-bit linux have a "Checking 'hlt' instruction" test where they repeatedly call the 'hlt' instruction, and then expect a timer interrupt to kick the CPU out of halt. This happens before any LAPIC or IOAPIC setup happens, which means that all of the APIC's are in virtual wire mode at this point. Unfortunately, the current implementation of virtual wire mode is hardcoded to only kick the BSP, so if a crash+kexec occurs on a different vcpu, it will never get kicked.
This patch makes
pic_unlock()do the equivalent ofkvm_irq_delivery_to_apic()for the IOAPIC code. That is, it runs through all of the vcpus looking for one that is in virtual wire mode. In the normal case where LAPICs and IOAPICs are configured, this won't be used at all. In the bootstrap phase of a modern OS, before the LAPICs and IOAPICs are configured, this will have exactly the same behavior as today; VCPU0 is always looked at first, so it will always get out of the loop after the first iteration. This will only go through the loop more than once during a kexec/kdump, in which case it will only do it a few times until the kexec'ed kernel programs the LAPIC and IOAPIC.Signed-off-by Chris Lalancette<[email protected]>--- arch/x86/kvm/i8259.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)arch/x86/kvm/i8259.c +2
-1@@ -44,16 +44,25 @@ static void pic_unlock(struct kvm_pic *s) __releases(&s->lock) {bool wakeup = s->wakeup_needed; -struct kvm_vcpu *vcpu; +struct kvm_vcpu *vcpu, *found =NULL ; +int i; s->wakeup_needed = false;raw_spin_unlock (&s->lock);
Quoted 14 lines
arch/x86/kvm/i8259.c static void pic_unlock(struct kvm_pic *s) · line 68
Quoted 11 lines
arch/x86/kvm/i8259.c +6
-3if (wakeup) { - vcpu = s->kvm->bsp_vcpu; -if (vcpu) -kvm_vcpu_kick (vcpu); +kvm_for_each_vcpu (i, vcpu, s->kvm) { +if (kvm_apic_accept_pic_intr (vcpu)) { + found = vcpu; +break ; + } + }Shouldn't we kick all vcpus that are in virtual write mode, not just first one found?
If two lapics are in ExtInt mode, both will perform the IntAck cycle and the PIC might get confused. I don't think it's a valid configuration. So I think the patch is fine.
There's a slight issue in that if an interrupt happens while a vcpu is turning off LVT0.ExtInt, the interrupt gets lost. But this is better than what we have now.
btw, I think virtual wire refers to:
pic -> ioapic(ExtInt) -> (apic bus) -> lapic
(virtual wire since the interrupt is passed over the apic bus, not a real wire)
while our configuration is
pic -> lint0 -> lapic lvt0 (ExtInt)
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 57 lines · Avi Kivity
Quoted 43 lines · Gleb Natapov
Quoted 42 lines · Chris Lalancette
Older versions of 32-bit linux have a "Checking 'hlt' instruction" test where they repeatedly call the 'hlt' instruction, and then expect a timer interrupt to kick the CPU out of halt. This happens before any LAPIC or IOAPIC setup happens, which means that all of the APIC's are in virtual wire mode at this point. Unfortunately, the current implementation of virtual wire mode is hardcoded to only kick the BSP, so if a crash+kexec occurs on a different vcpu, it will never get kicked.
This patch makes
pic_unlock()do the equivalent ofkvm_irq_delivery_to_apic()for the IOAPIC code. That is, it runs through all of the vcpus looking for one that is in virtual wire mode. In the normal case where LAPICs and IOAPICs are configured, this won't be used at all. In the bootstrap phase of a modern OS, before the LAPICs and IOAPICs are configured, this will have exactly the same behavior as today; VCPU0 is always looked at first, so it will always get out of the loop after the first iteration. This will only go through the loop more than once during a kexec/kdump, in which case it will only do it a few times until the kexec'ed kernel programs the LAPIC and IOAPIC.Signed-off-by Chris Lalancette<[email protected]>--- arch/x86/kvm/i8259.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)arch/x86/kvm/i8259.c +2
-1@@ -44,16 +44,25 @@ static void pic_unlock(struct kvm_pic *s) __releases(&s->lock) {bool wakeup = s->wakeup_needed; -struct kvm_vcpu *vcpu; +struct kvm_vcpu *vcpu, *found =NULL ; +int i; s->wakeup_needed = false;raw_spin_unlock (&s->lock);Quoted 12 lines
arch/x86/kvm/i8259.c static void pic_unlock(struct kvm_pic *s) · line 60
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3if (wakeup) { - vcpu = s->kvm->bsp_vcpu; -if (vcpu) -kvm_vcpu_kick (vcpu); +kvm_for_each_vcpu (i, vcpu, s->kvm) { +if (kvm_apic_accept_pic_intr (vcpu)) { + found = vcpu; +break ; + } + }Shouldn't we kick all vcpus that are in virtual write mode, not just first one found?
Quoted 4 lines
If two lapics are in ExtInt mode, both will perform the IntAck cycle and the PIC might get confused. I don't think it's a valid configuration. So I think the patch is fine.
May be, interesting what would happen on real HW. How kdump kernel knows that other cpu's lapics configured correctly?
Quoted 4 lines
There's a slight issue in that if an interrupt happens while a vcpu is turning off LVT0.ExtInt, the interrupt gets lost. But this is better than what we have now.
We can check pic output after LVT0.ExtInt is configured.
Quoted 11 lines
btw, I think virtual wire refers to:
pic -> ioapic(ExtInt) -> (apic bus) -> lapic
(virtual wire since the interrupt is passed over the apic bus, not a real wire)
while our configuration is
pic -> lint0 -> lapic lvt0 (ExtInt)
I saw both referred as virtual wire, may be erroneous.
How is the mode where lapic is disabled and pic interrupts are delivered directly to cpu is called?
--
Gleb.
Quoted 10 lines · Gleb Natapov
Quoted 7 lines
There's a slight issue in that if an interrupt happens while a vcpu is turning off LVT0.ExtInt, the interrupt gets lost. But this is better than what we have now.
We can check pic output after LVT0.ExtInt is configured.
Right.
Quoted 9 lines
Quoted 9 lines
btw, I think virtual wire refers to:
pic -> ioapic(ExtInt) -> (apic bus) -> lapic(virtual wire since the interrupt is passed over the apic bus, not a real wire)
while our configuration is
Quoted 8 lines
Quoted 3 lines
pic -> lint0 -> lapic lvt0 (ExtInt)I saw both referred as virtual wire, may be erroneous.
How is the mode where lapic is disabled and pic interrupts are delivered directly to cpu is called?
I'm just guessing based on the name, no idea really.
Signature · 1 line
error compiling committee.c: too many arguments to function
Avi Kivity
AppliedQuoted 9 lines · Chris Lalancette
Older versions of 32-bit linux have a "Checking 'hlt' instruction" test where they repeatedly call the 'hlt' instruction, and then expect a timer interrupt to kick the CPU out of halt. This happens before any LAPIC or IOAPIC setup happens, which means that all of the APIC's are in virtual wire mode at this point. Unfortunately, the current implementation of virtual wire mode is hardcoded to only kick the BSP, so if a crash+kexec occurs on a different vcpu, it will never get kicked.
Quoted 12 lines
This patch makes
pic_unlock()do the equivalent ofkvm_irq_delivery_to_apic()for the IOAPIC code. That is, it runs through all of the vcpus looking for one that is in virtual wire mode. In the normal case where LAPICs and IOAPICs are configured, this won't be used at all. In the bootstrap phase of a modern OS, before the LAPICs and IOAPICs are configured, this will have exactly the same behavior as today; VCPU0 is always looked at first, so it will always get out of the loop after the first iteration. This will only go through the loop more than once during a kexec/kdump, in which case it will only do it a few times until the kexec'ed kernel programs the LAPIC and IOAPIC.
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Chris Lalancette
Did you forget to push out a tree with this patch applied, or are you doing some testing before doing so? I don't see this patch in the current kvm tree (git head is
a63e16c655f9e68d49d6fae4275ffda16b1888b2).
No and yes. Under testing patches are queued in the 'next' branch; after testing they are merged into 'master'.
Use 'git fetch' instead of 'git pull' to see all branches.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.