Skip to content

Commit 03b2a32

Browse files
jgross1Ingo Molnar
authored andcommitted
x86/virt: Add enum for hypervisors to replace x86_hyper
The x86_hyper pointer is only used for checking whether a virtual device is supporting the hypervisor the system is running on. Use an enum for that purpose instead and drop the x86_hyper pointer. Signed-off-by: Juergen Gross <[email protected]> Acked-by: Thomas Gleixner <[email protected]> Acked-by: Xavier Deguillard <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent f72e38e commit 03b2a32

File tree

11 files changed

+40
-31
lines changed

11 files changed

+40
-31
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void hyperv_init(void)
113113
u64 guest_id;
114114
union hv_x64_msr_hypercall_contents hypercall_msr;
115115

116-
if (x86_hyper != &x86_hyper_ms_hyperv)
116+
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
117117
return;
118118

119119
/* Allocate percpu VP index */

arch/x86/include/asm/hypervisor.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,34 @@
2929
/*
3030
* x86 hypervisor information
3131
*/
32+
33+
enum x86_hypervisor_type {
34+
X86_HYPER_NATIVE = 0,
35+
X86_HYPER_VMWARE,
36+
X86_HYPER_MS_HYPERV,
37+
X86_HYPER_XEN_PV,
38+
X86_HYPER_XEN_HVM,
39+
X86_HYPER_KVM,
40+
};
41+
3242
struct hypervisor_x86 {
3343
/* Hypervisor name */
3444
const char *name;
3545

3646
/* Detection routine */
3747
uint32_t (*detect)(void);
3848

49+
/* Hypervisor type */
50+
enum x86_hypervisor_type type;
51+
3952
/* init time callbacks */
4053
struct x86_hyper_init init;
4154

4255
/* runtime callbacks */
4356
struct x86_hyper_runtime runtime;
4457
};
4558

46-
extern const struct hypervisor_x86 *x86_hyper;
47-
48-
/* Recognized hypervisors */
49-
extern const struct hypervisor_x86 x86_hyper_vmware;
50-
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
51-
extern const struct hypervisor_x86 x86_hyper_xen_pv;
52-
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
53-
extern const struct hypervisor_x86 x86_hyper_kvm;
54-
59+
extern enum x86_hypervisor_type x86_hyper_type;
5560
extern void init_hypervisor_platform(void);
5661
#else
5762
static inline void init_hypervisor_platform(void) { }

arch/x86/kernel/cpu/hypervisor.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
#include <asm/processor.h>
2727
#include <asm/hypervisor.h>
2828

29+
extern const struct hypervisor_x86 x86_hyper_vmware;
30+
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
31+
extern const struct hypervisor_x86 x86_hyper_xen_pv;
32+
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
33+
extern const struct hypervisor_x86 x86_hyper_kvm;
34+
2935
static const __initconst struct hypervisor_x86 * const hypervisors[] =
3036
{
3137
#ifdef CONFIG_XEN_PV
@@ -41,8 +47,8 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
4147
#endif
4248
};
4349

44-
const struct hypervisor_x86 *x86_hyper;
45-
EXPORT_SYMBOL(x86_hyper);
50+
enum x86_hypervisor_type x86_hyper_type;
51+
EXPORT_SYMBOL(x86_hyper_type);
4652

4753
static inline const struct hypervisor_x86 * __init
4854
detect_hypervisor_vendor(void)
@@ -87,6 +93,6 @@ void __init init_hypervisor_platform(void)
8793
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
8894
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
8995

90-
x86_hyper = h;
96+
x86_hyper_type = h->type;
9197
x86_init.hyper.init_platform();
9298
}

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,9 @@ static void __init ms_hyperv_init_platform(void)
254254
#endif
255255
}
256256

257-
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
257+
const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
258258
.name = "Microsoft Hyper-V",
259259
.detect = ms_hyperv_platform,
260+
.type = X86_HYPER_MS_HYPERV,
260261
.init.init_platform = ms_hyperv_init_platform,
261262
};
262-
EXPORT_SYMBOL(x86_hyper_ms_hyperv);

arch/x86/kernel/cpu/vmware.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ static bool __init vmware_legacy_x2apic_available(void)
205205
(eax & (1 << VMWARE_PORT_CMD_LEGACY_X2APIC)) != 0;
206206
}
207207

208-
const __refconst struct hypervisor_x86 x86_hyper_vmware = {
208+
const __initconst struct hypervisor_x86 x86_hyper_vmware = {
209209
.name = "VMware",
210210
.detect = vmware_platform,
211+
.type = X86_HYPER_VMWARE,
211212
.init.init_platform = vmware_platform_setup,
212213
.init.x2apic_available = vmware_legacy_x2apic_available,
213214
};
214-
EXPORT_SYMBOL(x86_hyper_vmware);

arch/x86/kernel/kvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ static uint32_t __init kvm_detect(void)
544544
return kvm_cpuid_base();
545545
}
546546

547-
const struct hypervisor_x86 x86_hyper_kvm __refconst = {
547+
const __initconst struct hypervisor_x86 x86_hyper_kvm = {
548548
.name = "KVM",
549549
.detect = kvm_detect,
550+
.type = X86_HYPER_KVM,
550551
.init.x2apic_available = kvm_para_available,
551552
};
552-
EXPORT_SYMBOL_GPL(x86_hyper_kvm);
553553

554554
static __init int activate_jump_labels(void)
555555
{

arch/x86/xen/enlighten_hvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ static uint32_t __init xen_platform_hvm(void)
226226
return xen_cpuid_base();
227227
}
228228

229-
const struct hypervisor_x86 x86_hyper_xen_hvm = {
229+
const __initconst struct hypervisor_x86 x86_hyper_xen_hvm = {
230230
.name = "Xen HVM",
231231
.detect = xen_platform_hvm,
232+
.type = X86_HYPER_XEN_HVM,
232233
.init.init_platform = xen_hvm_guest_init,
233234
.init.x2apic_available = xen_x2apic_para_available,
234235
.init.init_mem_mapping = xen_hvm_init_mem_mapping,
235236
.runtime.pin_vcpu = xen_pin_vcpu,
236237
};
237-
EXPORT_SYMBOL(x86_hyper_xen_hvm);

arch/x86/xen/enlighten_pv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,9 +1460,9 @@ static uint32_t __init xen_platform_pv(void)
14601460
return 0;
14611461
}
14621462

1463-
const struct hypervisor_x86 x86_hyper_xen_pv = {
1463+
const __initconst struct hypervisor_x86 x86_hyper_xen_pv = {
14641464
.name = "Xen PV",
14651465
.detect = xen_platform_pv,
1466+
.type = X86_HYPER_XEN_PV,
14661467
.runtime.pin_vcpu = xen_pin_vcpu,
14671468
};
1468-
EXPORT_SYMBOL(x86_hyper_xen_pv);

drivers/hv/vmbus_drv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ static int __init hv_acpi_init(void)
15341534
{
15351535
int ret, t;
15361536

1537-
if (x86_hyper != &x86_hyper_ms_hyperv)
1537+
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
15381538
return -ENODEV;
15391539

15401540
init_completion(&probe_event);

drivers/input/mouse/vmmouse.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,9 @@ static int vmmouse_enable(struct psmouse *psmouse)
316316
/*
317317
* Array of supported hypervisors.
318318
*/
319-
static const struct hypervisor_x86 *vmmouse_supported_hypervisors[] = {
320-
&x86_hyper_vmware,
321-
#ifdef CONFIG_KVM_GUEST
322-
&x86_hyper_kvm,
323-
#endif
319+
static enum x86_hypervisor_type vmmouse_supported_hypervisors[] = {
320+
X86_HYPER_VMWARE,
321+
X86_HYPER_KVM,
324322
};
325323

326324
/**
@@ -331,7 +329,7 @@ static bool vmmouse_check_hypervisor(void)
331329
int i;
332330

333331
for (i = 0; i < ARRAY_SIZE(vmmouse_supported_hypervisors); i++)
334-
if (vmmouse_supported_hypervisors[i] == x86_hyper)
332+
if (vmmouse_supported_hypervisors[i] == x86_hyper_type)
335333
return true;
336334

337335
return false;

0 commit comments

Comments
 (0)