Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Remove pmap_prealloc_lowmem_ptps on amd64. This fun...



details:   https://anonhg.NetBSD.org/src/rev/f18a431576dc
branches:  trunk
changeset: 346624:f18a431576dc
user:      maxv <maxv%NetBSD.org@localhost>
date:      Fri Jul 22 14:08:33 2016 +0000

description:
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.

diffstat:

 sys/arch/amd64/amd64/machdep.c |   7 +---
 sys/arch/amd64/include/pmap.h  |   3 +-
 sys/arch/x86/x86/pmap.c        |  70 +----------------------------------------
 3 files changed, 5 insertions(+), 75 deletions(-)

diffs (136 lines):

diff -r 4a57477ef461 -r f18a431576dc sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Fri Jul 22 13:01:43 2016 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Fri Jul 22 14:08:33 2016 +0000
@@ -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 @@
         */
        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);
diff -r 4a57477ef461 -r f18a431576dc sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h     Fri Jul 22 13:01:43 2016 +0000
+++ b/sys/arch/amd64/include/pmap.h     Fri Jul 22 14:08:33 2016 +0000
@@ -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 @@
 }
 #endif
 
-void pmap_prealloc_lowmem_ptps(void);
 void pmap_changeprot_local(vaddr_t, vm_prot_t);
 
 #include <x86/pmap_pv.h>
diff -r 4a57477ef461 -r f18a431576dc sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Fri Jul 22 13:01:43 2016 +0000
+++ b/sys/arch/x86/x86/pmap.c   Fri Jul 22 14:08:33 2016 +0000
@@ -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 @@
 }
 #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...



Home | Main Index | Thread Index | Old Index