* [PATCH] x86: properly handle KVM emulation of hyperv
@ 2013-07-19 10:25 Jason Wang
2013-07-19 12:10 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2013-07-19 10:25 UTC (permalink / raw)
To: gleb, pbonzini, tglx, mingo, hpa, x86, kvm, linux-kernel
Cc: Jason Wang, Vadim Rozenfeld, K. Y. Srinivasan
Recent kvm has some basic support of hyperv, this will cause the guest to
identify itself running on top of hyperv instead of kvm which will disable kvm
pv functionality. Solve this by check kvm para platform first and also check
KVM_CPUID_SIGNATURE_NEXT which were set when kvm emulate hyperv.
Cc: Gleb Natapov <gleb@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Vadim Rozenfeld <vrozenfe@redhat.com>
Cc: K. Y. Srinivasan <kys@microsoft.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
arch/x86/include/asm/kvm_para.h | 25 +++++++++++++++++--------
arch/x86/include/uapi/asm/kvm_para.h | 1 +
arch/x86/kernel/cpu/hypervisor.c | 2 +-
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index 695399f..aa8f3a7 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -85,22 +85,31 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
return ret;
}
-static inline bool kvm_para_available(void)
+static inline bool kvm_para_available_function(unsigned int function)
{
unsigned int eax, ebx, ecx, edx;
char signature[13];
+ cpuid(function, &eax, &ebx, &ecx, &edx);
+ memcpy(signature + 0, &ebx, 4);
+ memcpy(signature + 4, &ecx, 4);
+ memcpy(signature + 8, &edx, 4);
+ signature[12] = 0;
+
+ if (strcmp(signature, "KVMKVMKVM") == 0)
+ return true;
+
+ return false;
+}
+
+static inline bool kvm_para_available(void)
+{
if (boot_cpu_data.cpuid_level < 0)
return false; /* So we don't blow up on old processors */
if (cpu_has_hypervisor) {
- cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
- memcpy(signature + 0, &ebx, 4);
- memcpy(signature + 4, &ecx, 4);
- memcpy(signature + 8, &edx, 4);
- signature[12] = 0;
-
- if (strcmp(signature, "KVMKVMKVM") == 0)
+ if (kvm_para_available_function(KVM_CPUID_SIGNATURE) ||
+ kvm_para_available_function(KVM_CPUID_SIGNATURE_NEXT))
return true;
}
diff --git a/arch/x86/include/uapi/asm/kvm_para.h b/arch/x86/include/uapi/asm/kvm_para.h
index 06fdbd9..4e3ffd8 100644
--- a/arch/x86/include/uapi/asm/kvm_para.h
+++ b/arch/x86/include/uapi/asm/kvm_para.h
@@ -8,6 +8,7 @@
* should be used to determine that a VM is running under KVM.
*/
#define KVM_CPUID_SIGNATURE 0x40000000
+#define KVM_CPUID_SIGNATURE_NEXT 0x40000100
/* This CPUID returns a feature bitmap in eax. Before enabling a particular
* paravirtualization, the appropriate feature bit should be checked.
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
index 8727921..3e149b6 100644
--- a/arch/x86/kernel/cpu/hypervisor.c
+++ b/arch/x86/kernel/cpu/hypervisor.c
@@ -36,10 +36,10 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
&x86_hyper_xen_hvm,
#endif
&x86_hyper_vmware,
- &x86_hyper_ms_hyperv,
#ifdef CONFIG_KVM_GUEST
&x86_hyper_kvm,
#endif
+ &x86_hyper_ms_hyperv,
};
const struct hypervisor_x86 *x86_hyper;
--
1.7.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] x86: properly handle KVM emulation of hyperv
2013-07-19 10:25 [PATCH] x86: properly handle KVM emulation of hyperv Jason Wang
@ 2013-07-19 12:10 ` Paolo Bonzini
2013-07-19 20:59 ` H. Peter Anvin
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2013-07-19 12:10 UTC (permalink / raw)
To: Jason Wang
Cc: gleb, tglx, mingo, hpa, x86, kvm, linux-kernel, Vadim Rozenfeld,
K. Y. Srinivasan
Il 19/07/2013 12:25, Jason Wang ha scritto:
> Recent kvm has some basic support of hyperv, this will cause the guest to
> identify itself running on top of hyperv instead of kvm which will disable kvm
> pv functionality. Solve this by check kvm para platform first and also check
> KVM_CPUID_SIGNATURE_NEXT which were set when kvm emulate hyperv.
>
> Cc: Gleb Natapov <gleb@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Vadim Rozenfeld <vrozenfe@redhat.com>
> Cc: K. Y. Srinivasan <kys@microsoft.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
> arch/x86/include/asm/kvm_para.h | 25 +++++++++++++++++--------
> arch/x86/include/uapi/asm/kvm_para.h | 1 +
> arch/x86/kernel/cpu/hypervisor.c | 2 +-
> 3 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
> index 695399f..aa8f3a7 100644
> --- a/arch/x86/include/asm/kvm_para.h
> +++ b/arch/x86/include/asm/kvm_para.h
> @@ -85,22 +85,31 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
> return ret;
> }
>
> -static inline bool kvm_para_available(void)
> +static inline bool kvm_para_available_function(unsigned int function)
> {
> unsigned int eax, ebx, ecx, edx;
> char signature[13];
>
> + cpuid(function, &eax, &ebx, &ecx, &edx);
> + memcpy(signature + 0, &ebx, 4);
> + memcpy(signature + 4, &ecx, 4);
> + memcpy(signature + 8, &edx, 4);
> + signature[12] = 0;
> +
> + if (strcmp(signature, "KVMKVMKVM") == 0)
> + return true;
> +
> + return false;
> +}
> +
> +static inline bool kvm_para_available(void)
> +{
> if (boot_cpu_data.cpuid_level < 0)
> return false; /* So we don't blow up on old processors */
>
> if (cpu_has_hypervisor) {
> - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
> - memcpy(signature + 0, &ebx, 4);
> - memcpy(signature + 4, &ecx, 4);
> - memcpy(signature + 8, &edx, 4);
> - signature[12] = 0;
> -
> - if (strcmp(signature, "KVMKVMKVM") == 0)
> + if (kvm_para_available_function(KVM_CPUID_SIGNATURE) ||
> + kvm_para_available_function(KVM_CPUID_SIGNATURE_NEXT))
> return true;
> }
Nice catch. Just one small thing, you should loop until 0x40010000, as
done in arch/x86/include/asm/xen/hypervisor.h, in case one day a third
hypervisor implements three extensions (Hyper-V, KVM and its own set).
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86: properly handle KVM emulation of hyperv
2013-07-19 12:10 ` Paolo Bonzini
@ 2013-07-19 20:59 ` H. Peter Anvin
2013-07-19 21:00 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2013-07-19 20:59 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Jason Wang, gleb, tglx, mingo, x86, kvm, linux-kernel,
Vadim Rozenfeld, K. Y. Srinivasan
On 07/19/2013 05:10 AM, Paolo Bonzini wrote:
>> +
>> +static inline bool kvm_para_available(void)
>> +{
>> if (boot_cpu_data.cpuid_level < 0)
>> return false; /* So we don't blow up on old processors */
>>
>> if (cpu_has_hypervisor) {
>> - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
>> - memcpy(signature + 0, &ebx, 4);
>> - memcpy(signature + 4, &ecx, 4);
>> - memcpy(signature + 8, &edx, 4);
>> - signature[12] = 0;
>> -
>> - if (strcmp(signature, "KVMKVMKVM") == 0)
>> + if (kvm_para_available_function(KVM_CPUID_SIGNATURE) ||
>> + kvm_para_available_function(KVM_CPUID_SIGNATURE_NEXT))
>> return true;
>> }
>
> Nice catch. Just one small thing, you should loop until 0x40010000, as
> done in arch/x86/include/asm/xen/hypervisor.h, in case one day a third
> hypervisor implements three extensions (Hyper-V, KVM and its own set).
>
Any way we can centralize this stuff?
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86: properly handle KVM emulation of hyperv
2013-07-19 20:59 ` H. Peter Anvin
@ 2013-07-19 21:00 ` Paolo Bonzini
2013-07-19 21:03 ` H. Peter Anvin
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2013-07-19 21:00 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Jason Wang, gleb, tglx, mingo, x86, kvm, linux-kernel,
Vadim Rozenfeld, K. Y. Srinivasan
Il 19/07/2013 22:59, H. Peter Anvin ha scritto:
>>> >> - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
>>> >> - memcpy(signature + 0, &ebx, 4);
>>> >> - memcpy(signature + 4, &ecx, 4);
>>> >> - memcpy(signature + 8, &edx, 4);
>>> >> - signature[12] = 0;
>>> >> -
>>> >> - if (strcmp(signature, "KVMKVMKVM") == 0)
>>> >> + if (kvm_para_available_function(KVM_CPUID_SIGNATURE) ||
>>> >> + kvm_para_available_function(KVM_CPUID_SIGNATURE_NEXT))
>>> >> return true;
>>> >> }
>> >
>> > Nice catch. Just one small thing, you should loop until 0x40010000, as
>> > done in arch/x86/include/asm/xen/hypervisor.h, in case one day a third
>> > hypervisor implements three extensions (Hyper-V, KVM and its own set).
>> >
> Any way we can centralize this stuff?
I guess a function cpuid_hypervisor_base("KVMKVMKVM") that does the scan?
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] x86: properly handle KVM emulation of hyperv
2013-07-19 21:00 ` Paolo Bonzini
@ 2013-07-19 21:03 ` H. Peter Anvin
0 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2013-07-19 21:03 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Jason Wang, gleb, tglx, mingo, x86, kvm, linux-kernel,
Vadim Rozenfeld, K. Y. Srinivasan
On 07/19/2013 02:00 PM, Paolo Bonzini wrote:
> Il 19/07/2013 22:59, H. Peter Anvin ha scritto:
>>>>>> - cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
>>>>>> - memcpy(signature + 0, &ebx, 4);
>>>>>> - memcpy(signature + 4, &ecx, 4);
>>>>>> - memcpy(signature + 8, &edx, 4);
>>>>>> - signature[12] = 0;
>>>>>> -
>>>>>> - if (strcmp(signature, "KVMKVMKVM") == 0)
>>>>>> + if (kvm_para_available_function(KVM_CPUID_SIGNATURE) ||
>>>>>> + kvm_para_available_function(KVM_CPUID_SIGNATURE_NEXT))
>>>>>> return true;
>>>>>> }
>>>>
>>>> Nice catch. Just one small thing, you should loop until 0x40010000, as
>>>> done in arch/x86/include/asm/xen/hypervisor.h, in case one day a third
>>>> hypervisor implements three extensions (Hyper-V, KVM and its own set).
>>>>
>> Any way we can centralize this stuff?
>
> I guess a function cpuid_hypervisor_base("KVMKVMKVM") that does the scan?
>
Something like that.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-19 21:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-19 10:25 [PATCH] x86: properly handle KVM emulation of hyperv Jason Wang
2013-07-19 12:10 ` Paolo Bonzini
2013-07-19 20:59 ` H. Peter Anvin
2013-07-19 21:00 ` Paolo Bonzini
2013-07-19 21:03 ` H. Peter Anvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox