KVM: fix i8259 reset irq acking
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 14 Aug 2008 23:53:25 +0000 (20:53 -0300)
committerAvi Kivity <avi@qumranet.com>
Wed, 15 Oct 2008 08:15:19 +0000 (10:15 +0200)
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.

[avi: fix check whether pic interrupts are seen by cpu]

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
arch/x86/kvm/i8259.c

index de704995b819aed69164c608b828efd1ba55283c..71e3eeeccae8f0d131c655c1b70d06d5c514fd1d 100644 (file)
@@ -195,13 +195,19 @@ 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];
 
-       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;
+
+       for (irq = 0; irq < PIC_NUM_PINS/2; irq++) {
+               if (vcpu0 && kvm_apic_accept_pic_intr(vcpu0))
+                       if (s->irr & (1 << irq) || s->isr & (1 << irq))
+                               kvm_notify_acked_irq(kvm, irq+irqbase);
        }
        s->last_irr = 0;
        s->irr = 0;