KVM: fix i8259 reset irq acking
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.
The last one causes the BIOS to hang after the first reboot of Windows installation, since PIT interrupts stop.
arch/x86/kvm/i8259.c +10 -6
@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; -for (irq =0 ; irq <PIC_NUM_PINS ; irq++) { -if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ])) +for (irq =0 ; irq <PIC_NUM_PINS /2 ; irq++) +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase); s->last_irr =0 ; s->irr =0 ; s->imr =0 ;
Quoted 27 lines · Marcelo Tosatti
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.The last one causes the BIOS to hang after the first reboot of Windows installation, since PIT interrupts stop.
Signed-off-by Marcelo Tosatti <[email protected]>arch/x86/kvm/i8259.c +1
-3@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; -for (irq =0 ; irq <PIC_NUM_PINS ; irq++) { - if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) ||
arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 207
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3- s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ]))
What if the lapic is enabled and passes through PIC interrupts in EXTINT mode?
btw, this will oops if we have no vcpu 0.
arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm)
Quoted 4 lines
arch/x86/kvm/i8259.c +3
-0+for (irq =0 ; irq <PIC_NUM_PINS /2 ; irq++) +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase);
Yeah.
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 40 lines · Avi Kivity
Quoted 25 lines · Marcelo Tosatti
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.The last one causes the BIOS to hang after the first reboot of Windows installation, since PIT interrupts stop.
Signed-off-by Marcelo Tosatti <[email protected]>arch/x86/kvm/i8259.c +1
-2@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; - for (irq = 0; irq < PIC_NUM_PINS; irq++) { - if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) ||arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 206
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3- s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ]))What if the lapic is enabled and passes through PIC interrupts in EXTINT mode?
Quoted 1 line
btw, this will oops if we have no vcpu 0.
True. How's this:
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.
The last one causes the BIOS to hang after the first reboot of Windows
installation, since PIT interrupts stop.
arch/x86/kvm/i8259.c +14 -4
@@ -195,13 +195,23 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; +struct kvm_vcpu *vcpu0 = kvm->vcpus[0 ]; + +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ;for (irq =0 ; irq <PIC_NUM_PINS ; irq++) { -if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); +union ioapic_redir_entry entry; + entry = kvm->arch.vioapic->redirtbl[irq+irqbase]; +if ((vcpu0 && !kvm_lapic_enabled (vcpu0)) || + entry.fields.delivery_mode ==IOAPIC_EXTINT ) { +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase); + } } s->last_irr =0 ; s->irr =0 ;
Quoted 47 lines · Marcelo Tosatti
Quoted 40 lines · Avi Kivity
Quoted 26 lines · Marcelo Tosatti
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.The last one causes the BIOS to hang after the first reboot of Windows installation, since PIT interrupts stop.
Signed-off-by Marcelo Tosatti <[email protected]>arch/x86/kvm/i8259.c +1
-3@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; - for (irq = 0; irq < PIC_NUM_PINS; irq++) { -if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq)))arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 207
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-2-kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ]))What if the lapic is enabled and passes through PIC interrupts in EXTINT mode?
Quoted 2 lines
btw, this will oops if we have no vcpu 0.
True. How's this:
arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 214
Quoted 10 lines
arch/x86/kvm/i8259.c +7
-3-if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); +union ioapic_redir_entry entry; + entry = kvm->arch.vioapic->redirtbl[irq+irqbase]; +if ((vcpu0 && !kvm_lapic_enabled (vcpu0)) || + entry.fields.delivery_mode ==IOAPIC_EXTINT ) { +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase); + }
Why look at the ioapic? You need to check lapic lvt0 delivery mode for extint, not the ioapic.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 58 lines · Avi Kivity
Quoted 46 lines · Marcelo Tosatti
Quoted 39 lines · Avi Kivity
Quoted 25 lines · Marcelo Tosatti
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.The last one causes the BIOS to hang after the first reboot of Windows installation, since PIT interrupts stop.
Signed-off-by Marcelo Tosatti <[email protected]>arch/x86/kvm/i8259.c +1
-2@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; - for (irq = 0; irq < PIC_NUM_PINS; irq++) { - if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) ||arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 206
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3- s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ]))What if the lapic is enabled and passes through PIC interrupts in EXTINT mode?
Quoted 2 lines
btw, this will oops if we have no vcpu 0.
True. How's this:
arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 214
Quoted 10 lines
arch/x86/kvm/i8259.c +7
-3-if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); +union ioapic_redir_entry entry; + entry = kvm->arch.vioapic->redirtbl[irq+irqbase]; +if ((vcpu0 && !kvm_lapic_enabled (vcpu0)) || + entry.fields.delivery_mode ==IOAPIC_EXTINT ) { +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase); + }
Quoted 2 lines
Why look at the ioapic? You need to check lapic lvt0 delivery mode for extint, not the ioapic.
I changed it to use kvm_apic_accept_pic_intr() and applied.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 61 lines · Avi Kivity
Quoted 60 lines · Avi Kivity
Quoted 58 lines · Marcelo Tosatti
Quoted 41 lines · Avi Kivity
Quoted 26 lines · Marcelo Tosatti
The irq ack during pic reset has three problems:
- Ignores slave/master PIC, using gsi 0-8 for both.
- Generates an ACK even if the APIC is in control.
- Depends upon IMR being clear, which is broken if the irq was masked at the time it was generated.The last one causes the BIOS to hang after the first reboot of Windows
installation, since PIT interrupts stop.Signed-off-by Marcelo Tosatti <[email protected]>arch/x86/kvm/i8259.c +1
-2@@ -195,14 +195,18 @@ int kvm_pic_read_irq(struct kvm *kvm)void kvm_pic_reset (struct kvm_kpic_state *s) { -int irq; +int irq, irqbase;struct kvm *kvm = s->pics_state->irq_request_opaque; - for (irq = 0; irq < PIC_NUM_PINS; irq++) { - if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) ||arch/x86/kvm/i8259.c int kvm_pic_read_irq(struct kvm *kvm) · line 206
Quoted 10 lines
arch/x86/kvm/i8259.c +6
-3- s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); - } +if (s == &s->pics_state->pics[0 ]) + irqbase =0 ; +else + irqbase =8 ; + +if (!kvm_lapic_enabled (kvm->vcpus[0 ]))What if the lapic is enabled and passes through PIC interrupts in EXTINT mode?
Quoted 2 lines
btw, this will oops if we have no vcpu 0.
True. How's this:
arch/x86/kvm/i8259.c +7
-3-if (!(s->imr & (1 << irq)) && (s->irr & (1 << irq) || - s->isr & (1 << irq))) -kvm_notify_acked_irq (kvm, irq); +union ioapic_redir_entry entry; + entry = kvm->arch.vioapic->redirtbl[irq+irqbase]; +if ((vcpu0 && !kvm_lapic_enabled (vcpu0)) || + entry.fields.delivery_mode ==IOAPIC_EXTINT ) { +if (s->irr & (1 << irq) || s->isr & (1 << irq)) +kvm_notify_acked_irq (kvm, irq+irqbase); + }
Quoted 7 lines
Quoted 3 lines
Why look at the ioapic? You need to check lapic lvt0 delivery mode for extint, not the ioapic.
I changed it to use
kvm_apic_accept_pic_intr()and applied.
It still triggered the warning when the pit pending interrupt count dropped below zero (booting FC6-i386). I "fixed" it by making the pit tolerate this condition, but there may be a bigger problem lurking in there.
Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.