Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/powerpc/ibm4xx Try to sanitize usage of isync and s...
details: https://anonhg.NetBSD.org/src/rev/48ebc30c105f
branches: trunk
changeset: 934785:48ebc30c105f
user: rin <rin%NetBSD.org@localhost>
date: Fri Jun 19 07:31:59 2020 +0000
description:
Try to sanitize usage of isync and sync instructions.
According to reference manuals of 4xx, isync is "context synchronization",
which satisfies both 1 and 2:
1. instructions preceding it complete in the context that existed before it
2. instructions following it complete in the context that exists after it
Whereas sync (== msync for 440) is "execution synchronization", which
satisfies just 1, not 2. At the same time, sync guarantees "storage
synchronization", by which any previous storage references completes
before any subsequent instructions begin to execute.
Tested on 405 over months.
diffstat:
sys/arch/powerpc/ibm4xx/copyinstr.c | 16 ++++++------
sys/arch/powerpc/ibm4xx/copyoutstr.c | 16 ++++++------
sys/arch/powerpc/ibm4xx/pmap.c | 36 ++++++++++++++--------------
sys/arch/powerpc/ibm4xx/trap.c | 44 ++++++++++++++++++------------------
4 files changed, 56 insertions(+), 56 deletions(-)
diffs (truncated from 348 to 300 lines):
diff -r 289c4ca820a1 -r 48ebc30c105f sys/arch/powerpc/ibm4xx/copyinstr.c
--- a/sys/arch/powerpc/ibm4xx/copyinstr.c Fri Jun 19 07:25:20 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyinstr.c Fri Jun 19 07:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: copyinstr.c,v 1.13 2020/03/05 01:15:35 rin Exp $ */
+/* $NetBSD: copyinstr.c,v 1.14 2020/06/19 07:31:59 rin Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.13 2020/03/05 01:15:35 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyinstr.c,v 1.14 2020/06/19 07:31:59 rin Exp $");
#include <sys/param.h>
#include <uvm/uvm_extern.h>
@@ -75,22 +75,22 @@
"mfmsr %0;" /* Save MSR */
"li %1,0x20;"
"andc %1,%0,%1; mtmsr %1;" /* Disable IMMU */
+ "isync;"
"mfpid %1;" /* Save old PID */
- "sync; isync;"
"1: "
- "mtpid %4; sync;" /* Load user ctx */
+ "mtpid %4; isync;" /* Load user ctx */
"lbz %2,0(%5); addi %5,%5,1;" /* Load byte */
- "sync; isync;"
- "mtpid %1; sync;"
+ "sync;"
+ "mtpid %1; isync;"
"stb %2,0(%6); dcbst 0,%6; addi %6,%6,1;"
/* Store kernel byte */
- "sync; isync;"
"or. %2,%2,%2;"
+ "sync;"
"bdnzf 2,1b;" /* while(ctr-- && !zero) */
"mtpid %1; mtmsr %0;" /* Restore PID, MSR */
- "sync; isync;"
+ "isync;"
"mfctr %3;" /* Restore resid */
: "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
: "r" (ctx), "b" (udaddr), "b" (kaddr));
diff -r 289c4ca820a1 -r 48ebc30c105f sys/arch/powerpc/ibm4xx/copyoutstr.c
--- a/sys/arch/powerpc/ibm4xx/copyoutstr.c Fri Jun 19 07:25:20 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/copyoutstr.c Fri Jun 19 07:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: copyoutstr.c,v 1.13 2020/03/05 01:15:35 rin Exp $ */
+/* $NetBSD: copyoutstr.c,v 1.14 2020/06/19 07:31:59 rin Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.13 2020/03/05 01:15:35 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: copyoutstr.c,v 1.14 2020/06/19 07:31:59 rin Exp $");
#include <sys/param.h>
#include <uvm/uvm_extern.h>
@@ -75,22 +75,22 @@
"mfmsr %0;" /* Save MSR */
"li %1,0x20;"
"andc %1,%0,%1; mtmsr %1;" /* Disable IMMU */
+ "isync;"
"mfpid %1;" /* Save old PID */
- "sync; isync;"
"1:"
- "mtpid %1; sync;"
+ "mtpid %1; isync;"
"lbz %2,0(%6); addi %6,%6,1;" /* Store kernel byte */
- "sync; isync;"
- "mtpid %4; sync;" /* Load user ctx */
+ "sync;"
+ "mtpid %4; isync;" /* Load user ctx */
"stb %2,0(%5); dcbst 0,%5; addi %5,%5,1;"
/* Load byte */
- "sync; isync;"
"or. %2,%2,%2;"
+ "sync;"
"bdnzf 2,1b;" /* while(ctr-- && !zero) */
"mtpid %1; mtmsr %0;" /* Restore PID, MSR */
- "sync; isync;"
+ "isync;"
"mfctr %3;" /* Restore resid */
: "=&r" (msr), "=&r" (pid), "=&r" (data), "+r" (resid)
: "r" (ctx), "b" (udaddr), "b" (kaddr));
diff -r 289c4ca820a1 -r 48ebc30c105f sys/arch/powerpc/ibm4xx/pmap.c
--- a/sys/arch/powerpc/ibm4xx/pmap.c Fri Jun 19 07:25:20 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/pmap.c Fri Jun 19 07:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.87 2020/06/19 07:15:21 rin Exp $ */
+/* $NetBSD: pmap.c,v 1.88 2020/06/19 07:31:59 rin Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.87 2020/06/19 07:15:21 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.88 2020/06/19 07:31:59 rin Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
@@ -1178,19 +1178,20 @@
"li %1, %7;"
"andc %1,%0,%1;"
"mtmsr %1;"
- "sync;isync;"
+ "isync;"
"mfpid %1;"
"mtpid %2;"
- "sync; isync;"
+ "isync;"
"1:"
"dcbst 0,%3;"
"icbi 0,%3;"
"add %3,%3,%5;"
"addc. %4,%4,%6;"
"bge 1b;"
+ "sync;"
"mtpid %1;"
"mtmsr %0;"
- "sync; isync"
+ "isync;"
: "=&r" (msr), "=&r" (opid)
: "r" (ctx), "r" (va), "r" (len), "r" (step), "r" (-step),
"K" (PSL_IR | PSL_DR));
@@ -1213,13 +1214,14 @@
"mfmsr %2;" /* Save MSR */
"li %0,0;" /* Now clear MSR */
"mtmsr %0;"
+ "isync;"
"mtpid %4;" /* Set PID */
- "sync;"
+ "isync;"
"tlbsx. %0,0,%3;" /* Search TLB */
- "sync;"
+ "isync;"
"mtpid %1;" /* Restore PID */
"mtmsr %2;" /* Restore MSR */
- "sync;isync;"
+ "isync;"
"li %1,1;"
"beq 1f;"
"li %1,0;"
@@ -1230,7 +1232,7 @@
/* Now flush translation */
__asm volatile(
"tlbwe %0,%1,0;"
- "sync;isync;"
+ "isync;"
: : "r" (0), "r" (i));
tlb_info[i].ti_ctx = 0;
@@ -1249,14 +1251,12 @@
for (i = 0; i < NTLB; i++)
if (!TLB_LOCKED(i)) {
__asm volatile(
- "tlbwe %0,%1,0;"
- "sync;isync;"
- : : "r" (0), "r" (i));
+ "tlbwe %0,%1,0;" : : "r" (0), "r" (i));
tlb_info[i].ti_ctx = 0;
tlb_info[i].ti_flags = 0;
}
- __asm volatile("sync;isync");
+ __asm volatile("isync");
}
/* Find a TLB entry to evict. */
@@ -1321,14 +1321,15 @@
"mfmsr %0;" /* Save MSR */
"li %1,0;"
"mtmsr %1;" /* Clear MSR */
+ "isync;"
"tlbwe %1,%3,0;" /* Invalidate old entry. */
"mfpid %1;" /* Save old PID */
"mtpid %2;" /* Load translation ctx */
- "sync; isync;"
+ "isync;"
"tlbwe %4,%3,1; tlbwe %5,%3,0;" /* Set TLB */
- "sync; isync;"
+ "isync;"
"mtpid %1; mtmsr %0;" /* Restore PID and MSR */
- "sync; isync;"
+ "isync;"
: "=&r" (msr), "=&r" (pid)
: "r" (ctx), "r" (idx), "r" (tl), "r" (th));
}
@@ -1352,7 +1353,7 @@
__asm volatile(
"mtspr %0,%1;"
- "sync;"
+ "isync;"
:: "K"(SPR_ZPR), "r" (0x1b000000));
}
@@ -1453,7 +1454,6 @@
__asm volatile(
" tlbwe %1,%0,1 \n" /* write TLBLO */
" tlbwe %2,%0,0 \n" /* write TLBHI */
- " sync \n"
" isync \n"
: : "r" (tlb_nreserved), "r" (lo), "r" (hi));
diff -r 289c4ca820a1 -r 48ebc30c105f sys/arch/powerpc/ibm4xx/trap.c
--- a/sys/arch/powerpc/ibm4xx/trap.c Fri Jun 19 07:25:20 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap.c Fri Jun 19 07:31:59 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.80 2020/06/19 07:24:41 rin Exp $ */
+/* $NetBSD: trap.c,v 1.81 2020/06/19 07:31:59 rin Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.80 2020/06/19 07:24:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.81 2020/06/19 07:31:59 rin Exp $");
#include "opt_altivec.h"
#include "opt_ddb.h"
@@ -438,21 +438,21 @@
" mfmsr %[msr];" /* Save MSR */
" li %[pid],0x20;"
" andc %[pid],%[msr],%[pid]; mtmsr %[pid];" /* Disable IMMU */
+ " isync;"
" mfpid %[pid];" /* Save old PID */
- " sync; isync;"
" srwi. %[count],%[len],0x2;" /* How many words? */
" beq- 2f;" /* No words. Go do bytes */
" mtctr %[count];"
- "1: mtpid %[ctx]; sync;"
+ "1: mtpid %[ctx]; isync;"
#ifdef PPC_IBM403
" lswi %[tmp],%[udaddr],4;" /* Load user word */
#else
" lwz %[tmp],0(%[udaddr]);"
#endif
" addi %[udaddr],%[udaddr],0x4;" /* next udaddr word */
- " sync; isync;"
- " mtpid %[pid]; sync;"
+ " sync;"
+ " mtpid %[pid]; isync;"
#ifdef PPC_IBM403
" stswi %[tmp],%[kaddr],4;" /* Store kernel word */
#else
@@ -460,24 +460,24 @@
#endif
" dcbst 0,%[kaddr];" /* flush cache */
" addi %[kaddr],%[kaddr],0x4;" /* next udaddr word */
- " sync; isync;"
+ " sync;"
" bdnz 1b;" /* repeat */
"2: andi. %[count],%[len],0x3;" /* How many remaining bytes? */
" addi %[count],%[count],0x1;"
" mtctr %[count];"
"3: bdz 10f;" /* while count */
- " mtpid %[ctx]; sync;"
+ " mtpid %[ctx]; isync;"
" lbz %[tmp],0(%[udaddr]);" /* Load user byte */
" addi %[udaddr],%[udaddr],0x1;" /* next udaddr byte */
- " sync; isync;"
- " mtpid %[pid]; sync;"
+ " sync;"
+ " mtpid %[pid]; isync;"
" stb %[tmp],0(%[kaddr]);" /* Store kernel byte */
" dcbst 0,%[kaddr];" /* flush cache */
" addi %[kaddr],%[kaddr],0x1;"
- " sync; isync;"
+ " sync;"
" b 3b;"
- "10:mtpid %[pid]; mtmsr %[msr]; sync; isync;"
+ "10:mtpid %[pid]; mtmsr %[msr]; isync;"
/* Restore PID and MSR */
: [msr] "=&r" (msr), [pid] "=&r" (pid), [tmp] "=&r" (tmp)
: [udaddr] "b" (udaddr), [ctx] "b" (ctx), [kaddr] "b" (kaddr),
@@ -545,21 +545,21 @@
" mfmsr %[msr];" /* Save MSR */
" li %[pid],0x20;"
" andc %[pid],%[msr],%[pid]; mtmsr %[pid];" /* Disable IMMU */
+ " isync;"
" mfpid %[pid];" /* Save old PID */
- " sync; isync;"
" srwi. %[count],%[len],0x2;" /* How many words? */
Home |
Main Index |
Thread Index |
Old Index