Skip to content

Commit f72e38e

Browse files
jgross1Ingo Molnar
authored andcommitted
x86/virt, x86/platform: Merge 'struct x86_hyper' into 'struct x86_platform' and 'struct x86_init'
Instead of x86_hyper being either NULL on bare metal or a pointer to a struct hypervisor_x86 in case of the kernel running as a guest merge the struct into x86_platform and x86_init. This will remove the need for wrappers making it hard to find out what is being called. With dummy functions added for all callbacks testing for a NULL function pointer can be removed, too. Suggested-by: Ingo Molnar <[email protected]> Signed-off-by: Juergen Gross <[email protected]> Acked-by: Thomas Gleixner <[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] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent b5cd3b5 commit f72e38e

File tree

12 files changed

+81
-61
lines changed

12 files changed

+81
-61
lines changed

arch/x86/include/asm/hypervisor.h

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifdef CONFIG_HYPERVISOR_GUEST
2424

2525
#include <asm/kvm_para.h>
26+
#include <asm/x86_init.h>
2627
#include <asm/xen/hypervisor.h>
2728

2829
/*
@@ -35,17 +36,11 @@ struct hypervisor_x86 {
3536
/* Detection routine */
3637
uint32_t (*detect)(void);
3738

38-
/* Platform setup (run once per boot) */
39-
void (*init_platform)(void);
39+
/* init time callbacks */
40+
struct x86_hyper_init init;
4041

41-
/* X2APIC detection (run once per boot) */
42-
bool (*x2apic_available)(void);
43-
44-
/* pin current vcpu to specified physical cpu (run rarely) */
45-
void (*pin_vcpu)(int);
46-
47-
/* called during init_mem_mapping() to setup early mappings. */
48-
void (*init_mem_mapping)(void);
42+
/* runtime callbacks */
43+
struct x86_hyper_runtime runtime;
4944
};
5045

5146
extern const struct hypervisor_x86 *x86_hyper;
@@ -58,17 +53,7 @@ extern const struct hypervisor_x86 x86_hyper_xen_hvm;
5853
extern const struct hypervisor_x86 x86_hyper_kvm;
5954

6055
extern void init_hypervisor_platform(void);
61-
extern bool hypervisor_x2apic_available(void);
62-
extern void hypervisor_pin_vcpu(int cpu);
63-
64-
static inline void hypervisor_init_mem_mapping(void)
65-
{
66-
if (x86_hyper && x86_hyper->init_mem_mapping)
67-
x86_hyper->init_mem_mapping();
68-
}
6956
#else
7057
static inline void init_hypervisor_platform(void) { }
71-
static inline bool hypervisor_x2apic_available(void) { return false; }
72-
static inline void hypervisor_init_mem_mapping(void) { }
7358
#endif /* CONFIG_HYPERVISOR_GUEST */
7459
#endif /* _ASM_X86_HYPERVISOR_H */

arch/x86/include/asm/x86_init.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ struct x86_init_pci {
114114
void (*fixup_irqs)(void);
115115
};
116116

117+
/**
118+
* struct x86_hyper_init - x86 hypervisor init functions
119+
* @init_platform: platform setup
120+
* @x2apic_available: X2APIC detection
121+
* @init_mem_mapping: setup early mappings during init_mem_mapping()
122+
*/
123+
struct x86_hyper_init {
124+
void (*init_platform)(void);
125+
bool (*x2apic_available)(void);
126+
void (*init_mem_mapping)(void);
127+
};
128+
117129
/**
118130
* struct x86_init_ops - functions for platform specific setup
119131
*
@@ -127,6 +139,7 @@ struct x86_init_ops {
127139
struct x86_init_timers timers;
128140
struct x86_init_iommu iommu;
129141
struct x86_init_pci pci;
142+
struct x86_hyper_init hyper;
130143
};
131144

132145
/**
@@ -199,6 +212,15 @@ struct x86_legacy_features {
199212
struct x86_legacy_devices devices;
200213
};
201214

215+
/**
216+
* struct x86_hyper_runtime - x86 hypervisor specific runtime callbacks
217+
*
218+
* @pin_vcpu: pin current vcpu to specified physical cpu (run rarely)
219+
*/
220+
struct x86_hyper_runtime {
221+
void (*pin_vcpu)(int cpu);
222+
};
223+
202224
/**
203225
* struct x86_platform_ops - platform specific runtime functions
204226
* @calibrate_cpu: calibrate CPU
@@ -218,6 +240,7 @@ struct x86_legacy_features {
218240
* possible in x86_early_init_platform_quirks() by
219241
* only using the current x86_hardware_subarch
220242
* semantics.
243+
* @hyper: x86 hypervisor specific runtime callbacks
221244
*/
222245
struct x86_platform_ops {
223246
unsigned long (*calibrate_cpu)(void);
@@ -233,6 +256,7 @@ struct x86_platform_ops {
233256
void (*apic_post_init)(void);
234257
struct x86_legacy_features legacy;
235258
void (*set_legacy_features)(void);
259+
struct x86_hyper_runtime hyper;
236260
};
237261

238262
struct pci_dev;

arch/x86/kernel/apic/apic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ static __init void try_to_enable_x2apic(int remap_mode)
16451645
* under KVM
16461646
*/
16471647
if (max_physical_apicid > 255 ||
1648-
!hypervisor_x2apic_available()) {
1648+
!x86_init.hyper.x2apic_available()) {
16491649
pr_info("x2apic: IRQ remapping doesn't support X2APIC mode\n");
16501650
x2apic_disable();
16511651
return;

arch/x86/kernel/cpu/hypervisor.c

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,51 +44,49 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
4444
const struct hypervisor_x86 *x86_hyper;
4545
EXPORT_SYMBOL(x86_hyper);
4646

47-
static inline void __init
47+
static inline const struct hypervisor_x86 * __init
4848
detect_hypervisor_vendor(void)
4949
{
50-
const struct hypervisor_x86 *h, * const *p;
50+
const struct hypervisor_x86 *h = NULL, * const *p;
5151
uint32_t pri, max_pri = 0;
5252

5353
for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
54-
h = *p;
55-
pri = h->detect();
56-
if (pri != 0 && pri > max_pri) {
54+
pri = (*p)->detect();
55+
if (pri > max_pri) {
5756
max_pri = pri;
58-
x86_hyper = h;
57+
h = *p;
5958
}
6059
}
6160

62-
if (max_pri)
63-
pr_info("Hypervisor detected: %s\n", x86_hyper->name);
61+
if (h)
62+
pr_info("Hypervisor detected: %s\n", h->name);
63+
64+
return h;
6465
}
6566

66-
void __init init_hypervisor_platform(void)
67+
static void __init copy_array(const void *src, void *target, unsigned int size)
6768
{
69+
unsigned int i, n = size / sizeof(void *);
70+
const void * const *from = (const void * const *)src;
71+
const void **to = (const void **)target;
6872

69-
detect_hypervisor_vendor();
70-
71-
if (!x86_hyper)
72-
return;
73-
74-
if (x86_hyper->init_platform)
75-
x86_hyper->init_platform();
73+
for (i = 0; i < n; i++)
74+
if (from[i])
75+
to[i] = from[i];
7676
}
7777

78-
bool __init hypervisor_x2apic_available(void)
78+
void __init init_hypervisor_platform(void)
7979
{
80-
return x86_hyper &&
81-
x86_hyper->x2apic_available &&
82-
x86_hyper->x2apic_available();
83-
}
80+
const struct hypervisor_x86 *h;
8481

85-
void hypervisor_pin_vcpu(int cpu)
86-
{
87-
if (!x86_hyper)
82+
h = detect_hypervisor_vendor();
83+
84+
if (!h)
8885
return;
8986

90-
if (x86_hyper->pin_vcpu)
91-
x86_hyper->pin_vcpu(cpu);
92-
else
93-
WARN_ONCE(1, "vcpu pinning requested but not supported!\n");
87+
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
88+
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
89+
90+
x86_hyper = h;
91+
x86_init.hyper.init_platform();
9492
}

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,6 @@ static void __init ms_hyperv_init_platform(void)
257257
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
258258
.name = "Microsoft Hyper-V",
259259
.detect = ms_hyperv_platform,
260-
.init_platform = ms_hyperv_init_platform,
260+
.init.init_platform = ms_hyperv_init_platform,
261261
};
262262
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
@@ -208,7 +208,7 @@ static bool __init vmware_legacy_x2apic_available(void)
208208
const __refconst struct hypervisor_x86 x86_hyper_vmware = {
209209
.name = "VMware",
210210
.detect = vmware_platform,
211-
.init_platform = vmware_platform_setup,
212-
.x2apic_available = vmware_legacy_x2apic_available,
211+
.init.init_platform = vmware_platform_setup,
212+
.init.x2apic_available = vmware_legacy_x2apic_available,
213213
};
214214
EXPORT_SYMBOL(x86_hyper_vmware);

arch/x86/kernel/kvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static uint32_t __init kvm_detect(void)
547547
const struct hypervisor_x86 x86_hyper_kvm __refconst = {
548548
.name = "KVM",
549549
.detect = kvm_detect,
550-
.x2apic_available = kvm_para_available,
550+
.init.x2apic_available = kvm_para_available,
551551
};
552552
EXPORT_SYMBOL_GPL(x86_hyper_kvm);
553553

arch/x86/kernel/x86_init.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void x86_init_noop(void) { }
2828
void __init x86_init_uint_noop(unsigned int unused) { }
2929
int __init iommu_init_noop(void) { return 0; }
3030
void iommu_shutdown_noop(void) { }
31+
bool __init bool_x86_init_noop(void) { return false; }
32+
void x86_op_int_noop(int cpu) { }
3133

3234
/*
3335
* The platform setup functions are preset with the default functions
@@ -81,6 +83,12 @@ struct x86_init_ops x86_init __initdata = {
8183
.init_irq = x86_default_pci_init_irq,
8284
.fixup_irqs = x86_default_pci_fixup_irqs,
8385
},
86+
87+
.hyper = {
88+
.init_platform = x86_init_noop,
89+
.x2apic_available = bool_x86_init_noop,
90+
.init_mem_mapping = x86_init_noop,
91+
},
8492
};
8593

8694
struct x86_cpuinit_ops x86_cpuinit = {
@@ -101,6 +109,7 @@ struct x86_platform_ops x86_platform __ro_after_init = {
101109
.get_nmi_reason = default_get_nmi_reason,
102110
.save_sched_clock_state = tsc_save_sched_clock_state,
103111
.restore_sched_clock_state = tsc_restore_sched_clock_state,
112+
.hyper.pin_vcpu = x86_op_int_noop,
104113
};
105114

106115
EXPORT_SYMBOL_GPL(x86_platform);

arch/x86/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void __init init_mem_mapping(void)
671671
load_cr3(swapper_pg_dir);
672672
__flush_tlb_all();
673673

674-
hypervisor_init_mem_mapping();
674+
x86_init.hyper.init_mem_mapping();
675675

676676
early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
677677
}

arch/x86/xen/enlighten_hvm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ static uint32_t __init xen_platform_hvm(void)
229229
const struct hypervisor_x86 x86_hyper_xen_hvm = {
230230
.name = "Xen HVM",
231231
.detect = xen_platform_hvm,
232-
.init_platform = xen_hvm_guest_init,
233-
.pin_vcpu = xen_pin_vcpu,
234-
.x2apic_available = xen_x2apic_para_available,
235-
.init_mem_mapping = xen_hvm_init_mem_mapping,
232+
.init.init_platform = xen_hvm_guest_init,
233+
.init.x2apic_available = xen_x2apic_para_available,
234+
.init.init_mem_mapping = xen_hvm_init_mem_mapping,
235+
.runtime.pin_vcpu = xen_pin_vcpu,
236236
};
237237
EXPORT_SYMBOL(x86_hyper_xen_hvm);

0 commit comments

Comments
 (0)