hyperv: ensure VP index equal to QEMU cpu_index
cover hyperv: ensure VP index equal to QEMU cpu_index
Make sure QEMU owns the VP index (which is the number used to identify the vCPU in Hyper-V) and make it equal to QEMU cpu_index.
Roman Kagan (2):
hyperv: rename vcpu_id to vp_index
hyperv: ensure VP index equal to QEMU cpu_index
---
For the reference, all of the Hyper-V / VMBus stuff can be found at
https://src.openvz.org/scm/up/qemu
target/i386/hyperv.h | 7 ++++-- target/i386/kvm_i386.h | 2 ++ hw/i386/pc.c | 5 +++++ hw/misc/hyperv_testdev.c | 16 +++++++------- target/i386/hyperv.c | 16 +++++++++++--- target/i386/kvm-stub.c | 5 +++++ target/i386/kvm.c | 47 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 85 insertions(+), 13 deletions(-)
Signature · 1 line
2.17.1
PATCH 2/2 hyperv: ensure VP index equal to QEMU cpu_index
Hyper-V identifies vCPUs by Virtual Processor (VP) index which can be queried by the guest via HV_X64_MSR_VP_INDEX msr. It is defined by the spec as a sequential number which can't exceed the maximum number of vCPUs per VM.
It has to be owned by QEMU in order to preserve it across migration.
However, the initial implementation in KVM didn't allow to set this msr, and KVM used its own notion of VP index. Fortunately, the way vCPUs are created in QEMU/KVM makes it likely that the KVM value is equal to QEMU cpu_index.
So choose cpu_index as the value for vp_index, and push that to KVM on kernels that support setting the msr. On older ones that don't, query the kernel value and assert that it's in sync with QEMU.
Besides, since handling errors from vCPU init at hotplug time is impossible, disable vCPU hotplug.
This patch also introduces accessor functions to encapsulate the mapping between a vCPU and its vp_index.
--- target/i386/hyperv.h | 3 +++ target/i386/kvm_i386.h | 2 ++ hw/i386/pc.c | 5 +++++ target/i386/hyperv.c | 10 +++++++++ target/i386/kvm-stub.c | 5 +++++ target/i386/kvm.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 72 insertions(+)
target/i386/hyperv.h +3 -0
@@ -39,4 +39,7 @@ void kvm_hv_sint_route_destroy(HvSintRoute *sint_route);int kvm_hv_sint_route_set_sint (HvSintRoute *sint_route); +uint32_t hyperv_vp_index (X86CPU *cpu); +X86CPU *hyperv_find_vcpu (uint32_t vp_index); +#endif
target/i386/kvm_i386.h +2 -0
@@ -63,4 +63,6 @@ void kvm_put_apicbase(X86CPU *cpu, uint64_t value);bool kvm_enable_x2apic (void );bool kvm_has_x2apic_api (void ); + +bool kvm_hv_vpindex_settable (void );#endif
hw/i386/pc.c +5 -0
@@ -1998,6 +1998,11 @@ static void pc_cpu_pre_plug(HotplugHandler *hotplug_dev, } cpu->thread_id = topo.smt_id; +if (cpu->hyperv_vpindex && !kvm_hv_vpindex_settable ()) { +error_setg (errp,"kernel doesn't allow setting HyperV VP_INDEX" ); +return ; + } + cs =CPU (cpu); cs->cpu_index = idx;
target/i386/hyperv.c +10 -0
@@ -16,6 +16,16 @@#include "hyperv.h" #include "hyperv-proto.h" +uint32_t hyperv_vp_index (X86CPU *cpu) +{ +return CPU (cpu)->cpu_index; +} + +X86CPU *hyperv_find_vcpu (uint32_t vp_index) +{ +return X86_CPU (qemu_get_cpu (vp_index)); +} +int kvm_hv_handle_exit (X86CPU *cpu,struct kvm_hyperv_exit *exit) {CPUX86State *env = &cpu->env;
target/i386/kvm-stub.c +5 -0
@@ -40,3 +40,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function, abort(); }#endif + +bool kvm_hv_vpindex_settable (void ) +{ +return false; +}
target/i386/kvm.c +47 -0
83 lines not on this page · raw message
Signature · 1 line
2.17.1
Paolo Bonzini
AppliedQuoted 10 lines · Roman Kagan
Make sure QEMU owns the VP index (which is the number used to identify the vCPU in Hyper-V) and make it equal to QEMU
cpu_index.Roman Kagan (2):
hyperv: renamevcpu_idtovp_index
hyperv: ensure VP index equal to QEMUcpu_index---
For the reference, all of the Hyper-V / VMBus stuff can be found at
https://src.openvz.org/scm/up/qemu
Queued, thanks. It's a bug, so it's okay for 3.0.
Paolo