* [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist
@ 2014-01-27 18:11 Paolo Bonzini
2014-01-27 18:11 ` [PATCH 1/2] x86, kvm: cache the base of the KVM cpuid leaves Paolo Bonzini
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-01-27 18:11 UTC (permalink / raw)
To: linux-kernel; +Cc: gleb, hpa, mingo, tglx, mtosatti
When KVM also presents Hyper-V features (which is useful because Windows
behaves better), Linux guests prefer KVM because emulated leaves are at
0x40000000 and the native ones are at 0x40000100.
However, Linux is then not accounting for the offset when reading the
available hypervisor features from CPUID. Instead of looking at
0x40000101, it will always look at 0x40000001.
This series makes sure that features such as async page faults or steal
time are available even if, for whatever reason, Hyper-V features are
enabled.
As a side effect, patch 1 makes a bunch of code non inline, which also
makes sense since it should only be called during initialization. As
a result, vmlinux .text size decreases by 96 bytes.
Please review!
Paolo Bonzini (2):
x86, kvm: cache the base of the KVM cpuid leaves
x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101
arch/x86/include/asm/kvm_para.h | 33 ++++++++++++---------------------
arch/x86/kernel/kvm.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 21 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] x86, kvm: cache the base of the KVM cpuid leaves
2014-01-27 18:11 [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Paolo Bonzini
@ 2014-01-27 18:11 ` Paolo Bonzini
2014-01-27 18:11 ` [PATCH 2/2] x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101 Paolo Bonzini
2014-01-28 22:19 ` [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Marcelo Tosatti
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-01-27 18:11 UTC (permalink / raw)
To: linux-kernel; +Cc: gleb, hpa, mingo, tglx, mtosatti, stable
It is unnecessary to go through hypervisor_cpuid_base every time
a leaf is found (which will be every time a feature is requested
after the next patch).
Fixes: 1085ba7f552d84aa8ac0ae903fa8d0cc2ff9f79d
Cc: stable@vger.kernel.org
Cc: mtosatti@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/include/asm/kvm_para.h | 22 ++++++----------------
arch/x86/kernel/kvm.c | 26 ++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index 1df115909758..1679cc799b26 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -85,28 +85,13 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
return ret;
}
-static inline uint32_t kvm_cpuid_base(void)
-{
- if (boot_cpu_data.cpuid_level < 0)
- return 0; /* So we don't blow up on old processors */
-
- if (cpu_has_hypervisor)
- return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
-
- return 0;
-}
-
-static inline bool kvm_para_available(void)
-{
- return kvm_cpuid_base() != 0;
-}
-
static inline unsigned int kvm_arch_para_features(void)
{
return cpuid_eax(KVM_CPUID_FEATURES);
}
#ifdef CONFIG_KVM_GUEST
+bool kvm_para_available(void);
void __init kvm_guest_init(void);
void kvm_async_pf_task_wait(u32 token);
void kvm_async_pf_task_wake(u32 token);
@@ -126,6 +111,11 @@ static inline void kvm_spinlock_init(void)
#define kvm_async_pf_task_wait(T) do {} while(0)
#define kvm_async_pf_task_wake(T) do {} while(0)
+static inline bool kvm_para_available(void)
+{
+ return 0;
+}
+
static inline u32 kvm_read_and_reset_pf_reason(void)
{
return 0;
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 6dd802c6d780..108c103b34b7 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -500,6 +500,33 @@ void __init kvm_guest_init(void)
#endif
}
+static noinline uint32_t __kvm_cpuid_base(void)
+{
+ if (boot_cpu_data.cpuid_level < 0)
+ return 0; /* So we don't blow up on old processors */
+
+ if (cpu_has_hypervisor)
+ return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
+
+ return 0;
+}
+
+static inline uint32_t kvm_cpuid_base(void)
+{
+ static int kvm_cpuid_base = -1;
+
+ if (kvm_cpuid_base == -1)
+ kvm_cpuid_base = __kvm_cpuid_base();
+
+ return kvm_cpuid_base;
+}
+
+bool kvm_para_available(void)
+{
+ return kvm_cpuid_base() != 0;
+}
+EXPORT_SYMBOL_GPL(kvm_para_available);
+
static uint32_t __init kvm_detect(void)
{
return kvm_cpuid_base();
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101
2014-01-27 18:11 [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Paolo Bonzini
2014-01-27 18:11 ` [PATCH 1/2] x86, kvm: cache the base of the KVM cpuid leaves Paolo Bonzini
@ 2014-01-27 18:11 ` Paolo Bonzini
2014-01-28 22:19 ` [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Marcelo Tosatti
2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2014-01-27 18:11 UTC (permalink / raw)
To: linux-kernel; +Cc: gleb, hpa, mingo, tglx, mtosatti, stable
When Hyper-V hypervisor leaves are present, KVM must relocate
its own leaves at 0x40000100, because Windows does not look for
Hyper-V leaves at indices other than 0x40000000. In this case,
the KVM features are at 0x40000101, but the old code would always
look at 0x40000001.
Fix by using kvm_cpuid_base(). This also requires making the
function non-inline, since kvm_cpuid_base() is static.
Fixes: 1085ba7f552d84aa8ac0ae903fa8d0cc2ff9f79d
Cc: stable@vger.kernel.org
Cc: mtosatti@redhat.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/include/asm/kvm_para.h | 11 ++++++-----
arch/x86/kernel/kvm.c | 5 +++++
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index 1679cc799b26..c7678e43465b 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -85,13 +85,9 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
return ret;
}
-static inline unsigned int kvm_arch_para_features(void)
-{
- return cpuid_eax(KVM_CPUID_FEATURES);
-}
-
#ifdef CONFIG_KVM_GUEST
bool kvm_para_available(void);
+unsigned int kvm_arch_para_features(void);
void __init kvm_guest_init(void);
void kvm_async_pf_task_wait(u32 token);
void kvm_async_pf_task_wake(u32 token);
@@ -116,6 +112,11 @@ static inline bool kvm_para_available(void)
return 0;
}
+static inline unsigned int kvm_arch_para_features(void)
+{
+ return 0;
+}
+
static inline u32 kvm_read_and_reset_pf_reason(void)
{
return 0;
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 108c103b34b7..ae33e765b65b 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -527,6 +527,11 @@ bool kvm_para_available(void)
}
EXPORT_SYMBOL_GPL(kvm_para_available);
+unsigned int kvm_arch_para_features(void)
+{
+ return cpuid_eax(kvm_cpuid_base() | KVM_CPUID_FEATURES);
+}
+
static uint32_t __init kvm_detect(void)
{
return kvm_cpuid_base();
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist
2014-01-27 18:11 [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Paolo Bonzini
2014-01-27 18:11 ` [PATCH 1/2] x86, kvm: cache the base of the KVM cpuid leaves Paolo Bonzini
2014-01-27 18:11 ` [PATCH 2/2] x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101 Paolo Bonzini
@ 2014-01-28 22:19 ` Marcelo Tosatti
2 siblings, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2014-01-28 22:19 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: linux-kernel, gleb, hpa, mingo, tglx
On Mon, Jan 27, 2014 at 07:11:28PM +0100, Paolo Bonzini wrote:
> When KVM also presents Hyper-V features (which is useful because Windows
> behaves better), Linux guests prefer KVM because emulated leaves are at
> 0x40000000 and the native ones are at 0x40000100.
>
> However, Linux is then not accounting for the offset when reading the
> available hypervisor features from CPUID. Instead of looking at
> 0x40000101, it will always look at 0x40000001.
>
> This series makes sure that features such as async page faults or steal
> time are available even if, for whatever reason, Hyper-V features are
> enabled.
>
> As a side effect, patch 1 makes a bunch of code non inline, which also
> makes sense since it should only be called during initialization. As
> a result, vmlinux .text size decreases by 96 bytes.
>
> Please review!
>
> Paolo Bonzini (2):
> x86, kvm: cache the base of the KVM cpuid leaves
> x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101
>
> arch/x86/include/asm/kvm_para.h | 33 ++++++++++++---------------------
> arch/x86/kernel/kvm.c | 31 +++++++++++++++++++++++++++++++
> 2 files changed, 43 insertions(+), 21 deletions(-)
>
> --
> 1.8.3.1
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-01-28 22:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-27 18:11 [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Paolo Bonzini
2014-01-27 18:11 ` [PATCH 1/2] x86, kvm: cache the base of the KVM cpuid leaves Paolo Bonzini
2014-01-27 18:11 ` [PATCH 2/2] x86, kvm: correctly access the KVM_CPUID_FEATURES leaf at 0x40000101 Paolo Bonzini
2014-01-28 22:19 ` [PATCH 0/2] x86, kvm: fix detection of KVM features when KVM and Hyper-V coexist Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox