* [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race
@ 2015-10-08 18:23 Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 1/2] kvm: x86: set KVM_REQ_EVENT when updating IRR Radim Krčmář
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Radim Krčmář @ 2015-10-08 18:23 UTC (permalink / raw)
To: linux-kernel; +Cc: kvm, Paolo Bonzini, Steve Rutherford, stable
v2:
* rewritten [1/2] and
* refactored [2/2], all thanks to Paolo's comments
This problem is not fixed for split userspace part as I think that it
would be better to solve that by excluding edge interrupts from
eoi_exit_bitmap (see the next patch in kvm-list for discussion).
Radim Krčmář (2):
kvm: x86: set KVM_REQ_EVENT when updating IRR
KVM: x86: fix edge EOI and IOAPIC reconfig race
arch/x86/kvm/ioapic.c | 4 +++-
arch/x86/kvm/lapic.c | 2 ++
arch/x86/kvm/x86.c | 4 +++-
3 files changed, 8 insertions(+), 2 deletions(-)
--
2.5.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] kvm: x86: set KVM_REQ_EVENT when updating IRR
2015-10-08 18:23 [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
@ 2015-10-08 18:23 ` Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 2/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
2015-10-09 11:02 ` [PATCH v2 0/2] " Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Radim Krčmář @ 2015-10-08 18:23 UTC (permalink / raw)
To: linux-kernel; +Cc: kvm, Paolo Bonzini, Steve Rutherford, stable
After moving PIR to IRR, the interrupt needs to be delivered manually.
Reported-by: Paolo Bonzini <pbonzini@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
v2: completely rewritten
arch/x86/kvm/lapic.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 944b38a56929..168b8759bd73 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -348,6 +348,8 @@ void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir)
struct kvm_lapic *apic = vcpu->arch.apic;
__kvm_apic_update_irr(pir, apic->regs);
+
+ kvm_make_request(KVM_REQ_EVENT, vcpu);
}
EXPORT_SYMBOL_GPL(kvm_apic_update_irr);
--
2.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] KVM: x86: fix edge EOI and IOAPIC reconfig race
2015-10-08 18:23 [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 1/2] kvm: x86: set KVM_REQ_EVENT when updating IRR Radim Krčmář
@ 2015-10-08 18:23 ` Radim Krčmář
2015-10-09 11:02 ` [PATCH v2 0/2] " Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Radim Krčmář @ 2015-10-08 18:23 UTC (permalink / raw)
To: linux-kernel; +Cc: kvm, Paolo Bonzini, Steve Rutherford, stable
KVM uses eoi_exit_bitmap to track vectors that need an action on EOI.
The problem is that IOAPIC can be reconfigured while an interrupt with
old configuration is pending and eoi_exit_bitmap only remembers the
newest configuration; thus EOI from the pending interrupt is not
recognized.
(Reconfiguration is not a problem for level interrupts, because IOAPIC
sends interrupt with the new configuration.)
For an edge interrupt with ACK notifiers, like i8254 timer; things can
happen in this order
1) IOAPIC inject a vector from i8254
2) guest reconfigures that vector's VCPU and therefore eoi_exit_bitmap
on original VCPU gets cleared
3) guest's handler for the vector does EOI
4) KVM's EOI handler doesn't pass that vector to IOAPIC because it is
not in that VCPU's eoi_exit_bitmap
5) i8254 stops working
A simple solution is to set the IOAPIC vector in eoi_exit_bitmap if the
vector is in PIR/IRR/ISR.
This creates an unwanted situation if the vector is reused by a
non-IOAPIC source, but I think it is so rare that we don't want to make
the solution more sophisticated. The simple solution also doesn't work
if we are reconfiguring the vector. (Shouldn't happen in the wild and
I'd rather fix users of ACK notifiers instead of working around that.)
The are no races because ioapic injection and reconfig are locked.
Fixes: b053b2aef25d ("KVM: x86: Add EOI exit bitmap inference")
[Before b053b2aef25d, this bug happened only with APICv.]
Fixes: c7c9c56ca26f ("x86, apicv: add virtual interrupt delivery support")
Cc: <stable@vger.kernel.org>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
v2: moved sync_pir_to_irr out of kvm_ioapic_scan_entry [Paolo]
arch/x86/kvm/ioapic.c | 4 +++-
arch/x86/kvm/x86.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
index 2dcda0f188ba..88d0a92d3f94 100644
--- a/arch/x86/kvm/ioapic.c
+++ b/arch/x86/kvm/ioapic.c
@@ -246,7 +246,9 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
index == RTC_GSI) {
if (kvm_apic_match_dest(vcpu, NULL, 0,
- e->fields.dest_id, e->fields.dest_mode))
+ e->fields.dest_id, e->fields.dest_mode) ||
+ (e->fields.trig_mode == IOAPIC_EDGE_TRIG &&
+ kvm_apic_pending_eoi(vcpu, e->fields.vector)))
__set_bit(e->fields.vector,
(unsigned long *)eoi_exit_bitmap);
}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2d2c9bb0d6d6..7ed88020d414 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -6201,8 +6201,10 @@ static void vcpu_scan_ioapic(struct kvm_vcpu *vcpu)
if (irqchip_split(vcpu->kvm))
kvm_scan_ioapic_routes(vcpu, vcpu->arch.eoi_exit_bitmap);
- else
+ else {
+ kvm_x86_ops->sync_pir_to_irr(vcpu);
kvm_ioapic_scan_entry(vcpu, vcpu->arch.eoi_exit_bitmap);
+ }
kvm_x86_ops->load_eoi_exitmap(vcpu);
}
--
2.5.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race
2015-10-08 18:23 [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 1/2] kvm: x86: set KVM_REQ_EVENT when updating IRR Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 2/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
@ 2015-10-09 11:02 ` Paolo Bonzini
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-10-09 11:02 UTC (permalink / raw)
To: Radim Krčmář, linux-kernel; +Cc: kvm, Steve Rutherford, stable
On 08/10/2015 20:23, Radim Krčmář wrote:
> v2:
> * rewritten [1/2] and
> * refactored [2/2], all thanks to Paolo's comments
>
> This problem is not fixed for split userspace part as I think that it
> would be better to solve that by excluding edge interrupts from
> eoi_exit_bitmap (see the next patch in kvm-list for discussion).
Nice patches, thanks. Applying to kvm/queue.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-09 11:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-08 18:23 [PATCH v2 0/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 1/2] kvm: x86: set KVM_REQ_EVENT when updating IRR Radim Krčmář
2015-10-08 18:23 ` [PATCH v2 2/2] KVM: x86: fix edge EOI and IOAPIC reconfig race Radim Krčmář
2015-10-09 11:02 ` [PATCH v2 0/2] " Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).