linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS
@ 2019-01-17 17:12 Vitaly Kuznetsov
  2019-01-17 17:12 ` [PATCH 1/2] x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly Vitaly Kuznetsov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2019-01-17 17:12 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Radim Krčmář, linux-kernel, Liran Alon

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(-)

-- 
2.20.1


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

* [PATCH 1/2] x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly
  2019-01-17 17:12 [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Vitaly Kuznetsov
@ 2019-01-17 17:12 ` Vitaly Kuznetsov
  2019-01-17 17:12 ` [PATCH 2/2] KVM: selftests: check returned evmcs version range Vitaly Kuznetsov
  2019-01-25 17:50 ` [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2019-01-17 17:12 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Radim Krčmář, linux-kernel, Liran Alon

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")
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/vmx/evmcs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c
index 95bc2247478d..5466c6d85cf3 100644
--- a/arch/x86/kvm/vmx/evmcs.c
+++ b/arch/x86/kvm/vmx/evmcs.c
@@ -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;
-- 
2.20.1


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

* [PATCH 2/2] KVM: selftests: check returned evmcs version range
  2019-01-17 17:12 [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Vitaly Kuznetsov
  2019-01-17 17:12 ` [PATCH 1/2] x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly Vitaly Kuznetsov
@ 2019-01-17 17:12 ` Vitaly Kuznetsov
  2019-01-25 17:50 ` [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2019-01-17 17:12 UTC (permalink / raw)
  To: kvm; +Cc: Paolo Bonzini, Radim Krčmář, linux-kernel, Liran Alon

Check that KVM_CAP_HYPERV_ENLIGHTENED_VMCS returns correct version range.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 tools/testing/selftests/kvm/x86_64/evmcs_test.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
index ea3c73e8f4f6..c49c2a28b0eb 100644
--- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c
+++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c
@@ -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);
-- 
2.20.1


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

* Re: [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS
  2019-01-17 17:12 [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Vitaly Kuznetsov
  2019-01-17 17:12 ` [PATCH 1/2] x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly Vitaly Kuznetsov
  2019-01-17 17:12 ` [PATCH 2/2] KVM: selftests: check returned evmcs version range Vitaly Kuznetsov
@ 2019-01-25 17:50 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2019-01-25 17:50 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Radim Krčmář, linux-kernel, Liran Alon

On 17/01/19 18:12, Vitaly Kuznetsov wrote:
> 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(-)
> 


Queued, thanks.

Paolo

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

end of thread, other threads:[~2019-01-25 17:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-17 17:12 [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Vitaly Kuznetsov
2019-01-17 17:12 ` [PATCH 1/2] x86/kvm/hyper-v: nested_enable_evmcs() sets vmcs_version incorrectly Vitaly Kuznetsov
2019-01-17 17:12 ` [PATCH 2/2] KVM: selftests: check returned evmcs version range Vitaly Kuznetsov
2019-01-25 17:50 ` [PATCH 0/2] x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).