Source-Changes-HG archive

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

[src/netbsd-9]: src/sys/arch/powerpc/powerpc Pull up following revision(s) (r...



details:   https://anonhg.NetBSD.org/src/rev/73b078c3249c
branches:  netbsd-9
changeset: 963677:73b078c3249c
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Mar 03 18:54:59 2020 +0000

description:
Pull up following revision(s) (requested by rin in ticket #755):

        sys/arch/evbppc/conf/std.virtex: revision 1.4
        sys/arch/powerpc/powerpc/trap_subr.S: revision 1.81
        sys/arch/powerpc/ibm4xx/4xx_trap_subr.S: revision 1.8
        sys/arch/evbppc/conf/std.walnut: revision 1.9
        common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h: revision 1.7
        sys/arch/powerpc/include/asm.h: revision 1.49
        common/lib/libc/arch/powerpc/atomic/atomic_cas.S: revision 1.9
        sys/arch/powerpc/ibm4xx/trap_subr.S: revision 1.28
        sys/arch/powerpc/include/lock.h: revision 1.15
        sys/arch/evbppc/conf/std.obs266: revision 1.3
        common/lib/libc/arch/powerpc/atomic/atomic_swap.S: revision 1.8
        sys/arch/powerpc/powerpc/locore_subr.S: revision 1.61
        sys/arch/powerpc/powerpc/lock_stubs.S: revision 1.12
        sys/arch/evbppc/conf/std.obs200: revision 1.5

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 837a92b8f1ff -r 73b078c3249c common/lib/libc/arch/powerpc/atomic/atomic_cas.S
--- a/common/lib/libc/arch/powerpc/atomic/atomic_cas.S  Tue Mar 03 18:51:03 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_cas.S  Tue Mar 03 18:54:59 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.8.28.1 2020/03/03 18:54:59 martin 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.8.28.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h
--- a/common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h       Tue Mar 03 18:51:03 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_op_asm.h       Tue Mar 03 18:54:59 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.6.28.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c common/lib/libc/arch/powerpc/atomic/atomic_swap.S
--- a/common/lib/libc/arch/powerpc/atomic/atomic_swap.S Tue Mar 03 18:51:03 2020 +0000
+++ b/common/lib/libc/arch/powerpc/atomic/atomic_swap.S Tue Mar 03 18:54:59 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.7.28.1 2020/03/03 18:54:59 martin 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.7.28.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/evbppc/conf/std.obs200
--- a/sys/arch/evbppc/conf/std.obs200   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/evbppc/conf/std.obs200   Tue Mar 03 18:54:59 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.4.64.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/evbppc/conf/std.obs266
--- a/sys/arch/evbppc/conf/std.obs266   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/evbppc/conf/std.obs266   Tue Mar 03 18:54:59 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.2.60.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/evbppc/conf/std.virtex
--- a/sys/arch/evbppc/conf/std.virtex   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/evbppc/conf/std.virtex   Tue Mar 03 18:54:59 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.3.58.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/evbppc/conf/std.walnut
--- a/sys/arch/evbppc/conf/std.walnut   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/evbppc/conf/std.walnut   Tue Mar 03 18:54:59 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.8.58.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/powerpc/ibm4xx/4xx_trap_subr.S
--- a/sys/arch/powerpc/ibm4xx/4xx_trap_subr.S   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/4xx_trap_subr.S   Tue Mar 03 18:54:59 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.7.60.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/powerpc/ibm4xx/trap_subr.S
--- a/sys/arch/powerpc/ibm4xx/trap_subr.S       Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap_subr.S       Tue Mar 03 18:54:59 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.27.4.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/powerpc/include/asm.h
--- a/sys/arch/powerpc/include/asm.h    Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/powerpc/include/asm.h    Tue Mar 03 18:54:59 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.48.22.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/powerpc/include/lock.h
--- a/sys/arch/powerpc/include/lock.h   Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/powerpc/include/lock.h   Tue Mar 03 18:54:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock.h,v 1.13 2017/09/17 00:01:08 christos Exp $       */
+/*     $NetBSD: lock.h,v 1.13.8.1 2020/03/03 18:54:59 martin 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 837a92b8f1ff -r 73b078c3249c sys/arch/powerpc/powerpc/lock_stubs.S
--- a/sys/arch/powerpc/powerpc/lock_stubs.S     Tue Mar 03 18:51:03 2020 +0000
+++ b/sys/arch/powerpc/powerpc/lock_stubs.S     Tue Mar 03 18:54:59 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lock_stubs.S,v 1.10 2014/02/28 05:38:15 matt Exp $     */
+/*     $NetBSD: lock_stubs.S,v 1.10.34.1 2020/03/03 18:54:59 martin 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