• Jing Liu's avatar
    kvm: x86: Intercept #NM for saving IA32_XFD_ERR · ec5be88a
    Jing Liu authored
    Guest IA32_XFD_ERR is generally modified in two places:
    
      - Set by CPU when #NM is triggered;
      - Cleared by guest in its #NM handler;
    
    Intercept #NM for the first case when a nonzero value is written
    to IA32_XFD. Nonzero indicates that the guest is willing to do
    dynamic fpstate expansion for certain xfeatures, thus KVM needs to
    manage and virtualize guest XFD_ERR properly. The vcpu exception
    bitmap is updated in XFD write emulation according to guest_fpu::xfd.
    
    Save the current XFD_ERR value to the guest_fpu container in the #NM
    VM-exit handler. This must be done with interrupt disabled, otherwise
    the unsaved MSR value may be clobbered by host activity.
    
    The saving operation is conducted conditionally only when guest_fpu:xfd
    includes a non-zero value. Doing so also avoids misread on a platform
    which doesn't support XFD but #NM is triggered due to L1 interception.
    
    Queueing #NM to the guest is postponed to handle_exception_nmi(). This
    goes through the nested_vmx check so a virtual vmexit is queued instead
    when #NM is triggered in L2 but L1 wants to intercept it.
    
    Restore the host value (always ZERO outside of the host #NM
    handler) before enabling interrupt.
    
    Restore the guest value from the guest_fpu container right before
    entering the guest (with interrupt disabled).
    Suggested-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarJing Liu <jing2.liu@intel.com>
    Signed-off-by: default avatarKevin Tian <kevin.tian@intel.com>
    Signed-off-by: default avatarYang Zhong <yang.zhong@intel.com>
    Message-Id: <20220105123532.12586-13-yang.zhong@intel.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    ec5be88a
vmcs.h 4.23 KB