]> git.ipfire.org Git - thirdparty/qemu.git/commit
i386/cpu: Fix overflow of cache topology fields in CPUID.04H
authorQian Wen <qian.wen@intel.com>
Mon, 14 Jul 2025 08:08:58 +0000 (16:08 +0800)
committerMichael Tokarev <mjt@tls.msk.ru>
Thu, 17 Jul 2025 03:57:23 +0000 (06:57 +0300)
commit18224789994e0276a626a4e4e5554695857bd998
tree61c4147518131ec1f44180017fc01c0b52788048
parentd0975531586742ec2eff8796b7ba93bc4858e63d
i386/cpu: Fix overflow of cache topology fields in CPUID.04H

According to SDM, CPUID.0x4:EAX[31:26] indicates the Maximum number of
addressable IDs for processor cores in the physical package. If we
launch over 64 cores VM, the 6-bit field will overflow, and the wrong
core_id number will be reported.

Since the HW reports 0x3f when the intel processor has over 64 cores,
limit the max value written to EAX[31:26] to 63, so max num_cores should
be 64.

For EAX[14:25], though at present Q35 supports up to 4096 CPUs, by
constructing a specific topology, the width of the APIC ID can be
extended beyond 12 bits. For example, using `-smp threads=33,cores=9,
modules=9` results in a die level offset of 6 + 4 + 4 = 14 bits, which
can also cause overflow.  check and honor the maximum value for
EAX[14:25] as well.

In addition, for host-cache-info case, also apply the same checks and
fixes.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Qian Wen <qian.wen@intel.com>
Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250714080859.1960104-7-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 3e86124e7cb9b66e07fb992667865a308f16fcf2)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
target/i386/cpu.c