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

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


  • To: Chunjie Zhu (朱春杰) <chunjie.zhu@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
  • Date: Thu, 29 Oct 2026 17:54:59 +0000
  • Accept-language: en-US
  • 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=vGab5AIaR1STeapt5WDS0Xtnl2GjCzzUijhZvewu1AI=; b=DJ3sBDT9lTZexORZjef+f1ZECj5ZmX5d1YCEwdTO2TixMdgY89pMCI9niIV23MJDPE5hG07Y8tjqEnuUtMdqBG/7uXB9gkp200JA+IBBBXgHV2OgTVUZ14OnPMjk05F0vB9tt8UljlqSYiyGs1L/hgouisxP2ulZqBS4vRBjNfqQGgMH7ixwlUjtMhMrc33xT3gkOkfhCRLFOVaMepoEldLAiMijn9GYX/1WAUeZY4Lm7G0WZNpBtfszFHJMsu7vEG0Ida3XvnUouLqRRTXGgexBzorA3JDyVqy2+1SwUCeg+erOrO+NJYZPqUx16IWBaoLmQXh2CuiIJbFiAyDeSA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=h72JyTfQ8zNcjC6lGVFh2V3wBjdNO7flrH4z2lgTG0CxeCeTVeqTeG2QwQgvBy9N2HMpU+0Eg/1e6B/6/m2NPpJtmzOm7nz72AbuZ8njcYV4pZiLbARAQfARyb7gfm4QXvZ3Pp9typiMXllpgrLYUxkay6OQ2qQVK4BYbkHP/61313kj0m9y33c6B+Z+c2RLo1KdvEh9Zvbk1sKmrHWWa4NXWkgKJxzHOeVNm3Q4w4W57Wf094obcpAjetJH/O8LAXp+c9Mh/3T1BfpTF+DLDEIj/j472z6dgkzTZ3Ofq6xW6Anm9mH3EI67fd+xA0vFiA+/513TsFB7WmGc+8j/fg==
  • 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: "jason.andryuk@xxxxxxx" <jason.andryuk@xxxxxxx>, "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>, "roger@xxxxxxxxxxxxxx" <roger@xxxxxxxxxxxxxx>, "teddy.astie@xxxxxxxxxx" <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Thu, 29 Oct 2026 17:55:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Msip_labels:
  • Thread-index: AQHdXTzn+Hkg06vIsUeaRhcdK6IUircU3j9P
  • Thread-topic: [PATCH v2] x86/nestedsvm: write back V_NMI and V_NMI_MASK on nested #VMEXIT

> From: Xen-devel <xen-devel-bounces@xxxxxxxxxxxxxxxxxxxx> on behalf of 
> chunjie.zhu@xxxxxxxxxx <chunjie.zhu@xxxxxxxxxx>
> Sent: Friday, October 16, 2026 08:06
> To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>; xen-devel@xxxxxxxxxxxxxxxxxxxx 
> <xen-devel@xxxxxxxxxxxxxxxxxxxx>
> Cc: Chunjie Zhu (朱春杰) <chunjie.zhu@xxxxxxxxxx>; jason.andryuk@xxxxxxx 
> <jason.andryuk@xxxxxxx>; jbeulich@xxxxxxxx <jbeulich@xxxxxxxx>; 
> roger@xxxxxxxxxxxxxx <roger@xxxxxxxxxxxxxx>; teddy.astie@xxxxxxxxxx 
> <teddy.astie@xxxxxxxxxx>
> Subject: [PATCH v2] x86/nestedsvm: write back V_NMI and V_NMI_MASK on nested 
> #VMEXIT
>
>
> From: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
>
> When V_NMI_ENABLE is set, the processor manages V_NMI and V_NMI_MASK
> automatically (including on IRET), and writes both back to the VMCB on
> VMEXIT (APM vol.2 rev 3.44, "NMI Virtualization").
>
> 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.
>
> Fixes: 86a203ab8d38 ("x86/svm: Support vNMI on capable hardware")
> Signed-off-by: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
> ---
> v2:
>  * Reword commit message: the processor manages V_NMI/V_NMI_MASK itself.
>  * Add Fixes: tag.
>  * Cite APM by revision and section title.
> ---
>  xen/arch/x86/hvm/svm/nestedsvm.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c 
> b/xen/arch/x86/hvm/svm/nestedsvm.c
> index faacfe007832..3a0afa98129e 100644
> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
> @@ -1027,12 +1027,19 @@ 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, the processor manages V_NMI and
> +     * V_NMI_MASK itself and writes both back on #VMEXIT (APM vol.2 rev 3.44,
> +     * "NMI Virtualization").
>       */
>      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

The issue here is that Xen allows L1 to enable VNMI in the first place
while it hasn't exposed the feature to L1.  This is because Xen blindly
copies the entire vintr field (except V_INTR_MASKING) from VMCB(1-2),
which incidentally also allows the guest to enable AVIC and unexpectedly
get AVIC-related VMEXITs as reported here:
https://lore.kernel.org/xen-devel/CA+aCS-Ha4jSYFfxhOwMGiGJPdCOtgBJLt=3Q=v9dfp6SQJys4w@xxxxxxxxxxxxxx/T/#u

First, we need to fix that bug by copying only the relevant supported
parts of vintr from VMCB(1-2).

Then, as a separate series, expose the VNMI feature bit to the VM (if
supported by hardware) and make it work correctly.

Ross

 


Rackspace

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