Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc/powerpc Implement workaround for IBM405 Err...



details:   https://anonhg.NetBSD.org/src/rev/a118a313f3e1
branches:  trunk
changeset: 969805:a118a313f3e1
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Mar 01 23:23:36 2020 +0000

description:
Implement workaround for IBM405 Errata 77 (aka CPU_210), where
interrupted stwcx. may errantly write data to memory:

    https://elinux.org/images/1/1d/Ppc405gp-errata.pdf

This is because stwcx. is split into two pieces in the pipeline.

We need to
(1) insert dcbt before every stwcx. instruction, as well as
(2) insert sync before every rfi/rfci instruction.

It is unclear which processors are affected, but according to Linux,
all 405-based cores up until 405GPR and 405EP are affected:

    https://github.com/torvalds/linux/blob/master/arch/powerpc/platforms/40x/Kconfig#L140

For kernel, this workaround can be restricted to affected processors.
However, for kernel modules and userland, we have to enable it for all
32bit powerpc archs in order to share common binaries as before.

Proposed on port-powerpc:

    http://mail-index.netbsd.org/port-powerpc/2020/02/21/msg003583.html

diffstat:

 common/lib/libc/arch/powerpc/atomic/atomic_cas.S    |   5 +++--
 common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h |   4 +++-
 common/lib/libc/arch/powerpc/atomic/atomic_swap.S   |   5 +++--
 sys/arch/evbppc/conf/std.obs200                     |   4 +++-
 sys/arch/evbppc/conf/std.obs266                     |   4 +++-
 sys/arch/evbppc/conf/std.virtex                     |   6 +++++-
 sys/arch/evbppc/conf/std.walnut                     |   4 +++-
 sys/arch/powerpc/ibm4xx/4xx_trap_subr.S             |   4 +++-
 sys/arch/powerpc/ibm4xx/trap_subr.S                 |   4 +++-
 sys/arch/powerpc/include/asm.h                      |  18 +++++++++++++++++-
 sys/arch/powerpc/include/lock.h                     |  21 ++++++++++++++++-----
 sys/arch/powerpc/powerpc/lock_stubs.S               |   8 +++++++-
 sys/arch/powerpc/powerpc/locore_subr.S              |   6 +++++-
 sys/arch/powerpc/powerpc/trap_subr.S                |   9 ++++++++-
 14 files changed, 82 insertions(+), 20 deletions(-)

diffs (truncated from 427 to 300 lines):

diff -r 05f8c4fd15a9 -r a118a313f3e1 common/lib/libc/arch/powerpc/atomic/atomic_cas.S
--- a/common/lib/libc/arch/powerpc/atomic/atomic_cas.S  Sun Mar 01 22:47:26 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_cas.S  Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_cas.S,v 1.8 2014/03/07 07:17:54 matt Exp $      */
+/*     $NetBSD: atomic_cas.S,v 1.9 2020/03/01 23:23:36 rin Exp $       */
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "atomic_op_asm.h"
 
-__RCSID("$NetBSD: atomic_cas.S,v 1.8 2014/03/07 07:17:54 matt Exp $")
+__RCSID("$NetBSD: atomic_cas.S,v 1.9 2020/03/01 23:23:36 rin Exp $")
 
        .text
 ENTRY(_atomic_cas_32)
@@ -39,6 +39,7 @@
 1:     lwarx   %r3,0,%r10
        cmpw    %r3,%r4
        bnelr-
+       IBM405_ERRATA77_DCBT(0,%r10)
        stwcx.  %r5,0,%r10
        beqlr+
        b       1b
diff -r 05f8c4fd15a9 -r a118a313f3e1 common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h
--- a/common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h       Sun Mar 01 22:47:26 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h       Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_op_asm.h,v 1.6 2014/03/07 07:17:54 matt Exp $   */
+/*     $NetBSD: atomic_op_asm.h,v 1.7 2020/03/01 23:23:36 rin Exp $    */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -49,6 +49,7 @@
        mr      %r10,%r3        ; \
 1:     lwarx   %r3,0,%r10      ; \
        insn    %r5,%r3,arg     ; \
+       IBM405_ERRATA77_DCBT(0,%r10) ; \
        stwcx.  %r5,0,%r10      ; \
        beqlr+                  ; \
        b       1b              ; \
@@ -71,6 +72,7 @@
        mr      %r10,%r3        ; \
 1:     lwarx   %r3,0,%r10      ; \
        insn    %r3,%r3,arg     ; \
+       IBM405_ERRATA77_DCBT(0,%r10) ; \
        stwcx.  %r3,0,%r10      ; \
        beqlr+                  ; \
        b       1b              ; \
diff -r 05f8c4fd15a9 -r a118a313f3e1 common/lib/libc/arch/powerpc/atomic/atomic_swap.S
--- a/common/lib/libc/arch/powerpc/atomic/atomic_swap.S Sun Mar 01 22:47:26 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_swap.S Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_swap.S,v 1.7 2014/03/07 07:17:54 matt Exp $     */
+/*     $NetBSD: atomic_swap.S,v 1.8 2020/03/01 23:23:36 rin Exp $      */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -31,12 +31,13 @@
 
 #include "atomic_op_asm.h"
 
-__RCSID("$NetBSD: atomic_swap.S,v 1.7 2014/03/07 07:17:54 matt Exp $")
+__RCSID("$NetBSD: atomic_swap.S,v 1.8 2020/03/01 23:23:36 rin Exp $")
 
        .text
 ENTRY(_atomic_swap_32)
        mr      %r10,%r3
 1:     lwarx   %r3,0,%r10
+       IBM405_ERRATA77_DCBT(0,%r10)
        stwcx.  %r4,0,%r10
        beqlr+
        b       1b
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/evbppc/conf/std.obs200
--- a/sys/arch/evbppc/conf/std.obs200   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/evbppc/conf/std.obs200   Sun Mar 01 23:23:36 2020 +0000
@@ -1,9 +1,11 @@
-#      $NetBSD: std.obs200,v 1.4 2010/03/18 14:15:38 kiyohara Exp $
+#      $NetBSD: std.obs200,v 1.5 2020/03/01 23:23:36 rin Exp $
 #
 # Standard/required options for obs200
 
 include                "arch/evbppc/conf/std.obs405"
 
+options        IBM405_ERRATA77
+
 makeoptions    PRDCTTYPE="obs200"
 makeoptions    TEXTADDR=0x450000
 options        KERNBASE=0x450000
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/evbppc/conf/std.obs266
--- a/sys/arch/evbppc/conf/std.obs266   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/evbppc/conf/std.obs266   Sun Mar 01 23:23:36 2020 +0000
@@ -1,9 +1,11 @@
-#      $NetBSD: std.obs266,v 1.2 2011/04/04 19:55:16 dyoung Exp $
+#      $NetBSD: std.obs266,v 1.3 2020/03/01 23:23:36 rin Exp $
 #
 # Standard/required options for obs266.
 
 include                "arch/evbppc/conf/std.obs405"
 
+options        IBM405_ERRATA77
+
 makeoptions    PRDCTTYPE="obs266"
 makeoptions    TEXTADDR=0x25000
 options        KERNBASE=0x25000
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/evbppc/conf/std.virtex
--- a/sys/arch/evbppc/conf/std.virtex   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/evbppc/conf/std.virtex   Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: std.virtex,v 1.3 2011/06/20 17:44:33 matt Exp $
+#      $NetBSD: std.virtex,v 1.4 2020/03/01 23:23:36 rin Exp $
 #
 # Standard/required options for NetBSD/virtex.
 
@@ -8,6 +8,10 @@
 # standard ("mandatory") kernel options.
 options        PPC_IBM4XX      # IBM 40x family
 
+# XXX According to Linux, 405D5 (Virtex-II Pro) is affected, whereas
+# XXX 405F6 (Virtex-4) is not.
+options        IBM405_ERRATA77
+
 # Executable support:
 options        EXEC_ELF32      # (native) ELF32 binary support
 options        EXEC_AOUT       # (native) a.out binary support (deprecated)
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/evbppc/conf/std.walnut
--- a/sys/arch/evbppc/conf/std.walnut   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/evbppc/conf/std.walnut   Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: std.walnut,v 1.8 2011/06/22 18:06:32 matt Exp $
+#      $NetBSD: std.walnut,v 1.9 2020/03/01 23:23:36 rin Exp $
 #
 # Standard/required options for NetBSD/walnut.
 
@@ -8,6 +8,8 @@
 # standard ("mandatory") kernel options.
 options        PPC_IBM4XX      # IBM 40x family
 
+options        IBM405_ERRATA77
+
 # Executable support:
 options        EXEC_ELF32      # (native) ELF32 binary support
 options        EXEC_AOUT       # (native) a.out binary support (deprecated)
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/powerpc/ibm4xx/4xx_trap_subr.S
--- a/sys/arch/powerpc/ibm4xx/4xx_trap_subr.S   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/4xx_trap_subr.S   Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: 4xx_trap_subr.S,v 1.7 2011/05/19 07:51:50 kiyohara Exp $       */
+/*     $NetBSD: 4xx_trap_subr.S,v 1.8 2020/03/01 23:23:36 rin Exp $    */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -55,10 +55,12 @@
 _C_LABEL(pitfitwdogsize) = .-_C_LABEL(pitfitwdog)
 
 pithandler:
+       IBM405_ERRATA77_SYNC
        rfi
        ba      .       /* Protect against prefetch */
 
 wdoghandler:
+       IBM405_ERRATA77_SYNC
        rfi
        ba      .       /* Protect against prefetch */
 
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/powerpc/ibm4xx/trap_subr.S
--- a/sys/arch/powerpc/ibm4xx/trap_subr.S       Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap_subr.S       Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap_subr.S,v 1.27 2018/07/15 05:16:43 maxv Exp $      */
+/*     $NetBSD: trap_subr.S,v 1.28 2020/03/01 23:23:36 rin Exp $       */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -334,6 +334,7 @@
        mtpid   %r31
        mfsprg3 %r31
        mfsprg2 %r30
+       IBM405_ERRATA77_SYNC
        rfi
        ba      .               /* Protect against prefetch */
 
@@ -375,6 +376,7 @@
        mtpid   %r31
        mfsprg3 %r31
        mfsprg2 %r30
+       IBM405_ERRATA77_SYNC
        rfi
        ba      .       /* Protect against prefetch */
 
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/powerpc/include/asm.h
--- a/sys/arch/powerpc/include/asm.h    Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/powerpc/include/asm.h    Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: asm.h,v 1.48 2015/01/12 02:32:33 dennis Exp $  */
+/*     $NetBSD: asm.h,v 1.49 2020/03/01 23:23:36 rin Exp $     */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -432,4 +432,20 @@
 .endm
 #endif /* _LOCORE */
 
+#if defined(IBM405_ERRATA77) || \
+    ((defined(_MODULE) || !defined(_KERNEL)) && !defined(__LP64__))
+/*
+ * Workaround for IBM405 Errata 77 (CPU_210): interrupted stwcx. may
+ * errantly write data to memory
+ *
+ * (1) Insert dcbt before every stwcx. instruction
+ * (2) Insert sync before every rfi/rfci instruction
+ */
+#define        IBM405_ERRATA77_DCBT(ra, rb)    dcbt ra,rb
+#define        IBM405_ERRATA77_SYNC            sync
+#else
+#define        IBM405_ERRATA77_DCBT(ra, rb)    /* nothing */
+#define        IBM405_ERRATA77_SYNC            /* nothing */
+#endif
+
 #endif /* !_PPC_ASM_H_ */
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/powerpc/include/lock.h
--- a/sys/arch/powerpc/include/lock.h   Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/powerpc/include/lock.h   Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock.h,v 1.14 2019/11/29 20:05:59 riastradh Exp $      */
+/*     $NetBSD: lock.h,v 1.15 2020/03/01 23:23:36 rin Exp $    */
 
 /*-
  * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -80,7 +80,11 @@
 2:     lwzx    %0,0,%1         \n\
        cmpwi   %0,%2           \n\
        beq+    1b              \n\
-       b       2b              \n\
+       b       2b              \n"
+#ifdef IBM405_ERRATA77
+       "dcbt   0,%1            \n"
+#endif
+"                              \
 3:     stwcx.  %3,0,%1         \n\
        bne-    1b              \n\
        isync                   \n\
@@ -99,9 +103,16 @@
                                \n\
 1:     lwarx   %0,0,%1         \n\
        cmpwi   %0,%2           \n\
-       bne     2f              \n\
-       stwcx.  %3,0,%1         \n\
-       bne-    1b              \n\
+       bne     2f              \n"
+#ifdef IBM405_ERRATA77
+       "dcbt   0,%1            \n"
+#endif
+       "stwcx. %3,0,%1         \n\
+       bne-    1b              \n"
+#ifdef IBM405_ERRATA77
+       "dcbt   0,%4            \n"
+#endif
+"                              \
 2:     stwcx.  %3,0,%4         \n\
        isync                   \n\
                                \n"
diff -r 05f8c4fd15a9 -r a118a313f3e1 sys/arch/powerpc/powerpc/lock_stubs.S
--- a/sys/arch/powerpc/powerpc/lock_stubs.S     Sun Mar 01 22:47:26 2020 +0000
+++ b/sys/arch/powerpc/powerpc/lock_stubs.S     Sun Mar 01 23:23:36 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_stubs.S,v 1.11 2020/01/21 04:30:14 thorpej Exp $  */
+/*     $NetBSD: lock_stubs.S,v 1.12 2020/03/01 23:23:36 rin Exp $      */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -55,6 +55,7 @@
        lptrarx %r10,0,%r3
        cmpptr  %r10,%r4
        bne-    2f
+       IBM405_ERRATA77_DCBT(0,%r3)
        stptrcx. %r5,0,%r3
        bne-    1b
        SYNC
@@ -73,6 +74,7 @@
        lptrarx %r10,0,%r3
        cmpptri %r10,0
        bne-    2f
+       IBM405_ERRATA77_DCBT(0,%r3)
        stptrcx. %r13,0,%r3
        bne-    1b
        ISYNC
@@ -90,6 +92,7 @@
        lptrarx %r10,0,%r3
        cmpptr  %r10,%r13
        bne-    2f
+       IBM405_ERRATA77_DCBT(0,%r3)
        stptrcx. %r7,0,%r3
        bne-    1b
        blr
@@ -125,6 +128,7 @@
 2:     lptrarx %r10,0,%r3
        cmpptr  %r10,%r9



Home | Main Index | Thread Index | Old Index