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

[PATCH v1 1/2] x86/cpuid: Hide XSAVES from nested VMX guests


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: chunjie.zhu@xxxxxxxxxx
  • Date: Mon, 30 Nov 2026 15:38:49 +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=2KKzCTdmsoYSIyXmHKyJsfz2wTYqLR+pPWrVkNPLkus=; b=r4+3cKRaVN686Jf8TfS3sxH7u5LonVWhxL0Du80qMnOymohV28gNt0c4iqOXyezNdwJirJGkxSg39RtKc1U1M21gXYdSMHOXj1WNoIfjeXonFNWXkGr2iyyfhReqLzShl1phjgOAGAC4mDII620HTWtMTRpvZEw3yqauP9hCPkKs/L5Fhr1bRRpmVfZGDQ4NREozxi5naPRJfZkwfJ9hlf8f6Q+J7DPv13FuIfb0CgviE10GHRjSyJeclOQSa373CfluihzoPVQHzPEEt4ilNVIs5dyYx+P9HdN/kFDY1JkklRRKprxe5d+VW5+wAsiGXdGIbcBy2BlRVF/PFew6Ow==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=EOds/1s/NNDt/2c83bNkhD0lKHxEI1cLaaca4V8Wl0TnQ3PYTAG29/9jnOxtfgH7tD2v8L3XjaBDxiI0NBzNxIz+FdjWTD50cAgWIBUviCYVEm96YyzJyuelkuTXf5x/G1PFJYeWPNx3zFeB+Fuoampg2hyP1mE1W4DcBef68LDS7vHU0KqYgk+IroLeFE7aHVZpdK99rl8UdDRWFd0gzgV8K/80TUIB6HAFC2hvunf9T4zESEiWgNUAtNkix5PJfqYbX/04xMAjRi7Ww2jTvrxJKHEVvwuCKb6B5Oq2t2MKvCdiaQVXjGcqCrBI3oUURFLkwSVGaeVw6Paj+AnI1g==
  • 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, teddy.astie@xxxxxxxxxx, Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
  • Delivery-date: Mon, 30 Nov 2026 07:39:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

From: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>

Hyper-V (hvix64) requires the "enable XSAVES/XRSTORS" secondary
VM-execution control to be available whenever CPUID reports XSAVES, and
refuses to start otherwise.  Nested VMX does not offer that control to L1,
so a Hyper-V L1 sees an inconsistent view and fails early during boot.

Clear the XSAVES bit in CPUID.0xD[1].EAX, along with the IA32_XSS supported
bits in ECX:EDX, for HVM guests which have nested virt enabled and are
exposed VMX.

Signed-off-by: Chunjie Zhu <chunjie.zhu@xxxxxxxxxx>
---
 xen/arch/x86/cpuid.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index a9aeb2d268ad..0e79ce67dd3f 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -8,6 +8,7 @@
 #include <asm/cpu-policy.h>
 #include <asm/cpuid.h>
 #include <asm/guest-msr.h>
+#include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/viridian.h>
 #include <asm/xstate.h>
 
@@ -477,6 +478,19 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
             if ( p->xstate.xsavec )
                 res->b = xstate_compressed_size(v->arch.xcr0 |
                                                 v->arch.msrs->xss.raw);
+
+            /*
+             * Hyper-V (hvix64) requires the "enable XSAVES/XRSTORS" secondary
+             * VM-execution control whenever CPUID reports XSAVES.  Nested VMX
+             * does not offer that control, so hide XSAVES (and the XSS state
+             * components) from nested VMX guests.
+             */
+            if ( is_hvm_domain(d) && nestedhvm_enabled(d) && p->basic.vmx )
+            {
+                res->a &= ~(1u << 3); /* XSAVES */
+                res->c = 0;           /* IA32_XSS supported bits */
+                res->d = 0;
+            }
             break;
         }
         break;
-- 
2.34.1




 


Rackspace

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