Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Move the PTE area from slot 255 to slot 509. I've n...



details:   https://anonhg.NetBSD.org/src/rev/db834537ebfc
branches:  trunk
changeset: 365328:db834537ebfc
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sun Aug 12 12:42:53 2018 +0000

description:
Move the PTE area from slot 255 to slot 509. I've never understood why we
put it on 255; the "kernel" half of the VM space begins on slot 256, so
if anything, the PTE area should have been above it, not below.

Virtually extend the user slots in slotspace, because we don't want
(randomized) kernel mappings to land on slot 255.

The prekern is updated accordingly.

Tested on GENERIC, GENERIC_KASLR and XEN3_DOM0.

diffstat:

 sys/arch/amd64/amd64/machdep.c         |  10 +++++-----
 sys/arch/amd64/amd64/prekern.c         |   4 ++--
 sys/arch/amd64/include/pmap.h          |   6 +++---
 sys/arch/amd64/stand/prekern/pdir.h    |   6 +++---
 sys/arch/amd64/stand/prekern/prekern.c |   4 ++--
 sys/arch/x86/x86/pmap.c                |   6 +++---
 6 files changed, 18 insertions(+), 18 deletions(-)

diffs (146 lines):

diff -r ae3b33ff7796 -r db834537ebfc sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.312 2018/08/12 10:50:35 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.313 2018/08/12 12:42:53 maxv Exp $       */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.312 2018/08/12 10:50:35 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.313 2018/08/12 12:42:53 maxv Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -1597,10 +1597,10 @@
 
        memset(&slotspace, 0, sizeof(slotspace));
 
-       /* User. */
+       /* User. [256, because we want to land in >= 256] */
        slotspace.area[SLAREA_USER].sslot = 0;
-       slotspace.area[SLAREA_USER].mslot = PDIR_SLOT_PTE;
-       slotspace.area[SLAREA_USER].nslot = PDIR_SLOT_PTE;
+       slotspace.area[SLAREA_USER].mslot = PDIR_SLOT_USERLIM+1;
+       slotspace.area[SLAREA_USER].nslot = PDIR_SLOT_USERLIM+1;
        slotspace.area[SLAREA_USER].active = true;
        slotspace.area[SLAREA_USER].dropmax = false;
 
diff -r ae3b33ff7796 -r db834537ebfc sys/arch/amd64/amd64/prekern.c
--- a/sys/arch/amd64/amd64/prekern.c    Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/amd64/amd64/prekern.c    Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prekern.c,v 1.3 2018/08/02 17:18:00 maxv Exp $ */
+/*     $NetBSD: prekern.c,v 1.4 2018/08/12 12:42:53 maxv Exp $ */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -46,7 +46,7 @@
 #include <dev/isa/isareg.h>
 #include <machine/isa_machdep.h>
 
-#define PREKERN_API_VERSION    1
+#define PREKERN_API_VERSION    2
 
 struct prekern_args {
        int version;
diff -r ae3b33ff7796 -r db834537ebfc sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h     Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/amd64/include/pmap.h     Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.h,v 1.51 2018/08/12 12:23:33 maxv Exp $   */
+/*     $NetBSD: pmap.h,v 1.52 2018/08/12 12:42:53 maxv Exp $   */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -137,7 +137,7 @@
  */
 #define VA_SIGN_POS(va)                ((va) & ~VA_SIGN_MASK)
 
-#define L4_SLOT_PTE            255
+#define L4_SLOT_PTE            509
 #define L4_SLOT_KERN           slotspace.area[SLAREA_MAIN].sslot
 #define L4_SLOT_KERNBASE       511 /* pl4_i(KERNBASE) */
 
@@ -153,7 +153,7 @@
  * PDP_PDE: the VA of the PDE that points back to the PDP
  */
 
-#define PTE_BASE       ((pt_entry_t *)(L4_SLOT_PTE * NBPD_L4))
+#define PTE_BASE       ((pt_entry_t *)VA_SIGN_NEG((L4_SLOT_PTE * NBPD_L4)))
 
 #define L1_BASE        PTE_BASE
 #define L2_BASE        ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
diff -r ae3b33ff7796 -r db834537ebfc sys/arch/amd64/stand/prekern/pdir.h
--- a/sys/arch/amd64/stand/prekern/pdir.h       Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/amd64/stand/prekern/pdir.h       Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pdir.h,v 1.4 2018/01/21 10:59:21 maxv Exp $    */
+/*     $NetBSD: pdir.h,v 1.5 2018/08/12 12:42:54 maxv Exp $    */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -32,12 +32,12 @@
 #define PREKERNTEXTOFF (PREKERNBASE + 0x100000)
 
 #define L4_SLOT_PREKERN        0 /* pl4_i(PREKERNBASE) */
-#define L4_SLOT_PTE    255
+#define L4_SLOT_PTE    509
 
 #define PDIR_SLOT_KERN L4_SLOT_PREKERN
 #define PDIR_SLOT_PTE  L4_SLOT_PTE
 
-#define PTE_BASE       ((pt_entry_t *)(L4_SLOT_PTE * NBPD_L4))
+#define PTE_BASE       ((pt_entry_t *)VA_SIGN_NEG((L4_SLOT_PTE * NBPD_L4)))
 
 #define L1_BASE        PTE_BASE
 #define L2_BASE        ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
diff -r ae3b33ff7796 -r db834537ebfc sys/arch/amd64/stand/prekern/prekern.c
--- a/sys/arch/amd64/stand/prekern/prekern.c    Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/amd64/stand/prekern/prekern.c    Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prekern.c,v 1.9 2018/08/02 17:18:00 maxv Exp $ */
+/*     $NetBSD: prekern.c,v 1.10 2018/08/12 12:42:54 maxv Exp $        */
 
 /*
  * Copyright (c) 2017 The NetBSD Foundation, Inc. All rights reserved.
@@ -221,7 +221,7 @@
 
 /* -------------------------------------------------------------------------- */
 
-#define PREKERN_API_VERSION    1
+#define PREKERN_API_VERSION    2
 
 struct prekern_args {
        int version;
diff -r ae3b33ff7796 -r db834537ebfc sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Sun Aug 12 12:23:33 2018 +0000
+++ b/sys/arch/x86/x86/pmap.c   Sun Aug 12 12:42:53 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.300 2018/08/12 12:23:33 maxv Exp $  */
+/*     $NetBSD: pmap.c,v 1.301 2018/08/12 12:42:54 maxv Exp $  */
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -157,7 +157,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.300 2018/08/12 12:23:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.301 2018/08/12 12:42:54 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -1418,7 +1418,7 @@
 
        /* Get the holes. */
        nholes = 0;
-       size_t curslot = 0 + 255; /* end of SLAREA_USER */
+       size_t curslot = 0 + 256; /* end of SLAREA_USER */
        while (1) {
                /*
                 * Find the first occupied slot after the current one.



Home | Main Index | Thread Index | Old Index