Skip to content

Commit 43ff2f4

Browse files
committed
Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 platform updates from Ingo Molnar: "The main changes in this cycle were: - a refactoring of the early virt init code by merging 'struct x86_hyper' into 'struct x86_platform' and 'struct x86_init', which allows simplifications and also the addition of a new ->guest_late_init() callback. (Juergen Gross) - timer_setup() conversion of the UV code (Kees Cook)" * 'x86-platform-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/virt/xen: Use guest_late_init to detect Xen PVH guest x86/virt, x86/platform: Add ->guest_late_init() callback to hypervisor_x86 structure x86/virt, x86/acpi: Add test for ACPI_FADT_NO_VGA x86/virt: Add enum for hypervisors to replace x86_hyper x86/virt, x86/platform: Merge 'struct x86_hyper' into 'struct x86_platform' and 'struct x86_init' x86/platform/UV: Convert timers to use timer_setup()
2 parents 13e57da + 418492b commit 43ff2f4

File tree

21 files changed

+155
-108
lines changed

21 files changed

+155
-108
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: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,52 +23,42 @@
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
/*
2930
* x86 hypervisor information
3031
*/
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+
3142
struct hypervisor_x86 {
3243
/* Hypervisor name */
3344
const char *name;
3445

3546
/* Detection routine */
3647
uint32_t (*detect)(void);
3748

38-
/* Platform setup (run once per boot) */
39-
void (*init_platform)(void);
40-
41-
/* X2APIC detection (run once per boot) */
42-
bool (*x2apic_available)(void);
49+
/* Hypervisor type */
50+
enum x86_hypervisor_type type;
4351

44-
/* pin current vcpu to specified physical cpu (run rarely) */
45-
void (*pin_vcpu)(int);
52+
/* init time callbacks */
53+
struct x86_hyper_init init;
4654

47-
/* called during init_mem_mapping() to setup early mappings. */
48-
void (*init_mem_mapping)(void);
55+
/* runtime callbacks */
56+
struct x86_hyper_runtime runtime;
4957
};
5058

51-
extern const struct hypervisor_x86 *x86_hyper;
52-
53-
/* Recognized hypervisors */
54-
extern const struct hypervisor_x86 x86_hyper_vmware;
55-
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
56-
extern const struct hypervisor_x86 x86_hyper_xen_pv;
57-
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
58-
extern const struct hypervisor_x86 x86_hyper_kvm;
59-
59+
extern enum x86_hypervisor_type x86_hyper_type;
6060
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-
}
6961
#else
7062
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) { }
7363
#endif /* CONFIG_HYPERVISOR_GUEST */
7464
#endif /* _ASM_X86_HYPERVISOR_H */

arch/x86/include/asm/kvm_para.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
8888
#ifdef CONFIG_KVM_GUEST
8989
bool kvm_para_available(void);
9090
unsigned int kvm_arch_para_features(void);
91-
void __init kvm_guest_init(void);
9291
void kvm_async_pf_task_wait(u32 token, int interrupt_kernel);
9392
void kvm_async_pf_task_wake(u32 token);
9493
u32 kvm_read_and_reset_pf_reason(void);
@@ -103,7 +102,6 @@ static inline void kvm_spinlock_init(void)
103102
#endif /* CONFIG_PARAVIRT_SPINLOCKS */
104103

105104
#else /* CONFIG_KVM_GUEST */
106-
#define kvm_guest_init() do {} while (0)
107105
#define kvm_async_pf_task_wait(T, I) do {} while(0)
108106
#define kvm_async_pf_task_wake(T) do {} while(0)
109107

arch/x86/include/asm/x86_init.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ 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+
* @guest_late_init: guest late init
121+
* @x2apic_available: X2APIC detection
122+
* @init_mem_mapping: setup early mappings during init_mem_mapping()
123+
*/
124+
struct x86_hyper_init {
125+
void (*init_platform)(void);
126+
void (*guest_late_init)(void);
127+
bool (*x2apic_available)(void);
128+
void (*init_mem_mapping)(void);
129+
};
130+
117131
/**
118132
* struct x86_init_ops - functions for platform specific setup
119133
*
@@ -127,6 +141,7 @@ struct x86_init_ops {
127141
struct x86_init_timers timers;
128142
struct x86_init_iommu iommu;
129143
struct x86_init_pci pci;
144+
struct x86_hyper_init hyper;
130145
};
131146

132147
/**
@@ -195,10 +210,20 @@ enum x86_legacy_i8042_state {
195210
struct x86_legacy_features {
196211
enum x86_legacy_i8042_state i8042;
197212
int rtc;
213+
int no_vga;
198214
int reserve_bios_regions;
199215
struct x86_legacy_devices devices;
200216
};
201217

218+
/**
219+
* struct x86_hyper_runtime - x86 hypervisor specific runtime callbacks
220+
*
221+
* @pin_vcpu: pin current vcpu to specified physical cpu (run rarely)
222+
*/
223+
struct x86_hyper_runtime {
224+
void (*pin_vcpu)(int cpu);
225+
};
226+
202227
/**
203228
* struct x86_platform_ops - platform specific runtime functions
204229
* @calibrate_cpu: calibrate CPU
@@ -218,6 +243,7 @@ struct x86_legacy_features {
218243
* possible in x86_early_init_platform_quirks() by
219244
* only using the current x86_hardware_subarch
220245
* semantics.
246+
* @hyper: x86 hypervisor specific runtime callbacks
221247
*/
222248
struct x86_platform_ops {
223249
unsigned long (*calibrate_cpu)(void);
@@ -233,6 +259,7 @@ struct x86_platform_ops {
233259
void (*apic_post_init)(void);
234260
struct x86_legacy_features legacy;
235261
void (*set_legacy_features)(void);
262+
struct x86_hyper_runtime hyper;
236263
};
237264

238265
struct pci_dev;

arch/x86/kernel/acpi/boot.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,11 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
961961
x86_platform.legacy.rtc = 0;
962962
}
963963

964+
if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_VGA) {
965+
pr_debug("ACPI: probing for VGA not safe\n");
966+
x86_platform.legacy.no_vga = 1;
967+
}
968+
964969
#ifdef CONFIG_X86_PM_TIMER
965970
/* detect the location of the ACPI PM Timer */
966971
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {

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/apic/x2apic_uv_x.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,8 @@ static __init void uv_rtc_init(void)
920920
/*
921921
* percpu heartbeat timer
922922
*/
923-
static void uv_heartbeat(unsigned long ignored)
923+
static void uv_heartbeat(struct timer_list *timer)
924924
{
925-
struct timer_list *timer = &uv_scir_info->timer;
926925
unsigned char bits = uv_scir_info->state;
927926

928927
/* Flip heartbeat bit: */
@@ -947,7 +946,7 @@ static int uv_heartbeat_enable(unsigned int cpu)
947946
struct timer_list *timer = &uv_cpu_scir_info(cpu)->timer;
948947

949948
uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
950-
setup_pinned_timer(timer, uv_heartbeat, cpu);
949+
timer_setup(timer, uv_heartbeat, TIMER_PINNED);
951950
timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
952951
add_timer_on(timer, cpu);
953952
uv_cpu_scir_info(cpu)->enabled = 1;

arch/x86/kernel/cpu/hypervisor.c

Lines changed: 34 additions & 30 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,54 +47,52 @@ 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

47-
static inline void __init
53+
static inline const struct hypervisor_x86 * __init
4854
detect_hypervisor_vendor(void)
4955
{
50-
const struct hypervisor_x86 *h, * const *p;
56+
const struct hypervisor_x86 *h = NULL, * const *p;
5157
uint32_t pri, max_pri = 0;
5258

5359
for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
54-
h = *p;
55-
pri = h->detect();
56-
if (pri != 0 && pri > max_pri) {
60+
pri = (*p)->detect();
61+
if (pri > max_pri) {
5762
max_pri = pri;
58-
x86_hyper = h;
63+
h = *p;
5964
}
6065
}
6166

62-
if (max_pri)
63-
pr_info("Hypervisor detected: %s\n", x86_hyper->name);
67+
if (h)
68+
pr_info("Hypervisor detected: %s\n", h->name);
69+
70+
return h;
6471
}
6572

66-
void __init init_hypervisor_platform(void)
73+
static void __init copy_array(const void *src, void *target, unsigned int size)
6774
{
75+
unsigned int i, n = size / sizeof(void *);
76+
const void * const *from = (const void * const *)src;
77+
const void **to = (const void **)target;
6878

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

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

85-
void hypervisor_pin_vcpu(int cpu)
86-
{
87-
if (!x86_hyper)
88+
h = detect_hypervisor_vendor();
89+
90+
if (!h)
8891
return;
8992

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");
93+
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
94+
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
95+
96+
x86_hyper_type = h->type;
97+
x86_init.hyper.init_platform();
9498
}

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 3 additions & 3 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-
.init_platform = ms_hyperv_init_platform,
260+
.type = X86_HYPER_MS_HYPERV,
261+
.init.init_platform = ms_hyperv_init_platform,
261262
};
262-
EXPORT_SYMBOL(x86_hyper_ms_hyperv);

arch/x86/kernel/cpu/vmware.c

Lines changed: 4 additions & 4 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-
.init_platform = vmware_platform_setup,
212-
.x2apic_available = vmware_legacy_x2apic_available,
211+
.type = X86_HYPER_VMWARE,
212+
.init.init_platform = vmware_platform_setup,
213+
.init.x2apic_available = vmware_legacy_x2apic_available,
213214
};
214-
EXPORT_SYMBOL(x86_hyper_vmware);

arch/x86/kernel/kvm.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ static void __init kvm_apf_trap_init(void)
498498
update_intr_gate(X86_TRAP_PF, async_page_fault);
499499
}
500500

501-
void __init kvm_guest_init(void)
501+
static void __init kvm_guest_init(void)
502502
{
503503
int i;
504504

@@ -578,12 +578,13 @@ static uint32_t __init kvm_detect(void)
578578
return kvm_cpuid_base();
579579
}
580580

581-
const struct hypervisor_x86 x86_hyper_kvm __refconst = {
581+
const __initconst struct hypervisor_x86 x86_hyper_kvm = {
582582
.name = "KVM",
583583
.detect = kvm_detect,
584-
.x2apic_available = kvm_para_available,
584+
.type = X86_HYPER_KVM,
585+
.init.guest_late_init = kvm_guest_init,
586+
.init.x2apic_available = kvm_para_available,
585587
};
586-
EXPORT_SYMBOL_GPL(x86_hyper_kvm);
587588

588589
static __init int activate_jump_labels(void)
589590
{

arch/x86/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ void __init setup_arch(char **cmdline_p)
12961296

12971297
io_apic_init_mappings();
12981298

1299-
kvm_guest_init();
1299+
x86_init.hyper.guest_late_init();
13001300

13011301
e820__reserve_resources();
13021302
e820__register_nosave_regions(max_low_pfn);

arch/x86/kernel/x86_init.c

Lines changed: 10 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,13 @@ 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+
.guest_late_init = x86_init_noop,
90+
.x2apic_available = bool_x86_init_noop,
91+
.init_mem_mapping = x86_init_noop,
92+
},
8493
};
8594

8695
struct x86_cpuinit_ops x86_cpuinit = {
@@ -101,6 +110,7 @@ struct x86_platform_ops x86_platform __ro_after_init = {
101110
.get_nmi_reason = default_get_nmi_reason,
102111
.save_sched_clock_state = tsc_save_sched_clock_state,
103112
.restore_sched_clock_state = tsc_restore_sched_clock_state,
113+
.hyper.pin_vcpu = x86_op_int_noop,
104114
};
105115

106116
EXPORT_SYMBOL_GPL(x86_platform);

0 commit comments

Comments
 (0)