We implement mshv_get_supported_cpuid() and invoke it in
x86_cpu_get_supported_feature_word() retrieve the cpu features that the
host is supporting. Initially we mask the virtualization capabilitities
potentially we might need to mask more in the future.
Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
---
include/system/mshv.h | 3 +++
target/i386/cpu.c | 8 ++++++++
target/i386/mshv/mshv-cpu.c | 27 +++++++++++++++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/include/system/mshv.h b/include/system/mshv.h
index 75286baf16..51b0420735 100644
--- a/include/system/mshv.h
+++ b/include/system/mshv.h
@@ -60,4 +60,7 @@ int mshv_irqchip_add_irqfd_notifier_gsi(const EventNotifier *n,
const EventNotifier *rn, int virq);
int mshv_irqchip_remove_irqfd_notifier_gsi(const EventNotifier *n, int virq);
+/* cpuid */
+uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg);
+
#endif
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 0a7b884528..b611afc21a 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -26,6 +26,7 @@
#include "tcg/helper-tcg.h"
#include "exec/translation-block.h"
#include "system/hvf.h"
+#include "system/mshv.h"
#include "hvf/hvf-i386.h"
#include "kvm/kvm_i386.h"
#include "kvm/tdx.h"
@@ -7958,6 +7959,13 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
r = hvf_get_supported_cpuid(wi->cpuid.eax,
wi->cpuid.ecx,
wi->cpuid.reg);
+ } else if (mshv_enabled()) {
+ if (wi->type != CPUID_FEATURE_WORD) {
+ return 0;
+ }
+ r = mshv_get_supported_cpuid(wi->cpuid.eax,
+ wi->cpuid.ecx,
+ wi->cpuid.reg);
} else if (tcg_enabled()) {
r = wi->tcg_features;
} else {
diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
index 38e0a045c2..bbb58461a4 100644
--- a/target/i386/mshv/mshv-cpu.c
+++ b/target/i386/mshv/mshv-cpu.c
@@ -1757,6 +1757,33 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)
g_clear_pointer(&env->emu_mmio_buf, g_free);
}
+uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg)
+{
+ uint32_t eax, ebx, ecx, edx;
+ uint32_t ret = 0;
+
+ host_cpuid(func, idx, &eax, &ebx, &ecx, &edx);
+ switch (reg) {
+ case R_EAX:
+ ret = eax; break;
+ case R_EBX:
+ ret = ebx; break;
+ case R_ECX:
+ ret = ecx; break;
+ case R_EDX:
+ ret = edx; break;
+ }
+
+ /* Disable nested virtualization features not yet supported by MSHV */
+ if (func == 0x80000001 && reg == R_ECX) {
+ ret &= ~CPUID_EXT3_SVM;
+ }
+ if (func == 0x01 && reg == R_ECX) {
+ ret &= ~CPUID_EXT_VMX;
+ }
+ return ret;
+}
+
/*
* Default Microsoft Hypervisor behavior for unimplemented MSR is to send a
* fault to the guest if it tries to access it. It is possible to override
--
2.34.1
> On 11. Feb 2026, at 16:54, Magnus Kulke <magnuskulke@linux.microsoft.com> wrote:
>
> We implement mshv_get_supported_cpuid() and invoke it in
> x86_cpu_get_supported_feature_word() retrieve the cpu features that the
> host is supporting. Initially we mask the virtualization capabilitities
> potentially we might need to mask more in the future.
>
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
Hi,
Interesting. For WHPX on Arm, what’s done is creating a stub partition and extract CPUID info from
it (with necessary guest stub code if necessary) but doing it this way like HVF x86 does is intriguing too…
Is this future-proof or are there catches with this approach?
Thank you,
> ---
> include/system/mshv.h | 3 +++
> target/i386/cpu.c | 8 ++++++++
> target/i386/mshv/mshv-cpu.c | 27 +++++++++++++++++++++++++++
> 3 files changed, 38 insertions(+)
>
> diff --git a/include/system/mshv.h b/include/system/mshv.h
> index 75286baf16..51b0420735 100644
> --- a/include/system/mshv.h
> +++ b/include/system/mshv.h
> @@ -60,4 +60,7 @@ int mshv_irqchip_add_irqfd_notifier_gsi(const EventNotifier *n,
> const EventNotifier *rn, int virq);
> int mshv_irqchip_remove_irqfd_notifier_gsi(const EventNotifier *n, int virq);
>
> +/* cpuid */
> +uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg);
> +
> #endif
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 0a7b884528..b611afc21a 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -26,6 +26,7 @@
> #include "tcg/helper-tcg.h"
> #include "exec/translation-block.h"
> #include "system/hvf.h"
> +#include "system/mshv.h"
> #include "hvf/hvf-i386.h"
> #include "kvm/kvm_i386.h"
> #include "kvm/tdx.h"
> @@ -7958,6 +7959,13 @@ uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w)
> r = hvf_get_supported_cpuid(wi->cpuid.eax,
> wi->cpuid.ecx,
> wi->cpuid.reg);
> + } else if (mshv_enabled()) {
> + if (wi->type != CPUID_FEATURE_WORD) {
> + return 0;
> + }
> + r = mshv_get_supported_cpuid(wi->cpuid.eax,
> + wi->cpuid.ecx,
> + wi->cpuid.reg);
> } else if (tcg_enabled()) {
> r = wi->tcg_features;
> } else {
> diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
> index 38e0a045c2..bbb58461a4 100644
> --- a/target/i386/mshv/mshv-cpu.c
> +++ b/target/i386/mshv/mshv-cpu.c
> @@ -1757,6 +1757,33 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)
> g_clear_pointer(&env->emu_mmio_buf, g_free);
> }
>
> +uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg)
> +{
> + uint32_t eax, ebx, ecx, edx;
> + uint32_t ret = 0;
> +
> + host_cpuid(func, idx, &eax, &ebx, &ecx, &edx);
> + switch (reg) {
> + case R_EAX:
> + ret = eax; break;
> + case R_EBX:
> + ret = ebx; break;
> + case R_ECX:
> + ret = ecx; break;
> + case R_EDX:
> + ret = edx; break;
> + }
> +
> + /* Disable nested virtualization features not yet supported by MSHV */
> + if (func == 0x80000001 && reg == R_ECX) {
> + ret &= ~CPUID_EXT3_SVM;
> + }
> + if (func == 0x01 && reg == R_ECX) {
> + ret &= ~CPUID_EXT_VMX;
> + }
> + return ret;
> +}
> +
> /*
> * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a
> * fault to the guest if it tries to access it. It is possible to override
> --
> 2.34.1
>
>
On 2/12/26 00:35, Mohamed Mediouni wrote: > > >> On 11. Feb 2026, at 16:54, Magnus Kulke >> <magnuskulke@linux.microsoft.com> wrote: >> >> We implement mshv_get_supported_cpuid() and invoke it in >> x86_cpu_get_supported_feature_word() retrieve the cpu features >> that the host is supporting. Initially we mask the virtualization >> capabilitities potentially we might need to mask more in the >> future. >> >> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com> > > Hi, > > Interesting. For WHPX on Arm, what’s done is creating a stub > partition and extract CPUID info from it (with necessary guest stub > code if necessary) but doing it this way like HVF x86 does is > intriguing too… > > Is this future-proof or are there catches with this approach? No, it's absolutely not future proof. The difference is two-fold: first, HVF on x86 essentially implements the hypervisor itself. It operates at the VMCS level and is a mix of KVM and "regular" QEMU code. Second, for feature leaves HVF lists explicitly all the supported bits and it also limits EAX to 0xD (it does not try too hard with AMD leaves at 0x800000nn because HVF x86 is Intel-only anyway). So, what this patch implements is not like HVF x86. The stub partition idea is nice and more future proof. Paolo
On Thu, Feb 12, 2026 at 12:35:57AM +0100, Mohamed Mediouni wrote: > > Interesting. For WHPX on Arm, what’s done is creating a stub partition and extract CPUID info from > it (with necessary guest stub code if necessary) but doing it this way like HVF x86 does is intriguing too… > > Is this future-proof or are there catches with this approach? > I think this is a valid approach that we also considered. I assume for MSHV eventually we want to have a MSHV_GET_SUPPORTED_CPUID ioctl, similar to what exists in KVM, so we can make centralize some decisions instead of leaving it up to the VMM. This approach might end up using a dummy partition inside the kernel, but would be an implementation detail.
© 2016 - 2026 Red Hat, Inc.