[PATCH v7 13/19] xen: introduce flag to disable the local apic

From: Roger Pau Monne <roger.pau_at_citrix.com>
Date: Thu, 19 Dec 2013 19:54:50 +0100
PVH guests don't have an emulated lapic.
---
 sys/amd64/amd64/mp_machdep.c |   10 ++++++----
 sys/amd64/include/apicvar.h  |    1 +
 sys/i386/include/apicvar.h   |    1 +
 sys/i386/xen/xen_machdep.c   |    2 ++
 sys/x86/x86/local_apic.c     |    8 +++++---
 sys/x86/xen/pv.c             |    3 +++
 6 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/sys/amd64/amd64/mp_machdep.c b/sys/amd64/amd64/mp_machdep.c
index e302886..0296a92 100644
--- a/sys/amd64/amd64/mp_machdep.c
+++ b/sys/amd64/amd64/mp_machdep.c
_at__at_ -709,7 +709,8 _at__at_ init_secondary(void)
 	wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D);
 
 	/* Disable local APIC just to be sure. */
-	lapic_disable();
+	if (!lapic_disabled)
+		lapic_disable();
 
 	/* signal our startup to the BSP. */
 	mp_naps++;
_at__at_ -735,7 +736,7 _at__at_ init_secondary(void)
 
 	/* A quick check from sanity claus */
 	cpuid = PCPU_GET(cpuid);
-	if (PCPU_GET(apic_id) != lapic_id()) {
+	if (!lapic_disabled && (PCPU_GET(apic_id) != lapic_id())) {
 		printf("SMP: cpuid = %d\n", cpuid);
 		printf("SMP: actual apic_id = %d\n", lapic_id());
 		printf("SMP: correct apic_id = %d\n", PCPU_GET(apic_id));
_at__at_ -751,7 +752,8 _at__at_ init_secondary(void)
 	mtx_lock_spin(&ap_boot_mtx);
 
 	/* Init local apic for irq's */
-	lapic_setup(1);
+	if (!lapic_disabled)
+		lapic_setup(1);
 
 	/* Set memory range attributes for this CPU to match the BSP */
 	mem_range_AP_init();
_at__at_ -766,7 +768,7 _at__at_ init_secondary(void)
 	if (cpu_logical > 1 && PCPU_GET(apic_id) % cpu_logical != 0)
 		CPU_SET(cpuid, &logical_cpus_mask);
 
-	if (bootverbose)
+	if (!lapic_disabled && bootverbose)
 		lapic_dump("AP");
 
 	if (smp_cpus == mp_ncpus) {
diff --git a/sys/amd64/include/apicvar.h b/sys/amd64/include/apicvar.h
index e7423a3..84e01d4 100644
--- a/sys/amd64/include/apicvar.h
+++ b/sys/amd64/include/apicvar.h
_at__at_ -169,6 +169,7 _at__at_ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_disabled;
 
 u_int	apic_alloc_vector(u_int apic_id, u_int irq);
 u_int	apic_alloc_vectors(u_int apic_id, u_int *irqs, u_int count,
diff --git a/sys/i386/include/apicvar.h b/sys/i386/include/apicvar.h
index df99ebe..24c99f0 100644
--- a/sys/i386/include/apicvar.h
+++ b/sys/i386/include/apicvar.h
_at__at_ -168,6 +168,7 _at__at_ inthand_t
 
 extern vm_paddr_t lapic_paddr;
 extern int apic_cpuids[];
+extern bool lapic_disabled;
 
 u_int	apic_alloc_vector(u_int apic_id, u_int irq);
 u_int	apic_alloc_vectors(u_int apic_id, u_int *irqs, u_int count,
diff --git a/sys/i386/xen/xen_machdep.c b/sys/i386/xen/xen_machdep.c
index 09c01f1..7039b4a 100644
--- a/sys/i386/xen/xen_machdep.c
+++ b/sys/i386/xen/xen_machdep.c
_at__at_ -59,6 +59,7 _at__at_ __FBSDID("$FreeBSD$");
 #include <machine/intr_machdep.h>
 #include <machine/md_var.h>
 #include <machine/asmacros.h>
+#include <machine/apicvar.h>
 
 
 
_at__at_ -912,6 +913,7 _at__at_ initvalues(start_info_t *startinfo)
 #endif	
 	xen_start_info = startinfo;
 	HYPERVISOR_start_info = startinfo;
+	lapic_disabled = true;
 	xen_phys_machine = (xen_pfn_t *)startinfo->mfn_list;
 
 	IdlePTD = (pd_entry_t *)((uint8_t *)startinfo->pt_base + PAGE_SIZE);
diff --git a/sys/x86/x86/local_apic.c b/sys/x86/x86/local_apic.c
index 41bd602..85736c8 100644
--- a/sys/x86/x86/local_apic.c
+++ b/sys/x86/x86/local_apic.c
_at__at_ -156,6 +156,7 _at__at_ extern inthand_t IDTVEC(rsvd);
 
 volatile lapic_t *lapic;
 vm_paddr_t lapic_paddr;
+bool lapic_disabled;
 static u_long lapic_timer_divisor;
 static struct eventtimer lapic_et;
 
_at__at_ -1367,9 +1368,10 _at__at_ apic_setup_io(void *dummy __unused)
 	if (retval != 0)
 		printf("%s: Failed to setup I/O APICs: returned %d\n",
 		    best_enum->apic_name, retval);
-#ifdef XEN
-	return;
-#endif
+
+	if (lapic_disabled)
+		return;
+
 	/*
 	 * Finish setting up the local APIC on the BSP once we know how to
 	 * properly program the LINT pins.
diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c
index 7e45a83..e783bb8 100644
--- a/sys/x86/xen/pv.c
+++ b/sys/x86/xen/pv.c
_at__at_ -48,6 +48,7 _at__at_ __FBSDID("$FreeBSD$");
 #include <machine/clock.h>
 #include <machine/pc/bios.h>
 #include <machine/smp.h>
+#include <machine/apicvar.h>
 
 #include <xen/xen-os.h>
 #include <xen/pv.h>
_at__at_ -230,4 +231,6 _at__at_ xen_pv_set_init_ops(void)
 {
 	/* Init ops for Xen PV */
 	init_ops = xen_init_ops;
+	/* Disable lapic */
+	lapic_disabled = true;
 }
-- 
1.7.7.5 (Apple Git-26)
Received on Thu Dec 19 2013 - 18:25:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:45 UTC