Blob Blame History Raw
From: jbeulich@novell.com
Subject: Disallow all accesses to the local APIC page
Patch-mainline: n/a
References: bnc#191115

--- head.orig/arch/x86/include/asm/apic.h	2015-03-10 18:37:18.000000000 +0100
+++ head/arch/x86/include/asm/apic.h	2015-03-12 17:43:16.000000000 +0100
@@ -9,7 +9,9 @@
 #include <asm/processor.h>
 #include <asm/apicdef.h>
 #include <linux/atomic.h>
+#ifndef CONFIG_XEN
 #include <asm/fixmap.h>
+#endif
 #include <asm/mpspec.h>
 #include <asm/msr.h>
 #include <asm/idle.h>
@@ -48,6 +50,7 @@ static inline void generic_apic_probe(vo
 #ifdef CONFIG_X86_LOCAL_APIC
 
 extern unsigned int apic_verbosity;
+#ifndef CONFIG_XEN
 extern int local_apic_timer_c2_ok;
 
 extern int disable_apic;
@@ -117,6 +120,8 @@ static inline bool apic_is_x2apic_enable
 	return msr & X2APIC_ENABLE;
 }
 
+#endif /* CONFIG_XEN */
+
 #ifdef CONFIG_X86_X2APIC
 /*
  * Make previous memory operations globally visible before
@@ -274,16 +279,19 @@ static inline void disable_local_APIC(vo
 struct apic {
 	char *name;
 
+#ifndef CONFIG_XEN
 	int (*probe)(void);
 	int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
 	int (*apic_id_valid)(int apicid);
 	int (*apic_id_registered)(void);
+#endif
 
 	u32 irq_delivery_mode;
 	u32 irq_dest_mode;
 
 	const struct cpumask *(*target_cpus)(void);
 
+#ifndef CONFIG_XEN
 	int disable_esr;
 
 	int dest_logical;
@@ -299,8 +307,10 @@ struct apic {
 	int (*cpu_present_to_apicid)(int mps_cpu);
 	void (*apicid_to_cpu_present)(int phys_apicid, physid_mask_t *retmap);
 	int (*check_phys_apicid_present)(int phys_apicid);
+#endif
 	int (*phys_pkg_id)(int cpuid_apic, int index_msb);
 
+#ifndef CONFIG_XEN
 	unsigned int (*get_apic_id)(unsigned long x);
 	unsigned long (*set_apic_id)(unsigned int id);
 	unsigned long apic_id_mask;
@@ -308,6 +318,7 @@ struct apic {
 	int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask,
 				      const struct cpumask *andmask,
 				      unsigned int *apicid);
+#endif
 
 	/* ipi */
 	void (*send_IPI_mask)(const struct cpumask *mask, int vector);
@@ -317,6 +328,7 @@ struct apic {
 	void (*send_IPI_all)(int vector);
 	void (*send_IPI_self)(int vector);
 
+#ifndef CONFIG_XEN
 	/* wakeup_secondary_cpu */
 	int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip);
 
@@ -352,6 +364,7 @@ struct apic {
 	 */
 	int (*x86_32_early_logical_apicid)(int cpu);
 #endif
+#endif /* CONFIG_XEN */
 };
 
 /*
@@ -361,6 +374,8 @@ struct apic {
  */
 extern struct apic *apic;
 
+#ifndef CONFIG_XEN
+
 /*
  * APIC drivers are probed based on how they are listed in the .apicdrivers
  * section. So the order is important and enforced by the ordering
@@ -477,6 +492,7 @@ extern int default_check_phys_apicid_pre
 
 extern void generic_bigsmp_probe(void);
 
+#endif /* CONFIG_XEN */
 
 #ifdef CONFIG_X86_LOCAL_APIC
 
@@ -498,6 +514,8 @@ static inline const struct cpumask *onli
 	return cpu_online_mask;
 }
 
+#ifndef CONFIG_XEN
+
 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
 
 
@@ -635,6 +653,8 @@ extern int default_cpu_present_to_apicid
 extern int default_check_phys_apicid_present(int phys_apicid);
 #endif
 
+#endif /* CONFIG_XEN */
+
 #endif /* CONFIG_X86_LOCAL_APIC */
 extern void irq_enter(void);
 extern void irq_exit(void);
@@ -645,23 +665,27 @@ static inline void entering_irq(void)
 	exit_idle();
 }
 
+#ifndef CONFIG_XEN
 static inline void entering_ack_irq(void)
 {
 	ack_APIC_irq();
 	entering_irq();
 }
+#endif
 
 static inline void exiting_irq(void)
 {
 	irq_exit();
 }
 
+#ifndef CONFIG_XEN
 static inline void exiting_ack_irq(void)
 {
 	irq_exit();
 	/* Ack only at the end to avoid potential reentry */
 	ack_APIC_irq();
 }
+#endif
 
 extern void ioapic_zap_locks(void);
 
--- head.orig/arch/x86/include/asm/apicdef.h	2012-07-21 22:58:29.000000000 +0200
+++ head/arch/x86/include/asm/apicdef.h	2012-02-10 13:36:33.000000000 +0100
@@ -17,6 +17,8 @@
  */
 #define IO_APIC_SLOT_SIZE		1024
 
+#ifndef CONFIG_XEN
+
 #define	APIC_ID		0x20
 
 #define	APIC_LVR	0x30
@@ -147,6 +149,16 @@
 #define XAPIC_ENABLE	(1UL << 11)
 #define X2APIC_ENABLE	(1UL << 10)
 
+#else /* CONFIG_XEN */
+
+enum {
+	APIC_DEST_ALLBUT = 0x1,
+	APIC_DEST_SELF,
+	APIC_DEST_ALLINC
+};
+
+#endif /* CONFIG_XEN */
+
 #ifdef CONFIG_X86_32
 # define MAX_IO_APICS 64
 # define MAX_LOCAL_APIC 256
@@ -155,6 +167,8 @@
 # define MAX_LOCAL_APIC 32768
 #endif
 
+#ifndef CONFIG_XEN
+
 /*
  * All x86-64 systems are xAPIC compatible.
  * In the following, "apicid" is a physical APIC ID.
@@ -425,6 +439,8 @@ struct local_apic {
 
 #undef u32
 
+#endif /* CONFIG_XEN */
+
 #ifdef CONFIG_X86_32
  #define BAD_APICID 0xFFu
 #else
--- head.orig/arch/x86/include/mach-xen/asm/fixmap.h	2015-01-13 16:18:07.000000000 +0100
+++ head/arch/x86/include/mach-xen/asm/fixmap.h	2013-05-17 16:17:47.000000000 +0200
@@ -17,7 +17,6 @@
 #ifndef __ASSEMBLY__
 #include <linux/kernel.h>
 #include <asm/acpi.h>
-#include <asm/apicdef.h>
 #include <asm/page.h>
 #ifdef CONFIG_X86_32
 #include <linux/threads.h>
@@ -82,10 +81,10 @@ enum fixed_addresses {
 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
 	FIX_OHCI1394_BASE,
 #endif
+#ifndef CONFIG_XEN
 #ifdef CONFIG_X86_LOCAL_APIC
 	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
 #endif
-#ifndef CONFIG_XEN
 #ifdef CONFIG_X86_IO_APIC
 	FIX_IO_APIC_BASE_0,
 	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
--- head.orig/arch/x86/include/mach-xen/asm/smp.h	2014-11-27 16:33:02.000000000 +0100
+++ head/arch/x86/include/mach-xen/asm/smp.h	2013-01-09 17:54:39.000000000 +0100
@@ -14,7 +14,7 @@
 #  include <asm/io_apic.h>
 # endif
 #endif
-#include <asm/thread_info.h>
+#include <linux/thread_info.h>
 #include <asm/cpumask.h>
 #include <asm/cpufeature.h>
 
@@ -209,7 +209,7 @@ extern unsigned disabled_cpus;
 
 #include <asm/smp-processor-id.h>
 
-#ifdef CONFIG_X86_LOCAL_APIC
+#if defined(CONFIG_X86_LOCAL_APIC) && !defined(CONFIG_XEN)
 
 #ifndef CONFIG_X86_64
 static inline int logical_smp_processor_id(void)
--- head.orig/arch/x86/kernel/acpi/boot.c	2013-12-06 15:31:00.000000000 +0100
+++ head/arch/x86/kernel/acpi/boot.c	2015-01-14 14:53:53.000000000 +0100
@@ -72,14 +72,14 @@ int acpi_sci_override_gsi __initdata;
 int acpi_skip_timer_override __initdata;
 int acpi_use_timer_override __initdata;
 int acpi_fix_pin2_polarity __initdata;
-#else
-#define acpi_skip_timer_override 0
-#define acpi_fix_pin2_polarity 0
-#endif
 
 #ifdef CONFIG_X86_LOCAL_APIC
 static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
 #endif
+#else
+#define acpi_skip_timer_override 0
+#define acpi_fix_pin2_polarity 0
+#endif
 
 /*
  * Locks related to IOAPIC hotplug
@@ -150,6 +150,7 @@ static int __init acpi_parse_madt(struct
 		return -ENODEV;
 	}
 
+#ifndef CONFIG_XEN
 	if (madt->address) {
 		acpi_lapic_addr = (u64) madt->address;
 
@@ -157,7 +158,6 @@ static int __init acpi_parse_madt(struct
 		       madt->address);
 	}
 
-#ifndef CONFIG_XEN
 	default_acpi_madt_oem_check(madt->header.oem_id,
 				    madt->header.oem_table_id);
 #endif
@@ -282,6 +282,7 @@ static int __init
 acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
 			  const unsigned long end)
 {
+#ifndef CONFIG_XEN
 	struct acpi_madt_local_apic_override *lapic_addr_ovr = NULL;
 
 	lapic_addr_ovr = (struct acpi_madt_local_apic_override *)header;
@@ -290,6 +291,7 @@ acpi_parse_lapic_addr_ovr(struct acpi_su
 		return -EINVAL;
 
 	acpi_lapic_addr = lapic_addr_ovr->address;
+#endif
 
 	return 0;
 }
--- head.orig/arch/x86/kernel/irq-xen.c	2015-03-12 15:12:43.000000000 +0100
+++ head/arch/x86/kernel/irq-xen.c	2015-01-14 14:53:52.000000000 +0100
@@ -22,9 +22,9 @@
 #define CREATE_TRACE_POINTS
 #include <asm/trace/irq_vectors.h>
 
+#ifndef CONFIG_XEN
 atomic_t irq_err_count;
 
-#ifndef CONFIG_XEN
 /* Function pointer for generic interrupt vector handling */
 void (*x86_platform_ipi_callback)(void) = NULL;
 #endif
@@ -65,6 +65,7 @@ int arch_show_interrupts(struct seq_file
 		seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
 	seq_puts(p, "  Non-maskable interrupts\n");
 #ifdef CONFIG_X86_LOCAL_APIC
+#ifndef CONFIG_XEN
 	seq_printf(p, "%*s: ", prec, "LOC");
 	for_each_online_cpu(j)
 		seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
@@ -78,6 +79,7 @@ int arch_show_interrupts(struct seq_file
 	for_each_online_cpu(j)
 		seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs);
 	seq_puts(p, "  Performance monitoring interrupts\n");
+#endif
 	seq_printf(p, "%*s: ", prec, "IWI");
 	for_each_online_cpu(j)
 		seq_printf(p, "%10u ", irq_stats(j)->apic_irq_work_irqs);
@@ -146,10 +148,12 @@ int arch_show_interrupts(struct seq_file
 		seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
 	seq_puts(p, "  Hypervisor callback interrupts\n");
 #endif
+#ifndef CONFIG_XEN
 	seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
 #if defined(CONFIG_X86_IO_APIC)
 	seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
 #endif
+#endif
 	return 0;
 }
 
@@ -193,8 +197,12 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
 
 u64 arch_irq_stat(void)
 {
+#ifndef CONFIG_XEN
 	u64 sum = atomic_read(&irq_err_count);
 	return sum;
+#else
+	return 0;
+#endif
 }
 
 #ifndef CONFIG_XEN
--- head.orig/drivers/xen/core/smpboot.c	2014-10-31 17:09:43.000000000 +0100
+++ head/drivers/xen/core/smpboot.c	2013-08-12 16:18:29.000000000 +0200
@@ -270,7 +270,7 @@ void __init smp_prepare_cpus(unsigned in
 	 * Here we can be sure that there is an IO-APIC in the system. Let's
 	 * go and set it up:
 	 */
-	if (!skip_ioapic_setup && nr_ioapics)
+	if (cpu_has_apic && !skip_ioapic_setup && nr_ioapics)
 		setup_IO_APIC();
 #endif
 }