From 3a740f27c76ccd7fa2c0ece979a480bece592674 Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <pbonzini@redhat.com>
Date: Mon, 17 Feb 2020 16:23:20 -0500
Subject: [PATCH 05/12] target/i386: kvm: initialize microcode revision from
KVM
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
Message-id: <20200217162323.2572-4-pbonzini@redhat.com>
Patchwork-id: 93900
O-Subject: [RHEL7.9 qemu-kvm-rhev PATCH 3/6] target/i386: kvm: initialize microcode revision from KVM
Bugzilla: 1791653
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
KVM can return the host microcode revision as a feature MSR.
Use it as the default value for -cpu host.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <1579544504-3616-4-git-send-email-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 32c87d70ff55b96741f08c35108935cac6f40fe4)
[RHEL7: change kvm_arch_get_supported_msr_feature to return 64-bit
value, originally done for VMX features; split "if" statement in
two parts, originally done for upstream commit 2266d44311
("i386/cpu: make -cpu host support monitor/mwait", 2018-06-29)]
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
---
include/sysemu/kvm.h | 2 +-
target/i386/cpu.c | 17 ++++++++++++-----
target/i386/kvm.c | 7 ++++++-
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 3d8f294633..cd9a0206ce 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -464,7 +464,7 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);
uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
uint32_t index, int reg);
-uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
+uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index);
void kvm_set_sigmask_len(KVMState *s, unsigned int sigmask_len);
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index ad905d6f8c..3579bd53c5 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -4936,11 +4936,18 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
Error *local_err = NULL;
static bool ht_warned;
- if (xcc->host_cpuid_required && !accel_uses_host_cpuid()) {
- char *name = x86_cpu_class_get_model_name(xcc);
- error_setg(&local_err, "CPU model '%s' requires KVM", name);
- g_free(name);
- goto out;
+ if (xcc->host_cpuid_required) {
+ if (!accel_uses_host_cpuid()) {
+ char *name = x86_cpu_class_get_model_name(xcc);
+ error_setg(&local_err, "CPU model '%s' requires KVM", name);
+ g_free(name);
+ goto out;
+ }
+
+ if (kvm_enabled() && cpu->ucode_rev == 0) {
+ cpu->ucode_rev = kvm_arch_get_supported_msr_feature(kvm_state,
+ MSR_IA32_UCODE_REV);
+ }
}
if (cpu->ucode_rev == 0) {
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index d8a4dbfde3..4d43fba716 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -419,7 +419,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,
return ret;
}
-uint32_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index)
+uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index)
{
struct {
struct kvm_msrs info;
@@ -1828,6 +1828,11 @@ static void kvm_init_msrs(X86CPU *cpu)
env->features[FEAT_ARCH_CAPABILITIES]);
}
+ if (kvm_arch_get_supported_msr_feature(kvm_state,
+ MSR_IA32_UCODE_REV)) {
+ kvm_msr_entry_add(cpu, MSR_IA32_UCODE_REV, cpu->ucode_rev);
+ }
+
assert(kvm_buf_set_msrs(cpu) == 0);
}
--
2.18.2