From: Abdelkareem Abdelsaamad <[email protected]>

Currently, the Xen hypervisor delivers NMIs to the guests using the Event
Injection mechanism. The Event Injection mechanism does not block the
delivery of subsequent NMIs. So the Xen Hypervisor tracks the NMI delivery
and its completion (by intercepting the IRET instruction) before sending
a new NMI.

With the 4th generation AMD EPYC, a hardware NMI virtualization support,
Virtual NMI (VNMI), is introduced.  The vNMI allows the hypervisor to inject
the NMI into the guest w/o using Event Injection mechanism. No need to track
the guest NMI and intercepting the IRET instruction.

NMI Virtualization support is indicated by CPUID Fn8000_000A_EDX[VNMI] = 1.[1]

NMI Virtualization is enabled by setting V_NMI_ENABLE (bit 26 in offset 60h
of the VMCB). Enabling NMI Virtualization requires the NMI intercept bit to
be set. An attempt to run a guest with V_NMI_ENABLE without the NMI intercept
bit set results in #VMEXIT(INVALID) [1]

Three new bits are added to the VMCB field at offset 60h to provide NMI
virtualization hardware support:

V_NMI(11): Indicates whether a virtual NMI is pending in the guest. The
processor will clear V_NMI once it takes the virtual NMI.
V_NMI_MASK(12): Indicates whether virtual NMIs are masked. The processor will
set V_NMI_MASK once it takes the virtual NMI. V_NMI_MASK is cleared when the
guest successfully completes an IRET instruction or #VMEXIT occurs while
delivering the virtual NMI.
V_NMI_ENABLE(26): Enables NMI virtualization. [1]

--Abdelkareem Abdelsaamad
[1] https://docs.amd.com/v/u/en-US/24593_3.43

Abdelkareem Abdelsaamad (3):
  svm/vnmi: introduce the vnmi bit support in the cpuid feature set
  svm/vnmi: add the definitions for the svm vnmi management bits in the
    VMCB
  svm/vnmi: Add support for the SVM Virtual NMI

 xen/arch/x86/hvm/hvm.c             | 29 +++++++++++++++++++++--------
 xen/arch/x86/hvm/svm/intr.c        | 16 ++++++++++++++--
 xen/arch/x86/hvm/svm/svm.c         | 25 ++++++++++++++++++++++++-
 xen/arch/x86/hvm/svm/vmcb.c        |  3 +++
 xen/arch/x86/hvm/svm/vmcb.h        | 12 ++++++++----
 xen/arch/x86/include/asm/hvm/hvm.h | 12 +++++++++++-
 xen/arch/x86/include/asm/hvm/svm.h |  2 ++
 7 files changed, 83 insertions(+), 16 deletions(-)

-- 
2.52.0


Reply via email to