Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64 Adjust the kernel virtual address space so ...



details:   https://anonhg.NetBSD.org/src/rev/6b4f99c4c10e
branches:  trunk
changeset: 953794:6b4f99c4c10e
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sun Mar 21 07:32:44 2021 +0000

description:
Adjust the kernel virtual address space so that KASAN will map the kernel
seperately from managed kernel virtual memory and not map the unused space
between the two.

diffstat:

 sys/arch/aarch64/aarch64/aarch64_machdep.c |  25 ++++++++++++++++++++++---
 sys/arch/aarch64/include/asan.h            |  10 +++++++---
 sys/arch/aarch64/include/vmparam.h         |   8 ++++----
 3 files changed, 33 insertions(+), 10 deletions(-)

diffs (148 lines):

diff -r af5f8b7f40f9 -r 6b4f99c4c10e sys/arch/aarch64/aarch64/aarch64_machdep.c
--- a/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Mar 21 07:17:12 2021 +0000
+++ b/sys/arch/aarch64/aarch64/aarch64_machdep.c        Sun Mar 21 07:32:44 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch64_machdep.c,v 1.57 2021/03/21 07:17:12 skrll Exp $ */
+/* $NetBSD: aarch64_machdep.c,v 1.58 2021/03/21 07:32:44 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.57 2021/03/21 07:17:12 skrll Exp $");
+__KERNEL_RCSID(1, "$NetBSD: aarch64_machdep.c,v 1.58 2021/03/21 07:32:44 skrll Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_cpuoptions.h"
@@ -96,6 +96,11 @@
 static struct vm_map module_map_store;
 #endif
 
+#ifdef KASAN
+vaddr_t kasan_kernelstart;
+vaddr_t kasan_kernelsize;
+#endif
+
 /* XXX */
 vaddr_t physical_start;
 vaddr_t physical_end;
@@ -195,6 +200,11 @@
            kernstart_phys, kernend_phys, kernend_extra);
        fdt_memory_remove_range(kernstart_phys,
             kernend_phys - kernstart_phys + kernend_extra);
+
+#ifdef KASAN
+       kasan_kernelstart = kernstart;
+       kasan_kernelsize = L2_ROUND_BLOCK(kernend) - kernstart;
+#endif
 }
 
 
@@ -245,8 +255,10 @@
 
        kernstart = trunc_page((vaddr_t)__kernel_text);
        kernend = round_page((vaddr_t)_end);
+
        kernstart_l2 = L2_TRUNC_BLOCK(kernstart);
        kernend_l2 = L2_ROUND_BLOCK(kernend);
+
        kernelvmstart = kernend_l2;
 
 #ifdef MODULAR
@@ -266,6 +278,10 @@
        kernelvmstart = module_end;
 #endif /* MODULAR */
 
+       KASSERT(kernelvmstart < VM_KERNEL_VM_BASE);
+
+       kernelvmstart = VM_KERNEL_VM_BASE;
+
        paddr_t kernstart_phys __unused = KERN_VTOPHYS(kernstart);
        paddr_t kernend_phys __unused = KERN_VTOPHYS(kernend);
 
@@ -307,12 +323,13 @@
            "kernel_start_l2       = 0x%016lx\n"
            "kernel_start          = 0x%016lx\n"
            "kernel_end            = 0x%016lx\n"
+           "(extra)               = 0x%016lx\n"
            "kernel_end_l2         = 0x%016lx\n"
 #ifdef MODULAR
            "module_start          = 0x%016lx\n"
            "module_end            = 0x%016lx\n"
 #endif
-           "(kernel va area)\n"
+           "(kernel va area)      = 0x%016lx\n"
            "(devmap va area)      = 0x%016lx\n"
            "VM_MAX_KERNEL_ADDRESS = 0x%016lx\n"
            "------------------------------------------\n",
@@ -328,11 +345,13 @@
            kernstart_l2,
            kernstart,
            kernend,
+           kernend_extra,
            kernend_l2,
 #ifdef MODULAR
            module_start,
            module_end,
 #endif
+           VM_KERNEL_VM_BASE,
            VM_KERNEL_IO_ADDRESS,
            VM_MAX_KERNEL_ADDRESS);
 
diff -r af5f8b7f40f9 -r 6b4f99c4c10e sys/arch/aarch64/include/asan.h
--- a/sys/arch/aarch64/include/asan.h   Sun Mar 21 07:17:12 2021 +0000
+++ b/sys/arch/aarch64/include/asan.h   Sun Mar 21 07:32:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asan.h,v 1.16 2020/12/11 18:03:33 skrll Exp $  */
+/*     $NetBSD: asan.h,v 1.17 2021/03/21 07:32:44 skrll Exp $  */
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -206,10 +206,14 @@
 
        CTASSERT((__MD_SHADOW_SIZE / L0_SIZE) == 64);
 
+       extern vaddr_t kasan_kernelstart;
+       extern vaddr_t kasan_kernelsize;
+
+       kasan_shadow_map((void *)kasan_kernelstart, kasan_kernelsize);
+
        /* The VAs we've created until now. */
        vaddr_t eva = pmap_growkernel(VM_KERNEL_VM_BASE);
-       kasan_shadow_map((void *)VM_MIN_KERNEL_ADDRESS,
-           eva - VM_MIN_KERNEL_ADDRESS);
+       kasan_shadow_map((void *)VM_KERNEL_VM_BASE, eva - VM_KERNEL_VM_BASE);
 }
 
 static inline bool
diff -r af5f8b7f40f9 -r 6b4f99c4c10e sys/arch/aarch64/include/vmparam.h
--- a/sys/arch/aarch64/include/vmparam.h        Sun Mar 21 07:17:12 2021 +0000
+++ b/sys/arch/aarch64/include/vmparam.h        Sun Mar 21 07:32:44 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vmparam.h,v 1.17 2020/11/10 07:51:19 skrll Exp $ */
+/* $NetBSD: vmparam.h,v 1.18 2021/03/21 07:32:44 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -133,6 +133,7 @@
  *   0xffff_8000_0000_0000  -    1G  EFI_RUNTIME
  *   0xffff_8000_4000_0000  -   64T  (not used)
  *   0xffff_c000_0000_0000  -   64T  KERNEL VM Space (including text/data/bss)
+ *  (0xffff_c000_4000_0000     -1GB) KERNEL VM start of KVM
  *   0xffff_ffff_f000_0000  -  254M  KERNEL_IO for pmap_devmap
  *   0xffff_ffff_ffe0_0000  -    2M  RESERVED
  */
@@ -146,9 +147,8 @@
 #define VM_KERNEL_IO_ADDRESS   0xfffffffff0000000L
 #define VM_KERNEL_IO_SIZE      (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_IO_ADDRESS)
 
-#define VM_KERNEL_VM_BASE      VM_MIN_KERNEL_ADDRESS
-#define VM_KERNEL_VM_SIZE      (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_VM_BASE)
-
+#define VM_KERNEL_VM_BASE      (0xffffc00040000000L)
+#define VM_KERNEL_VM_SIZE      (VM_KERNEL_IO_ADDRESS - VM_KERNEL_VM_BASE)
 /*
  * Reserved space for EFI runtime services
  */



Home | Main Index | Thread Index | Old Index