[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/23] hyperv: set partition-wide MSRs only on first
From: |
Roman Kagan |
Subject: |
[Qemu-devel] [PATCH 03/23] hyperv: set partition-wide MSRs only on first vcpu |
Date: |
Tue, 6 Jun 2017 21:19:28 +0300 |
From: Evgeny Yakovlev <address@hidden>
Hyper-V has a notion of partition-wide MSRs. Those MSRs are read and
written as usual on each VCPU, however the hypervisor maintains a single
global value for all VCPUs. Thus writing such an MSR from any single
VCPU affects the global value that is read by all other VCPUs.
This leads to an issue during VCPU hotplug: the zero-initialzied values
of those MSRs get synced into KVM and override the global values as has
already been set by the guest.
This change makes the partition-wide MSRs only be synchronized on the
first vcpu.
Signed-off-by: Evgeny Yakovlev <address@hidden>
Signed-off-by: Roman Kagan <address@hidden>
---
target/i386/cpu.h | 5 ++++-
target/i386/kvm.c | 20 ++++++++++++--------
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 9335dcc..7af2cce 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1089,10 +1089,13 @@ typedef struct CPUX86State {
uint64_t async_pf_en_msr;
uint64_t pv_eoi_en_msr;
+ /* Partition-wide HV MSRs, will be updated only on the first vcpu */
uint64_t msr_hv_hypercall;
uint64_t msr_hv_guest_os_id;
- uint64_t msr_hv_vapic;
uint64_t msr_hv_tsc;
+
+ /* Per-VCPU HV MSRs */
+ uint64_t msr_hv_vapic;
uint64_t msr_hv_crash_params[HV_CRASH_PARAMS];
uint64_t msr_hv_runtime;
uint64_t msr_hv_synic_control;
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index a6debbd..3a80913 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1719,19 +1719,23 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
kvm_msr_entry_add(cpu, MSR_CORE_PERF_GLOBAL_CTRL,
env->msr_global_ctrl);
}
- if (has_msr_hv_hypercall) {
- kvm_msr_entry_add(cpu, HV_X64_MSR_GUEST_OS_ID,
- env->msr_hv_guest_os_id);
- kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL,
- env->msr_hv_hypercall);
+ /* Sync partition-wide MSRs only on first VCPU to avoid races */
+ if (current_cpu == first_cpu) {
+ if (has_msr_hv_hypercall) {
+ kvm_msr_entry_add(cpu, HV_X64_MSR_GUEST_OS_ID,
+ env->msr_hv_guest_os_id);
+ kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL,
+ env->msr_hv_hypercall);
+ }
+ if (cpu->hyperv_time) {
+ kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC,
+ env->msr_hv_tsc);
+ }
}
if (cpu->hyperv_vapic) {
kvm_msr_entry_add(cpu, HV_X64_MSR_APIC_ASSIST_PAGE,
env->msr_hv_vapic);
}
- if (cpu->hyperv_time) {
- kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, env->msr_hv_tsc);
- }
if (has_msr_hv_crash) {
int j;
--
2.9.4
- [Qemu-devel] [PATCH 00/23] hyperv fixes and enhancements, Roman Kagan, 2017/06/06
- [Qemu-devel] [PATCH 04/23] hyperv: ensure msrs are inited properly, Roman Kagan, 2017/06/06
- [Qemu-devel] [PATCH 03/23] hyperv: set partition-wide MSRs only on first vcpu,
Roman Kagan <=
- [Qemu-devel] [PATCH 01/23] hyperv: add header with protocol definitions, Roman Kagan, 2017/06/06
- [Qemu-devel] [PATCH 02/23] update-linux-headers: prepare for hyperv.h removal, Roman Kagan, 2017/06/06
- [Qemu-devel] [PATCH 06/23] hyperv: helper to find vcpu by VP index, Roman Kagan, 2017/06/06
- [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Roman Kagan, 2017/06/06
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Eduardo Habkost, 2017/06/13
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Roman Kagan, 2017/06/14
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Paolo Bonzini, 2017/06/14
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Igor Mammedov, 2017/06/14
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Roman Kagan, 2017/06/15
- Re: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index, Paolo Bonzini, 2017/06/15