]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
x86/virt, x86/platform: Merge 'struct x86_hyper' into 'struct x86_platform' and ...
authorJuergen Gross <jgross@suse.com>
Thu, 9 Nov 2017 13:27:35 +0000 (14:27 +0100)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Sat, 6 Jan 2018 12:23:03 +0000 (13:23 +0100)
CVE-2017-5754

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>
(cherry picked from commit f72e38e8ec8869ac0ba5a75d7d2f897d98a1454e)
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
12 files changed:
arch/x86/include/asm/hypervisor.h
arch/x86/include/asm/x86_init.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/cpu/hypervisor.c
arch/x86/kernel/cpu/mshyperv.c
arch/x86/kernel/cpu/vmware.c
arch/x86/kernel/kvm.c
arch/x86/kernel/x86_init.c
arch/x86/mm/init.c
arch/x86/xen/enlighten_hvm.c
arch/x86/xen/enlighten_pv.c
include/linux/hypervisor.h

index 0ead9dbb91301d0f7f8923dcf33f25515bd182b8..0eca7239a7aadee920ade2b3eab5e99adaa2fca2 100644 (file)
@@ -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 */
index 7ba7e90a9ad69e69723dd7dd152c2bc2b0e9ba16..4d95e5a13c0bc87ee0873e92aad469d80458f5f8 100644 (file)
@@ -113,6 +113,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
  *
@@ -126,6 +138,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;
 };
 
 /**
@@ -198,6 +211,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
@@ -217,6 +239,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);
@@ -232,6 +255,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;
index 4a7f962b53ff7c2c598598896c36a9739a866720..bb63c13505245e6ee56f3b94aed6323b0cbe8934 100644 (file)
@@ -1666,7 +1666,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;
index 4fa90006ac68cbeade534020a689c4a07b4f0e60..22226c1bf092a32b9ffc53d7f60ce9ada3badc29 100644 (file)
@@ -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();
 }
index 70e717fccdd6cabaf8eb778b6f407c43b6e0c412..9707e431da2726c7c1bca490716c336bd48b0f07 100644 (file)
@@ -255,6 +255,6 @@ static void __init ms_hyperv_init_platform(void)
 const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
        .name                   = "Microsoft HyperV",
        .detect                 = ms_hyperv_platform,
-       .init_platform          = ms_hyperv_init_platform,
+       .init.init_platform     = ms_hyperv_init_platform,
 };
 EXPORT_SYMBOL(x86_hyper_ms_hyperv);
index 40ed26852ebd9a7fb61b6bc24b06426c4faf9f62..4804c1d063c84f46cd6e70d3fc6654ae2082e509 100644 (file)
@@ -208,7 +208,7 @@ static bool __init vmware_legacy_x2apic_available(void)
 const __refconst struct hypervisor_x86 x86_hyper_vmware = {
        .name                   = "VMware",
        .detect                 = vmware_platform,
-       .init_platform          = vmware_platform_setup,
-       .x2apic_available       = vmware_legacy_x2apic_available,
+       .init.init_platform     = vmware_platform_setup,
+       .init.x2apic_available  = vmware_legacy_x2apic_available,
 };
 EXPORT_SYMBOL(x86_hyper_vmware);
index 9e3798b00e40eb39eeeb271d2233004028b4b6dd..54e373bfeab9b03d7549ea106b0bf9dd6077d77d 100644 (file)
@@ -547,7 +547,7 @@ static uint32_t __init kvm_detect(void)
 const struct hypervisor_x86 x86_hyper_kvm __refconst = {
        .name                   = "KVM",
        .detect                 = kvm_detect,
-       .x2apic_available       = kvm_para_available,
+       .init.x2apic_available  = kvm_para_available,
 };
 EXPORT_SYMBOL_GPL(x86_hyper_kvm);
 
index a088b2c47f7396dbfa9bd070ebc8f3c544a33d07..5b2d10c1973ab13cff47a9be663406a4c52171ed 100644 (file)
@@ -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
@@ -81,6 +83,12 @@ 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,
+               .x2apic_available       = bool_x86_init_noop,
+               .init_mem_mapping       = x86_init_noop,
+       },
 };
 
 struct x86_cpuinit_ops x86_cpuinit = {
@@ -101,6 +109,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);
index af5c1ed21d43ac651ecbe02e7a58dc7baa884168..a22c2b95e5133919e839d3c7a7a33b82b17e629c 100644 (file)
@@ -671,7 +671,7 @@ void __init init_mem_mapping(void)
        load_cr3(swapper_pg_dir);
        __flush_tlb_all();
 
-       hypervisor_init_mem_mapping();
+       x86_init.hyper.init_mem_mapping();
 
        early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
 }
index de503c225ae1f194b10c71b44528ad2a2a7a4c0d..7b1622089f96595d3fd082bfca6ed5ab02918e4a 100644 (file)
@@ -229,9 +229,9 @@ static uint32_t __init xen_platform_hvm(void)
 const struct hypervisor_x86 x86_hyper_xen_hvm = {
        .name                   = "Xen HVM",
        .detect                 = xen_platform_hvm,
-       .init_platform          = xen_hvm_guest_init,
-       .pin_vcpu               = xen_pin_vcpu,
-       .x2apic_available       = xen_x2apic_para_available,
-       .init_mem_mapping       = xen_hvm_init_mem_mapping,
+       .init.init_platform     = xen_hvm_guest_init,
+       .init.x2apic_available  = xen_x2apic_para_available,
+       .init.init_mem_mapping  = xen_hvm_init_mem_mapping,
+       .runtime.pin_vcpu       = xen_pin_vcpu,
 };
 EXPORT_SYMBOL(x86_hyper_xen_hvm);
index e7b213047724fc2705fd6c17ef0833b36f787023..4110fc9e5ee953ce373e8e85c0354df8f413a642 100644 (file)
@@ -1461,6 +1461,6 @@ static uint32_t __init xen_platform_pv(void)
 const struct hypervisor_x86 x86_hyper_xen_pv = {
        .name                   = "Xen PV",
        .detect                 = xen_platform_pv,
-       .pin_vcpu               = xen_pin_vcpu,
+       .runtime.pin_vcpu       = xen_pin_vcpu,
 };
 EXPORT_SYMBOL(x86_hyper_xen_pv);
index 3fa5ef2b37590cd1b059f7d27025e4467b171eac..35e170ca87a865985fa0bc8b6b7c9cb9055c80ae 100644 (file)
@@ -6,8 +6,12 @@
  *             Juergen Gross <jgross@suse.com>
  */
 
-#ifdef CONFIG_HYPERVISOR_GUEST
-#include <asm/hypervisor.h>
+#ifdef CONFIG_X86
+#include <asm/x86_init.h>
+static inline void hypervisor_pin_vcpu(int cpu)
+{
+       x86_platform.hyper.pin_vcpu(cpu);
+}
 #else
 static inline void hypervisor_pin_vcpu(int cpu)
 {