[PATCH v2 9/9] target/i386: Use AMD ucode-rev default for Hygon
Tina Zhang <[email protected]>
| Newsgroups | org.nongnu.qemu-devel,org.kernel.vger.kvm |
|---|---|
| Message-ID | <[email protected]> |
QEMU currently gives named Hygon Dhyana CPUs the non-AMD default ucode-rev value, 0x100000000. That is the Intel/KVM-VMX-shaped encoding, where the visible revision is in the high 32 bits. Linux reads MSR 0x8b for Hygon CPUs through the AMD patch-level path, using MSR_AMD64_PATCH_LEVEL and storing the low 32 bits as cpuinfo_x86.microcode. With the old QEMU default, a Dhyana guest sees microcode revision 0. Use the AMD/KVM-SVM-shaped default, 0x01000065, for Hygon on this specific MSR 0x8b default path. This does not route Hygon through AMD microcode loading and does not claim that Hygon CPUs are otherwise identical to AMD CPUs. Preserve migration ABI through the vendor CPU ABI compatibility gate used by this Hygon bug-fix group. pc-11.0 and older machine types leave that gate off, so they retain the previous ucode-rev default. Explicit user-provided ucode-rev values still override the default. Add qtest coverage for the new default, the compatibility cases, and an explicit user override. Signed-off-by: Tina Zhang <[email protected]> --- target/i386/cpu.c | 8 ++++++-- tests/qtest/test-x86-cpuid-compat.c | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4d8364f1ef..eb4295e562 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -10219,10 +10219,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) if (cpu->ucode_rev == 0) { /* * The default is the same as KVM's. Note that this check - * needs to happen after the evenual setting of ucode_rev in + * needs to happen after the eventual setting of ucode_rev in * accel-specific code in cpu_exec_realizefn. + * + * Hygon uses the AMD patch-level MSR 0x8b encoding, where the visible + * microcode revision is in the low 32 bits. */ - if (IS_AMD_CPU(env)) { + if (IS_AMD_CPU(env) || + (IS_HYGON_CPU(env) && cpu->hygon_vendor_abi_fixes)) { cpu->ucode_rev = 0x01000065; } else { cpu->ucode_rev = 0x100000000ULL; diff --git a/tests/qtest/test-x86-cpuid-compat.c b/tests/qtest/test-x86-cpuid-compat.c index b7f8834052..06cbf35d76 100644 --- a/tests/qtest/test-x86-cpuid-compat.c +++ b/tests/qtest/test-x86-cpuid-compat.c @@ -404,6 +404,25 @@ static const CpuidTestArgs cpuid_tests[] = { "486", "xlevel2=0xC0000002,xstore=on", NULL, "xlevel2", 0xC0000002, }, + { + "x86/cpuid/props/dhyana/ucode-rev/default", + "Dhyana", NULL, NULL, "ucode-rev", 0x01000065, + }, + { + "x86/cpuid/props/dhyana/ucode-rev/compat-off", + "Dhyana", "x-hygon-vendor-abi-fixes=off", NULL, + "ucode-rev", 0x100000000LL, + }, + { + "x86/cpuid/props/dhyana/ucode-rev/pc-i440fx-11.0", + "Dhyana", NULL, "pc-i440fx-11.0", + "ucode-rev", 0x100000000LL, + }, + { + "x86/cpuid/props/dhyana/ucode-rev/user", + "Dhyana", "ucode-rev=0x12345678", NULL, + "ucode-rev", 0x12345678, + }, }; /* -- 2.43.7