Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/aarch64/aarch64 pmap_procwr(): sync icache even if ...



details:   https://anonhg.NetBSD.org/src/rev/095f37439a6f
branches:  trunk
changeset: 973476:095f37439a6f
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Jul 02 13:01:11 2020 +0000

description:
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.

diffstat:

 sys/arch/aarch64/aarch64/pmap.c |  26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diffs (49 lines):

diff -r b264677dd9f2 -r 095f37439a6f sys/arch/aarch64/aarch64/pmap.c
--- a/sys/arch/aarch64/aarch64/pmap.c   Thu Jul 02 12:59:31 2020 +0000
+++ b/sys/arch/aarch64/aarch64/pmap.c   Thu Jul 02 13:01:11 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.81 2020/07/02 12:59:31 rin Exp $    */
+/*     $NetBSD: pmap.c,v 1.82 2020/07/02 13:01:11 rin Exp $    */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.81 2020/07/02 12:59:31 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.82 2020/07/02 13:01:11 rin Exp $");
 
 #include "opt_arm_debug.h"
 #include "opt_ddb.h"
@@ -942,12 +942,26 @@
  *
  */
 void
-pmap_procwr(struct proc *p, vaddr_t va, int len)
+pmap_procwr(struct proc *p, vaddr_t sva, int len)
 {
 
-       /* We only need to do anything if it is the current process. */
-       if (p == curproc)
-               cpu_icache_sync_range(va, len);
+       if (__predict_true(p == curproc))
+               cpu_icache_sync_range(sva, len);
+       else {
+               struct pmap *pm = p->p_vmspace->vm_map.pmap;
+               paddr_t pa;
+               vaddr_t va, eva;
+               int l;
+
+               for (va = sva; len > 0; va = eva, len -= l) {
+                       eva = uimin(va + len, trunc_page(va + PAGE_SIZE));
+                       l = eva - va;
+                       if (!pmap_extract(pm, va, &pa))
+                               continue;
+                       va = AARCH64_PA_TO_KVA(pa);
+                       cpu_icache_sync_range(va, l);
+               }
+       }
 }
 
 static pt_entry_t



Home | Main Index | Thread Index | Old Index