All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements
@ 2021-09-02  9:35 Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 1/8] i386: Add 6.2 machine types Vitaly Kuznetsov
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

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

-- 
2.31.1



^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/8] i386: Add 6.2 machine types
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features Vitaly Kuznetsov
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

Introduce 6.2 machine types and the required infrastructure for adding
compat properties to pre-6.2 machine types.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/hw/core/machine.c b/hw/core/machine.c
index 54e040587dd3..9d0d1194e1ef 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -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"},
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 102b22394689..1276bfeee456 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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" },
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 1bc30167acc0..c5da7739cef7 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -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);
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index eeb0b185b118..565fadce540c 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -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);
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index accd6eff35ab..463a5514f97d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -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;
 
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 88dffe751724..97b4ab79b534 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -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;
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 1/8] i386: Add 6.2 machine types Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-29 15:26   ` Paolo Bonzini
  2021-09-02  9:35 ` [PATCH v2 3/8] i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID Vitaly Kuznetsov
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

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 <vkuznets@redhat.com>
---
 docs/kvm-pv.txt | 92 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
 create mode 100644 docs/kvm-pv.txt

diff --git a/docs/kvm-pv.txt b/docs/kvm-pv.txt
new file mode 100644
index 000000000000..84ad7fa60f8d
--- /dev/null
+++ b/docs/kvm-pv.txt
@@ -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.
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/8] i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 1/8] i386: Add 6.2 machine types Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 4/8] i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID Vitaly Kuznetsov
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

By 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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/docs/kvm-pv.txt b/docs/kvm-pv.txt
index 84ad7fa60f8d..d1aac533feea 100644
--- a/docs/kvm-pv.txt
+++ b/docs/kvm-pv.txt
@@ -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.
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 97e250e8760d..a70038f172d9 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 6c50d3ab4f1d..20273a8069dd 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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;
 
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 500d2e0e686f..49f97f345069 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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);
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/8] i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (2 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 3/8] i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 5/8] i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to hyperv_fill_cpuids() Vitaly Kuznetsov
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

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. The feature is supported by Linux >= 5.14 and is
not enabled by default in QEMU.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/docs/hyperv.txt b/docs/hyperv.txt
index 000638a2fd38..072709a68f47 100644
--- a/docs/hyperv.txt
+++ b/docs/hyperv.txt
@@ -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
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index a70038f172d9..36e1b6ec9c9b 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 20273a8069dd..8822bea5c9a4 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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;
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 49f97f345069..bd0b53416315 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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;
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/8] i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to hyperv_fill_cpuids()
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (3 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 4/8] i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 6/8] i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment Vitaly Kuznetsov
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

In 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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 target/i386/kvm/kvm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index bd0b53416315..430007c2691a 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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) {
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 6/8] i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (4 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 5/8] i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to hyperv_fill_cpuids() Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 7/8] i386: Make Hyper-V version id configurable Vitaly Kuznetsov
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

The 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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/docs/hyperv.txt b/docs/hyperv.txt
index 072709a68f47..cd1ea3bbe9d7 100644
--- a/docs/hyperv.txt
+++ b/docs/hyperv.txt
@@ -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
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 36e1b6ec9c9b..a695e200d409 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 8822bea5c9a4..d22a8d259967 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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
diff --git a/target/i386/kvm/hyperv-proto.h b/target/i386/kvm/hyperv-proto.h
index 5fbb385cc136..89f81afda7c6 100644
--- a/target/i386/kvm/hyperv-proto.h
+++ b/target/i386/kvm/hyperv-proto.h
@@ -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)
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 430007c2691a..0f3cb61a9cfd 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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;
     }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 7/8] i386: Make Hyper-V version id configurable
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (5 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 6/8] i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-02  9:35 ` [PATCH v2 8/8] i386: Change the default Hyper-V version to match WS2016 Vitaly Kuznetsov
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

Currently, 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

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 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(-)

diff --git a/docs/hyperv.txt b/docs/hyperv.txt
index cd1ea3bbe9d7..7803495468b7 100644
--- a/docs/hyperv.txt
+++ b/docs/hyperv.txt
@@ -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
 =========================
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index a695e200d409..5766e720093d 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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),
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index d22a8d259967..5c2bf1079745 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -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;
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index 0f3cb61a9cfd..918472905e73 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -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;
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 8/8] i386: Change the default Hyper-V version to match WS2016
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (6 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 7/8] i386: Make Hyper-V version id configurable Vitaly Kuznetsov
@ 2021-09-02  9:35 ` Vitaly Kuznetsov
  2021-09-17  8:17 ` [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
  2021-09-29 15:29 ` Paolo Bonzini
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-02  9:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Eduardo Habkost, Marcelo Tosatti, Maxim Levitsky,
	Vadim Rozenfeld, Igor Mammedov, Paolo Bonzini

KVM 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.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 docs/hyperv.txt   | 2 +-
 hw/i386/pc.c      | 6 +++++-
 target/i386/cpu.c | 6 +++---
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/docs/hyperv.txt b/docs/hyperv.txt
index 7803495468b7..5d99fd9a72b8 100644
--- a/docs/hyperv.txt
+++ b/docs/hyperv.txt
@@ -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)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 1276bfeee456..b2e4eef9d211 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -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[] = {
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 5766e720093d..569840deaf93 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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),
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (7 preceding siblings ...)
  2021-09-02  9:35 ` [PATCH v2 8/8] i386: Change the default Hyper-V version to match WS2016 Vitaly Kuznetsov
@ 2021-09-17  8:17 ` Vitaly Kuznetsov
  2021-09-29 15:29 ` Paolo Bonzini
  9 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-17  8:17 UTC (permalink / raw)
  To: Eduardo Habkost, Paolo Bonzini
  Cc: Igor Mammedov, Vadim Rozenfeld, Marcelo Tosatti, qemu-devel,
	Maxim Levitsky

Vitaly Kuznetsov <vkuznets@redhat.com> writes:

> 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

Eduardo, Paolo, all,

any comments? It seems patches can still be applied to 'master' with no
issues.

-- 
Vitaly



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features
  2021-09-02  9:35 ` [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features Vitaly Kuznetsov
@ 2021-09-29 15:26   ` Paolo Bonzini
  0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2021-09-29 15:26 UTC (permalink / raw)
  To: Vitaly Kuznetsov, qemu-devel
  Cc: Igor Mammedov, Vadim Rozenfeld, Marcelo Tosatti, Eduardo Habkost,
	Maxim Levitsky

On 02/09/21 11:35, Vitaly Kuznetsov wrote:
> 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 <vkuznets@redhat.com>
> ---
>   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).

> diff --git a/docs/kvm-pv.txt b/docs/kvm-pv.txt
> new file mode 100644
> index 000000000000..84ad7fa60f8d
> --- /dev/null
> +++ b/docs/kvm-pv.txt
> @@ -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

> +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.

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

> +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.
> 



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements
  2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
                   ` (8 preceding siblings ...)
  2021-09-17  8:17 ` [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
@ 2021-09-29 15:29 ` Paolo Bonzini
  2021-09-30  8:09   ` Vitaly Kuznetsov
  9 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2021-09-29 15:29 UTC (permalink / raw)
  To: Vitaly Kuznetsov, qemu-devel
  Cc: Igor Mammedov, Vadim Rozenfeld, Marcelo Tosatti, Eduardo Habkost,
	Maxim Levitsky

On 02/09/21 11:35, Vitaly Kuznetsov wrote:
> 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
> 

Queued patches 3-8, thanks.

Paolo



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements
  2021-09-29 15:29 ` Paolo Bonzini
@ 2021-09-30  8:09   ` Vitaly Kuznetsov
  0 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2021-09-30  8:09 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: Igor Mammedov, Vadim Rozenfeld, Marcelo Tosatti, Eduardo Habkost,
	Maxim Levitsky

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 02/09/21 11:35, Vitaly Kuznetsov wrote:
>> 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
>> 
>
> 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!

-- 
Vitaly



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-09-30  8:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02  9:35 [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 1/8] i386: Add 6.2 machine types Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 2/8] i386: docs: Briefly describe KVM PV features Vitaly Kuznetsov
2021-09-29 15:26   ` Paolo Bonzini
2021-09-02  9:35 ` [PATCH v2 3/8] i386: Support KVM_CAP_ENFORCE_PV_FEATURE_CPUID Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 4/8] i386: Support KVM_CAP_HYPERV_ENFORCE_CPUID Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 5/8] i386: Move HV_APIC_ACCESS_RECOMMENDED bit setting to hyperv_fill_cpuids() Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 6/8] i386: Implement pseudo 'hv-avic' ('hv-apicv') enlightenment Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 7/8] i386: Make Hyper-V version id configurable Vitaly Kuznetsov
2021-09-02  9:35 ` [PATCH v2 8/8] i386: Change the default Hyper-V version to match WS2016 Vitaly Kuznetsov
2021-09-17  8:17 ` [PATCH v2 0/8] i386: Assorted KVM PV and Hyper-V feature improvements Vitaly Kuznetsov
2021-09-29 15:29 ` Paolo Bonzini
2021-09-30  8:09   ` Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.