The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Cc: Anirudh Rayabharam <anrayabh@linux.microsoft.com>,
	Sean Christopherson <seanjc@google.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>,
	Maxim Levitsky <mlevitsk@redhat.com>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH QEMU EXAMPLE] i386: Support Enlightened VMCS revisions
Date: Tue, 21 Jun 2022 17:59:12 +0200	[thread overview]
Message-ID: <20220621155912.60245-1-vkuznets@redhat.com> (raw)
In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com>

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 docs/system/i386/hyperv.rst |  4 ++++
 linux-headers/linux/kvm.h   |  3 ++-
 target/i386/cpu.c           |  1 +
 target/i386/cpu.h           |  1 +
 target/i386/kvm/kvm.c       | 17 ++++++++++++++---
 5 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/docs/system/i386/hyperv.rst b/docs/system/i386/hyperv.rst
index 2505dc4c86e0..967acc6814f6 100644
--- a/docs/system/i386/hyperv.rst
+++ b/docs/system/i386/hyperv.rst
@@ -278,6 +278,10 @@ Supplementary features
   feature alters this behavior and only allows the guest to use exposed Hyper-V
   enlightenments.
 
+``hv-evmcs-rev={revision}``
+  When Enlightened VMCS definitinon changes, KVM increases the supported
+  'revision' to make live migration to older hosts possible. Note:
+ ``hv-passthrough`` mode enables the latest supported revision.
 
 Useful links
 ------------
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 0d05d02ee4fe..425ec0d636df 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1097,7 +1097,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_PPC_NESTED_HV 160
 #define KVM_CAP_HYPERV_SEND_IPI 161
 #define KVM_CAP_COALESCED_PIO 162
-#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163
+#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 /* Obsolete */
 #define KVM_CAP_EXCEPTION_PAYLOAD 164
 #define KVM_CAP_ARM_VM_IPA_SIZE 165
 #define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 /* Obsolete */
@@ -1150,6 +1150,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_DISABLE_QUIRKS2 213
 /* #define KVM_CAP_VM_TSC_CONTROL 214 */
 #define KVM_CAP_SYSTEM_EVENT_DATA 215
+#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 220
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 6a57ef13af86..0d8b43f570f8 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6994,6 +6994,7 @@ static Property x86_cpu_properties[] = {
                       HYPERV_FEAT_SYNDBG, 0),
     DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false),
     DEFINE_PROP_BOOL("hv-enforce-cpuid", X86CPU, hyperv_enforce_cpuid, false),
+    DEFINE_PROP_UINT32("hv-evmcs-rev", X86CPU, hyperv_evmcs_rev, 1),
 
     /* WS2008R2 identify by default */
     DEFINE_PROP_UINT32("hv-version-id-build", X86CPU, hyperv_ver_id_build,
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index 82004b65b944..d7a069703943 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1805,6 +1805,7 @@ struct ArchCPU {
     uint64_t hyperv_features;
     bool hyperv_passthrough;
     OnOffAuto hyperv_no_nonarch_cs;
+    uint32_t hyperv_evmcs_rev;
     uint32_t hyperv_vendor_id[3];
     uint32_t hyperv_interface_id[4];
     uint32_t hyperv_limits[3];
diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
index e5331662b63b..490fa4582f8c 100644
--- a/target/i386/kvm/kvm.c
+++ b/target/i386/kvm/kvm.c
@@ -1635,9 +1635,20 @@ static int hyperv_init_vcpu(X86CPU *cpu)
     if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) {
         uint16_t evmcs_version = DEFAULT_EVMCS_VERSION;
         uint16_t supported_evmcs_version;
-
-        ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0,
-                                  (uintptr_t)&supported_evmcs_version);
+        uint32_t evmcs_revision =
+            cpu->hyperv_passthrough ? UINT32_MAX : cpu->hyperv_evmcs_rev;
+
+        if (kvm_check_extension(cs->kvm_state,
+                                KVM_CAP_HYPERV_ENLIGHTENED_VMCS2)) {
+            ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS2, 0,
+                                      evmcs_revision,
+                                      (uintptr_t)&supported_evmcs_version);
+        } else if (cpu->hyperv_evmcs_rev == 1) {
+            ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0,
+                                      (uintptr_t)&supported_evmcs_version);
+        } else {
+            ret = -ENOTSUP;
+        }
 
         /*
          * KVM is required to support EVMCS ver.1. as that's what 'hv-evmcs'
-- 
2.35.3


      parent reply	other threads:[~2022-06-21 16:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21 15:58 [PATCH 00/11] KVM: VMX: Support TscScaling and EnclsExitingBitmap whith eVMCS Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 01/11] KVM: x86: hyper-v: Expose access to debug MSRs in the partition privilege flags Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 02/11] x86/hyperv: Fix 'struct hv_enlightened_vmcs' definition Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 03/11] x86/hyperv: Update " Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 04/11] KVM: VMX: Define VMCS-to-EVMCS conversion for the new fields Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 05/11] KVM: nVMX: Support several new fields in eVMCSv1 Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 06/11] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 07/11] KVM: selftests: Switch to KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 08/11] KVM: VMX: Support TSC scaling with enlightened VMCS Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 09/11] KVM: selftests: Add ENCLS_EXITING_BITMAP{,HIGH} VMCS fields Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 10/11] KVM: selftests: Switch to updated eVMCSv1 definition Vitaly Kuznetsov
2022-06-21 15:58 ` [PATCH 11/11] KVM: selftests: Enable TSC scaling in evmcs selftest Vitaly Kuznetsov
2022-06-21 15:59 ` Vitaly Kuznetsov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220621155912.60245-1-vkuznets@redhat.com \
    --to=vkuznets@redhat.com \
    --cc=anrayabh@linux.microsoft.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox