x86/kvm/hyper-v: fix KVM_CAP_HYPERV_ENLIGHTENED_VMCS
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
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().
--- arch/x86/kvm/vmx/evmcs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/x86/kvm/vmx/evmcs.c +4 -3
@@ -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
PATCH 2/2 KVM: selftests: check returned evmcs version range
In reply to Vitaly KuznetsovCheck 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
@@ -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 , ®s1);
Signature · 1 line
2.20.1
Quoted 7 lines · Vitaly Kuznetsov
Commit
e2e871ab2f02("x86/kvm/hyper-v: Introducenested_get_evmcs_version()helper") brokeKVM_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()setsvmcs_versionincorrectly
KVM: selftests: check returned evmcs version rangearch/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