From: "Doru Blânzeanu" <dblanzeanu@linux.microsoft.com>
To: qemu-devel@nongnu.org
Cc: "Doru Blânzeanu" <dblanzeanu@microsoft.com>,
"Wei Liu" <liuwe@microsoft.com>,
"Magnus Kulke" <magnuskulke@linux.microsoft.com>,
"Magnus Kulke" <magnuskulke@microsoft.com>,
"Doru Blânzeanu" <dblanzeanu@linux.microsoft.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Wei Liu" <wei.liu@kernel.org>, "Zhao Liu" <zhao1.liu@intel.com>
Subject: [PATCH v4 1/2] mshv/mshv-cpu.c: Collect all Intel topology subleaves and AMD cache subleaves
Date: Thu, 3 Dec 2026 17:52:10 +0200 [thread overview]
Message-ID: <20261203155211.42970-2-dblanzeanu@linux.microsoft.com> (raw)
In-Reply-To: <20261203155211.42970-1-dblanzeanu@linux.microsoft.com>
Refactor collect_cpuid_entries() to use a switch statement to select
the enumeration logic for each CPUID leaf, preserving the existing
behavior for previously handled leaves.
This fix makes AMD cache overrides subleaf-specific, makes 0x8000_001E
apply regardless of ECX (not subleaf specific) and collects Intel
topology subleaves (0x0b, 0x1f).
Collect all subleaves for Intel topology leaves 0x0b and 0x1f and AMD
cache leaf 0x8000001d, including the terminating entries.
Mark TOPOEXT as supported matching KVM behavior.
Signed-off-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com>
---
target/i386/mshv/mshv-cpu.c | 124 +++++++++++++++++++++---------------
1 file changed, 73 insertions(+), 51 deletions(-)
diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
index c145bbc447..12d52e4ee1 100644
--- a/target/i386/mshv/mshv-cpu.c
+++ b/target/i386/mshv/mshv-cpu.c
@@ -1083,8 +1083,6 @@ static void collect_cpuid_entries(const CPUState *cpu, GList **cpuid_entries)
uint32_t leaf, subleaf;
uint32_t max_basic_leaf, max_extended_leaf, max_subleaf_7;
uint32_t max_subleaf = 0x20;
- uint32_t leaves_with_subleaves[] = {0x04, 0x07, 0x0d, 0x0f, 0x10};
- int n_subleaf_leaves = ARRAY_SIZE(leaves_with_subleaves);
/* Get maximum basic and and extended CPUID leaves */
cpu_x86_cpuid(env, 0, 0, &max_basic_leaf, &ebx, &ecx, &edx);
@@ -1092,66 +1090,94 @@ static void collect_cpuid_entries(const CPUState *cpu, GList **cpuid_entries)
/* Collect basic leaves (0x0 to max_basic_leaf) */
for (leaf = 0; leaf <= max_basic_leaf; leaf++) {
- bool has_subleaves = false;
- for (int i = 0; i < n_subleaf_leaves; i++) {
- if (leaf == leaves_with_subleaves[i]) {
- has_subleaves = true;
- break;
+ switch (leaf) {
+ case 0x07:
+ /*
+ * Valid subleaves are reported in 7.0:EAX. We need to register all
+ * subleaves to the maximum subleaf, even if they are 0. Otherwise
+ * the host will supply its own values for a unregistered subleaf,
+ * which can result in an inconsistent feature set.
+ */
+ cpu_x86_cpuid(env, leaf, 0, &max_subleaf_7, &ebx, &ecx, &edx);
+ for (subleaf = 0; subleaf <= max_subleaf_7; subleaf++) {
+ cpu_x86_cpuid(env, leaf, subleaf, &eax, &ebx, &ecx, &edx);
+ add_cpuid_entry(cpuid_entries, leaf, subleaf,
+ eax, ebx, ecx, edx);
}
- }
-
- if (!has_subleaves) {
- cpu_x86_cpuid(env, leaf, 0, &eax, &ebx, &ecx, &edx);
- add_cpuid_entry(cpuid_entries, leaf, 0, eax, ebx, ecx, edx);
- continue;
- }
+ break;
- /*
- * Valid XSAVE components can exist at a higher index se we need to set
- * all subleaves for leaf 0x0d, even if we encounter an empty one.
- */
- if (leaf == 0x0d) {
+ case 0x0d:
+ /*
+ * Valid XSAVE components can exist at a higher index so we need to
+ * set all subleaves for leaf 0x0d, even if we encounter an empty
+ * one.
+ */
for (subleaf = 0; subleaf <= 63; subleaf++) {
cpu_x86_cpuid(env, leaf, subleaf, &eax, &ebx, &ecx, &edx);
add_cpuid_entry(cpuid_entries, leaf, subleaf,
eax, ebx, ecx, edx);
}
- continue;
- }
+ break;
- /*
- * Valid subleaves for are reported in 7.0:EAX. We need to register all
- * subleaves to the maximum subleaf, even if they are 0. Otherwise the
- * host will supply its own values for a unregistered subleaf, which
- * can result in an inconsistent feature set.
- */
- if (leaf == 0x07) {
- cpu_x86_cpuid(env, leaf, 0, &max_subleaf_7, &ebx, &ecx, &edx);
- for (subleaf = 0; subleaf <= max_subleaf_7; subleaf++) {
- cpu_x86_cpuid(env, leaf, subleaf, &eax, &ebx, &ecx, &edx);
+ case 0x0b:
+ case 0x1f:
+ for (subleaf = 0; subleaf < max_subleaf; subleaf++) {
+ cpu_x86_cpuid(env, leaf, subleaf,
+ &eax, &ebx, &ecx, &edx);
add_cpuid_entry(cpuid_entries, leaf, subleaf,
eax, ebx, ecx, edx);
+
+ if ((ecx & 0xff00) == 0) {
+ break;
+ }
}
- continue;
- }
+ break;
- subleaf = 0;
- while (subleaf < max_subleaf) {
- cpu_x86_cpuid(env, leaf, subleaf, &eax, &ebx, &ecx, &edx);
+ case 0x04:
+ case 0x0f:
+ case 0x10:
+ subleaf = 0;
+ while (subleaf < max_subleaf) {
+ cpu_x86_cpuid(env, leaf, subleaf, &eax, &ebx, &ecx, &edx);
- /* register the "terminator" to the guest, before breaking */
- add_cpuid_entry(cpuid_entries, leaf, subleaf, eax, ebx, ecx, edx);
- if (eax == 0 && ebx == 0 && ecx == 0 && edx == 0) {
- break;
+ /* register the "terminator" to the guest, before breaking */
+ add_cpuid_entry(cpuid_entries, leaf, subleaf,
+ eax, ebx, ecx, edx);
+ if (eax == 0 && ebx == 0 && ecx == 0 && edx == 0) {
+ break;
+ }
+ subleaf++;
}
- subleaf++;
+ break;
+
+ default:
+ cpu_x86_cpuid(env, leaf, 0, &eax, &ebx, &ecx, &edx);
+ add_cpuid_entry(cpuid_entries, leaf, 0, eax, ebx, ecx, edx);
+ break;
}
+
}
/* Collect extended leaves (0x80000000 to max_extended_leaf) */
for (leaf = 0x80000000; leaf <= max_extended_leaf; leaf++) {
- cpu_x86_cpuid(env, leaf, 0, &eax, &ebx, &ecx, &edx);
- add_cpuid_entry(cpuid_entries, leaf, 0, eax, ebx, ecx, edx);
+ switch (leaf) {
+ case 0x8000001d:
+ for (subleaf = 0; subleaf < max_subleaf; subleaf++) {
+ cpu_x86_cpuid(env, leaf, subleaf,
+ &eax, &ebx, &ecx, &edx);
+
+ add_cpuid_entry(cpuid_entries, leaf, subleaf,
+ eax, ebx, ecx, edx);
+ if ((eax & 0x1f) == 0) {
+ break;
+ }
+ }
+ break;
+ default:
+ cpu_x86_cpuid(env, leaf, 0, &eax, &ebx, &ecx, &edx);
+ add_cpuid_entry(cpuid_entries, leaf, 0, eax, ebx, ecx, edx);
+ break;
+ }
}
}
@@ -1229,12 +1255,10 @@ static int register_intercept_result_cpuid(const CPUState *cpu,
* 0xb - Extended Topology Enumeration Leaf
* 0x1f - V2 Extended Topology Enumeration Leaf
* AMD
- * 0x8000_001e - Processor Topology Information
* 0x8000_0026 - Extended CPU Topology
*/
if (entry->function == 0xb ||
entry->function == 0x1f ||
- entry->function == 0x8000001e ||
entry->function == 0x80000026) {
subleaf_specific = 1;
always_override = 1;
@@ -1245,12 +1269,14 @@ static int register_intercept_result_cpuid(const CPUState *cpu,
* 0x0D: Processor Extended State Enumeration
* 0x0F: Platform QoS Monitoring
* 0x10: Platform QoS Enforcement
+ * 0x8000_001D: AMD Cache Topology
*/
} else if (entry->function == 0x04 ||
entry->function == 0x07 ||
entry->function == 0x0d ||
entry->function == 0x0f ||
- entry->function == 0x10) {
+ entry->function == 0x10 ||
+ entry->function == 0x8000001d) {
subleaf_specific = 1;
always_override = 1;
/* Basic feature leaves (no subleaves) */
@@ -2351,11 +2377,6 @@ void mshv_arch_init_vcpu(CPUState *cpu)
header = (X86XSaveHeader *)(env->xsave_buf + sizeof(X86LegacyXSaveArea));
header->xcomp_bv = header->xstate_bv | (1ULL << 63);
- /*
- * TODO: populate topology info:
- * X86CPUTopoInfo *topo_info = &env->topo_info;
- */
-
ret = init_cpuid2(cpu);
assert(ret == 0);
@@ -2406,6 +2427,7 @@ uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg)
/* Disable nested virtualization features not yet supported by MSHV */
if (func == 0x80000001 && reg == R_ECX) {
ret &= ~CPUID_EXT3_SVM;
+ ret |= CPUID_EXT3_TOPOEXT;
}
if (func == 0x01 && reg == R_ECX) {
ret &= ~CPUID_EXT_VMX;
--
2.48.1.vfs.0.0
next prev parent reply other threads:[~2026-12-03 15:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:52 [PATCH v4 0/2] Add CPU topology extension support for mshv guests Doru Blânzeanu
2026-12-03 15:52 ` Doru Blânzeanu [this message]
2026-12-03 15:52 ` [PATCH v4 2/2] target/i386/mshv: Initialize the extended CPUID limit for host/max CPUs Doru Blânzeanu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203155211.42970-2-dblanzeanu@linux.microsoft.com \
--to=dblanzeanu@linux.microsoft.com \
--cc=dblanzeanu@microsoft.com \
--cc=liuwe@microsoft.com \
--cc=magnuskulke@linux.microsoft.com \
--cc=magnuskulke@microsoft.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wei.liu@kernel.org \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.