kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
@ 2020-10-22  1:34 Wanpeng Li
  2020-10-22 13:02 ` Paolo Bonzini
  0 siblings, 1 reply; 13+ messages in thread
From: Wanpeng Li @ 2020-10-22  1:34 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

Per KVM_GET_SUPPORTED_CPUID ioctl documentation:

This ioctl returns x86 cpuid features which are supported by both the 
hardware and kvm in its default configuration.

A well-behaved userspace should not set the bit if it is not supported.

Suggested-by: Jim Mattson <jmattson@google.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 06a278b..225d251 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -789,7 +789,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 
 		entry->ebx = 0;
 		entry->ecx = 0;
-		entry->edx = 0;
+		entry->edx = (1 << KVM_HINTS_REALTIME);
 		break;
 	case 0x80000000:
 		entry->eax = min(entry->eax, 0x8000001f);
-- 
2.7.4


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22  1:34 [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID Wanpeng Li
@ 2020-10-22 13:02 ` Paolo Bonzini
  2020-10-22 13:25   ` Vitaly Kuznetsov
                     ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Paolo Bonzini @ 2020-10-22 13:02 UTC (permalink / raw)
  To: Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 22/10/20 03:34, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
> 
> This ioctl returns x86 cpuid features which are supported by both the 
> hardware and kvm in its default configuration.
> 
> A well-behaved userspace should not set the bit if it is not supported.
> 
> Suggested-by: Jim Mattson <jmattson@google.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>

It's common for userspace to copy all supported CPUID bits to
KVM_SET_CPUID2, I don't think this is the right behavior for
KVM_HINTS_REALTIME.

(But maybe this was discussed already; if so, please point me to the
previous discussion).

Paolo


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 13:02 ` Paolo Bonzini
@ 2020-10-22 13:25   ` Vitaly Kuznetsov
  2020-10-22 13:31   ` Xiaoyao Li
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Vitaly Kuznetsov @ 2020-10-22 13:25 UTC (permalink / raw)
  To: Paolo Bonzini, Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, Joerg Roedel

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 22/10/20 03:34, Wanpeng Li wrote:
>> From: Wanpeng Li <wanpengli@tencent.com>
>> 
>> Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
>> 
>> This ioctl returns x86 cpuid features which are supported by both the 
>> hardware and kvm in its default configuration.
>> 
>> A well-behaved userspace should not set the bit if it is not supported.
>> 
>> Suggested-by: Jim Mattson <jmattson@google.com>
>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>
> It's common for userspace to copy all supported CPUID bits to
> KVM_SET_CPUID2, I don't think this is the right behavior for
> KVM_HINTS_REALTIME.
>
> (But maybe this was discussed already; if so, please point me to the
> previous discussion).
>

Not for KVM_GET_SUPPORTED_CPUID but for KVM_GET_SUPPORTED_HV_CPUID: just
copying all the bits blindly is incorrect as e.g. SYNIC needs to be
enabled with KVM_CAP_HYPERV_SYNIC[2]. KVM PV features also have
pre-requisites, e.g. KVM_ASYNC_PF_DELIVERY_AS_INT requires an irqchip so
again copy/paste may not work.

-- 
Vitaly


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 13:02 ` Paolo Bonzini
  2020-10-22 13:25   ` Vitaly Kuznetsov
@ 2020-10-22 13:31   ` Xiaoyao Li
  2020-10-22 14:06     ` Paolo Bonzini
  2020-10-22 16:35   ` Jim Mattson
  2020-10-23  0:27   ` Wanpeng Li
  3 siblings, 1 reply; 13+ messages in thread
From: Xiaoyao Li @ 2020-10-22 13:31 UTC (permalink / raw)
  To: Paolo Bonzini, Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 10/22/2020 9:02 PM, Paolo Bonzini wrote:
> On 22/10/20 03:34, Wanpeng Li wrote:
>> From: Wanpeng Li <wanpengli@tencent.com>
>>
>> Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
>>
>> This ioctl returns x86 cpuid features which are supported by both the
>> hardware and kvm in its default configuration.
>>
>> A well-behaved userspace should not set the bit if it is not supported.
>>
>> Suggested-by: Jim Mattson <jmattson@google.com>
>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> 
> It's common for userspace to copy all supported CPUID bits to
> KVM_SET_CPUID2, I don't think this is the right behavior for
> KVM_HINTS_REALTIME.

It reminds of X86_FEATURE_WAITPKG, which is added to supported CPUID 
recently as a fix but QEMU exposes it to guest only when "-overcommit 
cpu-pm"

> (But maybe this was discussed already; if so, please point me to the
> previous discussion).
> 
> Paolo
> 


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 13:31   ` Xiaoyao Li
@ 2020-10-22 14:06     ` Paolo Bonzini
  2020-10-22 14:28       ` Xiaoyao Li
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2020-10-22 14:06 UTC (permalink / raw)
  To: Xiaoyao Li, Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 22/10/20 15:31, Xiaoyao Li wrote:
>>
>> It's common for userspace to copy all supported CPUID bits to
>> KVM_SET_CPUID2, I don't think this is the right behavior for
>> KVM_HINTS_REALTIME.
> 
> It reminds of X86_FEATURE_WAITPKG, which is added to supported CPUID
> recently as a fix but QEMU exposes it to guest only when "-overcommit
> cpu-pm"

WAITPKG is not included in KVM_GET_SUPPORTED_CPUID either.  QEMU detects
it through the MSR_IA32_UMWAIT register.

Paolo


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 14:06     ` Paolo Bonzini
@ 2020-10-22 14:28       ` Xiaoyao Li
  2020-10-22 14:44         ` Paolo Bonzini
  0 siblings, 1 reply; 13+ messages in thread
From: Xiaoyao Li @ 2020-10-22 14:28 UTC (permalink / raw)
  To: Paolo Bonzini, Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 10/22/2020 10:06 PM, Paolo Bonzini wrote:
> On 22/10/20 15:31, Xiaoyao Li wrote:
>>>
>>> It's common for userspace to copy all supported CPUID bits to
>>> KVM_SET_CPUID2, I don't think this is the right behavior for
>>> KVM_HINTS_REALTIME.
>>
>> It reminds of X86_FEATURE_WAITPKG, which is added to supported CPUID
>> recently as a fix but QEMU exposes it to guest only when "-overcommit
>> cpu-pm"
> 
> WAITPKG is not included in KVM_GET_SUPPORTED_CPUID either.  QEMU detects
> it through the MSR_IA32_UMWAIT register.

Doesn't 0abcc8f65cc2 ("KVM: VMX: enable X86_FEATURE_WAITPKG in KVM 
capabilities") add WAITPKG to KVM_GET_SUPPORTED_CPUID?

> Paolo
> 


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 14:28       ` Xiaoyao Li
@ 2020-10-22 14:44         ` Paolo Bonzini
  0 siblings, 0 replies; 13+ messages in thread
From: Paolo Bonzini @ 2020-10-22 14:44 UTC (permalink / raw)
  To: Xiaoyao Li, Wanpeng Li, linux-kernel, kvm
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 22/10/20 16:28, Xiaoyao Li wrote:
> On 10/22/2020 10:06 PM, Paolo Bonzini wrote:
>> On 22/10/20 15:31, Xiaoyao Li wrote:
>>>>
>>>> It's common for userspace to copy all supported CPUID bits to
>>>> KVM_SET_CPUID2, I don't think this is the right behavior for
>>>> KVM_HINTS_REALTIME.
>>>
>>> It reminds of X86_FEATURE_WAITPKG, which is added to supported CPUID
>>> recently as a fix but QEMU exposes it to guest only when "-overcommit
>>> cpu-pm"
>>
>> WAITPKG is not included in KVM_GET_SUPPORTED_CPUID either.  QEMU detects
>> it through the MSR_IA32_UMWAIT register.
> 
> Doesn't 0abcc8f65cc2 ("KVM: VMX: enable X86_FEATURE_WAITPKG in KVM
> capabilities") add WAITPKG to KVM_GET_SUPPORTED_CPUID?

You're right, I shouldn't have checked only cpuid.c. :)

Still I think WAITPKG is different, because it's only for userspace and
it's always possible for userspace to do "for(;;)" and burn CPU.
KVM_HINTS_REALTIME is more similar to MONITOR, which is not set.

Paolo


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 13:02 ` Paolo Bonzini
  2020-10-22 13:25   ` Vitaly Kuznetsov
  2020-10-22 13:31   ` Xiaoyao Li
@ 2020-10-22 16:35   ` Jim Mattson
  2020-10-22 16:37     ` Paolo Bonzini
  2020-10-23  0:27   ` Wanpeng Li
  3 siblings, 1 reply; 13+ messages in thread
From: Jim Mattson @ 2020-10-22 16:35 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Wanpeng Li, LKML, kvm list, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Joerg Roedel

On Thu, Oct 22, 2020 at 6:02 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 22/10/20 03:34, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
> >
> > This ioctl returns x86 cpuid features which are supported by both the
> > hardware and kvm in its default configuration.
> >
> > A well-behaved userspace should not set the bit if it is not supported.
> >
> > Suggested-by: Jim Mattson <jmattson@google.com>
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>
> It's common for userspace to copy all supported CPUID bits to
> KVM_SET_CPUID2, I don't think this is the right behavior for
> KVM_HINTS_REALTIME.

That is not how the API is defined, but I'm sure you know that. :-)

> (But maybe this was discussed already; if so, please point me to the
> previous discussion).
>
> Paolo

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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 16:35   ` Jim Mattson
@ 2020-10-22 16:37     ` Paolo Bonzini
  2020-10-22 17:13       ` Jim Mattson
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2020-10-22 16:37 UTC (permalink / raw)
  To: Jim Mattson
  Cc: Wanpeng Li, LKML, kvm list, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Joerg Roedel

On 22/10/20 18:35, Jim Mattson wrote:
> On Thu, Oct 22, 2020 at 6:02 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 22/10/20 03:34, Wanpeng Li wrote:
>>> From: Wanpeng Li <wanpengli@tencent.com>
>>>
>>> Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
>>>
>>> This ioctl returns x86 cpuid features which are supported by both the
>>> hardware and kvm in its default configuration.
>>>
>>> A well-behaved userspace should not set the bit if it is not supported.
>>>
>>> Suggested-by: Jim Mattson <jmattson@google.com>
>>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>>
>> It's common for userspace to copy all supported CPUID bits to
>> KVM_SET_CPUID2, I don't think this is the right behavior for
>> KVM_HINTS_REALTIME.
> 
> That is not how the API is defined, but I'm sure you know that. :-)

Yes, though in my defense :) KVM_HINTS_REALTIME is not a property of the
kernel, it's a property of the environment that the guest runs in.  This
was the original reason to separate it from other feature bits in the
same leaf.

Paolo


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 16:37     ` Paolo Bonzini
@ 2020-10-22 17:13       ` Jim Mattson
  2020-10-23  9:07         ` Paolo Bonzini
  0 siblings, 1 reply; 13+ messages in thread
From: Jim Mattson @ 2020-10-22 17:13 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Wanpeng Li, LKML, kvm list, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Joerg Roedel

On Thu, Oct 22, 2020 at 9:37 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 22/10/20 18:35, Jim Mattson wrote:
> > On Thu, Oct 22, 2020 at 6:02 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
> >>
> >> On 22/10/20 03:34, Wanpeng Li wrote:
> >>> From: Wanpeng Li <wanpengli@tencent.com>
> >>>
> >>> Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
> >>>
> >>> This ioctl returns x86 cpuid features which are supported by both the
> >>> hardware and kvm in its default configuration.
> >>>
> >>> A well-behaved userspace should not set the bit if it is not supported.
> >>>
> >>> Suggested-by: Jim Mattson <jmattson@google.com>
> >>> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> >>
> >> It's common for userspace to copy all supported CPUID bits to
> >> KVM_SET_CPUID2, I don't think this is the right behavior for
> >> KVM_HINTS_REALTIME.
> >
> > That is not how the API is defined, but I'm sure you know that. :-)
>
> Yes, though in my defense :) KVM_HINTS_REALTIME is not a property of the
> kernel, it's a property of the environment that the guest runs in.  This
> was the original reason to separate it from other feature bits in the
> same leaf.
>
> Paolo
>
We don't actually use KVM_GET_SUPPORTED_CPUID at all today. If it's
commonly being misinterpreted as you say, perhaps we should add a
KVM_GET_TRUE_SUPPORTED_CPUID ioctl. Or, perhaps we can just fix this
in the documentation?

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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 13:02 ` Paolo Bonzini
                     ` (2 preceding siblings ...)
  2020-10-22 16:35   ` Jim Mattson
@ 2020-10-23  0:27   ` Wanpeng Li
  3 siblings, 0 replies; 13+ messages in thread
From: Wanpeng Li @ 2020-10-23  0:27 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: LKML, kvm, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

On Thu, 22 Oct 2020 at 21:02, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 22/10/20 03:34, Wanpeng Li wrote:
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Per KVM_GET_SUPPORTED_CPUID ioctl documentation:
> >
> > This ioctl returns x86 cpuid features which are supported by both the
> > hardware and kvm in its default configuration.
> >
> > A well-behaved userspace should not set the bit if it is not supported.
> >
> > Suggested-by: Jim Mattson <jmattson@google.com>
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
>
> It's common for userspace to copy all supported CPUID bits to
> KVM_SET_CPUID2, I don't think this is the right behavior for
> KVM_HINTS_REALTIME.
>
> (But maybe this was discussed already; if so, please point me to the
> previous discussion).

The discussion is here. :) https://www.spinics.net/lists/kvm/msg227265.html

    Wanpeng

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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-22 17:13       ` Jim Mattson
@ 2020-10-23  9:07         ` Paolo Bonzini
  2020-10-23 17:03           ` Jim Mattson
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2020-10-23  9:07 UTC (permalink / raw)
  To: Jim Mattson
  Cc: Wanpeng Li, LKML, kvm list, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Joerg Roedel

On 22/10/20 19:13, Jim Mattson wrote:
> We don't actually use KVM_GET_SUPPORTED_CPUID at all today. If it's
> commonly being misinterpreted as you say, perhaps we should add a
> KVM_GET_TRUE_SUPPORTED_CPUID ioctl. Or, perhaps we can just fix this
> in the documentation?

Yes, I think we should fix the documentation and document the best
practices around MSRs and CPUID bits.  Mostly documenting what QEMU
does, perhaps without all the quirks it has to support old kernels that
messed things up even more.

Paolo


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

* Re: [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID
  2020-10-23  9:07         ` Paolo Bonzini
@ 2020-10-23 17:03           ` Jim Mattson
  0 siblings, 0 replies; 13+ messages in thread
From: Jim Mattson @ 2020-10-23 17:03 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Wanpeng Li, LKML, kvm list, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Joerg Roedel

On Fri, Oct 23, 2020 at 2:07 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 22/10/20 19:13, Jim Mattson wrote:
> > We don't actually use KVM_GET_SUPPORTED_CPUID at all today. If it's
> > commonly being misinterpreted as you say, perhaps we should add a
> > KVM_GET_TRUE_SUPPORTED_CPUID ioctl. Or, perhaps we can just fix this
> > in the documentation?
>
> Yes, I think we should fix the documentation and document the best
> practices around MSRs and CPUID bits.  Mostly documenting what QEMU
> does, perhaps without all the quirks it has to support old kernels that
> messed things up even more.
>
> Paolo

I'd really like to be able to call an ioctl that will help me
determine whether the host can support the guest CPUID information
that I already have (e.g. on the target of a live migration). At first
glance, KVM_GET_SUPPORTED_CPUID appeared to be that ioctl. Sadly, it
appears that no such ioctl exists.

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

end of thread, other threads:[~2020-10-23 17:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-22  1:34 [PATCH] KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID Wanpeng Li
2020-10-22 13:02 ` Paolo Bonzini
2020-10-22 13:25   ` Vitaly Kuznetsov
2020-10-22 13:31   ` Xiaoyao Li
2020-10-22 14:06     ` Paolo Bonzini
2020-10-22 14:28       ` Xiaoyao Li
2020-10-22 14:44         ` Paolo Bonzini
2020-10-22 16:35   ` Jim Mattson
2020-10-22 16:37     ` Paolo Bonzini
2020-10-22 17:13       ` Jim Mattson
2020-10-23  9:07         ` Paolo Bonzini
2020-10-23 17:03           ` Jim Mattson
2020-10-23  0:27   ` Wanpeng Li

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