Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64 Make pmapboot_enter panic if anything goes ...



details:   https://anonhg.NetBSD.org/src/rev/e944e43405d2
branches:  trunk
changeset: 981759:e944e43405d2
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat Mar 20 14:30:50 2021 +0000

description:
Make pmapboot_enter panic if anything goes wrong and any mappings overlap
rather than only doing it in locore.S

diffstat:

 sys/arch/aarch64/aarch64/locore.S   |  10 +++-------
 sys/arch/aarch64/aarch64/pmapboot.c |  35 +++++++++++++++++------------------
 sys/arch/aarch64/include/pmap.h     |   6 +++---
 3 files changed, 23 insertions(+), 28 deletions(-)

diffs (227 lines):

diff -r 4f7ee5204973 -r e944e43405d2 sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Sat Mar 20 14:27:47 2021 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Sat Mar 20 14:30:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.76 2021/01/09 15:07:42 jmcneill Exp $     */
+/*     $NetBSD: locore.S,v 1.77 2021/03/20 14:30:50 skrll Exp $        */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -38,7 +38,7 @@
 #include <aarch64/hypervisor.h>
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.76 2021/01/09 15:07:42 jmcneill Exp $")
+RCSID("$NetBSD: locore.S,v 1.77 2021/03/20 14:30:50 skrll Exp $")
 
 #ifdef AARCH64_DEVICE_MEM_STRONGLY_ORDERED
 #define        MAIR_DEVICE_MEM         MAIR_DEVICE_nGnRnE
@@ -832,7 +832,7 @@
 #endif
 
        /*
-        * int
+        * void
         * pmapboot_enter(
         *     x0: vaddr_t va,
         *     x1: paddr_t pa,
@@ -853,7 +853,6 @@
        orr     x4, x4, #LX_BLKPAG_UXN | LX_BLKPAG_PXN  /* attr */
        mov     x5, x26                         /* pr func */
        bl      pmapboot_enter
-       cbnz    x0, init_mmutable_error
 #endif
 
        /* identity mapping for kernel image */
@@ -869,7 +868,6 @@
        orr     x4, x4, #LX_BLKPAG_UXN
        mov     x5, x26                         /* pr func */
        bl      pmapboot_enter
-       cbnz    x0, init_mmutable_error
 
 #ifdef FDT
        VPRINT("Creating identity mapping for FDT\n")
@@ -884,7 +882,6 @@
        orr     x4, x4, #LX_BLKPAG_UXN | LX_BLKPAG_PXN  /* attr */
        mov     x5, x26                         /* pr func */
        bl      pmapboot_enter
-       cbnz    x0, init_mmutable_error
 #endif
 
        VPRINT("Creating KVA=PA tables\n")
@@ -897,7 +894,6 @@
        orr     x4, x4, #LX_BLKPAG_UXN
        mov     x5, x26                         /* pr func */
        bl      pmapboot_enter
-       cbnz    x0, init_mmutable_error
 
        VPRINT("OK\n");
        mov     x0, xzr
diff -r 4f7ee5204973 -r e944e43405d2 sys/arch/aarch64/aarch64/pmapboot.c
--- a/sys/arch/aarch64/aarch64/pmapboot.c       Sat Mar 20 14:27:47 2021 +0000
+++ b/sys/arch/aarch64/aarch64/pmapboot.c       Sat Mar 20 14:30:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmapboot.c,v 1.15 2021/01/09 13:42:25 jmcneill Exp $   */
+/*     $NetBSD: pmapboot.c,v 1.16 2021/03/20 14:30:50 skrll Exp $      */
 
 /*
  * Copyright (c) 2018 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmapboot.c,v 1.15 2021/01/09 13:42:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmapboot.c,v 1.16 2021/03/20 14:30:50 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -207,7 +207,7 @@
  * pmapboot_enter() accesses pagetables by physical address.
  * this should be called while identity mapping (VA=PA) available.
  */
-int
+void
 pmapboot_enter(vaddr_t va, paddr_t pa, psize_t size, psize_t blocksize,
     pt_entry_t attr, void (*pr)(const char *, ...) __printflike(1, 2))
 {
@@ -232,7 +232,7 @@
                level = 3;
                break;
        default:
-               return -1;
+               panic("%s: bad blocksize (%" PRIxPSIZE ")", __func__, blocksize);
        }
 
        VPRINTF("pmapboot_enter: va=0x%lx, pa=0x%lx, size=0x%lx, "
@@ -260,7 +260,8 @@
                ttbr = 1;
                break;
        default:
-               return -1;
+               panic("%s: unknown address space (%d/%" PRIxVADDR ")", __func__,
+                   aarch64_addressspace(va), va);
        }
 
        while (va < va_end) {
@@ -275,7 +276,7 @@
                        if (l1 == NULL) {
                                VPRINTF("pmapboot_enter: "
                                    "cannot allocate L1 page\n");
-                               return -1;
+                               panic("%s: can't allocate memory", __func__);
                        }
 
                        pte = (uint64_t)l1 | L0_TABLE;
@@ -320,7 +321,7 @@
                        if (l2 == NULL) {
                                VPRINTF("pmapboot_enter: "
                                    "cannot allocate L2 page\n");
-                               return -1;
+                               panic("%s: can't allocate memory", __func__);
                        }
 
                        pte = (uint64_t)l2 | L1_TABLE;
@@ -364,7 +365,7 @@
                        if (l3 == NULL) {
                                VPRINTF("pmapboot_enter: "
                                    "cannot allocate L3 page\n");
-                               return -1;
+                               panic("%s: can't allocate memory", __func__);
                        }
 
                        pte = (uint64_t)l3 | L2_TABLE;
@@ -440,7 +441,8 @@
 
        dsb(ish);
 
-       return nskip;
+       if (nskip != 0)
+               panic("%s: overlapping/incompatible mappings (%d)", __func__, nskip);
 }
 
 paddr_t pmapboot_pagebase __attribute__((__section__(".data")));
@@ -465,13 +467,12 @@
        return (pd_entry_t *)pa;
 }
 
-int
+void
 pmapboot_enter_range(vaddr_t va, paddr_t pa, psize_t size, pt_entry_t attr,
     void (*pr)(const char *, ...) __printflike(1, 2))
 {
        vaddr_t vend;
        vsize_t left, mapsize, nblocks;
-       int nskip = 0;
 
        vend = round_page(va + size);
        va = trunc_page(va);
@@ -484,7 +485,7 @@
                mapsize = nblocks * L3_SIZE;
                VPRINTF("Creating L3 tables: %016lx-%016lx : %016lx-%016lx\n",
                    va, va + mapsize - 1, pa, pa + mapsize - 1);
-               nskip += pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, pr);
+               pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, pr);
                va += mapsize;
                pa += mapsize;
                left -= mapsize;
@@ -497,7 +498,7 @@
                mapsize = nblocks * L2_SIZE;
                VPRINTF("Creating L2 tables: %016lx-%016lx : %016lx-%016lx\n",
                    va, va + mapsize - 1, pa, pa + mapsize - 1);
-               nskip += pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, pr);
+               pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, pr);
                va += mapsize;
                pa += mapsize;
                left -= mapsize;
@@ -508,7 +509,7 @@
                mapsize = nblocks * L1_SIZE;
                VPRINTF("Creating L1 tables: %016lx-%016lx : %016lx-%016lx\n",
                    va, va + mapsize - 1, pa, pa + mapsize - 1);
-               nskip += pmapboot_enter(va, pa, mapsize, L1_SIZE, attr, pr);
+               pmapboot_enter(va, pa, mapsize, L1_SIZE, attr, pr);
                va += mapsize;
                pa += mapsize;
                left -= mapsize;
@@ -519,7 +520,7 @@
                mapsize = nblocks * L2_SIZE;
                VPRINTF("Creating L2 tables: %016lx-%016lx : %016lx-%016lx\n",
                    va, va + mapsize - 1, pa, pa + mapsize - 1);
-               nskip += pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, pr);
+               pmapboot_enter(va, pa, mapsize, L2_SIZE, attr, pr);
                va += mapsize;
                pa += mapsize;
                left -= mapsize;
@@ -530,11 +531,9 @@
                mapsize = nblocks * L3_SIZE;
                VPRINTF("Creating L3 tables: %016lx-%016lx : %016lx-%016lx\n",
                    va, va + mapsize - 1, pa, pa + mapsize - 1);
-               nskip += pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, pr);
+               pmapboot_enter(va, pa, mapsize, L3_SIZE, attr, pr);
                va += mapsize;
                pa += mapsize;
                left -= mapsize;
        }
-
-       return nskip;
 }
diff -r 4f7ee5204973 -r e944e43405d2 sys/arch/aarch64/include/pmap.h
--- a/sys/arch/aarch64/include/pmap.h   Sat Mar 20 14:27:47 2021 +0000
+++ b/sys/arch/aarch64/include/pmap.h   Sat Mar 20 14:30:50 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.h,v 1.45 2021/01/31 08:14:58 skrll Exp $ */
+/* $NetBSD: pmap.h,v 1.46 2021/03/20 14:30:50 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -180,9 +180,9 @@
 
 /* pmapboot.c */
 pd_entry_t *pmapboot_pagealloc(void);
-int pmapboot_enter(vaddr_t, paddr_t, psize_t, psize_t, pt_entry_t,
+void pmapboot_enter(vaddr_t, paddr_t, psize_t, psize_t, pt_entry_t,
     void (*pr)(const char *, ...) __printflike(1, 2));
-int pmapboot_enter_range(vaddr_t, paddr_t, psize_t, pt_entry_t,
+void pmapboot_enter_range(vaddr_t, paddr_t, psize_t, pt_entry_t,
     void (*)(const char *, ...) __printflike(1, 2));
 int pmapboot_protect(vaddr_t, vaddr_t, vm_prot_t);
 void pmap_db_pte_print(pt_entry_t, int,



Home | Main Index | Thread Index | Old Index