Skip to contentSkip to conversation

i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1]

PATCH In review Zhao Liu 3 participants 3 messages Aug 4, 2025 – Aug 5, 2025

lore
Share & tools
lore

Zhao Liu

author
#0 lore raw

PATCH 1/1 i386/cpu: Move addressable ID encoding out of compat property in CPUID[0x1]

Currently, the addressable ID encoding for CPUID[0x1].EBX[bits 16-23] (Maximum number of addressable IDs for logical processors in this physical package) is covered by vendor_cpuid_only_v2 compat property. The previous consideration was to avoid breaking migration and this compat property makes it unfriendly to backport the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX [23:16]").

However, NetBSD booting is broken since the commit 88dd4ca06c83 ("i386/cpu: Use APIC ID info to encode cache topo in CPUID[4]"), because NetBSD calculates smt information via lp_max / core_max for legacy Intel CPUs which doesn't support 0xb leaf, where lp_max is from CPUID[0x1].EBX.bits[16-23] and core_max is from CPUID[0x4].0x0.bits[26 -31].

The commit 88dd4ca0 changed the encoding rule of core_max but didn't update lp_max, so that NetBSD would get the wrong smt information, which leads to the module loading failure.

Luckily, the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]") updated the encoding rule for lp_max and accidentally fixed the NetBSD issue too. This also shows that using CPUID[0x1] and CPUID[0x4].0x0 to calculate HT/SMT information is a common practice to detect CPU topology on legacy Intel CPUs.

Therefore, it's necessary to backport the commit f985a1195ba2 to previous stable QEMU to help address the similar issues as well. Then the compat property is not needed any more since all stable QEMUs will follow the same encoding way.

So, in CPUID[0x1], move addressable ID encoding out of compat property.

Fixes commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3061

---
 target/i386/cpu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/i386/cpu.c +1 -2
index 251d5760a0bd..673f8583c809 100644
@@ -7885,8 +7885,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
              * count, but Intel needs maximum number of addressable IDs for
              * logical processors per package.
              */
-            if (cpu->vendor_cpuid_only_v2 &&
-                (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
+            if ((IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
                 num = 1 << apicid_pkg_offset(topo_info);
             } else {
                 num = threads_per_pkg;
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v1 1/1
#1 lore raw
Quoted 46 lines · Zhao Liu

Currently, the addressable ID encoding for CPUID[0x1].EBX[bits 16-23] (Maximum number of addressable IDs for logical processors in this physical package) is covered by vendor_cpuid_only_v2 compat property. The previous consideration was to avoid breaking migration and this compat property makes it unfriendly to backport the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX [23:16]").

However, NetBSD booting is broken since the commit 88dd4ca06c83 ("i386/cpu: Use APIC ID info to encode cache topo in CPUID[4]"), because NetBSD calculates smt information via lp_max / core_max for legacy Intel CPUs which doesn't support 0xb leaf, where lp_max is from CPUID[0x1].EBX.bits[16-23] and core_max is from CPUID[0x4].0x0.bits[26 -31].

The commit 88dd4ca0 changed the encoding rule of core_max but didn't update lp_max, so that NetBSD would get the wrong smt information, which leads to the module loading failure.

Luckily, the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]") updated the encoding rule for lp_max and accidentally fixed the NetBSD issue too. This also shows that using CPUID[0x1] and CPUID[0x4].0x0 to calculate HT/SMT information is a common practice to detect CPU topology on legacy Intel CPUs.

Therefore, it's necessary to backport the commit f985a1195ba2 to previous stable QEMU to help address the similar issues as well. Then the compat property is not needed any more since all stable QEMUs will follow the same encoding way.

So, in CPUID[0x1], move addressable ID encoding out of compat property.

Fixes commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3061

---
  target/i386/cpu.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
target/i386/cpu.c +0 -0
index 251d5760a0bd..673f8583c809 100644

target/i386/cpu.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, · line 7891

Quoted 9 lines
target/i386/cpu.c +1 -2
@@ -7885,8 +7885,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
               * count, but Intel needs maximum number of addressable IDs for
               * logical processors per package.
               */
-            if (cpu->vendor_cpuid_only_v2 &&
-                (IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
+            if ((IS_INTEL_CPU(env) || IS_ZHAOXIN_CPU(env))) {
                  num = 1 << apicid_pkg_offset(topo_info);
              } else {
                  num = threads_per_pkg;

Thank you!

/mjt

#2 lore raw
In reply to Zhao Liu
Quoted 32 lines · Zhao Liu

Currently, the addressable ID encoding for CPUID[0x1].EBX[bits 16-23] (Maximum number of addressable IDs for logical processors in this physical package) is covered by vendor_cpuid_only_v2 compat property. The previous consideration was to avoid breaking migration and this compat property makes it unfriendly to backport the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX [23:16]").

However, NetBSD booting is broken since the commit 88dd4ca06c83 ("i386/cpu: Use APIC ID info to encode cache topo in CPUID[4]"), because NetBSD calculates smt information via lp_max / core_max for legacy Intel CPUs which doesn't support 0xb leaf, where lp_max is from CPUID[0x1].EBX.bits[16-23] and core_max is from CPUID[0x4].0x0.bits[26 -31].

The commit 88dd4ca0 changed the encoding rule of core_max but didn't update lp_max, so that NetBSD would get the wrong smt information, which leads to the module loading failure.

Luckily, the commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]") updated the encoding rule for lp_max and accidentally fixed the NetBSD issue too. This also shows that using CPUID[0x1] and CPUID[0x4].0x0 to calculate HT/SMT information is a common practice to detect CPU topology on legacy Intel CPUs.

Therefore, it's necessary to backport the commit f985a1195ba2 to previous stable QEMU to help address the similar issues as well. Then the compat property is not needed any more since all stable QEMUs will follow the same encoding way.

So, in CPUID[0x1], move addressable ID encoding out of compat property.

Quoted 8 lines
Fixes commit f985a1195ba2 ("i386/cpu: Fix number of addressable IDs field for CPUID.01H.EBX[23:16]")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3061

---
  target/i386/cpu.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

Patch queued, thanks!