> > > > + if (cpu->vendor_cpuid_only && IS_AMD_CPU(env)) { > > > > + *ebx |= threads_per_pkg << 16; > > > > + } else { > > > > + *ebx |= 1 << apicid_pkg_offset(&topo_info) << 16; > > > > + } > > > > > > you need to handle the overflow case when the number of logical > > > processors > 255. > > > > > It seems other cpuid cases of bit shifting don't condiser the overflow > > case too.. > > > > Since intel only reserves 8bits for this field, do you have any > > suggestions to make sure this field emulated > > > > correctly? > > the usual option can be masking the value to only 8 bits before shifting, > like > > ((1 << apicid_pkg_offset(&topo_info)) & 0xff) << 16 > > but when the value is greater than 255, it will be truncated, so we need > something like below to reflect the hardware behavior: > > MIN((1 << apicid_pkg_offset(&topo_info)), 255) << 16 > > This is what Qian's patch [1] wanted to fix last year, but that patch never > gets merged. > > [1] > https://lore.kernel.org/qemu-devel/20230829042405.932523-2-qian....@intel.com/ >
That's on my list. I had the plan to help Qian pick up it again and rebase that series on Chuang's change. -Zhao