Skip to contentSkip to conversation

x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS

PATCH Applied Vitaly Kuznetsov 2 participants 4 messages Jan 17, 2019 – Jan 25, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS

Commit e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper") broke KVM_CAP_HYPERV_ENLIGHTENED_VMCS: the returned evmcs version is always zero now. Fix the issue and add a check to evmcs selftest.

The offending commit is in 5.0-rc1, it would be great if the fix could be queued before 5.0.

Vitaly Kuznetsov (2):
x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly
KVM: selftests: check returned evmcs version range

 arch/x86/kvm/vmx/evmcs.c                        | 7 ++++---
 tools/testing/selftests/kvm/x86_64/evmcs_test.c | 6 ++++++
 2 files changed, 10 insertions(+), 3 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly

Commit e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper") broke EVMCS enablement: to set vmcs_version we now call nested_get_evmcs_version() but this function checks enlightened_vmcs_enabled flag which is not yet set so we end up returning zero.

Fix the issue by re-arranging things in nested_enable_evmcs().

Fixes e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper")
---
 arch/x86/kvm/vmx/evmcs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/evmcs.c +4 -3
index 95bc2247478d..5466c6d85cf3 100644
@@ -332,16 +332,17 @@ int nested_enable_evmcs(struct kvm_vcpu *vcpu,
 			uint16_t *vmcs_version)
 {
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
+	bool evmcs_already_enabled = vmx->nested.enlightened_vmcs_enabled;
+
+	vmx->nested.enlightened_vmcs_enabled = true;
 
 	if (vmcs_version)
 		*vmcs_version = nested_get_evmcs_version(vcpu);
 
 	/* We don't support disabling the feature for simplicity. */
-	if (vmx->nested.enlightened_vmcs_enabled)
+	if (evmcs_already_enabled)
 		return 0;
 
-	vmx->nested.enlightened_vmcs_enabled = true;
-
 	vmx->nested.msrs.pinbased_ctls_high &= ~EVMCS1_UNSUPPORTED_PINCTRL;
 	vmx->nested.msrs.entry_ctls_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
 	vmx->nested.msrs.exit_ctls_high &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 KVM: selftests: check returned evmcs version range

In reply to Vitaly Kuznetsov

Check that KVM_CAP_HYPERV_ENLIGHTENED_VMCS returns correct version range.

---
 tools/testing/selftests/kvm/x86_64/evmcs_test.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/testing/selftests/kvm/x86_64/evmcs_test.c +6 -0
index ea3c73e8f4f6..c49c2a28b0eb 100644
@@ -103,6 +103,12 @@ int main(int argc, char *argv[])
 
 	vcpu_ioctl(vm, VCPU_ID, KVM_ENABLE_CAP, &enable_evmcs_cap);
 
+	/* KVM should return supported EVMCS version range */
+	TEST_ASSERT(((evmcs_ver >> 8) >= (evmcs_ver & 0xff)) &&
+		    (evmcs_ver & 0xff) > 0,
+		    "Incorrect EVMCS version range: %x:%x\n",
+		    evmcs_ver & 0xff, evmcs_ver >> 8);
+
 	run = vcpu_state(vm, VCPU_ID);
 
 	vcpu_regs_get(vm, VCPU_ID, &regs1);
Signature · 1 line
2.20.1
maintainer Applied
#3 lore raw
In reply to Vitaly Kuznetsov
Quoted 7 lines · Vitaly Kuznetsov

Commit e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper") broke KVM_CAP_HYPERV_ENLIGHTENED_VMCS: the returned evmcs version is always zero now. Fix the issue and add a check to evmcs selftest.

The offending commit is in 5.0-rc1, it would be great if the fix could be queued before 5.0.

Quoted 8 lines

Vitaly Kuznetsov (2):
x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly
KVM: selftests: check returned evmcs version range

 arch/x86/kvm/vmx/evmcs.c                        | 7 ++++---
 tools/testing/selftests/kvm/x86_64/evmcs_test.c | 6 ++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

Queued, thanks.

Paolo