Skip to content

Commit 79cc741

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
x86/paravirt: Provide a way to check for hypervisors
There is no generic way to test whether a kernel is running on a specific hypervisor. But that's required to prevent the upcoming user address space separation feature in certain guest modes. Make the hypervisor type enum unconditionally available and provide a helper function which allows to test for a specific type. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Juergen Gross <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Boris Ostrovsky <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Laight <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: Eduardo Valentin <[email protected]> Cc: Greg KH <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent a035795 commit 79cc741

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

arch/x86/include/asm/hypervisor.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@
2020
#ifndef _ASM_X86_HYPERVISOR_H
2121
#define _ASM_X86_HYPERVISOR_H
2222

23-
#ifdef CONFIG_HYPERVISOR_GUEST
24-
25-
#include <asm/kvm_para.h>
26-
#include <asm/x86_init.h>
27-
#include <asm/xen/hypervisor.h>
28-
29-
/*
30-
* x86 hypervisor information
31-
*/
32-
23+
/* x86 hypervisor types */
3324
enum x86_hypervisor_type {
3425
X86_HYPER_NATIVE = 0,
3526
X86_HYPER_VMWARE,
@@ -39,6 +30,12 @@ enum x86_hypervisor_type {
3930
X86_HYPER_KVM,
4031
};
4132

33+
#ifdef CONFIG_HYPERVISOR_GUEST
34+
35+
#include <asm/kvm_para.h>
36+
#include <asm/x86_init.h>
37+
#include <asm/xen/hypervisor.h>
38+
4239
struct hypervisor_x86 {
4340
/* Hypervisor name */
4441
const char *name;
@@ -58,7 +55,15 @@ struct hypervisor_x86 {
5855

5956
extern enum x86_hypervisor_type x86_hyper_type;
6057
extern void init_hypervisor_platform(void);
58+
static inline bool hypervisor_is_type(enum x86_hypervisor_type type)
59+
{
60+
return x86_hyper_type == type;
61+
}
6162
#else
6263
static inline void init_hypervisor_platform(void) { }
64+
static inline bool hypervisor_is_type(enum x86_hypervisor_type type)
65+
{
66+
return type == X86_HYPER_NATIVE;
67+
}
6368
#endif /* CONFIG_HYPERVISOR_GUEST */
6469
#endif /* _ASM_X86_HYPERVISOR_H */

0 commit comments

Comments
 (0)