Module Name: src Committed By: reinoud Date: Fri Aug 3 11:18:22 UTC 2018
Modified Files: src/sys/arch/usermode/include: vmparam.h src/sys/arch/usermode/usermode: db_memrw.c pmap.c Log Message: Allow for setting kernel breakpoints in our remote kgdb To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/arch/usermode/include/vmparam.h cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/usermode/db_memrw.c cvs rdiff -u -r1.111 -r1.112 src/sys/arch/usermode/usermode/pmap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/usermode/include/vmparam.h diff -u src/sys/arch/usermode/include/vmparam.h:1.19 src/sys/arch/usermode/include/vmparam.h:1.20 --- src/sys/arch/usermode/include/vmparam.h:1.19 Wed Aug 1 12:09:02 2018 +++ src/sys/arch/usermode/include/vmparam.h Fri Aug 3 11:18:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: vmparam.h,v 1.19 2018/08/01 12:09:02 reinoud Exp $ */ +/* $NetBSD: vmparam.h,v 1.20 2018/08/03 11:18:22 reinoud Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -43,7 +43,7 @@ extern paddr_t kmem_user_start, kmem_use #define VM_MAX_ADDRESS kmem_user_end #define VM_MAXUSER_ADDRESS kmem_user_end #define VM_MIN_KERNEL_ADDRESS kmem_kvm_start -#define VM_MAX_KERNEL_ADDRESS kmem_kvm_end +#define VM_MAX_KERNEL_ADDRESS kmem_k_end #define VM_PHYSSEG_STRAT VM_PSTRAT_BIGFIRST #define VM_PHYSSEG_MAX 1 Index: src/sys/arch/usermode/usermode/db_memrw.c diff -u src/sys/arch/usermode/usermode/db_memrw.c:1.2 src/sys/arch/usermode/usermode/db_memrw.c:1.3 --- src/sys/arch/usermode/usermode/db_memrw.c:1.2 Wed Aug 1 10:27:28 2018 +++ src/sys/arch/usermode/usermode/db_memrw.c Fri Aug 3 11:18:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $ */ +/* $NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $ */ /*- * Copyright (c) 1996, 2000 The NetBSD Foundation, Inc. @@ -53,11 +53,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.2 2018/08/01 10:27:28 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_memrw.c,v 1.3 2018/08/03 11:18:22 reinoud Exp $"); #include <sys/param.h> #include <sys/proc.h> #include <sys/systm.h> +#include <sys/mman.h> #include <machine/pmap.h> #include <machine/db_machdep.h> @@ -211,29 +212,30 @@ db_write_text(vaddr_t addr, size_t size, void db_write_bytes(vaddr_t addr, size_t size, const char *data) { -// extern struct bootspace bootspace; char *dst; -// size_t i; + int ret; dst = (char *)addr; thunk_printf_debug("\n%s : %p + %d\n", __func__, dst, (int) size); -#if 0 - // TODO: check if we in kernel range and if so, do the mmap dance - // ourselves? - /* If any part is in kernel text or rodata, use db_write_text() */ - for (i = 0; i < BTSPACE_NSEGS; i++) { - if (bootspace.segs[i].type != BTSEG_TEXT && - bootspace.segs[i].type != BTSEG_RODATA) { - continue; - } - if (addr >= bootspace.segs[i].va && - addr < (bootspace.segs[i].va + bootspace.segs[i].sz)) { - db_write_text(addr, size, data); - return; - } + if (db_validate_address((vaddr_t)addr)) { + printf("address %p is invalid\n", (void *) addr); + return; + } + + /* + * if we are in the kernel range, just allow writing by using + * mprotect(); Note that this needs an unprotected binary, set with + * `paxctl -agm netbsd` + */ + if (addr > kmem_k_start) { + ret = thunk_mprotect((void *) trunc_page(addr), PAGE_SIZE, + PROT_READ | PROT_WRITE | PROT_EXEC); + if (ret != 0) + panic("please unprotect kernel binary with " + "`paxctl -agm netbsd`"); + assert(ret == 0); } -#endif dst = (char *)addr; Index: src/sys/arch/usermode/usermode/pmap.c diff -u src/sys/arch/usermode/usermode/pmap.c:1.111 src/sys/arch/usermode/usermode/pmap.c:1.112 --- src/sys/arch/usermode/usermode/pmap.c:1.111 Fri Aug 3 06:52:50 2018 +++ src/sys/arch/usermode/usermode/pmap.c Fri Aug 3 11:18:22 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $ */ +/* $NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $ */ /*- * Copyright (c) 2011 Reinoud Zandijk <rein...@netbsd.org> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.111 2018/08/03 06:52:50 reinoud Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.112 2018/08/03 11:18:22 reinoud Exp $"); #include "opt_memsize.h" #include "opt_kmempages.h" @@ -139,7 +139,7 @@ pmap_bootstrap(void) struct pmap *pmap; paddr_t DRAM_cfg; paddr_t fpos, file_len; - paddr_t pv_fpos, tlb_fpos, pm_l1_fpos, pm_fpos; + paddr_t kernel_fpos, pv_fpos, tlb_fpos, pm_l1_fpos, pm_fpos; paddr_t wlen; paddr_t barrier_len; paddr_t pv_table_size; @@ -281,9 +281,11 @@ pmap_bootstrap(void) assert(err == 0); /* map the kernel at the start of the 'memory' file */ - written = thunk_pwrite(mem_fh, (void *) kmem_k_start, kmem_k_length, 0); + kernel_fpos = 0; + written = thunk_pwrite(mem_fh, (void *) kmem_k_start, kmem_k_length, + kernel_fpos); assert(written == kmem_k_length); - fpos = kmem_k_length; + fpos = kernel_fpos + kmem_k_length; /* initialize counters */ free_start = fpos; /* in physical space ! */ @@ -298,7 +300,7 @@ pmap_bootstrap(void) (uint64_t) pv_table_size/1024, (uintptr_t) phys_npages); /* calculate number of pmap entries needed for a complete map */ - pm_nentries = (kmem_k_start - VM_MIN_ADDRESS) / PAGE_SIZE; + pm_nentries = (kmem_k_end - VM_MIN_ADDRESS) / PAGE_SIZE; pm_entries_size = round_page(pm_nentries * sizeof(struct pv_entry *)); thunk_printf_debug("tlb va->pa lookup table is %"PRIu64" KB for " "%d logical pages\n", pm_entries_size/1024, pm_nentries); @@ -417,6 +419,15 @@ pmap_bootstrap(void) pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0); } thunk_printf_debug("kernel pmap entries mem added to the kernel pmap\n"); +#if 0 + /* not yet, or not needed */ + for (pg = 0; pg < kmem_k_length; pg += PAGE_SIZE) { + pa = kernel_fpos + pg; + va = (vaddr_t) kmem_k_start + pg; + pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, 0); + } + thunk_printf_debug("kernel mem added to the kernel pmap\n"); +#endif /* add file space to uvm's FREELIST */ uvm_page_physload(atop(0),