[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1] x86/nestedsvm: write back V_NMI and V_NMI_MASK on nested #VMEXIT


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: chunjie.zhu@xxxxxxxxxx
  • Date: Thu, 15 Oct 2026 15:45:12 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5V+TveEByXy3LtetVMfKqEKKomgPXI/+10CtxBApa5c=; b=Jq4rE3Af4r/6RwACOprDikZVWqcdRrgutLCuguDLrH4ajKMzxRRYT3EzRh0DYnF63LRfMG1uJ2HhfmwwksG/CkkkqEe3w+yF0WvlOh9h0n7/SAmduee6khmwO2IEaE1BxHD0XQ83opZ2VmvRldRIDMeVpu3zyw96TYl3k5tsGInZo/z8Z2OI7NYZe8kKh0KZLSgMDPVfv27qQYuhUTffVV0zx7YlRB19E4D8IO2vxm/6Dzg/+QksXJHxlbpmtWURL1qki4+1CcRP+B8P/FBB0U3NHzP+dp2nTT79d20+qnHWOjFBHJtfIQIfT4ngcfXEpYFzL8zVV5f56XCKYL6+Gw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Nov+UzQCw3Y1KB1Uhr9ryjnKnufaYEY+P7I3P/bJ69jGph4D/8MJd9Hqha+Jb6W5XQ8QS9/wzkVNe7S9ZEk9Mp2RhcxaiJba8x88Z2GFlXF1tP4SbkWC8r5Le0plxQwTM+w372xxhcBEvy+61/Nj1gHbPi1kpdl0Xc9XPeSnmQQad8Z3ckupC9pmeXN+rfplyvVBvi69EM3o6L1ENeMDA6Vepy287hQnJx4qGKMmKJCyZw8QPj+IbVFw8BLMz+mmaIY1eoHQBsmH7lOQXuXf+SAUT7Ef2vnvibaKN+ccj7CrCAMdEDWZXw1xXzfynpp/PWUizEk/CFzUbQUqIChtFw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-Id:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: jbeulich@xxxxxxxx, andrew.cooper3@xxxxxxxxxx, roger@xxxxxxxxxxxxxx, jason.andryuk@xxxxxxx, teddy.astie@xxxxxxxxxx, Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
  • Delivery-date: Thu, 15 Oct 2026 07:45:40 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>

With V_NMI_ENABLE set, the processor clears V_NMI and sets V_NMI_MASK when
it takes the virtual NMI, and writes both back to the VMCB on #VMEXIT
(APM vol.2 15.21.10).

nsvm_vmcb_prepare4vmexit() only propagated V_TPR, V_IRQ and (conditionally)
V_GIF from the L2 shadow VMCB into vmcb12. V_NMI and V_NMI_MASK were never
copied back, so L1 kept seeing whatever it had last written, regardless of
what happened in L2.

Copy both back when L1 has enabled vNMI for its guest.

Signed-off-by: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
---
 xen/arch/x86/hvm/svm/nestedsvm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index faacfe007832..ecd89eb43f06 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -1027,12 +1027,18 @@ nsvm_vmcb_prepare4vmexit(struct vcpu *v, struct 
cpu_user_regs *regs)
     /*
      * Virtual Interrupts.  #VMEXIT writes back V_TPR and V_IRQ (APM vol.2
      * 15.6); the remaining fields do not change.  Copy vGIF back only if
-     * enabled in L1.
+     * enabled in L1.  With vNMI enabled, #VMEXIT also writes back V_NMI and
+     * V_NMI_MASK (APM vol.2 15.21.10).
      */
     ns_vmcb->_vintr.fields.tpr = n2vmcb->_vintr.fields.tpr;
     ns_vmcb->_vintr.fields.irq = n2vmcb->_vintr.fields.irq;
     if ( ns_vmcb->_vintr.fields.vgif_enable )
         ns_vmcb->_vintr.fields.vgif = n2vmcb->_vintr.fields.vgif;
+    if ( ns_vmcb->_vintr.fields.vnmi_enable )
+    {
+        ns_vmcb->_vintr.fields.vnmi_pending = 
n2vmcb->_vintr.fields.vnmi_pending;
+        ns_vmcb->_vintr.fields.vnmi_blocking = 
n2vmcb->_vintr.fields.vnmi_blocking;
+    }
 
     /* Interrupt state */
     ns_vmcb->int_stat = n2vmcb->int_stat;
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.