Skip to content

Commit 321ef62

Browse files
committed
KVM: nVMX: Fold requested virtual interrupt check into has_nested_events()
Check for a Requested Virtual Interrupt, i.e. a virtual interrupt that is pending delivery, in vmx_has_nested_events() and drop the one-off kvm_x86_ops.guest_apic_has_interrupt() hook. In addition to dropping a superfluous hook, this fixes a bug where KVM would incorrectly treat virtual interrupts _for L2_ as always enabled due to kvm_arch_interrupt_allowed(), by way of vmx_interrupt_blocked(), treating IRQs as enabled if L2 is active and vmcs12 is configured to exit on IRQs, i.e. KVM would treat a virtual interrupt for L2 as a valid wake event based on L1's IRQ blocking status. Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 27c4fa4 commit 321ef62

File tree

7 files changed

+5
-33
lines changed

7 files changed

+5
-33
lines changed

arch/x86/include/asm/kvm-x86-ops.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ KVM_X86_OP_OPTIONAL(update_cr8_intercept)
8585
KVM_X86_OP(refresh_apicv_exec_ctrl)
8686
KVM_X86_OP_OPTIONAL(hwapic_irr_update)
8787
KVM_X86_OP_OPTIONAL(hwapic_isr_update)
88-
KVM_X86_OP_OPTIONAL_RET0(guest_apic_has_interrupt)
8988
KVM_X86_OP_OPTIONAL(load_eoi_exitmap)
9089
KVM_X86_OP_OPTIONAL(set_virtual_apic_mode)
9190
KVM_X86_OP_OPTIONAL(set_apic_access_page_addr)

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,6 @@ struct kvm_x86_ops {
17151715
void (*refresh_apicv_exec_ctrl)(struct kvm_vcpu *vcpu);
17161716
void (*hwapic_irr_update)(struct kvm_vcpu *vcpu, int max_irr);
17171717
void (*hwapic_isr_update)(int isr);
1718-
bool (*guest_apic_has_interrupt)(struct kvm_vcpu *vcpu);
17191718
void (*load_eoi_exitmap)(struct kvm_vcpu *vcpu, u64 *eoi_exit_bitmap);
17201719
void (*set_virtual_apic_mode)(struct kvm_vcpu *vcpu);
17211720
void (*set_apic_access_page_addr)(struct kvm_vcpu *vcpu);

arch/x86/kvm/vmx/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
9797
.required_apicv_inhibits = VMX_REQUIRED_APICV_INHIBITS,
9898
.hwapic_irr_update = vmx_hwapic_irr_update,
9999
.hwapic_isr_update = vmx_hwapic_isr_update,
100-
.guest_apic_has_interrupt = vmx_guest_apic_has_interrupt,
101100
.sync_pir_to_irr = vmx_sync_pir_to_irr,
102101
.deliver_interrupt = vmx_deliver_interrupt,
103102
.dy_apicv_has_pending_interrupt = pi_has_pending_interrupt,

arch/x86/kvm/vmx/nested.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,10 @@ static bool vmx_has_nested_events(struct kvm_vcpu *vcpu, bool for_injection)
40604060

40614061
vppr = *((u32 *)(vapic + APIC_PROCPRI));
40624062

4063+
max_irr = vmx_get_rvi();
4064+
if ((max_irr & 0xf0) > (vppr & 0xf0))
4065+
return true;
4066+
40634067
if (vmx->nested.pi_pending && vmx->nested.pi_desc &&
40644068
pi_test_on(vmx->nested.pi_desc)) {
40654069
max_irr = pi_find_highest_vector(vmx->nested.pi_desc);

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4105,26 +4105,6 @@ void pt_update_intercept_for_msr(struct kvm_vcpu *vcpu)
41054105
}
41064106
}
41074107

4108-
bool vmx_guest_apic_has_interrupt(struct kvm_vcpu *vcpu)
4109-
{
4110-
struct vcpu_vmx *vmx = to_vmx(vcpu);
4111-
void *vapic_page;
4112-
u32 vppr;
4113-
int rvi;
4114-
4115-
if (WARN_ON_ONCE(!is_guest_mode(vcpu)) ||
4116-
!nested_cpu_has_vid(get_vmcs12(vcpu)) ||
4117-
WARN_ON_ONCE(!vmx->nested.virtual_apic_map.gfn))
4118-
return false;
4119-
4120-
rvi = vmx_get_rvi();
4121-
4122-
vapic_page = vmx->nested.virtual_apic_map.hva;
4123-
vppr = *((u32 *)(vapic_page + APIC_PROCPRI));
4124-
4125-
return ((rvi & 0xf0) > (vppr & 0xf0));
4126-
}
4127-
41284108
void vmx_msr_filter_changed(struct kvm_vcpu *vcpu)
41294109
{
41304110
struct vcpu_vmx *vmx = to_vmx(vcpu);

arch/x86/kvm/vmx/x86_ops.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void vmx_apicv_pre_state_restore(struct kvm_vcpu *vcpu);
4949
bool vmx_check_apicv_inhibit_reasons(enum kvm_apicv_inhibit reason);
5050
void vmx_hwapic_irr_update(struct kvm_vcpu *vcpu, int max_irr);
5151
void vmx_hwapic_isr_update(int max_isr);
52-
bool vmx_guest_apic_has_interrupt(struct kvm_vcpu *vcpu);
5352
int vmx_sync_pir_to_irr(struct kvm_vcpu *vcpu);
5453
void vmx_deliver_interrupt(struct kvm_lapic *apic, int delivery_mode,
5554
int trig_mode, int vector);

arch/x86/kvm/x86.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13108,12 +13108,6 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
1310813108
kvm_arch_free_memslot(kvm, old);
1310913109
}
1311013110

13111-
static inline bool kvm_guest_apic_has_interrupt(struct kvm_vcpu *vcpu)
13112-
{
13113-
return (is_guest_mode(vcpu) &&
13114-
static_call(kvm_x86_guest_apic_has_interrupt)(vcpu));
13115-
}
13116-
1311713111
static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
1311813112
{
1311913113
if (!list_empty_careful(&vcpu->async_pf.done))
@@ -13147,9 +13141,7 @@ static inline bool kvm_vcpu_has_events(struct kvm_vcpu *vcpu)
1314713141
if (kvm_test_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, vcpu))
1314813142
return true;
1314913143

13150-
if (kvm_arch_interrupt_allowed(vcpu) &&
13151-
(kvm_cpu_has_interrupt(vcpu) ||
13152-
kvm_guest_apic_has_interrupt(vcpu)))
13144+
if (kvm_arch_interrupt_allowed(vcpu) && kvm_cpu_has_interrupt(vcpu))
1315313145
return true;
1315413146

1315513147
if (kvm_hv_has_stimer_pending(vcpu))

0 commit comments

Comments
 (0)