Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm/pmap Support pmap_growkernel and KASAN shadow mappin...



details:   https://anonhg.NetBSD.org/src/rev/4d9a8ef16721
branches:  trunk
changeset: 960429:4d9a8ef16721
user:      skrll <skrll%NetBSD.org@localhost>
date:      Fri Mar 19 07:51:33 2021 +0000

description:
Support pmap_growkernel and KASAN shadow mapping of the new KVA.

Neither mips nor ppc booke actually use pmap_growkernel (at present).

Thanks to rin@ for testing a similar patch on ppc booke.

diffstat:

 sys/arch/mips/mips/pmap_machdep.c   |   6 ++++--
 sys/arch/powerpc/booke/booke_pmap.c |   7 +++++--
 sys/uvm/pmap/pmap.c                 |  33 ++++++++++++++++++++++++---------
 sys/uvm/pmap/pmap.h                 |   7 ++++++-
 4 files changed, 39 insertions(+), 14 deletions(-)

diffs (159 lines):

diff -r 3f5ca01bce94 -r 4d9a8ef16721 sys/arch/mips/mips/pmap_machdep.c
--- a/sys/arch/mips/mips/pmap_machdep.c Fri Mar 19 01:02:52 2021 +0000
+++ b/sys/arch/mips/mips/pmap_machdep.c Fri Mar 19 07:51:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap_machdep.c,v 1.33 2020/12/20 16:38:25 skrll Exp $  */
+/*     $NetBSD: pmap_machdep.c,v 1.34 2021/03/19 07:51:33 skrll Exp $  */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.33 2020/12/20 16:38:25 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap_machdep.c,v 1.34 2021/03/19 07:51:33 skrll Exp $");
 
 /*
  *     Manages physical address maps.
@@ -482,6 +482,8 @@
        }
        KASSERT(pmap_pte_lookup(pmap_kernel(), VM_MIN_KERNEL_ADDRESS) == sysmap);
 
+       /* update the top of the kernel VM - pmap_growkernel not required */
+       pmap_curmaxkvaddr = pmap_limits.virtual_end;
        /*
         * Initialize the pools.
         */
diff -r 3f5ca01bce94 -r 4d9a8ef16721 sys/arch/powerpc/booke/booke_pmap.c
--- a/sys/arch/powerpc/booke/booke_pmap.c       Fri Mar 19 01:02:52 2021 +0000
+++ b/sys/arch/powerpc/booke/booke_pmap.c       Fri Mar 19 07:51:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: booke_pmap.c,v 1.31 2021/01/06 07:56:19 rin Exp $      */
+/*     $NetBSD: booke_pmap.c,v 1.32 2021/03/19 07:51:33 skrll Exp $    */
 /*-
  * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -37,7 +37,7 @@
 #define __PMAP_PRIVATE
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.31 2021/01/06 07:56:19 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: booke_pmap.c,v 1.32 2021/03/19 07:51:33 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_multiprocessor.h"
@@ -206,6 +206,9 @@
                    + kv_nsegtabs * NBSEG;
        }
 
+       /* update the top of the kernel VM - pmap_growkernel not required */
+       pmap_curmaxkvaddr = pmap_limits.virtual_end;
+
        /*
         * Now actually allocate the kernel PTE array (must be done
         * after virtual_end is initialized).
diff -r 3f5ca01bce94 -r 4d9a8ef16721 sys/uvm/pmap/pmap.c
--- a/sys/uvm/pmap/pmap.c       Fri Mar 19 01:02:52 2021 +0000
+++ b/sys/uvm/pmap/pmap.c       Fri Mar 19 07:51:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.60 2021/03/13 17:14:11 skrll Exp $  */
+/*     $NetBSD: pmap.c,v 1.61 2021/03/19 07:51:33 skrll Exp $  */
 
 /*-
  * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.60 2021/03/13 17:14:11 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.61 2021/03/19 07:51:33 skrll Exp $");
 
 /*
  *     Manages physical address maps.
@@ -103,6 +103,7 @@
 
 #include <sys/param.h>
 
+#include <sys/asan.h>
 #include <sys/atomic.h>
 #include <sys/buf.h>
 #include <sys/cpu.h>
@@ -212,8 +213,12 @@
 
 struct pmap * const kernel_pmap_ptr = &kernel_pmap_store.kernel_pmap;
 
+/* The current top of kernel VM - gets updated by pmap_growkernel */
+vaddr_t pmap_curmaxkvaddr;
+
 struct pmap_limits pmap_limits = {     /* VA and PA limits */
        .virtual_start = VM_MIN_KERNEL_ADDRESS,
+       .virtual_end = VM_MAX_KERNEL_ADDRESS,
 };
 
 #ifdef UVMHIST
@@ -453,26 +458,36 @@
 vaddr_t
 pmap_growkernel(vaddr_t maxkvaddr)
 {
-       vaddr_t virtual_end = pmap_limits.virtual_end;
+       UVMHIST_FUNC(__func__);
+       UVMHIST_CALLARGS(pmaphist, "maxkvaddr=%#jx (%#jx)", maxkvaddr,
+           pmap_curmaxkvaddr, 0, 0);
+
+       vaddr_t virtual_end = pmap_curmaxkvaddr;
        maxkvaddr = pmap_round_seg(maxkvaddr) - 1;
 
        /*
+        * Don't exceed VM_MAX_KERNEL_ADDRESS!
+        */
+       if (maxkvaddr == 0 || maxkvaddr > VM_MAX_KERNEL_ADDRESS)
+               maxkvaddr = VM_MAX_KERNEL_ADDRESS;
+
+       /*
         * Reserve PTEs for the new KVA space.
         */
        for (; virtual_end < maxkvaddr; virtual_end += NBSEG) {
                pmap_pte_reserve(pmap_kernel(), virtual_end, 0);
        }
 
-       /*
-        * Don't exceed VM_MAX_KERNEL_ADDRESS!
-        */
-       if (virtual_end == 0 || virtual_end > VM_MAX_KERNEL_ADDRESS)
-               virtual_end = VM_MAX_KERNEL_ADDRESS;
+       kasan_shadow_map((void *)pmap_curmaxkvaddr,
+           (size_t)(virtual_end - pmap_curmaxkvaddr));
 
        /*
         * Update new end.
         */
-       pmap_limits.virtual_end = virtual_end;
+       pmap_curmaxkvaddr = virtual_end;
+
+       UVMHIST_LOG(pmaphist, " <-- done", 0, 0, 0, 0);
+
        return virtual_end;
 }
 
diff -r 3f5ca01bce94 -r 4d9a8ef16721 sys/uvm/pmap/pmap.h
--- a/sys/uvm/pmap/pmap.h       Fri Mar 19 01:02:52 2021 +0000
+++ b/sys/uvm/pmap/pmap.h       Fri Mar 19 07:51:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.h,v 1.19 2020/12/21 08:41:38 skrll Exp $  */
+/*     $NetBSD: pmap.h,v 1.20 2021/03/19 07:51:33 skrll Exp $  */
 
 /*
  * Copyright (c) 1992, 1993
@@ -186,6 +186,11 @@
 
 extern pmap_segtab_t pmap_kern_segtab;
 
+/*
+ * The current top of kernel VM
+ */
+extern vaddr_t pmap_curmaxkvaddr;
+
 #define        pmap_wired_count(pmap)  ((pmap)->pm_stats.wired_count)
 #define pmap_resident_count(pmap) ((pmap)->pm_stats.resident_count)
 



Home | Main Index | Thread Index | Old Index