Skip to content
  • Sean Christopherson's avatar
    KVM: VMX: Store the host kernel's IDT base in a global variable · 2342080c
    Sean Christopherson authored
    Although the kernel may use multiple IDTs, KVM should only ever see the
    "real" IDT, e.g. the early init IDT is long gone by the time KVM runs
    and the debug stack IDT is only used for small windows of time in very
    specific flows.
    
    Before commit a547c6db
    
     ("KVM: VMX: Enable acknowledge interupt on
    vmexit"), the kernel's IDT base was consumed by KVM only when setting
    constant VMCS state, i.e. to set VMCS.HOST_IDTR_BASE.  Because constant
    host state is done once per vCPU, there was ostensibly no need to cache
    the kernel's IDT base.
    
    When support for "ack interrupt on exit" was introduced, KVM added a
    second consumer of the IDT base as handling already-acked interrupts
    requires directly calling the interrupt handler, i.e. KVM uses the IDT
    base to find the address of the handler.  Because interrupts are a fast
    path, KVM cached the IDT base to avoid having to VMREAD HOST_IDTR_BASE.
    Presumably, the IDT base was cached on a per-vCPU basis simply because
    the existing code grabbed the IDT base on a per-vCPU (VMCS) basis.
    
    Note, all post-boot IDTs use the same handlers for external interrupts,
    i.e. the "ack interrupt on exit" use of the IDT base would be unaffected
    even if the cached IDT somehow did not match the current IDT.  And as
    for the original use case of setting VMCS.HOST_IDTR_BASE, if any of the
    above analysis is wrong then KVM has had a bug since the beginning of
    time since KVM has effectively been caching the IDT at vCPU creation
    since commit a8b732ca01c ("[PATCH] kvm: userspace interface").
    
    Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    2342080c