i386: simplify Hyper-V enlightenments enablement
v2 cover i386: simplify Hyper-V enlightenments enablement
Changes since v1:
- Moved X86MachineClass related setup to x86_cpu_pre_plug [Eduardo], introduced kvm_hv_evmcs_available() to support the change.
- Droped PATCHes0-4 from v1 as x86_cpu_hyperv_realize() is not needed for the purpose of this series. I'll be sending them out as part of "KVM: expand Hyper-V features early" series after 5.11-rc1 Linux release.
Original description:
This series is a part of the previously sent "[PATCH RFC v3 00/23] i386:
KVM: expand Hyper-V features early":
https://lists.gnu.org/archive/html/qemu-devel/2020-10/msg02443.html
We're not ready to merge the full patch set yet because the required KVM capability is only queued for 5.11. We can, however, extract the part providing 'hyperv=on' option to x86 machine types which is valuable on its own.
Vitaly Kuznetsov (2):
i386: introduce kvm_hv_evmcs_available()
i386: provide simple 'hyperv=on' option to x86 machine types
docs/hyperv.txt | 8 ++++++++ hw/i386/x86.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/x86.h | 7 +++++++ target/i386/kvm-stub.c | 5 +++++ target/i386/kvm.c | 8 ++++++++ target/i386/kvm_i386.h | 1 + 6 files changed, 71 insertions(+)
Signature · 1 line
2.29.2
PATCH v2 1/2 i386: introduce kvm_hv_evmcs_available()
Enlightened VMCS feature is hardware specific, it is only supported on Intel CPUs. Introduce a simple kvm_hv_evmcs_available() helper, it will be used to filter out 'hv_evmcs' when 'hyperv=on' option is added to X86MachineClass.
--- target/i386/kvm-stub.c | 5 +++++ target/i386/kvm.c | 8 ++++++++ target/i386/kvm_i386.h | 1 + 3 files changed, 14 insertions(+)
target/i386/kvm-stub.c +5 -0
@@ -39,3 +39,8 @@ bool kvm_hv_vpindex_settable(void) {return false; } + +bool kvm_hv_evmcs_available (void ) +{ +return false; +}
target/i386/kvm.c +8 -0
@@ -95,6 +95,7 @@ static bool has_msr_hv_crash;static bool has_msr_hv_reset;static bool has_msr_hv_vpindex;static bool hv_vpindex_settable; +static bool hv_evmcs_available;static bool has_msr_hv_runtime;static bool has_msr_hv_synic;static bool has_msr_hv_stimer;
@@ -192,6 +193,11 @@ bool kvm_hv_vpindex_settable(void)return hv_vpindex_settable; } +bool kvm_hv_evmcs_available (void ) +{ +return hv_evmcs_available; +} +static int kvm_get_tsc (CPUState *cs) {X86CPU *cpu =X86_CPU (cs);
@@ -2124,6 +2130,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) has_pit_state2 =kvm_check_extension (s,KVM_CAP_PIT_STATE2 ); hv_vpindex_settable =kvm_check_extension (s,KVM_CAP_HYPERV_VP_INDEX ); + hv_evmcs_available = +kvm_check_extension (s,KVM_CAP_HYPERV_ENLIGHTENED_VMCS ); has_exception_payload =kvm_check_extension (s,KVM_CAP_EXCEPTION_PAYLOAD );if (has_exception_payload) {
target/i386/kvm_i386.h +1 -0
@@ -47,6 +47,7 @@ bool kvm_has_x2apic_api(void);bool kvm_has_waitpkg (void );bool kvm_hv_vpindex_settable (void ); +bool kvm_hv_evmcs_available (void );uint64_t kvm_swizzle_msi_ext_dest_id (uint64_t address);
Signature · 1 line
2.29.2
PATCH v2 2/2 i386: provide simple 'hyperv=on' option to x86 machine types
In reply to Vitaly KuznetsovEnabling Hyper-V emulation for a Windows VM is a tiring experience as it requires listing all currently supported enlightenments ("hv_*" CPU features) explicitly. We do have a 'hv_passthrough' mode enabling everything but it can't be used in production as it prevents migration.
Introduce a simple 'hyperv=on' option for all x86 machine types enabling all currently supported Hyper-V enlightenments. Later, when new enlightenments get implemented, we will be adding them to newer machine types only (by disabling them for legacy machine types) thus preserving migration.
--- docs/hyperv.txt | 8 ++++++++ hw/i386/x86.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/hw/i386/x86.h | 7 +++++++ 3 files changed, 57 insertions(+)
docs/hyperv.txt +8 -0
@@ -29,6 +29,14 @@ When any set of the Hyper-V enlightenments is enabled, QEMU changes hypervisor identification (CPUID 0x40000000..0x4000000A) to Hyper-V. KVM identification and features are kept in leaves 0x40000100..0x40000101. +Hyper-V enlightenments can be enabled in bulk by specifying 'hyperv=on' to an +x86 machine type: + + qemu-system-x86_64 -machine q35,accel=kvm,kernel-irqchip=split,hyperv=on ... + +Note, new enlightenments are only added to the latest (in-develompent) machine +type, older machine types keep the list of the supported features intact to +safeguard migration. 3. Existing enlightenments ===========================
hw/i386/x86.c +42 -0
66 lines not on this page · raw message
include/hw/i386/x86.h +7 -0
@@ -38,6 +38,9 @@ struct X86MachineClass {bool save_tsc_khz;/* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; + +/* Hyper-V features enabled with 'hyperv=on' */ +uint64_t default_hyperv_features; };struct X86MachineState {
@@ -72,10 +75,14 @@ struct X86MachineState {* will be translated to MSI messages in the address space. */ AddressSpace *ioapic_as; + +/* Hyper-V emulation */ +bool hyperv_enabled; };#define X86_MACHINE_SMM "smm"#define X86_MACHINE_ACPI "acpi" +#define X86_MACHINE_HYPERV "hyperv"#define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86")OBJECT_DECLARE_TYPE (X86MachineState, X86MachineClass,X86_MACHINE )
Signature · 1 line
2.29.2