Skip to contentSkip to conversation

KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID

PATCH In review Wanpeng Li 5 participants 13 messages Oct 22, 2020 – Oct 23, 2020

Subsystems (3)
lore
Share & tools
lore

Wanpeng Li

author
#0 lore raw

PATCH 1/1 KVM: X86: Expose KVM_HINTS_REALTIME in KVM_GET_SUPPORTED_CPUID

From: Wanpeng Li <[email protected]>

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.

---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/cpuid.c +1 -1
index 06a278b..225d251 100644
@@ -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);
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 11 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

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

#2 lore raw
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

Quoted 7 lines

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.

Signature · 1 line
Vitaly
#3 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

Quoted 8 lines
Quoted 4 lines

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

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"

Quoted 5 lines

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

Paolo

maintainer
#4 lore raw
Quoted 8 lines · Xiaoyao Li
Quoted 4 lines

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

#5 lore raw
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · Xiaoyao Li
Quoted 4 lines

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.

Quoted 6 lines
Quoted 3 lines

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?

Quoted 2 lines

Paolo

maintainer
#6 lore raw
Quoted 11 lines · Xiaoyao Li
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines · Xiaoyao Li
Quoted 4 lines

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"

Quoted 5 lines
Quoted 2 lines

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

#7 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini
Quoted 7 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

Quoted 8 lines
Quoted 4 lines

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

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

Quoted 4 lines

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

Paolo

maintainer
#8 lore raw
Quoted 12 lines · Jim Mattson
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

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

#9 lore raw
Quoted 21 lines · Paolo Bonzini
Quoted 19 lines · Jim Mattson
Quoted 17 lines · Paolo Bonzini
Quoted 11 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

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.

Quoted 9 lines
Quoted 1 line

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?

maintainer
#10 lore raw
Quoted 4 lines · Jim Mattson

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

#11 lore raw
Quoted 7 lines · Paolo Bonzini
Quoted 4 lines · Jim Mattson

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?

Quoted 6 lines

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.

author
#12 lore raw
In reply to Paolo Bonzini
Quoted 14 lines · Paolo Bonzini
Quoted 11 lines · Wanpeng Li

From: Wanpeng Li <[email protected]>

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.

Quoted 6 lines

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