Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ic Fix a possible race condition in spc_msgin() in N...



details:   https://anonhg.NetBSD.org/src/rev/8b5f1554fb9a
branches:  trunk
changeset: 960030:8b5f1554fb9a
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Mar 06 05:37:18 2021 +0000

description:
Fix a possible race condition in spc_msgin() in NO_MANUAL_XFER case.

To avoid the race, check SSTS and INTS after XFR command as
spc_pio_datain() does.

Reported from isaki@, observed on nono emulator.

diffstat:

 sys/dev/ic/mb89352.c |  13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diffs (46 lines):

diff -r cf2df7efbe4b -r 8b5f1554fb9a sys/dev/ic/mb89352.c
--- a/sys/dev/ic/mb89352.c      Fri Mar 05 20:30:56 2021 +0000
+++ b/sys/dev/ic/mb89352.c      Sat Mar 06 05:37:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $   */
+/*     $NetBSD: mb89352.c,v 1.58 2021/03/06 05:37:18 tsutsui Exp $     */
 /*     NecBSD: mb89352.c,v 1.4 1998/03/14 07:31:20 kmatsuda Exp        */
 
 /*-
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.57 2018/09/03 16:29:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mb89352.c,v 1.58 2021/03/06 05:37:18 tsutsui Exp $");
 
 #ifdef DDB
 #define        integrate
@@ -932,6 +932,7 @@
         */
        for (;;) {
 #ifdef NO_MANUAL_XFER /* XXX */
+               uint8_t intstat;
                if (bus_space_read_1(iot, ioh, INTS) != 0) {
                        /*
                         * Target left MESSAGE IN, probably because it
@@ -960,12 +961,18 @@
 #else
                bus_space_write_1(iot, ioh, SCMD, SCMD_XFR | SCMD_PROG_XFR);
 #endif
+               intstat = 0;
                for (;;) {
                        if ((bus_space_read_1(iot, ioh, SSTS) &
                            SSTS_DREG_EMPTY) == 0)
                                break;
-                       if (bus_space_read_1(iot, ioh, INTS) != 0)
+                       /*
+                        * We have to read INTS before checking SSTS to avoid
+                        * race between SSTS_DREG_EMPTY and INTS_CMD_DONE.
+                        */
+                       if (intstat != 0)
                                goto out;
+                       intstat = bus_space_read_1(iot, ioh, INTS);
                }
                msg = bus_space_read_1(iot, ioh, DREG);
 #else



Home | Main Index | Thread Index | Old Index