Skip to content

Commit

Permalink
Merge branch 'x86-platform-for-linus' of git://git.kernel.org/pub/scm…
Browse files Browse the repository at this point in the history
…/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()
  • Loading branch information
torvalds committed Nov 14, 2017
2 parents 13e57da + 418492b commit 43ff2f4
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 108 deletions.
2 changes: 1 addition & 1 deletion arch/x86/hyperv/hv_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void hyperv_init(void)
u64 guest_id;
union hv_x64_msr_hypercall_contents hypercall_msr;

if (x86_hyper != &x86_hyper_ms_hyperv)
if (x86_hyper_type != X86_HYPER_MS_HYPERV)
return;

/* Allocate percpu VP index */
Expand Down
46 changes: 18 additions & 28 deletions arch/x86/include/asm/hypervisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,42 @@
#ifdef CONFIG_HYPERVISOR_GUEST

#include <asm/kvm_para.h>
#include <asm/x86_init.h>
#include <asm/xen/hypervisor.h>

/*
* x86 hypervisor information
*/

enum x86_hypervisor_type {
X86_HYPER_NATIVE = 0,
X86_HYPER_VMWARE,
X86_HYPER_MS_HYPERV,
X86_HYPER_XEN_PV,
X86_HYPER_XEN_HVM,
X86_HYPER_KVM,
};

struct hypervisor_x86 {
/* Hypervisor name */
const char *name;

/* Detection routine */
uint32_t (*detect)(void);

/* Platform setup (run once per boot) */
void (*init_platform)(void);

/* X2APIC detection (run once per boot) */
bool (*x2apic_available)(void);
/* Hypervisor type */
enum x86_hypervisor_type type;

/* pin current vcpu to specified physical cpu (run rarely) */
void (*pin_vcpu)(int);
/* init time callbacks */
struct x86_hyper_init init;

/* called during init_mem_mapping() to setup early mappings. */
void (*init_mem_mapping)(void);
/* runtime callbacks */
struct x86_hyper_runtime runtime;
};

extern const struct hypervisor_x86 *x86_hyper;

/* Recognized hypervisors */
extern const struct hypervisor_x86 x86_hyper_vmware;
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
extern const struct hypervisor_x86 x86_hyper_xen_pv;
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
extern const struct hypervisor_x86 x86_hyper_kvm;

extern enum x86_hypervisor_type x86_hyper_type;
extern void init_hypervisor_platform(void);
extern bool hypervisor_x2apic_available(void);
extern void hypervisor_pin_vcpu(int cpu);

static inline void hypervisor_init_mem_mapping(void)
{
if (x86_hyper && x86_hyper->init_mem_mapping)
x86_hyper->init_mem_mapping();
}
#else
static inline void init_hypervisor_platform(void) { }
static inline bool hypervisor_x2apic_available(void) { return false; }
static inline void hypervisor_init_mem_mapping(void) { }
#endif /* CONFIG_HYPERVISOR_GUEST */
#endif /* _ASM_X86_HYPERVISOR_H */
2 changes: 0 additions & 2 deletions arch/x86/include/asm/kvm_para.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
#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, int interrupt_kernel);
void kvm_async_pf_task_wake(u32 token);
u32 kvm_read_and_reset_pf_reason(void);
Expand All @@ -103,7 +102,6 @@ static inline void kvm_spinlock_init(void)
#endif /* CONFIG_PARAVIRT_SPINLOCKS */

#else /* CONFIG_KVM_GUEST */
#define kvm_guest_init() do {} while (0)
#define kvm_async_pf_task_wait(T, I) do {} while(0)
#define kvm_async_pf_task_wake(T) do {} while(0)

Expand Down
27 changes: 27 additions & 0 deletions arch/x86/include/asm/x86_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ struct x86_init_pci {
void (*fixup_irqs)(void);
};

/**
* struct x86_hyper_init - x86 hypervisor init functions
* @init_platform: platform setup
* @guest_late_init: guest late init
* @x2apic_available: X2APIC detection
* @init_mem_mapping: setup early mappings during init_mem_mapping()
*/
struct x86_hyper_init {
void (*init_platform)(void);
void (*guest_late_init)(void);
bool (*x2apic_available)(void);
void (*init_mem_mapping)(void);
};

/**
* struct x86_init_ops - functions for platform specific setup
*
Expand All @@ -127,6 +141,7 @@ struct x86_init_ops {
struct x86_init_timers timers;
struct x86_init_iommu iommu;
struct x86_init_pci pci;
struct x86_hyper_init hyper;
};

/**
Expand Down Expand Up @@ -195,10 +210,20 @@ enum x86_legacy_i8042_state {
struct x86_legacy_features {
enum x86_legacy_i8042_state i8042;
int rtc;
int no_vga;
int reserve_bios_regions;
struct x86_legacy_devices devices;
};

/**
* struct x86_hyper_runtime - x86 hypervisor specific runtime callbacks
*
* @pin_vcpu: pin current vcpu to specified physical cpu (run rarely)
*/
struct x86_hyper_runtime {
void (*pin_vcpu)(int cpu);
};

/**
* struct x86_platform_ops - platform specific runtime functions
* @calibrate_cpu: calibrate CPU
Expand All @@ -218,6 +243,7 @@ struct x86_legacy_features {
* possible in x86_early_init_platform_quirks() by
* only using the current x86_hardware_subarch
* semantics.
* @hyper: x86 hypervisor specific runtime callbacks
*/
struct x86_platform_ops {
unsigned long (*calibrate_cpu)(void);
Expand All @@ -233,6 +259,7 @@ struct x86_platform_ops {
void (*apic_post_init)(void);
struct x86_legacy_features legacy;
void (*set_legacy_features)(void);
struct x86_hyper_runtime hyper;
};

struct pci_dev;
Expand Down
5 changes: 5 additions & 0 deletions arch/x86/kernel/acpi/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,11 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
x86_platform.legacy.rtc = 0;
}

if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_VGA) {
pr_debug("ACPI: probing for VGA not safe\n");
x86_platform.legacy.no_vga = 1;
}

#ifdef CONFIG_X86_PM_TIMER
/* detect the location of the ACPI PM Timer */
if (acpi_gbl_FADT.header.revision >= FADT2_REVISION_ID) {
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/apic/apic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ static __init void try_to_enable_x2apic(int remap_mode)
* under KVM
*/
if (max_physical_apicid > 255 ||
!hypervisor_x2apic_available()) {
!x86_init.hyper.x2apic_available()) {
pr_info("x2apic: IRQ remapping doesn't support X2APIC mode\n");
x2apic_disable();
return;
Expand Down
5 changes: 2 additions & 3 deletions arch/x86/kernel/apic/x2apic_uv_x.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,8 @@ static __init void uv_rtc_init(void)
/*
* percpu heartbeat timer
*/
static void uv_heartbeat(unsigned long ignored)
static void uv_heartbeat(struct timer_list *timer)
{
struct timer_list *timer = &uv_scir_info->timer;
unsigned char bits = uv_scir_info->state;

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

uv_set_cpu_scir_bits(cpu, SCIR_CPU_HEARTBEAT|SCIR_CPU_ACTIVITY);
setup_pinned_timer(timer, uv_heartbeat, cpu);
timer_setup(timer, uv_heartbeat, TIMER_PINNED);
timer->expires = jiffies + SCIR_CPU_HB_INTERVAL;
add_timer_on(timer, cpu);
uv_cpu_scir_info(cpu)->enabled = 1;
Expand Down
64 changes: 34 additions & 30 deletions arch/x86/kernel/cpu/hypervisor.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#include <asm/processor.h>
#include <asm/hypervisor.h>

extern const struct hypervisor_x86 x86_hyper_vmware;
extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
extern const struct hypervisor_x86 x86_hyper_xen_pv;
extern const struct hypervisor_x86 x86_hyper_xen_hvm;
extern const struct hypervisor_x86 x86_hyper_kvm;

static const __initconst struct hypervisor_x86 * const hypervisors[] =
{
#ifdef CONFIG_XEN_PV
Expand All @@ -41,54 +47,52 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
#endif
};

const struct hypervisor_x86 *x86_hyper;
EXPORT_SYMBOL(x86_hyper);
enum x86_hypervisor_type x86_hyper_type;
EXPORT_SYMBOL(x86_hyper_type);

static inline void __init
static inline const struct hypervisor_x86 * __init
detect_hypervisor_vendor(void)
{
const struct hypervisor_x86 *h, * const *p;
const struct hypervisor_x86 *h = NULL, * const *p;
uint32_t pri, max_pri = 0;

for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
h = *p;
pri = h->detect();
if (pri != 0 && pri > max_pri) {
pri = (*p)->detect();
if (pri > max_pri) {
max_pri = pri;
x86_hyper = h;
h = *p;
}
}

if (max_pri)
pr_info("Hypervisor detected: %s\n", x86_hyper->name);
if (h)
pr_info("Hypervisor detected: %s\n", h->name);

return h;
}

void __init init_hypervisor_platform(void)
static void __init copy_array(const void *src, void *target, unsigned int size)
{
unsigned int i, n = size / sizeof(void *);
const void * const *from = (const void * const *)src;
const void **to = (const void **)target;

detect_hypervisor_vendor();

if (!x86_hyper)
return;

if (x86_hyper->init_platform)
x86_hyper->init_platform();
for (i = 0; i < n; i++)
if (from[i])
to[i] = from[i];
}

bool __init hypervisor_x2apic_available(void)
void __init init_hypervisor_platform(void)
{
return x86_hyper &&
x86_hyper->x2apic_available &&
x86_hyper->x2apic_available();
}
const struct hypervisor_x86 *h;

void hypervisor_pin_vcpu(int cpu)
{
if (!x86_hyper)
h = detect_hypervisor_vendor();

if (!h)
return;

if (x86_hyper->pin_vcpu)
x86_hyper->pin_vcpu(cpu);
else
WARN_ONCE(1, "vcpu pinning requested but not supported!\n");
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));

x86_hyper_type = h->type;
x86_init.hyper.init_platform();
}
6 changes: 3 additions & 3 deletions arch/x86/kernel/cpu/mshyperv.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ static void __init ms_hyperv_init_platform(void)
#endif
}

const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
.name = "Microsoft Hyper-V",
.detect = ms_hyperv_platform,
.init_platform = ms_hyperv_init_platform,
.type = X86_HYPER_MS_HYPERV,
.init.init_platform = ms_hyperv_init_platform,
};
EXPORT_SYMBOL(x86_hyper_ms_hyperv);
8 changes: 4 additions & 4 deletions arch/x86/kernel/cpu/vmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ static bool __init vmware_legacy_x2apic_available(void)
(eax & (1 << VMWARE_PORT_CMD_LEGACY_X2APIC)) != 0;
}

const __refconst struct hypervisor_x86 x86_hyper_vmware = {
const __initconst struct hypervisor_x86 x86_hyper_vmware = {
.name = "VMware",
.detect = vmware_platform,
.init_platform = vmware_platform_setup,
.x2apic_available = vmware_legacy_x2apic_available,
.type = X86_HYPER_VMWARE,
.init.init_platform = vmware_platform_setup,
.init.x2apic_available = vmware_legacy_x2apic_available,
};
EXPORT_SYMBOL(x86_hyper_vmware);
9 changes: 5 additions & 4 deletions arch/x86/kernel/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ static void __init kvm_apf_trap_init(void)
update_intr_gate(X86_TRAP_PF, async_page_fault);
}

void __init kvm_guest_init(void)
static void __init kvm_guest_init(void)
{
int i;

Expand Down Expand Up @@ -578,12 +578,13 @@ static uint32_t __init kvm_detect(void)
return kvm_cpuid_base();
}

const struct hypervisor_x86 x86_hyper_kvm __refconst = {
const __initconst struct hypervisor_x86 x86_hyper_kvm = {
.name = "KVM",
.detect = kvm_detect,
.x2apic_available = kvm_para_available,
.type = X86_HYPER_KVM,
.init.guest_late_init = kvm_guest_init,
.init.x2apic_available = kvm_para_available,
};
EXPORT_SYMBOL_GPL(x86_hyper_kvm);

static __init int activate_jump_labels(void)
{
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ void __init setup_arch(char **cmdline_p)

io_apic_init_mappings();

kvm_guest_init();
x86_init.hyper.guest_late_init();

e820__reserve_resources();
e820__register_nosave_regions(max_low_pfn);
Expand Down
10 changes: 10 additions & 0 deletions arch/x86/kernel/x86_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void x86_init_noop(void) { }
void __init x86_init_uint_noop(unsigned int unused) { }
int __init iommu_init_noop(void) { return 0; }
void iommu_shutdown_noop(void) { }
bool __init bool_x86_init_noop(void) { return false; }
void x86_op_int_noop(int cpu) { }

/*
* The platform setup functions are preset with the default functions
Expand Down Expand Up @@ -81,6 +83,13 @@ struct x86_init_ops x86_init __initdata = {
.init_irq = x86_default_pci_init_irq,
.fixup_irqs = x86_default_pci_fixup_irqs,
},

.hyper = {
.init_platform = x86_init_noop,
.guest_late_init = x86_init_noop,
.x2apic_available = bool_x86_init_noop,
.init_mem_mapping = x86_init_noop,
},
};

struct x86_cpuinit_ops x86_cpuinit = {
Expand All @@ -101,6 +110,7 @@ struct x86_platform_ops x86_platform __ro_after_init = {
.get_nmi_reason = default_get_nmi_reason,
.save_sched_clock_state = tsc_save_sched_clock_state,
.restore_sched_clock_state = tsc_restore_sched_clock_state,
.hyper.pin_vcpu = x86_op_int_noop,
};

EXPORT_SYMBOL_GPL(x86_platform);
Expand Down
Loading

0 comments on commit 43ff2f4

Please sign in to comment.