From: Andrew Cooper Date: Tue, 28 Nov 2017 14:53:51 +0000 (+0000) Subject: x86/entry: Probe for Xen early during boot X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~806 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f141540feb6b43c428fe719a3204bad92ba538c1;p=xen.git x86/entry: Probe for Xen early during boot Signed-off-by: Andrew Cooper --- diff --git a/xen/arch/x86/guest/Makefile b/xen/arch/x86/guest/Makefile index a5f1625ab1..1345a60c81 100644 --- a/xen/arch/x86/guest/Makefile +++ b/xen/arch/x86/guest/Makefile @@ -1 +1,3 @@ +obj-y += xen.o + obj-bin-$(CONFIG_PVH_GUEST) += pvh-boot.init.o diff --git a/xen/arch/x86/guest/xen.c b/xen/arch/x86/guest/xen.c new file mode 100644 index 0000000000..8507757841 --- /dev/null +++ b/xen/arch/x86/guest/xen.c @@ -0,0 +1,75 @@ +/****************************************************************************** + * arch/x86/guest/xen.c + * + * Support for detecting and running under Xen. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2017 Citrix Systems Ltd. + */ +#include +#include + +#include +#include + +#include + +bool __read_mostly xen_guest; + +static __read_mostly uint32_t xen_cpuid_base; + +static void __init find_xen_leaves(void) +{ + uint32_t eax, ebx, ecx, edx, base; + + for ( base = XEN_CPUID_FIRST_LEAF; + base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 ) + { + cpuid(base, &eax, &ebx, &ecx, &edx); + + if ( (ebx == XEN_CPUID_SIGNATURE_EBX) && + (ecx == XEN_CPUID_SIGNATURE_ECX) && + (edx == XEN_CPUID_SIGNATURE_EDX) && + ((eax - base) >= 2) ) + { + xen_cpuid_base = base; + break; + } + } +} + +void __init probe_hypervisor(void) +{ + /* Too early to use cpu_has_hypervisor */ + if ( !(cpuid_ecx(1) & cpufeat_mask(X86_FEATURE_HYPERVISOR)) ) + return; + + find_xen_leaves(); + + if ( !xen_cpuid_base ) + return; + + xen_guest = true; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 3aa4e2f7b0..c485bfb5a7 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -716,6 +716,8 @@ void __init noreturn __start_xen(unsigned long mbi_p) * allocing any xenheap structures wanted in lower memory. */ kexec_early_calculations(); + probe_hypervisor(); + parse_video_info(); rdmsrl(MSR_EFER, this_cpu(efer)); diff --git a/xen/include/asm-x86/guest.h b/xen/include/asm-x86/guest.h index 630c092c25..8d91f81451 100644 --- a/xen/include/asm-x86/guest.h +++ b/xen/include/asm-x86/guest.h @@ -20,6 +20,7 @@ #define __X86_GUEST_H__ #include +#include #endif /* __X86_GUEST_H__ */ diff --git a/xen/include/asm-x86/guest/xen.h b/xen/include/asm-x86/guest/xen.h new file mode 100644 index 0000000000..97a7c8d531 --- /dev/null +++ b/xen/include/asm-x86/guest/xen.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * asm-x86/guest/xen.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms and conditions of the GNU General Public + * License, version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; If not, see . + * + * Copyright (c) 2017 Citrix Systems Ltd. + */ + +#ifndef __X86_GUEST_XEN_H__ +#define __X86_GUEST_XEN_H__ + +#include + +#ifdef CONFIG_XEN_GUEST + +extern bool xen_guest; + +void probe_hypervisor(void); + +#else + +#define xen_guest 0 + +static inline void probe_hypervisor(void) {}; + +#endif /* CONFIG_XEN_GUEST */ +#endif /* __X86_GUEST_XEN_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */