Source-Changes-HG archive

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

[src/trunk]: src/sys/dev assert kernel lock is held in a few places in inside...



details:   https://anonhg.NetBSD.org/src/rev/e6bb0e51fe67
branches:  trunk
changeset: 777491:e6bb0e51fe67
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Feb 20 20:09:08 2012 +0000

description:
assert kernel lock is held in a few places in inside scsipi.
lock the kernel when calling into scsipi from umass and usscanner.

with these two in place on usbmp branch, umass appears stable.

diffstat:

 sys/dev/scsipi/scsipi_base.c |   9 +++++++--
 sys/dev/usb/umass_scsipi.c   |  20 +++++++++++++++++---
 sys/dev/usb/usscanner.c      |   8 ++++++--
 3 files changed, 30 insertions(+), 7 deletions(-)

diffs (165 lines):

diff -r 60990cd36851 -r e6bb0e51fe67 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c      Mon Feb 20 19:14:23 2012 +0000
+++ b/sys/dev/scsipi/scsipi_base.c      Mon Feb 20 20:09:08 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipi_base.c,v 1.155 2010/11/13 13:52:11 uebayasi Exp $       */
+/*     $NetBSD: scsipi_base.c,v 1.156 2012/02/20 20:09:08 mrg Exp $    */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.155 2010/11/13 13:52:11 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.156 2012/02/20 20:09:08 mrg Exp $");
 
 #include "opt_scsi.h"
 
@@ -218,6 +218,8 @@
        uint32_t hash;
        int s;
 
+       KASSERT(KERNEL_LOCKED_P());
+
        if (target >= chan->chan_ntargets ||
            lun >= chan->chan_nluns)
                return (NULL);
@@ -1261,6 +1263,8 @@
        struct scsipi_channel *chan = periph->periph_channel;
        int s, freezecnt;
 
+       KASSERT(KERNEL_LOCKED_P());
+
        SC_DEBUG(periph, SCSIPI_DB2, ("scsipi_done\n"));
 #ifdef SCSIPI_DEBUG
        if (periph->periph_dbflags & SCSIPI_DB1)
@@ -1860,6 +1864,7 @@
        int oasync, async, poll, error, s;
 
        KASSERT(!cold);
+       KASSERT(KERNEL_LOCKED_P());
 
        (chan->chan_bustype->bustype_cmd)(xs);
 
diff -r 60990cd36851 -r e6bb0e51fe67 sys/dev/usb/umass_scsipi.c
--- a/sys/dev/usb/umass_scsipi.c        Mon Feb 20 19:14:23 2012 +0000
+++ b/sys/dev/usb/umass_scsipi.c        Mon Feb 20 20:09:08 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umass_scsipi.c,v 1.38 2011/08/24 11:28:50 mbalmer Exp $        */
+/*     $NetBSD: umass_scsipi.c,v 1.39 2012/02/20 20:09:09 mrg Exp $    */
 
 /*
  * Copyright (c) 2001, 2003 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.38 2011/08/24 11:28:50 mbalmer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umass_scsipi.c,v 1.39 2012/02/20 20:09:09 mrg Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_umass.h"
@@ -317,7 +317,9 @@
 
                /* Return if command finishes early. */
  done:
+               KERNEL_LOCK(1, curlwp);
                scsipi_done(xs);
+               KERNEL_UNLOCK_ONE(curlwp);
                return;
        default:
                /* Not supported, nothing to do. */
@@ -451,7 +453,9 @@
             xs->error, xs->xs_status, xs->resid));
 
        s = splbio();
+       KERNEL_LOCK(1, curlwp);
        scsipi_done(xs);
+       KERNEL_UNLOCK_ONE(curlwp);
        splx(s);
 }
 
@@ -490,7 +494,9 @@
                xs->resid));
 
        s = splbio();
+       KERNEL_LOCK(1, curlwp);
        scsipi_done(xs);
+       KERNEL_UNLOCK_ONE(curlwp);
        splx(s);
 }
 
@@ -510,12 +516,17 @@
        if (target != UMASS_ATAPI_DRIVE)        /* only probe drive 0 */
                return;
 
+       KERNEL_LOCK(1, curlwp);
+
        /* skip if already attached */
-       if (scsipi_lookup_periph(chan, target, 0) != NULL)
+       if (scsipi_lookup_periph(chan, target, 0) != NULL) {
+               KERNEL_UNLOCK_ONE(curlwp);
                return;
+       }
 
        periph = scsipi_alloc_periph(M_NOWAIT);
        if (periph == NULL) {
+               KERNEL_UNLOCK_ONE(curlwp);
                aprint_error_dev(atapi->sc_dev,
                    "can't allocate link for drive %d\n", target);
                return;
@@ -531,6 +542,7 @@
        /* Now go ask the device all about itself. */
        memset(&inqbuf, 0, sizeof(inqbuf));
        if (scsipi_inquire(periph, &inqbuf, XS_CTL_DISCOVERY) != 0) {
+               KERNEL_UNLOCK_ONE(curlwp);
                DPRINTF(UDMASS_SCSI, ("umass_atapi_probe_device: "
                    "scsipi_inquire failed\n"));
                free(periph, M_DEVBUF);
@@ -556,5 +568,7 @@
                              "'%s' '%s' '%s'\n", vendor, product, revision));
        atapi_probe_device(atapi, target, periph, &sa);
        /* atapi_probe_device() frees the periph when there is no device.*/
+
+       KERNEL_UNLOCK_ONE(curlwp);
 }
 #endif
diff -r 60990cd36851 -r e6bb0e51fe67 sys/dev/usb/usscanner.c
--- a/sys/dev/usb/usscanner.c   Mon Feb 20 19:14:23 2012 +0000
+++ b/sys/dev/usb/usscanner.c   Mon Feb 20 20:09:08 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usscanner.c,v 1.32 2011/12/23 00:51:49 jakllsch Exp $  */
+/*     $NetBSD: usscanner.c,v 1.33 2012/02/20 20:09:09 mrg Exp $       */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usscanner.c,v 1.32 2011/12/23 00:51:49 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usscanner.c,v 1.33 2012/02/20 20:09:09 mrg Exp $");
 
 #include "scsibus.h"
 #include <sys/param.h>
@@ -482,7 +482,9 @@
        sc->sc_state = UAS_IDLE;
 
        s = splbio();
+       KERNEL_LOCK(1, curlwp);
        scsipi_done(sc->sc_xs);
+       KERNEL_UNLOCK_ONE(curlwp);
        splx(s);
 }
 
@@ -760,7 +762,9 @@
 
  done:
                sc->sc_state = UAS_IDLE;
+               KERNEL_LOCK(1, curlwp);
                scsipi_done(xs);
+               KERNEL_UNLOCK_ONE(curlwp);
                return;
 
        case ADAPTER_REQ_GROW_RESOURCES:



Home | Main Index | Thread Index | Old Index