Module Name:    src
Committed By:   maxv
Date:           Sun Dec 11 08:31:53 UTC 2016

Modified Files:
        src/sys/arch/amd64/amd64: machdep.c
        src/sys/arch/i386/i386: machdep.c
        src/sys/arch/x86/x86: pmap.c

Log Message:
Kenter local_apic_va to a fake physical page, because our x86
implementation expects this va to be valid even if no lapic is present;
which probably is a bug in itself, but let's just reproduce the old
behavior and rehide that bug.


To generate a diff of this commit:
cvs rdiff -u -r1.235 -r1.236 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.764 -r1.765 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.229 -r1.230 src/sys/arch/x86/x86/pmap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.235 src/sys/arch/amd64/amd64/machdep.c:1.236
--- src/sys/arch/amd64/amd64/machdep.c:1.235	Fri Dec  9 17:57:24 2016
+++ src/sys/arch/amd64/amd64/machdep.c	Sun Dec 11 08:31:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.235 2016/12/09 17:57:24 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.236 2016/12/11 08:31:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.235 2016/12/09 17:57:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.236 2016/12/11 08:31:53 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1537,6 +1537,7 @@ void
 init_x86_64(paddr_t first_avail)
 {
 	extern void consinit(void);
+	extern paddr_t local_apic_pa;
 	struct region_descriptor region;
 	struct mem_segment_descriptor *ldt_segp;
 	int x;
@@ -1639,6 +1640,11 @@ init_x86_64(paddr_t first_avail)
 
 	kpreempt_disable();
 
+	pmap_kenter_pa(local_apic_va, local_apic_pa,
+	    VM_PROT_READ|VM_PROT_WRITE, 0);
+	pmap_update(pmap_kernel());
+	memset((void *)local_apic_va, 0, PAGE_SIZE);
+
 	pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	pmap_kenter_pa(gdt_vaddr, gdt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	pmap_kenter_pa(ldt_vaddr, ldt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.764 src/sys/arch/i386/i386/machdep.c:1.765
--- src/sys/arch/i386/i386/machdep.c:1.764	Tue Nov 15 15:00:55 2016
+++ src/sys/arch/i386/i386/machdep.c	Sun Dec 11 08:31:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.764 2016/11/15 15:00:55 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.765 2016/12/11 08:31:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.764 2016/11/15 15:00:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.765 2016/12/11 08:31:53 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1131,6 +1131,7 @@ void
 init386(paddr_t first_avail)
 {
 	extern void consinit(void);
+	extern paddr_t local_apic_pa;
 	int x;
 #ifndef XEN
 	union descriptor *tgdt;
@@ -1301,6 +1302,11 @@ init386(paddr_t first_avail)
 	cpu_info_primary.ci_pmap = pmap_kernel();
 #endif
 
+	pmap_kenter_pa(local_apic_va, local_apic_pa,
+	    VM_PROT_READ|VM_PROT_WRITE, 0);
+	pmap_update(pmap_kernel());
+	memset((void *)local_apic_va, 0, PAGE_SIZE);
+
 	pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	pmap_kenter_pa(gdt_vaddr, gdt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
 	pmap_kenter_pa(ldt_vaddr, ldt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.229 src/sys/arch/x86/x86/pmap.c:1.230
--- src/sys/arch/x86/x86/pmap.c:1.229	Fri Nov 25 14:26:53 2016
+++ src/sys/arch/x86/x86/pmap.c	Sun Dec 11 08:31:53 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.229 2016/11/25 14:26:53 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.229 2016/11/25 14:26:53 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.230 2016/12/11 08:31:53 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -483,9 +483,10 @@ static vaddr_t virtual_avail __read_most
 static vaddr_t virtual_end __read_mostly;	/* VA of last free KVA */
 
 /*
- * LAPIC virtual address.
+ * LAPIC virtual address, and fake physical address.
  */
 volatile vaddr_t local_apic_va;
+paddr_t local_apic_pa;
 
 /*
  * pool that pmap structures are allocated from
@@ -1467,7 +1468,17 @@ pmap_bootstrap(vaddr_t kva_start)
 static void
 pmap_init_lapic(void)
 {
+	/*
+	 * On CPUs that have no LAPIC, local_apic_va is never kentered. But our
+	 * x86 implementation relies a lot on this address to be valid; so just
+	 * allocate a fake physical page that will be kentered into
+	 * local_apic_va by machdep.
+	 *
+	 * If the LAPIC is present, the va will be remapped somewhere else
+	 * later in lapic_map.
+	 */
 	local_apic_va = pmap_bootstrap_valloc(1);
+	local_apic_pa = pmap_bootstrap_palloc(1);
 }
 
 #ifdef __HAVE_DIRECT_MAP

Reply via email to