Skip to contentSkip to conversation

KVM: x86: don't announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS when it is unavailable

PATCH Applied Vitaly Kuznetsov 3 participants 5 messages Aug 28, 2019 – Sep 17, 2019

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

v2 cover KVM: x86: don't announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS when it is unavailable

It was discovered that hyperv_cpuid test now fails on AMD as it tries to enable KVM_CAP_HYPERV_ENLIGHTENED_VMCS which is (wrongfully) reported as available.

Changes since v1:
- This is a v2 for '[PATCH 0/3] KVM: x86: fix a couple of issues with Enlightened VMCS enablement' renamed as the first patch of the series was already merged.
- Added Jim's Reviewed-by: to PATCH1
- Added missing break in PATCH2 [Jim Mattson, Sean Christopherson]

Vitaly Kuznetsov (2):
KVM: x86: svm: remove unneeded nested_enable_evmcs() hook
KVM: x86: announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support only when
it is available

 arch/x86/kvm/svm.c | 9 +--------
 arch/x86/kvm/x86.c | 4 +++-
 2 files changed, 4 insertions(+), 9 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/2 KVM: x86: svm: remove unneeded nested_enable_evmcs() hook

Since commit 5158917c7b019 ("KVM: x86: nVMX: Allow nested_enable_evmcs to be NULL") the code in x86.c is prepared to see nested_enable_evmcs being NULL and in VMX case it actually is when nesting is disabled. Remove the unneeded stub from SVM code.

---
 arch/x86/kvm/svm.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
arch/x86/kvm/svm.c +1 -8
index 40175c42f116..6d52c65d625b 100644
@@ -7122,13 +7122,6 @@ static int svm_unregister_enc_region(struct kvm *kvm,
 	return ret;
 }
 
-static int nested_enable_evmcs(struct kvm_vcpu *vcpu,
-				   uint16_t *vmcs_version)
-{
-	/* Intel-only feature */
-	return -ENODEV;
-}
-
 static bool svm_need_emulation_on_page_fault(struct kvm_vcpu *vcpu)
 {
 	unsigned long cr4 = kvm_read_cr4(vcpu);
@@ -7337,7 +7330,7 @@ static struct kvm_x86_ops svm_x86_ops __ro_after_init = {
 	.mem_enc_reg_region = svm_register_enc_region,
 	.mem_enc_unreg_region = svm_unregister_enc_region,
 
-	.nested_enable_evmcs = nested_enable_evmcs,
+	.nested_enable_evmcs = NULL,
 	.nested_get_evmcs_version = NULL,
 
 	.need_emulation_on_page_fault = svm_need_emulation_on_page_fault,
Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/2 KVM: x86: announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support only when it is available

In reply to Vitaly Kuznetsov

It was discovered that after commit 65efa61dc0d5 ("selftests: kvm: provide common function to enable eVMCS") hyperv_cpuid selftest is failing on AMD. The reason is that the commit changed _vcpu_ioctl() to vcpu_ioctl() in the test and this one can't fail.

Instead of fixing the test is seems to make more sense to not announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support if it is definitely missing (on svm and in case kvm_intel.nested=0).

---
 arch/x86/kvm/x86.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +3 -1
index d1cd0fcff9e7..149511f47377 100644
@@ -3106,7 +3106,6 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 	case KVM_CAP_HYPERV_EVENTFD:
 	case KVM_CAP_HYPERV_TLBFLUSH:
 	case KVM_CAP_HYPERV_SEND_IPI:
-	case KVM_CAP_HYPERV_ENLIGHTENED_VMCS:
 	case KVM_CAP_HYPERV_CPUID:
 	case KVM_CAP_PCI_SEGMENT:
 	case KVM_CAP_DEBUGREGS:
@@ -3183,6 +3182,9 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		r = kvm_x86_ops->get_nested_state ?
 			kvm_x86_ops->get_nested_state(NULL, NULL, 0) : 0;
 		break;
+	case KVM_CAP_HYPERV_ENLIGHTENED_VMCS:
+		r = kvm_x86_ops->nested_enable_evmcs != NULL;
+		break;
 	default:
 		break;
 	}
Signature · 1 line
2.20.1
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] KVM: x86: announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support only when it is available

Quoted 11 lines · Vitaly Kuznetsov

It was discovered that after commit 65efa61dc0d5 ("selftests: kvm: provide common function to enable eVMCS") hyperv_cpuid selftest is failing on AMD. The reason is that the commit changed _vcpu_ioctl() to vcpu_ioctl() in the test and this one can't fail.

Instead of fixing the test is seems to make more sense to not announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support if it is definitely missing (on svm and in case kvm_intel.nested=0).

maintainer Applied
#4 lore raw
In reply to Vitaly Kuznetsov
Quoted 11 lines · Vitaly Kuznetsov

It was discovered that hyperv_cpuid test now fails on AMD as it tries to enable KVM_CAP_HYPERV_ENLIGHTENED_VMCS which is (wrongfully) reported as available.

Changes since v1:
- This is a v2 for '[PATCH 0/3] KVM: x86: fix a couple of issues with Enlightened VMCS enablement' renamed as the first patch of the series was already merged.
- Added Jim's Reviewed-by: to PATCH1
- Added missing break in PATCH2 [Jim Mattson, Sean Christopherson]

Quoted 9 lines

Vitaly Kuznetsov (2):
KVM: x86: svm: remove unneeded nested_enable_evmcs() hook
KVM: x86: announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support only when
it is available

 arch/x86/kvm/svm.c | 9 +--------
 arch/x86/kvm/x86.c | 4 +++-
 2 files changed, 4 insertions(+), 9 deletions(-)

Queued, thanks.

Paolo