Module Name:    src
Committed By:   maxv
Date:           Fri Jul 22 14:08:33 UTC 2016

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

Log Message:
Remove pmap_prealloc_lowmem_ptps on amd64. This function creates levels in
the page tree so that the first 2MB of virtual memory can be kentered in
L1.

Strictly speaking, the kernel should never kenter a virtual page below
VM_MIN_KERNEL_ADDRESS, because then it wouldn't be available in userland.
It used to need the first 2MB in order to map the CPU trampoline and the
initial VAs used by the bootstrap code. Now, the CPU trampoline VA is
allocated with uvm_km_alloc and the VAs used by the bootstrap code are
allocated with pmap_bootstrap_valloc, and in either case the resulting VA
is above VM_MIN_KERNEL_ADDRESS.

The low levels in the page tree are therefore unused. By removing this
function, we are making sure no one will be tempted to map an area below
VM_MIN_KERNEL_ADDRESS in kernel mode, and particularly, we are making sure
NULL cannot be kentered.

In short, there is no way to map NULL in kernel mode anymore.


To generate a diff of this commit:
cvs rdiff -u -r1.225 -r1.226 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/amd64/include/pmap.h
cvs rdiff -u -r1.215 -r1.216 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.225 src/sys/arch/amd64/amd64/machdep.c:1.226
--- src/sys/arch/amd64/amd64/machdep.c:1.225	Wed Jul 20 13:49:17 2016
+++ src/sys/arch/amd64/amd64/machdep.c	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.225 2016/07/20 13:49:17 maxv Exp $	*/
+/*	$NetBSD: machdep.c,v 1.226 2016/07/22 14:08:33 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.225 2016/07/20 13:49:17 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.226 2016/07/22 14:08:33 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1605,9 +1605,6 @@ init_x86_64(paddr_t first_avail)
 	 */
 	pmap_bootstrap(VM_MIN_KERNEL_ADDRESS);
 
-	if (avail_start != PAGE_SIZE)
-		pmap_prealloc_lowmem_ptps();
-
 #ifndef XEN
 	/* Internalize the physical pages into the VM system. */
 	init_x86_vm(first_avail);

Index: src/sys/arch/amd64/include/pmap.h
diff -u src/sys/arch/amd64/include/pmap.h:1.37 src/sys/arch/amd64/include/pmap.h:1.38
--- src/sys/arch/amd64/include/pmap.h:1.37	Sat May 21 07:00:18 2016
+++ src/sys/arch/amd64/include/pmap.h	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.h,v 1.37 2016/05/21 07:00:18 maxv Exp $	*/
+/*	$NetBSD: pmap.h,v 1.38 2016/07/22 14:08:33 maxv Exp $	*/
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -323,7 +323,6 @@ pmap_pte_flush(void)
 }
 #endif
 
-void pmap_prealloc_lowmem_ptps(void);
 void pmap_changeprot_local(vaddr_t, vm_prot_t);
 
 #include <x86/pmap_pv.h>

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.215 src/sys/arch/x86/x86/pmap.c:1.216
--- src/sys/arch/x86/x86/pmap.c:1.215	Fri Jul 22 13:01:43 2016
+++ src/sys/arch/x86/x86/pmap.c	Fri Jul 22 14:08:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.215 2016/07/22 13:01:43 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.216 2016/07/22 14:08:33 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.215 2016/07/22 13:01:43 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.216 2016/07/22 14:08:33 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1616,72 +1616,6 @@ pmap_remap_largepages(void)
 }
 #endif /* !XEN */
 
-#if defined(__x86_64__)
-/*
- * Pre-allocate PTPs for low memory, so that 1:1 mappings for various
- * trampoline code can be entered.
- */
-void
-pmap_prealloc_lowmem_ptps(void)
-{
-	int level;
-	paddr_t newp;
-	pd_entry_t *pdes;
-
-	const pd_entry_t pteflags = PG_k | PG_V | PG_RW;
-
-	pdes = pmap_kernel()->pm_pdir;
-	level = PTP_LEVELS;
-	for (;;) {
-		newp = pmap_bootstrap_palloc(1);
-
-#ifdef __HAVE_DIRECT_MAP
-		memset((void *)PMAP_DIRECT_MAP(newp), 0, PAGE_SIZE);
-#else
-		pmap_pte_set(early_zero_pte, pmap_pa2pte(newp) | pteflags |
-		    pmap_pg_nx);
-		pmap_pte_flush();
-		pmap_update_pg((vaddr_t)early_zerop);
-		memset(early_zerop, 0, PAGE_SIZE);
-#endif
-
-#ifdef XEN
-		/* Mark R/O before installing */
-		HYPERVISOR_update_va_mapping ((vaddr_t)early_zerop,
-		    xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-		if (newp < (NKL2_KIMG_ENTRIES * NBPD_L2))
-			HYPERVISOR_update_va_mapping (newp + KERNBASE,
-			    xpmap_ptom_masked(newp) | PG_u | PG_V, UVMF_INVLPG);
-
-		if (level == PTP_LEVELS) { /* Top level pde is per-cpu */
-			pd_entry_t *kpm_pdir;
-			/* Reach it via recursive mapping */
-			kpm_pdir = normal_pdes[PTP_LEVELS - 2];
-
-			/* Set it as usual. We can't defer this
-			 * outside the loop since recursive
-			 * pte entries won't be accessible during
-			 * further iterations at lower levels
-			 * otherwise.
-			 */
-			pmap_pte_set(&kpm_pdir[pl_i(0, PTP_LEVELS)],
-			    pmap_pa2pte(newp) | pteflags);
-		}
-#endif /* XEN */
-
-		pmap_pte_set(&pdes[pl_i(0, level)],
-		    pmap_pa2pte(newp) | pteflags);
-
-		pmap_pte_flush();
-
-		level--;
-		if (level <= 1)
-			break;
-		pdes = normal_pdes[level - 2];
-	}
-}
-#endif /* defined(__x86_64__) */
-
 /*
  * pmap_init: called from uvm_init, our job is to get the pmap
  * system ready to manage mappings...

Reply via email to