Skip to content
  • Nadav Har'El's avatar
    KVM: nVMX: Correct handling of idt vectoring info · 66c78ae4
    Nadav Har'El authored
    
    
    This patch adds correct handling of IDT_VECTORING_INFO_FIELD for the nested
    case.
    
    When a guest exits while delivering an interrupt or exception, we get this
    information in IDT_VECTORING_INFO_FIELD in the VMCS. When L2 exits to L1,
    there's nothing we need to do, because L1 will see this field in vmcs12, and
    handle it itself. However, when L2 exits and L0 handles the exit itself and
    plans to return to L2, L0 must inject this event to L2.
    
    In the normal non-nested case, the idt_vectoring_info case is discovered after
    the exit, and the decision to inject (though not the injection itself) is made
    at that point. However, in the nested case a decision of whether to return
    to L2 or L1 also happens during the injection phase (see the previous
    patches), so in the nested case we can only decide what to do about the
    idt_vectoring_info right after the injection, i.e., in the beginning of
    vmx_vcpu_run, which is the first time we know for sure if we're staying in
    L2.
    
    Therefore, when we exit L2 (is_guest_mode(vcpu)), we disable the regular
    vmx_complete_interrupts() code which queues the idt_vectoring_info for
    injection on next entry - because such injection would not be appropriate
    if we will decide to exit to L1. Rather, we just save the idt_vectoring_info
    and related fields in vmcs12 (which is a convenient place to save these
    fields). On the next entry in vmx_vcpu_run (*after* the injection phase,
    potentially exiting to L1 to inject an event requested by user space), if
    we find ourselves in L1 we don't need to do anything with those values
    we saved (as explained above). But if we find that we're in L2, or rather
    *still* at L2 (it's not nested_run_pending, meaning that this is the first
    round of L2 running after L1 having just launched it), we need to inject
    the event saved in those fields - by writing the appropriate VMCS fields.
    
    Signed-off-by: default avatarNadav Har'El <nyh@il.ibm.com>
    Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
    66c78ae4