diff mbox series

[3/3] KVM: x86: announce KVM_CAP_HYPERV_ENLIGHTENED_VMCS support only when it is available

Message ID 20190827160404.14098-4-vkuznets@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: fix a couple of issues with Enlightened VMCS enablement | expand

Commit Message

Vitaly Kuznetsov Aug. 27, 2019, 4:04 p.m. UTC
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).

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/x86.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jim Mattson Aug. 27, 2019, 4:54 p.m. UTC | #1
On Tue, Aug 27, 2019 at 9:04 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>
> 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).
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/x86.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index d1cd0fcff9e7..ef2e8b138300 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -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,8 @@ 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;

You should probably have an explicit break here, in case someone later
adds another case below.

>         default:
>                 break;
>         }
> --
> 2.20.1
>
Sean Christopherson Aug. 27, 2019, 7:52 p.m. UTC | #2
On Tue, Aug 27, 2019 at 09:54:39AM -0700, Jim Mattson wrote:
> On Tue, Aug 27, 2019 at 9:04 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
> >
> > 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).
> >
> > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> > ---
> >  arch/x86/kvm/x86.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index d1cd0fcff9e7..ef2e8b138300 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -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,8 @@ 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;
> 
> You should probably have an explicit break here, in case someone later
> adds another case below.

Yep, this will trigger a warning on compilers with -Wimplicit-fallthrough.
Vitaly Kuznetsov Aug. 28, 2019, 7:30 a.m. UTC | #3
Sean Christopherson <sean.j.christopherson@intel.com> writes:

> On Tue, Aug 27, 2019 at 09:54:39AM -0700, Jim Mattson wrote:
>> On Tue, Aug 27, 2019 at 9:04 AM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>> >
>> > 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).
>> >
>> > Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
>> > ---
>> >  arch/x86/kvm/x86.c | 3 ++-
>> >  1 file changed, 2 insertions(+), 1 deletion(-)
>> >
>> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> > index d1cd0fcff9e7..ef2e8b138300 100644
>> > --- a/arch/x86/kvm/x86.c
>> > +++ b/arch/x86/kvm/x86.c
>> > @@ -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,8 @@ 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;
>> 
>> You should probably have an explicit break here, in case someone later
>> adds another case below.
>
> Yep, this will trigger a warning on compilers with -Wimplicit-fallthrough.

I always forget there's more than checkpatch.pl :-) Thanks you your
reviews guys, I'm going to send v2 of this patchset without PATCH1 which
was already queued by Radim.
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d1cd0fcff9e7..ef2e8b138300 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -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,8 @@  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;
 	default:
 		break;
 	}