Skip to content

Commit f3200d0

Browse files
Gleb Natapovmatosatti
authored andcommitted
KVM: inject ExtINT interrupt before APIC interrupts
According to Intel SDM Volume 3 Section 10.8.1 "Interrupt Handling with the Pentium 4 and Intel Xeon Processors" and Section 10.8.2 "Interrupt Handling with the P6 Family and Pentium Processors" ExtINT interrupts are sent directly to the processor core for handling. Currently KVM checks APIC before it considers ExtINT interrupts for injection which is backwards from the spec. Make code behave according to the SDM. Signed-off-by: Gleb Natapov <gleb@redhat.com> Acked-by: "Zhang, Yang Z" <yang.z.zhang@intel.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
1 parent 5e2c688 commit f3200d0

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

‎arch/x86/kvm/i8259.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ int kvm_pic_read_irq(struct kvm *kvm)
241241
int irq, irq2, intno;
242242
struct kvm_pic *s = pic_irqchip(kvm);
243243

244+
s->output = 0;
245+
244246
pic_lock(s);
245247
irq = pic_get_irq(&s->pics[0]);
246248
if (irq >= 0) {

‎arch/x86/kvm/irq.c‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
4848
if (!irqchip_in_kernel(v->kvm))
4949
return v->arch.interrupt.pending;
5050

51-
if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */
52-
if (kvm_apic_accept_pic_intr(v)) {
53-
s = pic_irqchip(v->kvm); /* PIC */
54-
return s->output;
55-
} else
56-
return 0;
57-
}
58-
return 1;
51+
if (kvm_apic_accept_pic_intr(v) && pic_irqchip(v->kvm)->output)
52+
return pic_irqchip(v->kvm)->output; /* PIC */
53+
54+
return kvm_apic_has_interrupt(v) != -1; /* LAPIC */
5955
}
6056
EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt);
6157

@@ -65,20 +61,14 @@ EXPORT_SYMBOL_GPL(kvm_cpu_has_interrupt);
6561
int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
6662
{
6763
struct kvm_pic *s;
68-
int vector;
6964

7065
if (!irqchip_in_kernel(v->kvm))
7166
return v->arch.interrupt.nr;
7267

73-
vector = kvm_get_apic_interrupt(v); /* APIC */
74-
if (vector == -1) {
75-
if (kvm_apic_accept_pic_intr(v)) {
76-
s = pic_irqchip(v->kvm);
77-
s->output = 0; /* PIC */
78-
vector = kvm_pic_read_irq(v->kvm);
79-
}
80-
}
81-
return vector;
68+
if (kvm_apic_accept_pic_intr(v) && pic_irqchip(v->kvm)->output)
69+
return kvm_pic_read_irq(v->kvm); /* PIC */
70+
71+
return kvm_get_apic_interrupt(v); /* APIC */
8272
}
8373
EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt);
8474

0 commit comments

Comments
 (0)