Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/arm32 In the ARM_MMU_EXTENDED case make sure th...



details:   https://anonhg.NetBSD.org/src/rev/86882522e4c8
branches:  trunk
changeset: 341838:86882522e4c8
user:      skrll <skrll%NetBSD.org@localhost>
date:      Wed Nov 25 08:36:50 2015 +0000

description:
In the ARM_MMU_EXTENDED case make sure the kernel mappings are marked with
XN (eXecute Never) appropriately.

The XN logic is inconsistent and could do with changing to XN always set
and cleared for VM_PROT_EXECUTE (or the inverse) everywhere.

diffstat:

 sys/arch/arm/arm32/arm32_kvminit.c |  19 ++++++++-----------
 sys/arch/arm/arm32/pmap.c          |  27 +++++++++++----------------
 2 files changed, 19 insertions(+), 27 deletions(-)

diffs (148 lines):

diff -r c17398e592ae -r 86882522e4c8 sys/arch/arm/arm32/arm32_kvminit.c
--- a/sys/arch/arm/arm32/arm32_kvminit.c        Wed Nov 25 08:32:33 2015 +0000
+++ b/sys/arch/arm/arm32/arm32_kvminit.c        Wed Nov 25 08:36:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: arm32_kvminit.c,v 1.36 2015/11/25 08:32:33 skrll Exp $ */
+/*     $NetBSD: arm32_kvminit.c,v 1.37 2015/11/25 08:36:50 skrll Exp $ */
 
 /*
  * Copyright (c) 2002, 2003, 2005  Genetec Corporation.  All rights reserved.
@@ -124,7 +124,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.36 2015/11/25 08:32:33 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: arm32_kvminit.c,v 1.37 2015/11/25 08:36:50 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -442,11 +442,10 @@
        kernel_size = round_page(kernel_size);
 
        /*
-        * Now we know how many L2 pages it will take.  If we've mapped
-        * all of memory, then it won't take any.
+        * Now we know how many L2 pages it will take.
         */
-       const size_t KERNEL_L2PT_KERNEL_NUM = mapallmem_p
-           ? 0 : round_page(kernel_size + L2_S_SEGSIZE - 1) / L2_S_SEGSIZE;
+       const size_t KERNEL_L2PT_KERNEL_NUM =
+           round_page(kernel_size + L2_S_SEGSIZE - 1) / L2_S_SEGSIZE;
 
 #ifdef VERBOSE_INIT_ARM
        printf("%s: %zu L2 pages are needed to map %#zx kernel bytes\n",
@@ -514,8 +513,6 @@
 #ifdef VERBOSE_INIT_ARM
        printf(" kernel");
 #endif
-       KASSERT(mapallmem_p || KERNEL_L2PT_KERNEL_NUM > 0);
-       KASSERT(!mapallmem_p || KERNEL_L2PT_KERNEL_NUM == 0);
        for (size_t idx = 0; idx < KERNEL_L2PT_KERNEL_NUM; ++idx) {
                valloc_pages(bmi, &kernel_l2pt[idx], 1,
                    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE, true);
@@ -584,7 +581,7 @@
                 * This page will just contain the system vectors and can be
                 * shared by all processes.
                 */
-               valloc_pages(bmi, &systempage, 1, VM_PROT_READ|VM_PROT_WRITE,
+               valloc_pages(bmi, &systempage, 1, VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE,
                    PTE_CACHE, true);
        }
        systempage.pv_va = vectors;
@@ -684,7 +681,7 @@
        text.pv_pa = bmi->bmi_kernelstart;
        text.pv_va = KERN_PHYSTOV(bmi, bmi->bmi_kernelstart);
        text.pv_size = textsize;
-       text.pv_prot = VM_PROT_READ|VM_PROT_WRITE; /* XXX VM_PROT_EXECUTE */
+       text.pv_prot = VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE;
        text.pv_cache = PTE_CACHE;
 
 #ifdef VERBOSE_INIT_ARM
@@ -842,7 +839,7 @@
        if (map_vectors_p) {
                /* Map the vector page. */
                pmap_map_entry(l1pt_va, systempage.pv_va, systempage.pv_pa,
-                   VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
+                   VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE, PTE_CACHE);
        }
 
        /* Map the Mini-Data cache clean area. */
diff -r c17398e592ae -r 86882522e4c8 sys/arch/arm/arm32/pmap.c
--- a/sys/arch/arm/arm32/pmap.c Wed Nov 25 08:32:33 2015 +0000
+++ b/sys/arch/arm/arm32/pmap.c Wed Nov 25 08:36:50 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.330 2015/11/13 08:04:21 skrll Exp $ */
+/*     $NetBSD: pmap.c,v 1.331 2015/11/25 08:36:50 skrll Exp $ */
 
 /*
  * Copyright 2003 Wasabi Systems, Inc.
@@ -217,7 +217,7 @@
 
 #include <arm/locore.h>
 
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.330 2015/11/13 08:04:21 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.331 2015/11/25 08:36:50 skrll Exp $");
 
 //#define PMAP_DEBUG
 #ifdef PMAP_DEBUG
@@ -6730,10 +6730,8 @@
                if (L1_SS_PROTO && L1_SS_MAPPABLE_P(va, pa, resid)) {
                        /* Supersection are always domain 0 */
                        const pd_entry_t npde = L1_SS_PROTO | pa
-#ifdef ARM_MMU_EXTENDED_XXX
+#ifdef ARM_MMU_EXTENDED
                            | ((prot & VM_PROT_EXECUTE) ? 0 : L1_S_V6_XN)
-#endif
-#ifdef ARM_MMU_EXTENDED
                            | (va & 0x80000000 ? 0 : L1_S_V6_nG)
 #endif
                            | L1_S_PROT(PTE_KERNEL, prot) | f1;
@@ -6751,10 +6749,8 @@
                /* See if we can use a section mapping. */
                if (L1_S_MAPPABLE_P(va, pa, resid)) {
                        const pd_entry_t npde = L1_S_PROTO | pa
-#ifdef ARM_MMU_EXTENDED_XXX
+#ifdef ARM_MMU_EXTENDED
                            | ((prot & VM_PROT_EXECUTE) ? 0 : L1_S_V6_XN)
-#endif
-#ifdef ARM_MMU_EXTENDED
                            | (va & 0x80000000 ? 0 : L1_S_V6_nG)
 #endif
                            | L1_S_PROT(PTE_KERNEL, prot) | f1
@@ -6788,10 +6784,8 @@
                /* See if we can use a L2 large page mapping. */
                if (L2_L_MAPPABLE_P(va, pa, resid)) {
                        const pt_entry_t npte = L2_L_PROTO | pa
-#ifdef ARM_MMU_EXTENDED_XXX
+#ifdef ARM_MMU_EXTENDED
                            | ((prot & VM_PROT_EXECUTE) ? 0 : L2_XS_L_XN)
-#endif
-#ifdef ARM_MMU_EXTENDED
                            | (va & 0x80000000 ? 0 : L2_XS_nG)
 #endif
                            | L2_L_PROT(PTE_KERNEL, prot) | f2l;
@@ -6806,18 +6800,19 @@
                        continue;
                }
 
-               /* Use a small page mapping. */
 #ifdef VERBOSE_INIT_ARM
                printf("P");
 #endif
-               const pt_entry_t npte = L2_S_PROTO | pa
-#ifdef ARM_MMU_EXTENDED_XXX
+               /* Use a small page mapping. */
+               pt_entry_t npte = L2_S_PROTO | pa
+#ifdef ARM_MMU_EXTENDED
                    | ((prot & VM_PROT_EXECUTE) ? 0 : L2_XS_XN)
-#endif
-#ifdef ARM_MMU_EXTENDED
                    | (va & 0x80000000 ? 0 : L2_XS_nG)
 #endif
                    | L2_S_PROT(PTE_KERNEL, prot) | f2s;
+#ifdef ARM_MMU_EXTENDED
+               npte &= ((prot & VM_PROT_EXECUTE) ? ~L2_XS_XN : ~0);
+#endif
                l2pte_set(ptep, npte, 0);
                PTE_SYNC(ptep);
                va += PAGE_SIZE;



Home | Main Index | Thread Index | Old Index