Fri Jan 1 12:54:08 2021 UTC ()
Pull up following revision(s) (requested by rin in ticket #1171):

	sys/arch/aarch64/aarch64/pmap.c: revision 1.82
	sys/arch/aarch64/aarch64/pmap.c: revision 1.83

pmap_procwr(): sync icache even if p != curproc. This fixes applications
like GDB for arm32, that rewrite text of other process.

Thanks to ryo@ for discussion.

Use tlen for temporary length variable instead of l, which is usually
used for struct lwp *.
No binary changes.


(martin)
diff -r1.41.2.7 -r1.41.2.8 src/sys/arch/aarch64/aarch64/pmap.c

cvs diff -r1.41.2.7 -r1.41.2.8 src/sys/arch/aarch64/aarch64/pmap.c (expand / switch to unified diff)

--- src/sys/arch/aarch64/aarch64/pmap.c 2021/01/01 12:38:49 1.41.2.7
+++ src/sys/arch/aarch64/aarch64/pmap.c 2021/01/01 12:54:07 1.41.2.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pmap.c,v 1.41.2.7 2021/01/01 12:38:49 martin Exp $ */ 1/* $NetBSD: pmap.c,v 1.41.2.8 2021/01/01 12:54:07 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org> 4 * Copyright (c) 2017 Ryo Shimizu <ryo@nerv.org>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.41.2.7 2021/01/01 12:38:49 martin Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.41.2.8 2021/01/01 12:54:07 martin Exp $");
31 31
32#include "opt_arm_debug.h" 32#include "opt_arm_debug.h"
33#include "opt_ddb.h" 33#include "opt_ddb.h"
34#include "opt_kasan.h" 34#include "opt_kasan.h"
35#include "opt_multiprocessor.h" 35#include "opt_multiprocessor.h"
36#include "opt_pmap.h" 36#include "opt_pmap.h"
37#include "opt_uvmhist.h" 37#include "opt_uvmhist.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/types.h> 40#include <sys/types.h>
41#include <sys/kmem.h> 41#include <sys/kmem.h>
42#include <sys/vmem.h> 42#include <sys/vmem.h>
43#include <sys/atomic.h> 43#include <sys/atomic.h>
@@ -869,32 +869,46 @@ pmap_icache_sync_range(pmap_t pm, vaddr_ @@ -869,32 +869,46 @@ pmap_icache_sync_range(pmap_t pm, vaddr_
869 } 869 }
870 870
871 pm_unlock(pm); 871 pm_unlock(pm);
872} 872}
873 873
874/* 874/*
875 * Routine: pmap_procwr 875 * Routine: pmap_procwr
876 * 876 *
877 * Function: 877 * Function:
878 * Synchronize caches corresponding to [addr, addr+len) in p. 878 * Synchronize caches corresponding to [addr, addr+len) in p.
879 * 879 *
880 */ 880 */
881void 881void
882pmap_procwr(struct proc *p, vaddr_t va, int len) 882pmap_procwr(struct proc *p, vaddr_t sva, int len)
883{ 883{
884 884
885 /* We only need to do anything if it is the current process. */ 885 if (__predict_true(p == curproc))
886 if (p == curproc) 886 cpu_icache_sync_range(sva, len);
887 cpu_icache_sync_range(va, len); 887 else {
 888 struct pmap *pm = p->p_vmspace->vm_map.pmap;
 889 paddr_t pa;
 890 vaddr_t va, eva;
 891 int tlen;
 892
 893 for (va = sva; len > 0; va = eva, len -= tlen) {
 894 eva = uimin(va + len, trunc_page(va + PAGE_SIZE));
 895 tlen = eva - va;
 896 if (!pmap_extract(pm, va, &pa))
 897 continue;
 898 va = AARCH64_PA_TO_KVA(pa);
 899 cpu_icache_sync_range(va, tlen);
 900 }
 901 }
888} 902}
889 903
890static pt_entry_t 904static pt_entry_t
891_pmap_pte_adjust_prot(pt_entry_t pte, vm_prot_t prot, vm_prot_t protmask, 905_pmap_pte_adjust_prot(pt_entry_t pte, vm_prot_t prot, vm_prot_t protmask,
892 bool user) 906 bool user)
893{ 907{
894 vm_prot_t masked; 908 vm_prot_t masked;
895 pt_entry_t xn; 909 pt_entry_t xn;
896 910
897 masked = prot & protmask; 911 masked = prot & protmask;
898 pte &= ~(LX_BLKPAG_OS_RWMASK|LX_BLKPAG_AF|LX_BLKPAG_AP); 912 pte &= ~(LX_BLKPAG_OS_RWMASK|LX_BLKPAG_AF|LX_BLKPAG_AP);
899 913
900 /* keep prot for ref/mod emulation */ 914 /* keep prot for ref/mod emulation */