Blame SOURCES/kvm-target-i386-add-a-ucode-rev-property.patch

4636b8
From ce999ee40575a2d6ebd862697af96169c8bfcb5f Mon Sep 17 00:00:00 2001
4636b8
From: Paolo Bonzini <pbonzini@redhat.com>
4636b8
Date: Mon, 17 Feb 2020 16:23:19 -0500
4636b8
Subject: [PATCH 04/12] target/i386: add a ucode-rev property
4636b8
4636b8
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
4636b8
Message-id: <20200217162323.2572-3-pbonzini@redhat.com>
4636b8
Patchwork-id: 93901
4636b8
O-Subject: [RHEL7.9 qemu-kvm-rhev PATCH 2/6] target/i386: add a ucode-rev property
4636b8
Bugzilla: 1791653
4636b8
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
4636b8
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
4636b8
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
4636b8
4636b8
Add the property and plumb it in TCG and HVF (the latter of which
4636b8
tried to support returning a constant value but used the wrong MSR).
4636b8
4636b8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4636b8
Message-Id: <1579544504-3616-3-git-send-email-pbonzini@redhat.com>
4636b8
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
4636b8
(cherry picked from commit 4e45aff398cd1542c2a384a2a3b8600f23337d86)
4636b8
4636b8
[RHEL7: replace env_archcpu with x86_env_get_cpu]
4636b8
4636b8
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
4636b8
---
4636b8
 target/i386/cpu.c         | 10 ++++++++++
4636b8
 target/i386/cpu.h         |  4 ++++
4636b8
 target/i386/hvf/x86_emu.c |  4 +---
4636b8
 target/i386/misc_helper.c |  4 ++++
4636b8
 4 files changed, 19 insertions(+), 3 deletions(-)
4636b8
4636b8
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
4636b8
index 4d87879328..ad905d6f8c 100644
4636b8
--- a/target/i386/cpu.c
4636b8
+++ b/target/i386/cpu.c
4636b8
@@ -4943,6 +4943,15 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
4636b8
         goto out;
4636b8
     }
4636b8
 
4636b8
+    if (cpu->ucode_rev == 0) {
4636b8
+        /* The default is the same as KVM's.  */
4636b8
+        if (IS_AMD_CPU(env)) {
4636b8
+            cpu->ucode_rev = 0x01000065;
4636b8
+        } else {
4636b8
+            cpu->ucode_rev = 0x100000000ULL;
4636b8
+        }
4636b8
+    }
4636b8
+
4636b8
     if (cpu->apic_id == UNASSIGNED_APIC_ID) {
4636b8
         error_setg(errp, "apic-id property was not initialized properly");
4636b8
         return;
4636b8
@@ -5553,6 +5562,7 @@ static Property x86_cpu_properties[] = {
4636b8
     DEFINE_PROP_UINT32("min-level", X86CPU, env.cpuid_min_level, 0),
4636b8
     DEFINE_PROP_UINT32("min-xlevel", X86CPU, env.cpuid_min_xlevel, 0),
4636b8
     DEFINE_PROP_UINT32("min-xlevel2", X86CPU, env.cpuid_min_xlevel2, 0),
4636b8
+    DEFINE_PROP_UINT64("ucode-rev", X86CPU, ucode_rev, 0),
4636b8
     DEFINE_PROP_BOOL("full-cpuid-auto-level", X86CPU, full_cpuid_auto_level, true),
4636b8
     DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor_id),
4636b8
     DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true),
4636b8
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
4636b8
index 65c4fda102..4f3fc8ed59 100644
4636b8
--- a/target/i386/cpu.h
4636b8
+++ b/target/i386/cpu.h
4636b8
@@ -353,6 +353,8 @@ typedef enum X86Seg {
4636b8
 #define MSR_IA32_SPEC_CTRL              0x48
4636b8
 #define MSR_VIRT_SSBD                   0xc001011f
4636b8
 #define MSR_IA32_PRED_CMD               0x49
4636b8
+#define MSR_IA32_UCODE_REV              0x8b
4636b8
+
4636b8
 #define MSR_IA32_ARCH_CAPABILITIES      0x10a
4636b8
 #define ARCH_CAP_TSX_CTRL_MSR		(1<<7)
4636b8
 
4636b8
@@ -1370,6 +1372,8 @@ struct X86CPU {
4636b8
 
4636b8
     CPUX86State env;
4636b8
 
4636b8
+    uint64_t ucode_rev;
4636b8
+
4636b8
     bool hyperv_vapic;
4636b8
     bool hyperv_relaxed_timing;
4636b8
     int hyperv_spinlock_attempts;
4636b8
diff --git a/target/i386/hvf/x86_emu.c b/target/i386/hvf/x86_emu.c
4636b8
index 3ea18edc68..e0986a9b5a 100644
4636b8
--- a/target/i386/hvf/x86_emu.c
4636b8
+++ b/target/i386/hvf/x86_emu.c
4636b8
@@ -658,8 +658,6 @@ static void exec_lods(struct CPUX86State *env, struct x86_decode *decode)
4636b8
     RIP(env) += decode->len;
4636b8
 }
4636b8
 
4636b8
-#define MSR_IA32_UCODE_REV 0x00000017
4636b8
-
4636b8
 void simulate_rdmsr(struct CPUState *cpu)
4636b8
 {
4636b8
     X86CPU *x86_cpu = X86_CPU(cpu);
4636b8
@@ -675,7 +673,7 @@ void simulate_rdmsr(struct CPUState *cpu)
4636b8
         val = cpu_get_apic_base(X86_CPU(cpu)->apic_state);
4636b8
         break;
4636b8
     case MSR_IA32_UCODE_REV:
4636b8
-        val = (0x100000000ULL << 32) | 0x100000000ULL;
4636b8
+        val = x86_cpu->ucode_rev;
4636b8
         break;
4636b8
     case MSR_EFER:
4636b8
         val = rvmcs(cpu->hvf_fd, VMCS_GUEST_IA32_EFER);
4636b8
diff --git a/target/i386/misc_helper.c b/target/i386/misc_helper.c
4636b8
index 628f64aad5..f93e61f05d 100644
4636b8
--- a/target/i386/misc_helper.c
4636b8
+++ b/target/i386/misc_helper.c
4636b8
@@ -229,6 +229,7 @@ void helper_rdmsr(CPUX86State *env)
4636b8
 #else
4636b8
 void helper_wrmsr(CPUX86State *env)
4636b8
 {
4636b8
+    X86CPU *x86_cpu = x86_env_get_cpu(env);
4636b8
     uint64_t val;
4636b8
 
4636b8
     cpu_svm_check_intercept_param(env, SVM_EXIT_MSR, 1, GETPC());
4636b8
@@ -371,6 +372,9 @@ void helper_wrmsr(CPUX86State *env)
4636b8
         env->msr_bndcfgs = val;
4636b8
         cpu_sync_bndcs_hflags(env);
4636b8
         break;
4636b8
+     case MSR_IA32_UCODE_REV:
4636b8
+        val = x86_cpu->ucode_rev;
4636b8
+        break;
4636b8
     default:
4636b8
         if ((uint32_t)env->regs[R_ECX] >= MSR_MC0_CTL
4636b8
             && (uint32_t)env->regs[R_ECX] < MSR_MC0_CTL +
4636b8
-- 
4636b8
2.18.2
4636b8