Commit f1ed0450 authored by Jan Kiszka's avatar Jan Kiszka Committed by Gleb Natapov

KVM: x86: Remove support for reporting coalesced APIC IRQs

Since the arrival of posted interrupt support we can no longer guarantee
that coalesced IRQs are always reported to the IRQ source. Moreover,
accumulated APIC timer events could cause a busy loop when a VCPU should
rather be halted. The consensus is to remove coalesced tracking from the
LAPIC.
Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
Acked-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarGleb Natapov <gleb@redhat.com>
parent e2858b4a
...@@ -405,17 +405,17 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu) ...@@ -405,17 +405,17 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
return highest_irr; return highest_irr;
} }
static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, static void __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
int vector, int level, int trig_mode, int vector, int level, int trig_mode,
unsigned long *dest_map); unsigned long *dest_map);
int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq, void kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
unsigned long *dest_map) unsigned long *dest_map)
{ {
struct kvm_lapic *apic = vcpu->arch.apic; struct kvm_lapic *apic = vcpu->arch.apic;
return __apic_accept_irq(apic, irq->delivery_mode, irq->vector, __apic_accept_irq(apic, irq->delivery_mode, irq->vector,
irq->level, irq->trig_mode, dest_map); irq->level, irq->trig_mode, dest_map);
} }
static int pv_eoi_put_user(struct kvm_vcpu *vcpu, u8 val) static int pv_eoi_put_user(struct kvm_vcpu *vcpu, u8 val)
...@@ -608,7 +608,8 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, ...@@ -608,7 +608,8 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
*r = -1; *r = -1;
if (irq->shorthand == APIC_DEST_SELF) { if (irq->shorthand == APIC_DEST_SELF) {
*r = kvm_apic_set_irq(src->vcpu, irq, dest_map); kvm_apic_set_irq(src->vcpu, irq, dest_map);
*r = 1;
return true; return true;
} }
...@@ -653,7 +654,8 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, ...@@ -653,7 +654,8 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
continue; continue;
if (*r < 0) if (*r < 0)
*r = 0; *r = 0;
*r += kvm_apic_set_irq(dst[i]->vcpu, irq, dest_map); kvm_apic_set_irq(dst[i]->vcpu, irq, dest_map);
*r += 1;
} }
ret = true; ret = true;
...@@ -662,15 +664,11 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, ...@@ -662,15 +664,11 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
return ret; return ret;
} }
/* /* Set an IRQ pending in the lapic. */
* Add a pending IRQ into lapic. static void __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
* Return 1 if successfully added and 0 if discarded. int vector, int level, int trig_mode,
*/ unsigned long *dest_map)
static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
int vector, int level, int trig_mode,
unsigned long *dest_map)
{ {
int result = 0;
struct kvm_vcpu *vcpu = apic->vcpu; struct kvm_vcpu *vcpu = apic->vcpu;
switch (delivery_mode) { switch (delivery_mode) {
...@@ -684,13 +682,10 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -684,13 +682,10 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
if (dest_map) if (dest_map)
__set_bit(vcpu->vcpu_id, dest_map); __set_bit(vcpu->vcpu_id, dest_map);
if (kvm_x86_ops->deliver_posted_interrupt) { if (kvm_x86_ops->deliver_posted_interrupt)
result = 1;
kvm_x86_ops->deliver_posted_interrupt(vcpu, vector); kvm_x86_ops->deliver_posted_interrupt(vcpu, vector);
} else { else {
result = !apic_test_and_set_irr(vector, apic); if (apic_test_and_set_irr(vector, apic)) {
if (!result) {
if (trig_mode) if (trig_mode)
apic_debug("level trig mode repeatedly " apic_debug("level trig mode repeatedly "
"for vector %d", vector); "for vector %d", vector);
...@@ -702,7 +697,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -702,7 +697,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
} }
out: out:
trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode, trace_kvm_apic_accept_irq(vcpu->vcpu_id, delivery_mode,
trig_mode, vector, !result); trig_mode, vector, false);
break; break;
case APIC_DM_REMRD: case APIC_DM_REMRD:
...@@ -714,14 +709,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -714,14 +709,12 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
break; break;
case APIC_DM_NMI: case APIC_DM_NMI:
result = 1;
kvm_inject_nmi(vcpu); kvm_inject_nmi(vcpu);
kvm_vcpu_kick(vcpu); kvm_vcpu_kick(vcpu);
break; break;
case APIC_DM_INIT: case APIC_DM_INIT:
if (!trig_mode || level) { if (!trig_mode || level) {
result = 1;
/* assumes that there are only KVM_APIC_INIT/SIPI */ /* assumes that there are only KVM_APIC_INIT/SIPI */
apic->pending_events = (1UL << KVM_APIC_INIT); apic->pending_events = (1UL << KVM_APIC_INIT);
/* make sure pending_events is visible before sending /* make sure pending_events is visible before sending
...@@ -738,7 +731,6 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -738,7 +731,6 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
case APIC_DM_STARTUP: case APIC_DM_STARTUP:
apic_debug("SIPI to vcpu %d vector 0x%02x\n", apic_debug("SIPI to vcpu %d vector 0x%02x\n",
vcpu->vcpu_id, vector); vcpu->vcpu_id, vector);
result = 1;
apic->sipi_vector = vector; apic->sipi_vector = vector;
/* make sure sipi_vector is visible for the receiver */ /* make sure sipi_vector is visible for the receiver */
smp_wmb(); smp_wmb();
...@@ -760,7 +752,6 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, ...@@ -760,7 +752,6 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
delivery_mode); delivery_mode);
break; break;
} }
return result;
} }
int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2) int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2)
...@@ -1470,7 +1461,7 @@ int apic_has_pending_timer(struct kvm_vcpu *vcpu) ...@@ -1470,7 +1461,7 @@ int apic_has_pending_timer(struct kvm_vcpu *vcpu)
return 0; return 0;
} }
int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type) void kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type)
{ {
u32 reg = kvm_apic_get_reg(apic, lvt_type); u32 reg = kvm_apic_get_reg(apic, lvt_type);
int vector, mode, trig_mode; int vector, mode, trig_mode;
...@@ -1479,10 +1470,8 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type) ...@@ -1479,10 +1470,8 @@ int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type)
vector = reg & APIC_VECTOR_MASK; vector = reg & APIC_VECTOR_MASK;
mode = reg & APIC_MODE_MASK; mode = reg & APIC_MODE_MASK;
trig_mode = reg & APIC_LVT_LEVEL_TRIGGER; trig_mode = reg & APIC_LVT_LEVEL_TRIGGER;
return __apic_accept_irq(apic, mode, vector, 1, trig_mode, __apic_accept_irq(apic, mode, vector, 1, trig_mode, NULL);
NULL);
} }
return 0;
} }
void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu) void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu)
...@@ -1608,8 +1597,8 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu) ...@@ -1608,8 +1597,8 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
return; return;
if (atomic_read(&apic->lapic_timer.pending) > 0) { if (atomic_read(&apic->lapic_timer.pending) > 0) {
if (kvm_apic_local_deliver(apic, APIC_LVTT)) kvm_apic_local_deliver(apic, APIC_LVTT);
atomic_dec(&apic->lapic_timer.pending); atomic_set(&apic->lapic_timer.pending, 0);
} }
} }
......
...@@ -57,9 +57,9 @@ void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr); ...@@ -57,9 +57,9 @@ void kvm_apic_update_tmr(struct kvm_vcpu *vcpu, u32 *tmr);
void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir); void kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir);
int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda);
int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq, void kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
unsigned long *dest_map); unsigned long *dest_map);
int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type); void kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type);
bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map); struct kvm_lapic_irq *irq, int *r, unsigned long *dest_map);
......
...@@ -91,7 +91,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, ...@@ -91,7 +91,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
if (!kvm_is_dm_lowest_prio(irq)) { if (!kvm_is_dm_lowest_prio(irq)) {
if (r < 0) if (r < 0)
r = 0; r = 0;
r += kvm_apic_set_irq(vcpu, irq, dest_map); kvm_apic_set_irq(vcpu, irq, dest_map);
r++;
} else if (kvm_lapic_enabled(vcpu)) { } else if (kvm_lapic_enabled(vcpu)) {
if (!lowest) if (!lowest)
lowest = vcpu; lowest = vcpu;
...@@ -100,8 +101,10 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, ...@@ -100,8 +101,10 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
} }
} }
if (lowest) if (lowest) {
r = kvm_apic_set_irq(lowest, irq, dest_map); kvm_apic_set_irq(lowest, irq, dest_map);
r = 1;
}
return r; return r;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment