|
|
4636b8 |
From d72e41f9a16360eb23e9d943fa7e33291c5fcd87 Mon Sep 17 00:00:00 2001
|
|
|
4636b8 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4636b8 |
Date: Mon, 17 Feb 2020 16:23:18 -0500
|
|
|
4636b8 |
Subject: [PATCH 03/12] target/i386: kvm: initialize feature MSRs very early
|
|
|
4636b8 |
MIME-Version: 1.0
|
|
|
4636b8 |
Content-Type: text/plain; charset=UTF-8
|
|
|
4636b8 |
Content-Transfer-Encoding: 8bit
|
|
|
4636b8 |
|
|
|
4636b8 |
RH-Author: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4636b8 |
Message-id: <20200217162323.2572-2-pbonzini@redhat.com>
|
|
|
4636b8 |
Patchwork-id: 93896
|
|
|
4636b8 |
O-Subject: [RHEL7.9 qemu-kvm-rhev PATCH 1/6] target/i386: kvm: initialize feature MSRs very early
|
|
|
4636b8 |
Bugzilla: 1791653
|
|
|
4636b8 |
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
|
|
|
4636b8 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
4636b8 |
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
4636b8 |
|
|
|
4636b8 |
Some read-only MSRs affect the behavior of ioctls such as
|
|
|
4636b8 |
KVM_SET_NESTED_STATE. We can initialize them once and for all
|
|
|
4636b8 |
right after the CPU is realized, since they will never be modified
|
|
|
4636b8 |
by the guest.
|
|
|
4636b8 |
|
|
|
4636b8 |
Reported-by: Qingua Cheng <qcheng@redhat.com>
|
|
|
4636b8 |
Cc: qemu-stable@nongnu.org
|
|
|
4636b8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4636b8 |
Message-Id: <1579544504-3616-2-git-send-email-pbonzini@redhat.com>
|
|
|
4636b8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
4636b8 |
(cherry picked from commit 420ae1fc51c99abfd03b1c590f55617edd2a2bed)
|
|
|
4636b8 |
|
|
|
4636b8 |
[RHEL7: no MSR_IA32_CORE_CAPABILITY]
|
|
|
4636b8 |
|
|
|
4636b8 |
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
|
|
|
4636b8 |
---
|
|
|
4636b8 |
target/i386/kvm.c | 55 +++++++++++++++++++++++++++---------------
|
|
|
4636b8 |
target/i386/kvm_i386.h | 1 +
|
|
|
4636b8 |
2 files changed, 36 insertions(+), 20 deletions(-)
|
|
|
4636b8 |
|
|
|
4636b8 |
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
|
|
|
4636b8 |
index a6e5a87cf5..d8a4dbfde3 100644
|
|
|
4636b8 |
--- a/target/i386/kvm.c
|
|
|
4636b8 |
+++ b/target/i386/kvm.c
|
|
|
4636b8 |
@@ -65,6 +65,8 @@
|
|
|
4636b8 |
* 255 kvm_msr_entry structs */
|
|
|
4636b8 |
#define MSR_BUF_SIZE 4096
|
|
|
4636b8 |
|
|
|
4636b8 |
+static void kvm_init_msrs(X86CPU *cpu);
|
|
|
4636b8 |
+
|
|
|
4636b8 |
const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
|
|
|
4636b8 |
KVM_CAP_INFO(SET_TSS_ADDR),
|
|
|
4636b8 |
KVM_CAP_INFO(EXT_CPUID),
|
|
|
4636b8 |
@@ -1175,6 +1177,8 @@ int kvm_arch_init_vcpu(CPUState *cs)
|
|
|
4636b8 |
has_msr_tsc_aux = false;
|
|
|
4636b8 |
}
|
|
|
4636b8 |
|
|
|
4636b8 |
+ kvm_init_msrs(cpu);
|
|
|
4636b8 |
+
|
|
|
4636b8 |
return 0;
|
|
|
4636b8 |
|
|
|
4636b8 |
fail:
|
|
|
4636b8 |
@@ -1797,11 +1801,40 @@ static int kvm_put_msr_feature_control(X86CPU *cpu)
|
|
|
4636b8 |
return 0;
|
|
|
4636b8 |
}
|
|
|
4636b8 |
|
|
|
4636b8 |
+static int kvm_buf_set_msrs(X86CPU *cpu)
|
|
|
4636b8 |
+{
|
|
|
4636b8 |
+ int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, cpu->kvm_msr_buf);
|
|
|
4636b8 |
+ if (ret < 0) {
|
|
|
4636b8 |
+ return ret;
|
|
|
4636b8 |
+ }
|
|
|
4636b8 |
+
|
|
|
4636b8 |
+ if (ret < cpu->kvm_msr_buf->nmsrs) {
|
|
|
4636b8 |
+ struct kvm_msr_entry *e = &cpu->kvm_msr_buf->entries[ret];
|
|
|
4636b8 |
+ error_report("error: failed to set MSR 0x%" PRIx32 " to 0x%" PRIx64,
|
|
|
4636b8 |
+ (uint32_t)e->index, (uint64_t)e->data);
|
|
|
4636b8 |
+ }
|
|
|
4636b8 |
+
|
|
|
4636b8 |
+ assert(ret == cpu->kvm_msr_buf->nmsrs);
|
|
|
4636b8 |
+ return 0;
|
|
|
4636b8 |
+}
|
|
|
4636b8 |
+
|
|
|
4636b8 |
+static void kvm_init_msrs(X86CPU *cpu)
|
|
|
4636b8 |
+{
|
|
|
4636b8 |
+ CPUX86State *env = &cpu->env;
|
|
|
4636b8 |
+
|
|
|
4636b8 |
+ kvm_msr_buf_reset(cpu);
|
|
|
4636b8 |
+ if (has_msr_arch_capabs) {
|
|
|
4636b8 |
+ kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
|
|
|
4636b8 |
+ env->features[FEAT_ARCH_CAPABILITIES]);
|
|
|
4636b8 |
+ }
|
|
|
4636b8 |
+
|
|
|
4636b8 |
+ assert(kvm_buf_set_msrs(cpu) == 0);
|
|
|
4636b8 |
+}
|
|
|
4636b8 |
+
|
|
|
4636b8 |
static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
4636b8 |
{
|
|
|
4636b8 |
CPUX86State *env = &cpu->env;
|
|
|
4636b8 |
int i;
|
|
|
4636b8 |
- int ret;
|
|
|
4636b8 |
|
|
|
4636b8 |
kvm_msr_buf_reset(cpu);
|
|
|
4636b8 |
|
|
|
4636b8 |
@@ -1856,12 +1889,6 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
4636b8 |
}
|
|
|
4636b8 |
#endif
|
|
|
4636b8 |
|
|
|
4636b8 |
- /* If host supports feature MSR, write down. */
|
|
|
4636b8 |
- if (has_msr_arch_capabs) {
|
|
|
4636b8 |
- kvm_msr_entry_add(cpu, MSR_IA32_ARCH_CAPABILITIES,
|
|
|
4636b8 |
- env->features[FEAT_ARCH_CAPABILITIES]);
|
|
|
4636b8 |
- }
|
|
|
4636b8 |
-
|
|
|
4636b8 |
/*
|
|
|
4636b8 |
* The following MSRs have side effects on the guest or are too heavy
|
|
|
4636b8 |
* for normal writeback. Limit them to reset or full state updates.
|
|
|
4636b8 |
@@ -2040,19 +2067,7 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
|
|
|
4636b8 |
}
|
|
|
4636b8 |
}
|
|
|
4636b8 |
|
|
|
4636b8 |
- ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MSRS, cpu->kvm_msr_buf);
|
|
|
4636b8 |
- if (ret < 0) {
|
|
|
4636b8 |
- return ret;
|
|
|
4636b8 |
- }
|
|
|
4636b8 |
-
|
|
|
4636b8 |
- if (ret < cpu->kvm_msr_buf->nmsrs) {
|
|
|
4636b8 |
- struct kvm_msr_entry *e = &cpu->kvm_msr_buf->entries[ret];
|
|
|
4636b8 |
- error_report("error: failed to set MSR 0x%" PRIx32 " to 0x%" PRIx64,
|
|
|
4636b8 |
- (uint32_t)e->index, (uint64_t)e->data);
|
|
|
4636b8 |
- }
|
|
|
4636b8 |
-
|
|
|
4636b8 |
- assert(ret == cpu->kvm_msr_buf->nmsrs);
|
|
|
4636b8 |
- return 0;
|
|
|
4636b8 |
+ return kvm_buf_set_msrs(cpu);
|
|
|
4636b8 |
}
|
|
|
4636b8 |
|
|
|
4636b8 |
|
|
|
4636b8 |
diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h
|
|
|
4636b8 |
index 1de9876cd9..856044750e 100644
|
|
|
4636b8 |
--- a/target/i386/kvm_i386.h
|
|
|
4636b8 |
+++ b/target/i386/kvm_i386.h
|
|
|
4636b8 |
@@ -69,4 +69,5 @@ void kvm_put_apicbase(X86CPU *cpu, uint64_t value);
|
|
|
4636b8 |
|
|
|
4636b8 |
bool kvm_enable_x2apic(void);
|
|
|
4636b8 |
bool kvm_has_x2apic_api(void);
|
|
|
4636b8 |
+
|
|
|
4636b8 |
#endif
|
|
|
4636b8 |
--
|
|
|
4636b8 |
2.18.2
|
|
|
4636b8 |
|