Skip to content

Commit f729851

Browse files
committed
KVM: x86: Don't move VMX's nested PI notification vector from IRR to ISR
When getting an IRQ from the local APIC, don't move the vector to the ISR and skip the PPR update if the found vector is the vCPU's nested posted interrupt notification vector, i.e. if the IRQ should trigger posted interrupt processing in L2 instead of being deliver to L1. For now, pass in -1 from all callers and defer passing the actual nested notification vector to a separate patch, as more prep work is needed. Functionally, this should be a glorified nop, i.e. no true functional change intended. Cc: stable@vger.kernel.org Reviewed-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20240720000138.3027780-4-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent cb14e45 commit f729851

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v);
22562256
int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
22572257
int kvm_cpu_has_extint(struct kvm_vcpu *v);
22582258
int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
2259-
int kvm_cpu_get_interrupt(struct kvm_vcpu *v);
2259+
int kvm_cpu_get_interrupt(struct kvm_vcpu *v, int nested_pi_nv);
22602260
void kvm_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
22612261

22622262
int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,

arch/x86/kvm/irq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ static int kvm_cpu_get_extint(struct kvm_vcpu *v)
135135
/*
136136
* Read pending interrupt vector and intack.
137137
*/
138-
int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
138+
int kvm_cpu_get_interrupt(struct kvm_vcpu *v, int nested_pi_nv)
139139
{
140140
int vector = kvm_cpu_get_extint(v);
141141
if (vector != -1)
142-
return vector; /* PIC */
142+
return vector; /* PIC */
143143

144-
return kvm_get_apic_interrupt(v); /* APIC */
144+
return kvm_get_apic_interrupt(v, nested_pi_nv); /* APIC */
145145
}
146146
EXPORT_SYMBOL_GPL(kvm_cpu_get_interrupt);
147147

arch/x86/kvm/lapic.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
29222922
}
29232923
}
29242924

2925-
int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
2925+
int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu, int nested_pi_nv)
29262926
{
29272927
int vector = kvm_apic_has_interrupt(vcpu);
29282928
struct kvm_lapic *apic = vcpu->arch.apic;
@@ -2937,8 +2937,16 @@ int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu)
29372937
* on exit" mode. Then we cannot inject the interrupt via RVI,
29382938
* because the process would deliver it through the IDT.
29392939
*/
2940-
29412940
apic_clear_irr(vector, apic);
2941+
2942+
/*
2943+
* If the vector is L2's posted interrupt notification vector, return
2944+
* without moving the vector to the ISR, as notification interrupts
2945+
* trigger processing in L2, i.e. aren't delivered to L1.
2946+
*/
2947+
if (vector == nested_pi_nv)
2948+
return vector;
2949+
29422950
if (kvm_hv_synic_auto_eoi_set(vcpu, vector)) {
29432951
/*
29442952
* For auto-EOI interrupts, there might be another pending

arch/x86/kvm/lapic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu);
8989

9090
int kvm_apic_has_interrupt(struct kvm_vcpu *vcpu);
9191
int kvm_apic_accept_pic_intr(struct kvm_vcpu *vcpu);
92-
int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu);
92+
int kvm_get_apic_interrupt(struct kvm_vcpu *vcpu, int nested_pi_nv);
9393
int kvm_apic_accept_events(struct kvm_vcpu *vcpu);
9494
void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event);
9595
u64 kvm_lapic_get_cr8(struct kvm_vcpu *vcpu);

arch/x86/kvm/vmx/nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4295,7 +4295,7 @@ static int vmx_check_nested_events(struct kvm_vcpu *vcpu)
42954295
if (nested_exit_intr_ack_set(vcpu)) {
42964296
int irq;
42974297

4298-
irq = kvm_cpu_get_interrupt(vcpu);
4298+
irq = kvm_cpu_get_interrupt(vcpu, -1);
42994299
if (WARN_ON_ONCE(irq < 0))
43004300
goto no_vmexit;
43014301

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10548,7 +10548,7 @@ static int kvm_check_and_inject_events(struct kvm_vcpu *vcpu,
1054810548
if (r < 0)
1054910549
goto out;
1055010550
if (r) {
10551-
int irq = kvm_cpu_get_interrupt(vcpu);
10551+
int irq = kvm_cpu_get_interrupt(vcpu, -1);
1055210552

1055310553
if (!WARN_ON_ONCE(irq == -1)) {
1055410554
kvm_queue_interrupt(vcpu, irq, false);

0 commit comments

Comments
 (0)