i386: Assorted KVM PV and Hyper-V feature improvements
v2 cover i386: Assorted KVM PV and Hyper-V feature improvements
This is a continuation of "[PATCH 0/3] i386/kvm: Paravirtualized features usage enforcement" series, thus v2.
This series implements several unrelated features but as there are code dependencies between them I'm sending it as one series.
PATCH1 adds empty 6.2 machine types and the required compat infrastructure (to be used by PATCH8)
PATCH2 adds documentation for KVM PV features
PATCH3 adds support for KVM_CAP_ENFORCE_PV_FEATURE_CPUID PATCH4 adds support for KVM_CAP_HYPERV_ENFORCE_CPUID PATCHes5-6 add 'hv-avic' feature
PATCH7 makes Hyper-V version info settable
PATCH8 changes the default Hyper-V version to 2016
Vitaly Kuznetsov (8):
i386: Add 6.2 machine types
i386: docs: Briefly describe KVM PV features
i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID
i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID
i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to
hyperv_fill_cpuids()
i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment
i386: Make Hyper-V version id configurable
i386: Change the default Hyper-V version to match WS2016
docs/hyperv.txt | 41 +++++++++++-- docs/kvm-pv.txt | 103 +++++++++++++++++++++++++++++++++ hw/core/machine.c | 3 + hw/i386/pc.c | 7 +++ hw/i386/pc_piix.c | 14 ++++- hw/i386/pc_q35.c | 13 ++++- include/hw/boards.h | 3 + include/hw/i386/pc.h | 3 + target/i386/cpu.c | 22 +++++-- target/i386/cpu.h | 12 +++- target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 62 +++++++++++++++----- 12 files changed, 260 insertions(+), 24 deletions(-) create mode 100644 docs/kvm-pv.txt
Signature · 1 line
2.31.1
PATCH v2 1/8 i386: Add 6.2 machine types
Introduce 6.2 machine types and the required infrastructure for adding compat properties to pre-6.2 machine types.
--- hw/core/machine.c | 3 +++ hw/i386/pc.c | 3 +++ hw/i386/pc_piix.c | 14 +++++++++++++- hw/i386/pc_q35.c | 13 ++++++++++++- include/hw/boards.h | 3 +++ include/hw/i386/pc.h | 3 +++ 6 files changed, 37 insertions(+), 2 deletions(-)
hw/core/machine.c +3 -0
@@ -46,6 +46,9 @@ GlobalProperty hw_compat_6_0[] = { };const size_t hw_compat_6_0_len =G_N_ELEMENTS (hw_compat_6_0); +GlobalProperty hw_compat_6_1[] = {}; +const size_t hw_compat_6_1_len =G_N_ELEMENTS (hw_compat_6_1); +GlobalProperty hw_compat_5_2[] = { {"ICH9-LPC" ,"smm-compat" ,"on" }, {"PIIX4_PM" ,"smm-compat" ,"on" },
hw/i386/pc.c +3 -0
@@ -93,6 +93,9 @@#include "trace.h" #include CONFIG_DEVICES +GlobalProperty pc_compat_6_1[] = {}; +const size_t pc_compat_6_1_len =G_N_ELEMENTS (pc_compat_6_1); +GlobalProperty pc_compat_6_0[] = { {"qemu64" "-" TYPE_X86_CPU ,"family" ,"6" }, {"qemu64" "-" TYPE_X86_CPU ,"model" ,"6" },
hw/i386/pc_piix.c +13 -1
@@ -412,7 +412,7 @@ static void pc_i440fx_machine_options(MachineClass *m)machine_class_allow_dynamic_sysbus_dev (m,TYPE_VMBUS_BRIDGE ); } -static void pc_i440fx_6_1_machine_options (MachineClass *m) +static void pc_i440fx_6_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_machine_options (m);
@@ -421,6 +421,18 @@ static void pc_i440fx_6_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_I440FX_MACHINE (v6_2,"pc-i440fx-6.2" ,NULL , + pc_i440fx_6_2_machine_options); + +static void pc_i440fx_6_1_machine_options (MachineClass *m) +{ +pc_i440fx_6_2_machine_options (m); + m->alias =NULL ; + m->is_default = false; +compat_props_add (m->compat_props, hw_compat_6_1, hw_compat_6_1_len); +compat_props_add (m->compat_props, pc_compat_6_1, pc_compat_6_1_len); +} +DEFINE_I440FX_MACHINE (v6_1,"pc-i440fx-6.1" ,NULL , pc_i440fx_6_1_machine_options);
hw/i386/pc_q35.c +12 -1
@@ -354,7 +354,7 @@ static void pc_q35_machine_options(MachineClass *m) m->max_cpus =288 ; } -static void pc_q35_6_1_machine_options (MachineClass *m) +static void pc_q35_6_2_machine_options (MachineClass *m) {PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_machine_options (m);
@@ -362,6 +362,17 @@ static void pc_q35_6_1_machine_options(MachineClass *m) pcmc->default_cpu_version =1 ; } +DEFINE_Q35_MACHINE (v6_2,"pc-q35-6.2" ,NULL , + pc_q35_6_2_machine_options); + +static void pc_q35_6_1_machine_options (MachineClass *m) +{ +pc_q35_6_2_machine_options (m); + m->alias =NULL ; +compat_props_add (m->compat_props, hw_compat_6_1, hw_compat_6_1_len); +compat_props_add (m->compat_props, pc_compat_6_1, pc_compat_6_1_len); +} +DEFINE_Q35_MACHINE (v6_1,"pc-q35-6.1" ,NULL , pc_q35_6_1_machine_options);
include/hw/boards.h +3 -0
@@ -353,6 +353,9 @@ struct MachineState { } \ type_init(machine_initfn##_register_types) +extern GlobalProperty hw_compat_6_1[]; +extern const size_t hw_compat_6_1_len; +extern GlobalProperty hw_compat_6_0[];extern const size_t hw_compat_6_0_len;
include/hw/i386/pc.h +3 -0
@@ -196,6 +196,9 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size);void pc_madt_cpu_entry (AcpiDeviceIf *adev,int uid,const CPUArchIdList *apic_ids,GArray *entry); +extern GlobalProperty pc_compat_6_1[]; +extern const size_t pc_compat_6_1_len; +extern GlobalProperty pc_compat_6_0[];extern const size_t pc_compat_6_0_len;
Signature · 1 line
2.31.1
PATCH v2 2/8 i386: docs: Briefly describe KVM PV features
In reply to Vitaly KuznetsovKVM PV features don't seem to be documented anywhere, in particular, the fact that some of the features are enabled by default and some are not can only be figured out from the code.
--- docs/kvm-pv.txt | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 docs/kvm-pv.txt
docs/kvm-pv.txt new file +92 -0
@@ -0,0 +1,92 @@ +KVM paravirtualized features +============================ + + +1. Description +=============== +In some cases when implementing a hardware interface in software is slow, KVM +implements its own paravirtualized interfaces. + +2. Setup +========= +KVM PV features are represented as CPU flags. The following features are enabled +by default for any CPU model when KVM is enabled: + kvmclock + kvm-nopiodelay + kvm-asyncpf + kvm-steal-time + kvm-pv-eoi + kvmclock-stable-bit + +'kvm-msi-ext-dest-id' feature is enabled by default in x2apic mode with split +irqchip (e.g. "-machine ...,kernel-irqchip=split -cpu ...,x2apic"). + +Note: when cpu model 'host' is used, QEMU passes through all KVM PV features +exposed by KVM to the guest. + +3. Existing features +==================== + +3.1. kvmclock +================ +This feature exposes KVM specific PV clocksource to the guest. + +3.2. kvm-nopiodelay +=================== +The guest doesn't need to perform delays on PIO operations. + +3.3. kvm-mmu +============ +This feature is deprecated. + +3.4. kvm-asyncpf +================ +Enables asynchronous page fault mechanism. Note: since Linux-5.10 the feature is +deprecated and not enabled by KVM. Use "kvm-asyncpf-int" instead. + +3.5. kvm-steal-time +=================== +Enables stolen (when guest vCPU is not running) time accounting. + +3.6. kvm-pv-eoi +=============== +Enables paravirtualized end-of-interrupt signaling. + +3.7. kvm-pv-unhalt +================== +Enables paravirtualized spinlocks support. + +3.8. kvm-pv-tlb-flush +===================== +Enables paravirtualized TLB flush mechanism. + +3.9. kvm-pv-ipi +=============== +Enables paravirtualized IPI mechanism. + +3.10. kvm-poll-control +====================== +Enables host-side polling on HLT control from the guest. + +3.11. kvm-pv-sched-yield +======================== +Enables paravirtualized sched yield feature. + +3.12. kvm-asyncpf-int +===================== +Enables interrupt based asynchronous page fault mechanism. + +3.13. kvm-msi-ext-dest-id +========================= +Support 'Extended Destination ID' for external interrupts. The feature allows +to use up to 32768 CPUs without IRQ remapping (but other limits may apply making +the number of supported vCPUs for a given configuration lower). + +3.14. kvmclock-stable-bit +========================= +Tells the guest that guest visible TSC value can be fully trusted for kvmclock +computations and no warps are expected. + +4. Useful links +================ +Please refer to Documentation/virt/kvm in Linux for additional detail.
Signature · 1 line
2.31.1
Re: [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features
Quoted 9 lines · Vitaly Kuznetsov
KVM PV features don't seem to be documented anywhere, in particular, the fact that some of the features are enabled by default and some are not can only be figured out from the code.
Signed-off-by Vitaly Kuznetsov <[email protected]>--- docs/kvm-pv.txt | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)create mode 100644
docs/kvm-pv.txt
Please place this in docs/system/i386 (linked from docs/system/target-i386.rst).
docs/kvm-pv.txt line 6
Quoted 12 lines
docs/kvm-pv.txt new file +6
-0@@ -0,0 +1,92 @@ +KVM paravirtualized features +============================ + + +1. Description +===============
In addition to other conversions to rst, please:
a) use --- for headings at the second level
Quoted 15 lines
docs/kvm-pv.txt new file +15
-0+In some cases when implementing a hardware interface in software is slow, KVM +implements its own paravirtualized interfaces. + +2. Setup +========= +KVM PV features are represented as CPU flags. The following features are enabled +by default for any CPU model when KVM is enabled: + kvmclock + kvm-nopiodelay + kvm-asyncpf + kvm-steal-time + kvm-pv-eoi + kvmclock-stable-bit + +'kvm-msi-ext-dest-id' feature is enabled by default in x2apic mode with split
docs/kvm-pv.txt line 32
Quoted 10 lines
docs/kvm-pv.txt new file +10
-0+irqchip (e.g. "-machine ...,kernel-irqchip=split -cpu ...,x2apic"). + +Note: when cpu model 'host' is used, QEMU passes through all KVM PV features +exposed by KVM to the guest. + +3. Existing features +==================== +3.1. kvmclock +================ +This feature exposes KVM specific PV clocksource to the guest.
b) use a definition list like
kvmclock
Expose a KVM-specific paravirtualized clocksource to the guest.
kvm-nopiodelay
...
You may also want to highlight the version of Linux that introduced the feature.
Paolo
Quoted 60 lines
docs/kvm-pv.txt new file +59
-0+3.2. kvm-nopiodelay +=================== +The guest doesn't need to perform delays on PIO operations. + +3.3. kvm-mmu +============ +This feature is deprecated. + +3.4. kvm-asyncpf +================ +Enables asynchronous page fault mechanism. Note: since Linux-5.10 the feature is +deprecated and not enabled by KVM. Use "kvm-asyncpf-int" instead. + +3.5. kvm-steal-time +=================== +Enables stolen (when guest vCPU is not running) time accounting. + +3.6. kvm-pv-eoi +=============== +Enables paravirtualized end-of-interrupt signaling. + +3.7. kvm-pv-unhalt +================== +Enables paravirtualized spinlocks support. + +3.8. kvm-pv-tlb-flush +===================== +Enables paravirtualized TLB flush mechanism. + +3.9. kvm-pv-ipi +=============== +Enables paravirtualized IPI mechanism. + +3.10. kvm-poll-control +====================== +Enables host-side polling on HLT control from the guest. + +3.11. kvm-pv-sched-yield +======================== +Enables paravirtualized sched yield feature. + +3.12. kvm-asyncpf-int +===================== +Enables interrupt based asynchronous page fault mechanism. + +3.13. kvm-msi-ext-dest-id +========================= +Support 'Extended Destination ID' for external interrupts. The feature allows +to use up to 32768 CPUs without IRQ remapping (but other limits may apply making +the number of supported vCPUs for a given configuration lower). + +3.14. kvmclock-stable-bit +========================= +Tells the guest that guest visible TSC value can be fully trusted for kvmclock +computations and no warps are expected. + +4. Useful links +================ +Please refer to Documentation/virt/kvm in Linux for additional detail.
PATCH v2 3/8 i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID
In reply to Vitaly KuznetsovBy default, KVM allows the guest to use all currently supported PV features even when they were not announced in guest visible CPUIDs. Introduce a new "kvm-pv-enforce-cpuid" flag to limit the supported feature set to the exposed features. The feature is supported by Linux >= 5.10 and is not enabled by default in QEMU.
--- docs/kvm-pv.txt | 13 ++++++++++++- target/i386/cpu.c | 2 ++ target/i386/cpu.h | 3 +++ target/i386/kvm/kvm.c | 10 ++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-)
docs/kvm-pv.txt +12 -1
@@ -87,6 +87,17 @@ the number of supported vCPUs for a given configuration lower). Tells the guest that guest visible TSC value can be fully trusted for kvmclock computations and no warps are expected. -4. Useful links +4. Supplementary features +========================= + +4.1. kvm-pv-enforce-cpuid +========================= +By default, KVM allows the guest to use all currently supported PV features even +when they were not announced in guest visible CPUIDs. 'kvm-pv-enforce-cpuid' +feature alters this behavior and limits the supported feature set to the +exposed features only. + + +5. Useful links ================ Please refer to Documentation/virt/kvm in Linux for additional detail.
target/i386/cpu.c +2 -0
@@ -6691,6 +6691,8 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("l3-cache" ,X86CPU , enable_l3_cache, true),DEFINE_PROP_BOOL ("kvm-no-smi-migration" ,X86CPU , kvm_no_smi_migration, false), +DEFINE_PROP_BOOL ("kvm-pv-enforce-cpuid" ,X86CPU , kvm_pv_enforce_cpuid, + false),DEFINE_PROP_BOOL ("vmware-cpuid-freq" ,X86CPU , vmware_cpuid_freq, true),DEFINE_PROP_BOOL ("tcg-cpuid" ,X86CPU , expose_tcg, true), DEFINE_PROP_BOOL("x-migrate-smi-count", X86CPU, migrate_smi_count,
target/i386/cpu.h +3 -0
@@ -1782,6 +1782,9 @@ struct X86CPU {/* Stop SMI delivery for migration compatibility with old machines */ bool kvm_no_smi_migration; +/* Forcefully disable KVM PV features not exposed in guest CPUIDs */ +bool kvm_pv_enforce_cpuid; +/* Number of physical address bits supported */ uint32_t phys_bits;
target/i386/kvm/kvm.c +10 -0
@@ -1629,6 +1629,16 @@ int kvm_arch_init_vcpu(CPUState *cs)cpu_x86_cpuid (env,0 ,0 , &limit, &unused, &unused, &unused); +if (cpu->kvm_pv_enforce_cpuid) { + r =kvm_vcpu_enable_cap (cs,KVM_CAP_ENFORCE_PV_FEATURE_CPUID ,0 ,1 ); +if (r <0 ) { +fprintf (stderr, +"failed to enable KVM_CAP_ENFORCE_PV_FEATURE_CPUID: %s" , +strerror (-r)); +abort (); + } + } +for (i =0 ; i <= limit; i++) {if (cpuid_i ==KVM_MAX_CPUID_ENTRIES ) {fprintf (stderr,"unsupported level value: 0x%x\n" , limit);
Signature · 1 line
2.31.1
PATCH v2 4/8 i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID
In reply to Vitaly KuznetsovBy default, KVM allows the guest to use all currently supported Hyper-V enlightenments when Hyper-V CPUID interface was exposed, regardless of if some features were not announced in guest visible CPUIDs. hv-enforce-cpuid feature alters this behavior and only allows the guest to use exposed Hyper-V enlightenments. The feature is supported by Linux >= 5.14 and is not enabled by default in QEMU.
--- docs/hyperv.txt | 17 ++++++++++++++--- target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 9 +++++++++ 4 files changed, 25 insertions(+), 3 deletions(-)
docs/hyperv.txt +14 -3
@@ -203,8 +203,11 @@ When the option is set to 'on' QEMU will always enable the feature, regardless of host setup. To keep guests secure, this can only be used in conjunction with exposing correct vCPU topology and vCPU pinning. -4. Development features -======================== +4. Supplementary features +========================= + +4.1. hv-passthrough +=================== In some cases (e.g. during development) it may make sense to use QEMU in 'pass-through' mode and give Windows guests all enlightenments currently supported by KVM. This pass-through mode is enabled by "hv-passthrough" CPU
@@ -215,8 +218,16 @@ values from KVM to QEMU. "hv-passthrough" overrides all other "hv-*" settings on the command line. Also, enabling this flag effectively prevents migration as the list of enabled enlightenments may differ between target and destination hosts. +4.2. hv-enforce-cpuid +===================== +By default, KVM allows the guest to use all currently supported Hyper-V +enlightenments when Hyper-V CPUID interface was exposed, regardless of if +some features were not announced in guest visible CPUIDs. 'hv-enforce-cpuid' +feature alters this behavior and only allows the guest to use exposed Hyper-V +enlightenments. + -4. Useful links +5. Useful links ================ Hyper-V Top Level Functional specification and other information: https://github.com/MicrosoftDocs/Virtualization-Documentation
target/i386/cpu.c +1 -0
@@ -6665,6 +6665,7 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_ON_OFF_AUTO ("hv-no-nonarch-coresharing" ,X86CPU , hyperv_no_nonarch_cs,ON_OFF_AUTO_OFF ),DEFINE_PROP_BOOL ("hv-passthrough" ,X86CPU , hyperv_passthrough, false), +DEFINE_PROP_BOOL ("hv-enforce-cpuid" ,X86CPU , hyperv_enforce_cpuid, false),DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
target/i386/cpu.h +1 -0
@@ -1699,6 +1699,7 @@ struct X86CPU {uint32_t hyperv_version_id[4 ];uint32_t hyperv_limits[3 ];uint32_t hyperv_nested[4 ]; +bool hyperv_enforce_cpuid;bool check_cpuid;bool enforce_cpuid;
target/i386/kvm/kvm.c +9 -0
@@ -1531,6 +1531,15 @@ static int hyperv_init_vcpu(X86CPU *cpu) cpu->hyperv_nested[0 ] = evmcs_version; } +if (cpu->hyperv_enforce_cpuid) { + ret =kvm_vcpu_enable_cap (cs,KVM_CAP_HYPERV_ENFORCE_CPUID ,0 ,1 ); +if (ret <0 ) { +error_report ("failed to enable KVM_CAP_HYPERV_ENFORCE_CPUID: %s" , +strerror (-ret)); +return ret; + } + } +return 0 ; }
Signature · 1 line
2.31.1
PATCH v2 5/8 i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to hyperv_fill_cpuids()
In reply to Vitaly KuznetsovIn preparation to enabling Hyper-V + APICv/AVIC move HV_APIC_ACCESS_RECOMMENDED setting out of kvm_hyperv_properties[]: the 'real' feature bit for the vAPIC features is HV_APIC_ACCESS_AVAILABLE, HV_APIC_ACCESS_RECOMMENDED is a recommendation to use the feature which we may not always want to give.
--- target/i386/kvm/kvm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
target/i386/kvm/kvm.c +6 -3
@@ -821,9 +821,7 @@ static struct { .desc = "virtual APIC (hv-vapic)", .flags = { {.func = HV_CPUID_FEATURES, .reg = R_EAX, - .bits = HV_APIC_ACCESS_AVAILABLE}, - {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX, - .bits = HV_APIC_ACCESS_RECOMMENDED} + .bits = HV_APIC_ACCESS_AVAILABLE} } }, [HYPERV_FEAT_TIME] = {
@@ -1366,6 +1364,7 @@ static int hyperv_fill_cpuids(CPUState *cs, c->ebx |=HV_POST_MESSAGES |HV_SIGNAL_EVENTS ; } +/* Not exposed by KVM but needed to make CPU hotplug in Windows work */ c->edx |=HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE ;
@@ -1374,6 +1373,10 @@ static int hyperv_fill_cpuids(CPUState *cs, c->eax =hv_build_cpuid_leaf (cs,HV_CPUID_ENLIGHTMENT_INFO ,R_EAX ); c->ebx = cpu->hyperv_spinlock_attempts; +if (hyperv_feat_enabled (cpu,HYPERV_FEAT_VAPIC )) { + c->eax |=HV_APIC_ACCESS_RECOMMENDED ; + } +if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_ON ) { c->eax |=HV_NO_NONARCH_CORESHARING ; }else if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_AUTO ) {
Signature · 1 line
2.31.1
PATCH v2 6/8 i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment
In reply to Vitaly KuznetsovThe enlightenment allows to use Hyper-V SynIC with hardware APICv/AVIC enabled. Normally, Hyper-V SynIC disables these hardware features and suggests the guest to use paravirtualized AutoEOI feature. Linux-4.15 gains support for conditional APICv/AVIC disablement, the feature stays on until the guest tries to use AutoEOI feature with SynIC. With 'HV_DEPRECATING_AEOI_RECOMMENDED' bit exposed, modern enough Windows/ Hyper-V versions should follow the recommendation and not use the (unwanted) feature.
--- docs/hyperv.txt | 10 +++++++++- target/i386/cpu.c | 4 ++++ target/i386/cpu.h | 1 + target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 10 +++++++++- 5 files changed, 24 insertions(+), 2 deletions(-)
docs/hyperv.txt +9 -1
@@ -189,7 +189,15 @@ enabled. Requires: hv-vpindex, hv-synic, hv-time, hv-stimer -3.17. hv-no-nonarch-coresharing=on/off/auto +3.18. hv-avic (hv-apicv) +======================= +The enlightenment allows to use Hyper-V SynIC with hardware APICv/AVIC enabled. +Normally, Hyper-V SynIC disables these hardware feature and suggests the guest +to use paravirtualized AutoEOI feature. +Note: enabling this feature on old hardware (without APICv/AVIC support) may +have negative effect on guest's performace. + +3.19. hv-no-nonarch-coresharing=on/off/auto =========================================== This enlightenment tells guest OS that virtual processors will never share a physical core unless they are reported as sibling SMT threads. This information
target/i386/cpu.c +4 -0
@@ -6477,6 +6477,8 @@ static void x86_cpu_initfn(Object *obj)object_property_add_alias (obj,"sse4_1" , obj,"sse4.1" );object_property_add_alias (obj,"sse4_2" , obj,"sse4.2" ); +object_property_add_alias (obj,"hv-apicv" , obj,"hv-avic" ); +if (xcc->model) {x86_cpu_load_model (cpu, xcc->model); }
@@ -6662,6 +6664,8 @@ static Property x86_cpu_properties[] = { HYPERV_FEAT_IPI, 0),DEFINE_PROP_BIT64 ("hv-stimer-direct" ,X86CPU , hyperv_features,HYPERV_FEAT_STIMER_DIRECT ,0 ), +DEFINE_PROP_BIT64 ("hv-avic" ,X86CPU , hyperv_features, +HYPERV_FEAT_AVIC ,0 ),DEFINE_PROP_ON_OFF_AUTO ("hv-no-nonarch-coresharing" ,X86CPU , hyperv_no_nonarch_cs,ON_OFF_AUTO_OFF ), DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false),
target/i386/cpu.h +1 -0
@@ -1038,6 +1038,7 @@ typedef uint64_t FeatureWordArray[FEATURE_WORDS];#define HYPERV_FEAT_EVMCS 12#define HYPERV_FEAT_IPI 13#define HYPERV_FEAT_STIMER_DIRECT 14 +#define HYPERV_FEAT_AVIC 15#ifndef HYPERV_SPINLOCK_NEVER_NOTIFY #define HYPERV_SPINLOCK_NEVER_NOTIFY 0xFFFFFFFF
target/i386/kvm/hyperv-proto.h +1 -0
@@ -66,6 +66,7 @@#define HV_APIC_ACCESS_RECOMMENDED (1u << 3)#define HV_SYSTEM_RESET_RECOMMENDED (1u << 4)#define HV_RELAXED_TIMING_RECOMMENDED (1u << 5) +#define HV_DEPRECATING_AEOI_RECOMMENDED (1u << 9)#define HV_CLUSTER_IPI_RECOMMENDED (1u << 10)#define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11)#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14)
target/i386/kvm/kvm.c +9 -1
@@ -924,6 +924,13 @@ static struct { }, .dependencies = BIT(HYPERV_FEAT_STIMER) }, + [HYPERV_FEAT_AVIC] = { + .desc = "AVIC/APICv support (hv-avic/hv-apicv)", + .flags = { + {.func = HV_CPUID_ENLIGHTMENT_INFO, .reg = R_EAX, + .bits = HV_DEPRECATING_AEOI_RECOMMENDED} + } + }, }; static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max,
@@ -1373,7 +1380,8 @@ static int hyperv_fill_cpuids(CPUState *cs, c->eax =hv_build_cpuid_leaf (cs,HV_CPUID_ENLIGHTMENT_INFO ,R_EAX ); c->ebx = cpu->hyperv_spinlock_attempts; -if (hyperv_feat_enabled (cpu,HYPERV_FEAT_VAPIC )) { +if (hyperv_feat_enabled (cpu,HYPERV_FEAT_VAPIC ) && + !hyperv_feat_enabled (cpu,HYPERV_FEAT_AVIC )) { c->eax |=HV_APIC_ACCESS_RECOMMENDED ; }
Signature · 1 line
2.31.1
PATCH v2 7/8 i386: Make Hyper-V version id configurable
In reply to Vitaly KuznetsovCurrently, we hardcode Hyper-V version id (CPUID 0x40000002) to WS2008R2 and it is known that certain tools in Windows check this. It seems useful to provide some flexibility by making it possible to change this info at will. CPUID information is defined in TLFS as:
EAX: Build Number
EBX Bits 31-16: Major Version
Bits 15-0: Minor Version
ECX Service Pack
EDX Bits 31-24: Service Branch
Bits 23-0: Service Number
--- docs/hyperv.txt | 14 ++++++++++++++ target/i386/cpu.c | 15 +++++++++++---- target/i386/cpu.h | 7 ++++++- target/i386/kvm/kvm.c | 26 ++++++++++++++++---------- 4 files changed, 47 insertions(+), 15 deletions(-)
docs/hyperv.txt +14 -0
@@ -211,6 +211,20 @@ When the option is set to 'on' QEMU will always enable the feature, regardless of host setup. To keep guests secure, this can only be used in conjunction with exposing correct vCPU topology and vCPU pinning. +3.20. hv-version-id-{build,major,minor,spack,sbranch,snumber} +============================================================= +This changes Hyper-V version identification in CPUID 0x40000002.EAX-EDX from the +default (WS2008R2). +- hv-version-id-build sets 'Build Number' (32 bits) +- hv-version-id-major sets 'Major Version' (16 bits) +- hv-version-id-minor sets 'Minor Version' (16 bits) +- hv-version-id-spack sets 'Service Pack' (32 bits) +- hv-version-id-sbranch sets 'Service Branch' (8 bits) +- hv-version-id-snumber sets 'Service Number' (24 bits) + +Note: hv-version-id-* are not enlightenments and thus don't enable Hyper-V +identification when specified without any other enlightenments. + 4. Supplementary features =========================
target/i386/cpu.c +11 -4
@@ -6093,10 +6093,6 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) cpu->hyperv_interface_id[2 ] =0 ; cpu->hyperv_interface_id[3 ] =0 ; -/* Hypervisor system identity */ - cpu->hyperv_version_id[0 ] =0x00001bbc ; - cpu->hyperv_version_id[1 ] =0x00060001 ; -/* Hypervisor implementation limits */ cpu->hyperv_limits[0 ] =64 ; cpu->hyperv_limits[1 ] =0 ;
@@ -6671,6 +6667,17 @@ static Property x86_cpu_properties[] = {DEFINE_PROP_BOOL ("hv-passthrough" ,X86CPU , hyperv_passthrough, false),DEFINE_PROP_BOOL ("hv-enforce-cpuid" ,X86CPU , hyperv_enforce_cpuid, false), +/* WS2008R2 identify by default */ +DEFINE_PROP_UINT32 ("hv-version-id-build" ,X86CPU , hyperv_ver_id_build, +0x1bbc ), +DEFINE_PROP_UINT16 ("hv-version-id-major" ,X86CPU , hyperv_ver_id_major, +0x0006 ), +DEFINE_PROP_UINT16 ("hv-version-id-minor" ,X86CPU , hyperv_ver_id_minor, +0x0001 ), +DEFINE_PROP_UINT32 ("hv-version-id-spack" ,X86CPU , hyperv_ver_id_sp,0 ), +DEFINE_PROP_UINT8 ("hv-version-id-sbranch" ,X86CPU , hyperv_ver_id_sb,0 ), +DEFINE_PROP_UINT32 ("hv-version-id-snumber" ,X86CPU , hyperv_ver_id_sn,0 ), +DEFINE_PROP_BOOL ("check" ,X86CPU , check_cpuid, true),DEFINE_PROP_BOOL ("enforce" ,X86CPU , enforce_cpuid, false), DEFINE_PROP_BOOL("x-force-features", X86CPU, force_features, false),
target/i386/cpu.h +6 -1
@@ -1697,10 +1697,15 @@ struct X86CPU {OnOffAuto hyperv_no_nonarch_cs;uint32_t hyperv_vendor_id[3 ];uint32_t hyperv_interface_id[4 ]; -uint32_t hyperv_version_id[4 ];uint32_t hyperv_limits[3 ];uint32_t hyperv_nested[4 ];bool hyperv_enforce_cpuid; +uint32_t hyperv_ver_id_build; +uint16_t hyperv_ver_id_major; +uint16_t hyperv_ver_id_minor; +uint32_t hyperv_ver_id_sp; +uint8_t hyperv_ver_id_sb; +uint32_t hyperv_ver_id_sn;bool check_cpuid;bool enforce_cpuid;
target/i386/kvm/kvm.c +16 -10
@@ -1258,14 +1258,18 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) cpu->hyperv_interface_id[3 ] =hv_cpuid_get_host (cs,HV_CPUID_INTERFACE ,R_EDX ); - cpu->hyperv_version_id[0 ] = + cpu->hyperv_ver_id_build =hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EAX ); - cpu->hyperv_version_id[1 ] = -hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EBX ); - cpu->hyperv_version_id[2 ] = + cpu->hyperv_ver_id_major = +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EBX ) >>16 ; + cpu->hyperv_ver_id_minor = +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EBX ) &0xffff ; + cpu->hyperv_ver_id_sp =hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_ECX ); - cpu->hyperv_version_id[3 ] = -hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EDX ); + cpu->hyperv_ver_id_sb = +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EDX ) >>24 ; + cpu->hyperv_ver_id_sn = +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EDX ) &0xffffff ; cpu->hv_max_vps =hv_cpuid_get_host (cs,HV_CPUID_IMPLEMENT_LIMITS ,R_EAX );
@@ -1351,10 +1355,12 @@ static int hyperv_fill_cpuids(CPUState *cs, c = &cpuid_ent[cpuid_i++]; c->function =HV_CPUID_VERSION ; - c->eax = cpu->hyperv_version_id[0 ]; - c->ebx = cpu->hyperv_version_id[1 ]; - c->ecx = cpu->hyperv_version_id[2 ]; - c->edx = cpu->hyperv_version_id[3 ]; + c->eax = cpu->hyperv_ver_id_build; + c->ebx = (uint32_t )cpu->hyperv_ver_id_major <<16 | + cpu->hyperv_ver_id_minor; + c->ecx = cpu->hyperv_ver_id_sp; + c->edx = (uint32_t )cpu->hyperv_ver_id_sb <<24 | + (cpu->hyperv_ver_id_sn &0xffffff ); c = &cpuid_ent[cpuid_i++]; c->function =HV_CPUID_FEATURES ;
Signature · 1 line
2.31.1
PATCH v2 8/8 i386: Change the default Hyper-V version to match WS2016
In reply to Vitaly KuznetsovKVM implements some Hyper-V 2016 functions so providing WS2008R2 version is somewhat incorrect. While generally guests shouldn't care about it and always check feature bits, it is known that some tools in Windows actually check version info.
For compatibility reasons make the change for 7.2 machine types only.
--- docs/hyperv.txt | 2 +- hw/i386/pc.c | 6 +++++- target/i386/cpu.c | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-)
docs/hyperv.txt +1 -1
@@ -214,7 +214,7 @@ exposing correct vCPU topology and vCPU pinning. 3.20. hv-version-id-{build,major,minor,spack,sbranch,snumber} ============================================================= This changes Hyper-V version identification in CPUID 0x40000002.EAX-EDX from the -default (WS2008R2). +default (WS2016). - hv-version-id-build sets 'Build Number' (32 bits) - hv-version-id-major sets 'Major Version' (16 bits) - hv-version-id-minor sets 'Minor Version' (16 bits)
hw/i386/pc.c +5 -1
@@ -93,7 +93,11 @@#include "trace.h" #include CONFIG_DEVICES -GlobalProperty pc_compat_6_1[] = {}; +GlobalProperty pc_compat_6_1[] = { + {TYPE_X86_CPU ,"hv-version-id-build" ,"0x1bbc" }, + {TYPE_X86_CPU ,"hv-version-id-major" ,"0x0006" }, + {TYPE_X86_CPU ,"hv-version-id-minor" ,"0x0001" }, +};const size_t pc_compat_6_1_len =G_N_ELEMENTS (pc_compat_6_1);GlobalProperty pc_compat_6_0[] = {
target/i386/cpu.c +3 -3
@@ -6669,11 +6669,11 @@ static Property x86_cpu_properties[] = {/* WS2008R2 identify by default */ DEFINE_PROP_UINT32 ("hv-version-id-build" ,X86CPU , hyperv_ver_id_build, -0x1bbc ), +0x3839 ),DEFINE_PROP_UINT16 ("hv-version-id-major" ,X86CPU , hyperv_ver_id_major, -0x0006 ), +0x000A ),DEFINE_PROP_UINT16 ("hv-version-id-minor" ,X86CPU , hyperv_ver_id_minor, -0x0001 ), +0x0000 ),DEFINE_PROP_UINT32 ("hv-version-id-spack" ,X86CPU , hyperv_ver_id_sp,0 ),DEFINE_PROP_UINT8 ("hv-version-id-sbranch" ,X86CPU , hyperv_ver_id_sb,0 ), DEFINE_PROP_UINT32("hv-version-id-snumber", X86CPU, hyperv_ver_id_sn, 0),
Signature · 1 line
2.31.1
Quoted 6 lines · Vitaly Kuznetsov
This is a continuation of "[PATCH 0/3] i386/kvm: Paravirtualized features usage enforcement" series, thus v2.
This series implements several unrelated features but as there are code dependencies between them I'm sending it as one series.
Quoted 8 lines
PATCH1 adds empty 6.2 machine types and the required compat infrastructure (to be used by PATCH8)
PATCH2 adds documentation for KVM PV features
PATCH3 adds support forKVM_CAP_ENFORCE_PV_FEATURE_CPUIDPATCH4 adds support forKVM_CAP_HYPERV_ENFORCE_CPUIDPATCHes5-6 add 'hv-avic' feature
PATCH7 makes Hyper-V version info settable
PATCH8 changes the default Hyper-V version to 2016
Eduardo, Paolo, all,
any comments? It seems patches can still be applied to 'master' with no issues.
Signature · 1 line
Vitaly
Paolo Bonzini
AppliedQuoted 39 lines · Vitaly Kuznetsov
This is a continuation of "[PATCH 0/3] i386/kvm: Paravirtualized features usage enforcement" series, thus v2.
This series implements several unrelated features but as there are code dependencies between them I'm sending it as one series.
PATCH1 adds empty 6.2 machine types and the required compat infrastructure (to be used by PATCH8)
PATCH2 adds documentation for KVM PV features
PATCH3 adds support forKVM_CAP_ENFORCE_PV_FEATURE_CPUIDPATCH4 adds support forKVM_CAP_HYPERV_ENFORCE_CPUIDPATCHes5-6 add 'hv-avic' feature
PATCH7 makes Hyper-V version info settable
PATCH8 changes the default Hyper-V version to 2016Vitaly Kuznetsov (8):
i386: Add 6.2 machine types
i386: docs: Briefly describe KVM PV features
i386: SupportKVM_CAP_ENFORCE_PV_FEATURE_CPUID
i386: SupportKVM_CAP_HYPERV_ENFORCE_CPUID
i386: MoveHV_APIC_ACCESS_RECOMMENDEDbit setting to
hyperv_fill_cpuids()
i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment
i386: Make Hyper-V version id configurable
i386: Change the default Hyper-V version to match WS2016docs/hyperv.txt | 41 +++++++++++-- docs/kvm-pv.txt | 103 +++++++++++++++++++++++++++++++++ hw/core/machine.c | 3 + hw/i386/pc.c | 7 +++ hw/i386/pc_piix.c | 14 ++++- hw/i386/pc_q35.c | 13 ++++- include/hw/boards.h | 3 + include/hw/i386/pc.h | 3 + target/i386/cpu.c | 22 +++++-- target/i386/cpu.h | 12 +++- target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 62 +++++++++++++++----- 12 files changed, 260 insertions(+), 24 deletions(-)
Quoted 2 lines
create mode 100644
docs/kvm-pv.txt
Queued patches 3-8, thanks.
Paolo
Quoted 43 lines · Paolo Bonzini
Quoted 39 lines · Vitaly Kuznetsov
This is a continuation of "[PATCH 0/3] i386/kvm: Paravirtualized features usage enforcement" series, thus v2.
This series implements several unrelated features but as there are code dependencies between them I'm sending it as one series.
PATCH1 adds empty 6.2 machine types and the required compat infrastructure (to be used by PATCH8)
PATCH2 adds documentation for KVM PV features
PATCH3 adds support forKVM_CAP_ENFORCE_PV_FEATURE_CPUIDPATCH4 adds support forKVM_CAP_HYPERV_ENFORCE_CPUIDPATCHes5-6 add 'hv-avic' feature
PATCH7 makes Hyper-V version info settable
PATCH8 changes the default Hyper-V version to 2016Vitaly Kuznetsov (8):
i386: Add 6.2 machine types
i386: docs: Briefly describe KVM PV features
i386: SupportKVM_CAP_ENFORCE_PV_FEATURE_CPUID
i386: SupportKVM_CAP_HYPERV_ENFORCE_CPUID
i386: MoveHV_APIC_ACCESS_RECOMMENDEDbit setting to
hyperv_fill_cpuids()
i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment
i386: Make Hyper-V version id configurable
i386: Change the default Hyper-V version to match WS2016docs/hyperv.txt | 41 +++++++++++-- docs/kvm-pv.txt | 103 +++++++++++++++++++++++++++++++++ hw/core/machine.c | 3 + hw/i386/pc.c | 7 +++ hw/i386/pc_piix.c | 14 ++++- hw/i386/pc_q35.c | 13 ++++- include/hw/boards.h | 3 + include/hw/i386/pc.h | 3 + target/i386/cpu.c | 22 +++++-- target/i386/cpu.h | 12 +++- target/i386/kvm/hyperv-proto.h | 1 + target/i386/kvm/kvm.c | 62 +++++++++++++++----- 12 files changed, 260 insertions(+), 24 deletions(-)Quoted 2 lines
create mode 100644
docs/kvm-pv.txt
Quoted 1 line
Queued patches 3-8, thanks.
Patch3 with the hunk to docs/kvm-pv.txt dropped I suppose (as PATCH2 introducing the file is not queued)? I can include it in the next submission then.
Thanks!
Signature · 1 line
Vitaly