Commit cd8f11bd authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Paolo Bonzini

KVM: selftests: Split off load_evmcs() from load_vmcs()

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: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Message-Id: <20221101145426.251680-42-vkuznets@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent e8f3d23c
...@@ -256,6 +256,16 @@ static inline int evmcs_vmptrld(uint64_t vmcs_pa, void *vmcs) ...@@ -256,6 +256,16 @@ static inline int evmcs_vmptrld(uint64_t vmcs_pa, void *vmcs)
return 0; 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) static inline int evmcs_vmptrst(uint64_t *value)
{ {
*value = current_vp_assist->current_nested_vmcs & *value = current_vp_assist->current_nested_vmcs &
......
...@@ -171,26 +171,18 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx) ...@@ -171,26 +171,18 @@ bool prepare_for_vmx_operation(struct vmx_pages *vmx)
bool load_vmcs(struct vmx_pages *vmx) bool load_vmcs(struct vmx_pages *vmx)
{ {
if (!enable_evmcs) { /* Load a VMCS. */
/* Load a VMCS. */ *(uint32_t *)(vmx->vmcs) = vmcs_revision();
*(uint32_t *)(vmx->vmcs) = vmcs_revision(); if (vmclear(vmx->vmcs_gpa))
if (vmclear(vmx->vmcs_gpa)) return false;
return false;
if (vmptrld(vmx->vmcs_gpa))
if (vmptrld(vmx->vmcs_gpa)) return false;
return false;
/* Setup shadow VMCS, do not load it yet. */
/* Setup shadow VMCS, do not load it yet. */ *(uint32_t *)(vmx->shadow_vmcs) = vmcs_revision() | 0x80000000ul;
*(uint32_t *)(vmx->shadow_vmcs) = if (vmclear(vmx->shadow_vmcs_gpa))
vmcs_revision() | 0x80000000ul; return false;
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;
}
return true; return true;
} }
......
...@@ -81,10 +81,10 @@ void guest_code(struct vmx_pages *vmx_pages) ...@@ -81,10 +81,10 @@ void guest_code(struct vmx_pages *vmx_pages)
enable_vp_assist(vmx_pages->vp_assist_gpa, vmx_pages->vp_assist); enable_vp_assist(vmx_pages->vp_assist_gpa, vmx_pages->vp_assist);
evmcs_enable(); evmcs_enable();
GUEST_ASSERT(vmx_pages->vmcs_gpa);
GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages)); GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages));
GUEST_SYNC(3); 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_ASSERT(vmptrstz() == vmx_pages->enlightened_vmcs_gpa);
GUEST_SYNC(4); GUEST_SYNC(4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment