]> git.itanic.dy.fi Git - linux-stable/commitdiff
KVM: selftests: Split off load_evmcs() from load_vmcs()
authorVitaly Kuznetsov <vkuznets@redhat.com>
Tue, 1 Nov 2022 14:54:19 +0000 (15:54 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 21 Nov 2022 11:40:42 +0000 (06:40 -0500)
In preparation to putting Hyper-V specific test pages to a dedicated
struct, move eVMCS load logic from load_vmcs(). Tests call load_vmcs()
directly and the only one which needs 'enlightened' version is
evmcs_test so there's not much gain in having this merged.

Temporary pass both GPA and HVA to load_evmcs().

Reviewed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221101145426.251680-42-vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/x86_64/evmcs.h
tools/testing/selftests/kvm/lib/x86_64/vmx.c
tools/testing/selftests/kvm/x86_64/evmcs_test.c

index 2530b5aeb4bae6d032ea1ae8d34c841639a292a6..59b60d45b8f6ae55f15df8fb4d02fe4f97f1b593 100644 (file)
@@ -256,6 +256,16 @@ static inline int evmcs_vmptrld(uint64_t vmcs_pa, void *vmcs)
        return 0;
 }
 
+static inline bool load_evmcs(uint64_t enlightened_vmcs_gpa, void *enlightened_vmcs)
+{
+       if (evmcs_vmptrld(enlightened_vmcs_gpa, enlightened_vmcs))
+               return false;
+
+       current_evmcs->revision_id = EVMCS_VERSION;
+
+       return true;
+}
+
 static inline int evmcs_vmptrst(uint64_t *value)
 {
        *value = current_vp_assist->current_nested_vmcs &
index 3e4ea846366cbadad29f72b13c0397cc5bdda6a6..318ee4658f0b91ef143a273dd675e777593905d6 100644 (file)
@@ -171,26 +171,18 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)
 
 bool load_vmcs(struct vmx_pages *vmx)
 {
-       if (!enable_evmcs) {
-               /* Load a VMCS. */
-               *(uint32_t *)(vmx->vmcs) = vmcs_revision();
-               if (vmclear(vmx->vmcs_gpa))
-                       return false;
-
-               if (vmptrld(vmx->vmcs_gpa))
-                       return false;
-
-               /* Setup shadow VMCS, do not load it yet. */
-               *(uint32_t *)(vmx->shadow_vmcs) =
-                       vmcs_revision() | 0x80000000ul;
-               if (vmclear(vmx->shadow_vmcs_gpa))
-                       return false;
-       } else {
-               if (evmcs_vmptrld(vmx->enlightened_vmcs_gpa,
-                                 vmx->enlightened_vmcs))
-                       return false;
-               current_evmcs->revision_id = EVMCS_VERSION;
-       }
+       /* Load a VMCS. */
+       *(uint32_t *)(vmx->vmcs) = vmcs_revision();
+       if (vmclear(vmx->vmcs_gpa))
+               return false;
+
+       if (vmptrld(vmx->vmcs_gpa))
+               return false;
+
+       /* Setup shadow VMCS, do not load it yet. */
+       *(uint32_t *)(vmx->shadow_vmcs) = vmcs_revision() | 0x80000000ul;
+       if (vmclear(vmx->shadow_vmcs_gpa))
+               return false;
 
        return true;
 }
index 9007fb04343bc0c7e6c9b8355e3ef804d07c127f..5a4c8b1873aab5001e7f05a1ab2e4dbb44815e57 100644 (file)
@@ -81,10 +81,10 @@ void guest_code(struct vmx_pages *vmx_pages)
        enable_vp_assist(vmx_pages->vp_assist_gpa, vmx_pages->vp_assist);
        evmcs_enable();
 
-       GUEST_ASSERT(vmx_pages->vmcs_gpa);
        GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
        GUEST_SYNC(3);
-       GUEST_ASSERT(load_vmcs(vmx_pages));
+       GUEST_ASSERT(load_evmcs(vmx_pages->enlightened_vmcs_gpa,
+                               vmx_pages->enlightened_vmcs));
        GUEST_ASSERT(vmptrstz() == vmx_pages->enlightened_vmcs_gpa);
 
        GUEST_SYNC(4);