From: Zhao Liu Date: Thu, 11 Dec 2025 06:07:45 +0000 (+0800) Subject: i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d88caf0954dfc7598a7db27c2cc98937c7ad6ead;p=thirdparty%2Fqemu.git i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves The x86_ext_save_areas[] is expected to be well initialized by accelerators and its xstate detail information cannot be changed by user. So use x86_ext_save_areas[] to encode CPUID.0XD subleaves directly without other hardcoding & masking. And for arch LBR, KVM fills its xstate in x86_ext_save_areas[] via host_cpuid(). The info obtained this way matches what would be retrieved from x86_cpu_get_supported_cpuid() (since KVM just fills CPUID with the host xstate info directly anyway). So just use the initialized x86_ext_save_areas[] instead of calling x86_cpu_get_supported_cpuid(). Tested-by: Farrah Chen Signed-off-by: Zhao Liu Link: https://lore.kernel.org/r/20251211060801.3600039-7-zhao1.liu@intel.com Signed-off-by: Paolo Bonzini --- diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 812a215147..f4c0ae533d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -8188,20 +8188,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } } else if (count == 0xf && cpu->enable_pmu && (env->features[FEAT_7_0_EDX] & CPUID_7_0_EDX_ARCH_LBR)) { - x86_cpu_get_supported_cpuid(0xD, count, eax, ebx, ecx, edx); + const ExtSaveArea *esa = &x86_ext_save_areas[count]; + + *eax = esa->size; + *ebx = esa->offset; + *ecx = esa->ecx; } else if (count < ARRAY_SIZE(x86_ext_save_areas)) { const ExtSaveArea *esa = &x86_ext_save_areas[count]; - if (x86_cpu_xsave_xcr0_components(cpu) & (1ULL << count)) { - *eax = esa->size; - *ebx = esa->offset; - *ecx = esa->ecx & - (ESA_FEATURE_ALIGN64_MASK | ESA_FEATURE_XFD_MASK); - } else if (x86_cpu_xsave_xss_components(cpu) & (1ULL << count)) { - *eax = esa->size; - *ebx = 0; - *ecx = 1; - } + *eax = esa->size; + *ebx = esa->offset; + *ecx = esa->ecx; } break; }