Skip to content

Commit 91a5f41

Browse files
vittyvkbonzini
authored andcommitted
KVM: nVMX: handle nested posted interrupts when apicv is disabled for L1
Even when APICv is disabled for L1 it can (and, actually, is) still available for L2, this means we need to always call vmx_deliver_nested_posted_interrupt() when attempting an interrupt delivery. Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Vitaly Kuznetsov <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 93fd966 commit 91a5f41

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ struct kvm_x86_ops {
11461146
void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
11471147
void (*set_virtual_apic_mode)(struct kvm_vcpu *vcpu);
11481148
void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu, hpa_t hpa);
1149-
void (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector);
1149+
int (*deliver_posted_interrupt)(struct kvm_vcpu *vcpu, int vector);
11501150
int (*sync_pir_to_irr)(struct kvm_vcpu *vcpu);
11511151
int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
11521152
int (*set_identity_map_addr)(struct kvm *kvm, u64 ident_addr);

arch/x86/kvm/lapic.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,11 +1046,8 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
10461046
apic->regs + APIC_TMR);
10471047
}
10481048

1049-
if (vcpu->arch.apicv_active)
1050-
kvm_x86_ops->deliver_posted_interrupt(vcpu, vector);
1051-
else {
1049+
if (kvm_x86_ops->deliver_posted_interrupt(vcpu, vector)) {
10521050
kvm_lapic_set_irr(vector, apic);
1053-
10541051
kvm_make_request(KVM_REQ_EVENT, vcpu);
10551052
kvm_vcpu_kick(vcpu);
10561053
}

arch/x86/kvm/svm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5258,8 +5258,11 @@ static void svm_load_eoi_exitmap(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap)
52585258
return;
52595259
}
52605260

5261-
static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)
5261+
static int svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)
52625262
{
5263+
if (!vcpu->arch.apicv_active)
5264+
return -1;
5265+
52635266
kvm_lapic_set_irr(vec, vcpu->arch.apic);
52645267
smp_mb__after_atomic();
52655268

@@ -5271,6 +5274,8 @@ static void svm_deliver_avic_intr(struct kvm_vcpu *vcpu, int vec)
52715274
put_cpu();
52725275
} else
52735276
kvm_vcpu_wake_up(vcpu);
5277+
5278+
return 0;
52745279
}
52755280

52765281
static bool svm_dy_apicv_has_pending_interrupt(struct kvm_vcpu *vcpu)

arch/x86/kvm/vmx/vmx.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3822,24 +3822,29 @@ static int vmx_deliver_nested_posted_interrupt(struct kvm_vcpu *vcpu,
38223822
* 2. If target vcpu isn't running(root mode), kick it to pick up the
38233823
* interrupt from PIR in next vmentry.
38243824
*/
3825-
static void vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector)
3825+
static int vmx_deliver_posted_interrupt(struct kvm_vcpu *vcpu, int vector)
38263826
{
38273827
struct vcpu_vmx *vmx = to_vmx(vcpu);
38283828
int r;
38293829

38303830
r = vmx_deliver_nested_posted_interrupt(vcpu, vector);
38313831
if (!r)
3832-
return;
3832+
return 0;
3833+
3834+
if (!vcpu->arch.apicv_active)
3835+
return -1;
38333836

38343837
if (pi_test_and_set_pir(vector, &vmx->pi_desc))
3835-
return;
3838+
return 0;
38363839

38373840
/* If a previous notification has sent the IPI, nothing to do. */
38383841
if (pi_test_and_set_on(&vmx->pi_desc))
3839-
return;
3842+
return 0;
38403843

38413844
if (!kvm_vcpu_trigger_posted_interrupt(vcpu, false))
38423845
kvm_vcpu_kick(vcpu);
3846+
3847+
return 0;
38433848
}
38443849

38453850
/*

0 commit comments

Comments
 (0)