Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f72e38e8 authored by Juergen Gross's avatar Juergen Gross Committed by Ingo Molnar
Browse files

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: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: akataria@vmware.com
Cc: boris.ostrovsky@oracle.com
Cc: devel@linuxdriverproject.org
Cc: haiyangz@microsoft.com
Cc: kvm@vger.kernel.org
Cc: kys@microsoft.com
Cc: pbonzini@redhat.com
Cc: rkrcmar@redhat.com
Cc: rusty@rustcorp.com.au
Cc: sthemmin@microsoft.com
Cc: virtualization@lists.linux-foundation.org
Cc: xen-devel@lists.xenproject.org
Link: http://lkml.kernel.org/r/20171109132739.23465-2-jgross@suse.com


Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent b5cd3b51
Loading
Loading
Loading
Loading
+5 −20
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#ifdef CONFIG_HYPERVISOR_GUEST

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

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

	/* Platform setup (run once per boot) */
	void		(*init_platform)(void);
	/* init time callbacks */
	struct x86_hyper_init init;

	/* X2APIC detection (run once per boot) */
	bool		(*x2apic_available)(void);

	/* pin current vcpu to specified physical cpu (run rarely) */
	void		(*pin_vcpu)(int);

	/* 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;
@@ -58,17 +53,7 @@ extern const struct hypervisor_x86 x86_hyper_xen_hvm;
extern const struct hypervisor_x86 x86_hyper_kvm;

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 */
+24 −0
Original line number Diff line number Diff line
@@ -114,6 +114,18 @@ struct x86_init_pci {
	void (*fixup_irqs)(void);
};

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

/**
 * struct x86_init_ops - functions for platform specific setup
 *
@@ -127,6 +139,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;
};

/**
@@ -199,6 +212,15 @@ struct x86_legacy_features {
	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
@@ -218,6 +240,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);
@@ -233,6 +256,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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
+26 −28
Original line number Diff line number Diff line
@@ -44,51 +44,49 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
const struct hypervisor_x86 *x86_hyper;
EXPORT_SYMBOL(x86_hyper);

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 = h;
	x86_init.hyper.init_platform();
}
+1 −1
Original line number Diff line number Diff line
@@ -257,6 +257,6 @@ static void __init ms_hyperv_init_platform(void)
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
	.name			= "Microsoft Hyper-V",
	.detect			= ms_hyperv_platform,
	.init_platform		= ms_hyperv_init_platform,
	.init.init_platform	= ms_hyperv_init_platform,
};
EXPORT_SYMBOL(x86_hyper_ms_hyperv);
Loading