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 <mingo@kernel.org> Signed-off-by: Juergen Gross <jgross@suse.com> Acked-by: Thomas 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: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
b5cd3b51e2
commit
f72e38e8ec
@@ -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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
if (from[i])
|
||||
to[i] = from[i];
|
||||
}
|
||||
|
||||
void __init init_hypervisor_platform(void)
|
||||
{
|
||||
const struct hypervisor_x86 *h;
|
||||
|
||||
detect_hypervisor_vendor();
|
||||
h = detect_hypervisor_vendor();
|
||||
|
||||
if (!x86_hyper)
|
||||
if (!h)
|
||||
return;
|
||||
|
||||
if (x86_hyper->init_platform)
|
||||
x86_hyper->init_platform();
|
||||
}
|
||||
copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
|
||||
copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
|
||||
|
||||
bool __init hypervisor_x2apic_available(void)
|
||||
{
|
||||
return x86_hyper &&
|
||||
x86_hyper->x2apic_available &&
|
||||
x86_hyper->x2apic_available();
|
||||
}
|
||||
|
||||
void hypervisor_pin_vcpu(int cpu)
|
||||
{
|
||||
if (!x86_hyper)
|
||||
return;
|
||||
|
||||
if (x86_hyper->pin_vcpu)
|
||||
x86_hyper->pin_vcpu(cpu);
|
||||
else
|
||||
WARN_ONCE(1, "vcpu pinning requested but not supported!\n");
|
||||
x86_hyper = h;
|
||||
x86_init.hyper.init_platform();
|
||||
}
|
||||
|
Reference in New Issue
Block a user