target/i386: suppress CPUID leaves not defined by the CPU vendor
PATCH 1/1 target/i386: suppress CPUID leaves not defined by the CPU vendor
Currently all built-in CPUs report cache information via CPUID leaves 2 and 4, but these have never been defined for AMD. In the case of SEV-SNP this can cause issues with CPUID enforcement. Address this by allowing CPU types to suppress these via a new "x-vendor-cpuid-only" CPU property, which is true by default, but switched off for older machine types to maintain compatibility.
--- hw/i386/pc.c | 1 + target/i386/cpu.c | 6 ++++++ target/i386/cpu.h | 3 +++ 3 files changed, 10 insertions(+)
hw/i386/pc.c +1 -0
@@ -98,6 +98,7 @@ GlobalProperty pc_compat_6_0[] = { { "qemu64" "-" TYPE_X86_CPU, "family", "6" }, { "qemu64" "-" TYPE_X86_CPU, "model", "6" }, { "qemu64" "-" TYPE_X86_CPU, "stepping", "3" }, + { TYPE_X86_CPU, "x-vendor-cpuid-only", "off" }, };const size_t pc_compat_6_0_len =G_N_ELEMENTS (pc_compat_6_0);
target/i386/cpu.c +6 -0
@@ -5155,6 +5155,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if (cpu->cache_info_passthrough) {host_cpuid (index,0 , eax, ebx, ecx, edx);break ; + }else if (cpu->vendor_cpuid_only &&IS_AMD_CPU (env)) { + *eax = *ebx = *ecx = *edx =0 ; +break ; } *eax =1 ;/* Number of CPUID[EAX=2] calls required */ *ebx =0 ;
@@ -5176,6 +5179,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,if ((*eax &31 ) && cs->nr_cores >1 ) { *eax |= (cs->nr_cores -1 ) <<26 ; } + }else if (cpu->vendor_cpuid_only &&IS_AMD_CPU (env)) { + *eax = *ebx = *ecx = *edx =0 ; }else { *eax =0 ;switch (count) {
@@ -6647,6 +6652,7 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("full-cpuid-auto-level" ,X86CPU , full_cpuid_auto_level, true),DEFINE_PROP_STRING ("hv-vendor-id" ,X86CPU , hyperv_vendor),DEFINE_PROP_BOOL ("cpuid-0xb" ,X86CPU , enable_cpuid_0xb, true), +DEFINE_PROP_BOOL ("x-vendor-cpuid-only" ,X86CPU , vendor_cpuid_only, true),DEFINE_PROP_BOOL ("lmce" ,X86CPU , enable_lmce, false),DEFINE_PROP_BOOL ("l3-cache" ,X86CPU , enable_l3_cache, true), DEFINE_PROP_BOOL("kvm-no-smi-migration", X86CPU, kvm_no_smi_migration,
target/i386/cpu.h +3 -0
@@ -1746,6 +1746,9 @@ struct X86CPU {/* Enable auto level-increase for all CPUID leaves */ bool full_cpuid_auto_level; +/* Only advertise CPUID leaves defined by the vendor */ +bool vendor_cpuid_only; +/* Enable auto level-increase for Intel Processor Trace leave */ bool intel_pt_auto_level;
Signature · 1 line
2.25.1
PATCH 1/1 target/i386: Fix cpuid level for AMD
From: zhenwei pi <[email protected]>
A AMD server typically has cpuid level 0x10(test on Rome/Milan), it should not be changed to 0x1f in multi-dies case.
* to maintain compatibility with older machine types, only implement this change when the CPU's "x-vendor-cpuid-only" property is false
--- target/i386/cpu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
target/i386/cpu.c +9 -2
@@ -5950,8 +5950,15 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp) } } -/* CPU topology with multi-dies support requires CPUID[0x1F] */ -if (env->nr_dies >1 ) { +/* +* Intel CPU topology with multi-dies support requires CPUID[0x1F]. +* For AMD Rome/Milan, cpuid level is 0x10, and guest OS should detect +* extended toplogy by leaf 0xB. Only adjust it for Intel CPU, unless +* cpu->vendor_cpuid_only has been unset for compatibility with older +* machine types. +*/ +if ((env->nr_dies >1 ) && + (IS_INTEL_CPU (env) || !cpu->vendor_cpuid_only)) {x86_cpu_adjust_level (cpu, &env->cpuid_min_level,0x1F ); }
Signature · 1 line
2.25.1
Eduardo Habkost
AppliedRe: [PATCH] target/i386: Fix cpuid level for AMD
Quoted 12 lines · Michael Roth
From: zhenwei pi <[email protected]>
A AMD server typically has cpuid level 0x10(test on Rome/Milan), it should not be changed to
0x1fin multi-dies case.Cc "Dr. David Alan Gilbert" <[email protected]>Cc Eduardo Habkost <[email protected]>Cc Richard Henderson <[email protected]>Cc Igor Mammedov <[email protected]>Cc zhenwei pi <[email protected]>Fixes a94e1428991 (target/i386: Add CPUID.1F generation support for multi-dies PCMachine)Signed-off-by zhenwei pi <[email protected]>
Quoted 3 lines
* to maintain compatibility with older machine types, only implement this change when the CPU's "x-vendor-cpuid-only" property is false
Signed-off-by Michael Roth <[email protected]>
Queued, thanks!
Signature · 1 line
Eduardo
Eduardo Habkost
AppliedQuoted 7 lines · Michael Roth
Currently all built-in CPUs report cache information via CPUID leaves 2 and 4, but these have never been defined for AMD. In the case of SEV-SNP this can cause issues with CPUID enforcement. Address this by allowing CPU types to suppress these via a new "x-vendor-cpuid-only" CPU property, which is true by default, but switched off for older machine types to maintain compatibility.
Quoted 7 lines
Cc "Dr. David Alan Gilbert" <[email protected]>Cc Eduardo Habkost <[email protected]>Cc Richard Henderson <[email protected]>Cc Igor Mammedov <[email protected]>Cc zhenwei pi <[email protected]>Suggested-by Eduardo Habkost <[email protected]>Signed-off-by Michael Roth <[email protected]>
Queued, thanks!
Signature · 1 line
Eduardo