• Wanpeng Li's avatar
    KVM: nVMX: fix "acknowledge interrupt on exit" when APICv is in use · f5c694cf
    Wanpeng Li authored
    commit 56cc2406 upstream.
    
    After commit 77b0f5d6 (KVM: nVMX: Ack and write vector info to intr_info
    if L1 asks us to), "Acknowledge interrupt on exit" behavior can be
    emulated. To do so, KVM will ask the APIC for the interrupt vector if
    during a nested vmexit if VM_EXIT_ACK_INTR_ON_EXIT is set.  With APICv,
    kvm_get_apic_interrupt would return -1 and give the following WARNING:
    
    Call Trace:
     [<ffffffff81493563>] dump_stack+0x49/0x5e
     [<ffffffff8103f0eb>] warn_slowpath_common+0x7c/0x96
     [<ffffffffa059709a>] ? nested_vmx_vmexit+0xa4/0x233 [kvm_intel]
     [<ffffffff8103f11a>] warn_slowpath_null+0x15/0x17
     [<ffffffffa059709a>] nested_vmx_vmexit+0xa4/0x233 [kvm_intel]
     [<ffffffffa0594295>] ? nested_vmx_exit_handled+0x6a/0x39e [kvm_intel]
     [<ffffffffa0537931>] ? kvm_apic_has_interrupt+0x80/0xd5 [kvm]
     [<ffffffffa05972ec>] vmx_check_nested_events+0xc3/0xd3 [kvm_intel]
     [<ffffffffa051ebe9>] inject_pending_event+0xd0/0x16e [kvm]
     [<ffffffffa051efa0>] vcpu_enter_guest+0x319/0x704 [kvm]
    
    To fix this, we cannot rely on the processor's virtual interrupt delivery,
    because "acknowledge interrupt on exit" must only update the virtual
    ISR/PPR/IRR registers (and SVI, which is just a cache of the virtual ISR)
    but it should not deliver the interrupt through the IDT.  Thus, KVM has
    to deliver the interrupt "by hand", similar to the treatment of EOI in
    commit fc57ac2c (KVM: lapic: sync highest ISR to hardware apic on
    EOI, 2014-05-14).
    
    The patch modifies kvm_cpu_get_interrupt to always acknowledge an
    interrupt; there are only two callers, and the other is not affected
    because it is never reached with kvm_apic_vid_enabled() == true.  Then it
    modifies apic_set_isr and apic_clear_irr to update SVI and RVI in addition
    to the registers.
    Suggested-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Suggested-by: default avatar"Zhang, Yang Z" <yang.z.zhang@intel.com>
    Tested-by: default avatarLiu, RongrongX <rongrongx.liu@intel.com>
    Tested-by: default avatarFelipe Reyes <freyes@suse.com>
    Fixes: 77b0f5d6Signed-off-by: default avatarWanpeng Li <wanpeng.li@linux.intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    f5c694cf
lapic.c 47.5 KB