* [PATCH v1 1/2] x86/cpuid: Hide XSAVES from nested VMX guests
2026-11-30 7:38 [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED from nested VMX guests chunjie.zhu
@ 2026-11-30 7:38 ` chunjie.zhu
2026-11-30 7:38 ` [PATCH v1 2/2] x86/cpuid: Hide RDRAND and RDSEED " chunjie.zhu
2026-12-01 11:09 ` [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED " Andrew Cooper
2 siblings, 0 replies; 5+ messages in thread
From: chunjie.zhu @ 2026-11-30 7:38 UTC (permalink / raw)
To: xen-devel; +Cc: jbeulich, andrew.cooper3, roger, teddy.astie, Chunjie Zhu
From: Chunjie Zhu <chunjie.zhu@citrix.com>
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@citrix.com>
---
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 2/2] x86/cpuid: Hide RDRAND and RDSEED from nested VMX guests
2026-11-30 7:38 [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED from nested VMX guests chunjie.zhu
2026-11-30 7:38 ` [PATCH v1 1/2] x86/cpuid: Hide XSAVES " chunjie.zhu
@ 2026-11-30 7:38 ` chunjie.zhu
2026-11-30 22:15 ` Teddy Astie
2026-12-01 11:09 ` [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED " Andrew Cooper
2 siblings, 1 reply; 5+ messages in thread
From: chunjie.zhu @ 2026-11-30 7:38 UTC (permalink / raw)
To: xen-devel; +Cc: jbeulich, andrew.cooper3, roger, teddy.astie, Chunjie Zhu
From: Chunjie Zhu <chunjie.zhu@citrix.com>
Hyper-V (hvix64) requires the "RDRAND exiting" secondary VM-execution
control to be available whenever CPUID reports RDRAND (and likewise
"RDSEED exiting" for RDSEED). Nested VMX does not offer either control to
L1, so a Hyper-V L1 sees an inconsistent view and fails early during boot.
Clear CPUID.1[ECX].RDRAND and CPUID.7[0].EBX.RDSEED for HVM guests which
have nested virt enabled and are exposed VMX.
Signed-off-by: Chunjie Zhu <chunjie.zhu@citrix.com>
---
xen/arch/x86/cpuid.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 0e79ce67dd3f..d89fde27c454 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -281,6 +281,14 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
if ( is_hvm_domain(d) )
res->b |= (v->vcpu_id * 2) << 24;
+ /*
+ * Hyper-V (hvix64) requires the "RDRAND exiting" secondary VM-execution
+ * control whenever CPUID reports RDRAND. Nested VMX does not offer
+ * it, so hide RDRAND (and RDSEED, below) from nested VMX guests.
+ */
+ if ( is_hvm_domain(d) && nestedhvm_enabled(d) && p->basic.vmx )
+ res->c &= ~cpufeat_mask(X86_FEATURE_RDRAND);
+
/* TODO: Rework vPMU control in terms of toolstack choices. */
if ( vpmu_available(v) &&
vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) )
@@ -432,6 +440,9 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
? v->arch.pv.ctrlreg[4]
: v->arch.hvm.guest_cr[4]) & X86_CR4_PKE )
res->c |= cpufeat_mask(X86_FEATURE_OSPKE);
+
+ if ( is_hvm_domain(d) && nestedhvm_enabled(d) && p->basic.vmx )
+ res->b &= ~cpufeat_mask(X86_FEATURE_RDSEED);
break;
}
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 2/2] x86/cpuid: Hide RDRAND and RDSEED from nested VMX guests
2026-11-30 7:38 ` [PATCH v1 2/2] x86/cpuid: Hide RDRAND and RDSEED " chunjie.zhu
@ 2026-11-30 22:15 ` Teddy Astie
0 siblings, 0 replies; 5+ messages in thread
From: Teddy Astie @ 2026-11-30 22:15 UTC (permalink / raw)
To: chunjie.zhu, xen-devel; +Cc: jbeulich, andrew.cooper3, roger
[-- Attachment #1.1: Type: text/plain, Size: 2475 bytes --]
Le 30/11/2026 à 08:41, chunjie.zhu@citrix.com a écrit :
> From: Chunjie Zhu <chunjie.zhu@citrix.com>
>
> Hyper-V (hvix64) requires the "RDRAND exiting" secondary VM-execution
> control to be available whenever CPUID reports RDRAND (and likewise
> "RDSEED exiting" for RDSEED). Nested VMX does not offer either control to
> L1, so a Hyper-V L1 sees an inconsistent view and fails early during boot.
>
> Clear CPUID.1[ECX].RDRAND and CPUID.7[0].EBX.RDSEED for HVM guests which
> have nested virt enabled and are exposed VMX.
>
> Signed-off-by: Chunjie Zhu <chunjie.zhu@citrix.com>
> ---
> xen/arch/x86/cpuid.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
> index 0e79ce67dd3f..d89fde27c454 100644
> --- a/xen/arch/x86/cpuid.c
> +++ b/xen/arch/x86/cpuid.c
> @@ -281,6 +281,14 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
> if ( is_hvm_domain(d) )
> res->b |= (v->vcpu_id * 2) << 24;
>
> + /*
> + * Hyper-V (hvix64) requires the "RDRAND exiting" secondary VM-execution
> + * control whenever CPUID reports RDRAND. Nested VMX does not offer
> + * it, so hide RDRAND (and RDSEED, below) from nested VMX guests.
> + */
> + if ( is_hvm_domain(d) && nestedhvm_enabled(d) && p->basic.vmx )
> + res->c &= ~cpufeat_mask(X86_FEATURE_RDRAND);
> +
> /* TODO: Rework vPMU control in terms of toolstack choices. */
> if ( vpmu_available(v) &&
> vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) )
> @@ -432,6 +440,9 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf,
> ? v->arch.pv.ctrlreg[4]
> : v->arch.hvm.guest_cr[4]) & X86_CR4_PKE )
> res->c |= cpufeat_mask(X86_FEATURE_OSPKE);
> +
> + if ( is_hvm_domain(d) && nestedhvm_enabled(d) && p->basic.vmx )
> + res->b &= ~cpufeat_mask(X86_FEATURE_RDSEED);
> break;
> }
> break;
I don't think this is a good idea to mask some CPUID features because of
missing bits in the nested virt code, especially if it's to workaround
Hyper-V requirements.
In this case, even though Xen doesn't use RDRAND exiting, we can still
virtualize it i.e when running L2, intercept it, and reinject the VMEXIT
to L1 like we do for preemption timers among other things.
Teddy
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 665 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED from nested VMX guests
2026-11-30 7:38 [PATCH v1 0/2] x86/cpuid: Hide XSAVES/RDRAND/RDSEED from nested VMX guests chunjie.zhu
2026-11-30 7:38 ` [PATCH v1 1/2] x86/cpuid: Hide XSAVES " chunjie.zhu
2026-11-30 7:38 ` [PATCH v1 2/2] x86/cpuid: Hide RDRAND and RDSEED " chunjie.zhu
@ 2026-12-01 11:09 ` Andrew Cooper
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Cooper @ 2026-12-01 11:09 UTC (permalink / raw)
To: chunjie.zhu, xen-devel; +Cc: Andrew Cooper, jbeulich, roger, teddy.astie
On 30/11/2026 7:38 am, chunjie.zhu@citrix.com wrote:
> From: Chunjie Zhu <chunjie.zhu@citrix.com>
>
> Hyper-V (hvix64) as an L1 guest on Xen checks that every feature CPUID
> reports has the matching secondary VM-execution control available in
> IA32_VMX_PROCBASED_CTLS2, and fails early during boot otherwise. Xen's
> nested VMX does not offer the XSAVES, RDRAND-exiting or RDSEED-exiting
> controls, so hide the features from L1 instead.
>
> This is a pragmatic workaround rather than a complete answer. Ideally the
> CPUID policy would be derived from what nested VMX can actually offer, at
> the toolstack level, and I'd welcome guidance on whether that is the
> preferred direction before this goes any further.
>
> Tested with a Hyper-V L1 guest, which gets past the VMX capability checks
> with these applied. Applies on top of current master.
It is HyperV's choice to demand those features. It is arguably a bug
that Xen doesn't expose the exiting controls, but nested virt had been
abandoned for so long that it's not surprising that these weren't
implemented.
However, you can't simply hide the features like this. If nothing else,
it's playing behind the back of a toolstack which thinks the VM can see
the features.
For RDRAND and RDSEED, it's probably easier to add support for exiting
than to play with CPUID. It's just two extra intercept checks.
XSAVES is harder. We probably should hide XSAVES generally; we do not
support any supervisor states, and there's a long list of things needing
doing before we can expose any. Only then will we be able to reason
about what's required to make it work under nested virt.
~Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread