]> 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)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 14 Jul 2025 08:29:17 +0000 (10:29 +0200)
commit3e86124e7cb9b66e07fb992667865a308f16fcf2
tree6f8d7599c15ca75daec4ee71fea21962301822b5
parenta62fef58299562aae6667b8d8552247423e886b3
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>
target/i386/cpu.c