Module Name: src
Committed By: mrg
Date: Mon Feb 20 20:35:40 UTC 2012
Modified Files:
src/sys/dev/scsipi [jmcneill-usbmp]: scsipi_base.c
src/sys/dev/usb [jmcneill-usbmp]: umass_scsipi.c usscanner.c
Log Message:
pullup from -current:
>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.
To generate a diff of this commit:
cvs rdiff -u -r1.155 -r1.155.12.1 src/sys/dev/scsipi/scsipi_base.c
cvs rdiff -u -r1.38 -r1.38.6.1 src/sys/dev/usb/umass_scsipi.c
cvs rdiff -u -r1.30.12.1 -r1.30.12.2 src/sys/dev/usb/usscanner.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/scsipi/scsipi_base.c
diff -u src/sys/dev/scsipi/scsipi_base.c:1.155 src/sys/dev/scsipi/scsipi_base.c:1.155.12.1
--- src/sys/dev/scsipi/scsipi_base.c:1.155 Sat Nov 13 13:52:11 2010
+++ src/sys/dev/scsipi/scsipi_base.c Mon Feb 20 20:35:40 2012
@@ -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.155.12.1 2012/02/20 20:35:40 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.155.12.1 2012/02/20 20:35:40 mrg Exp $");
#include "opt_scsi.h"
@@ -218,6 +218,8 @@ scsipi_lookup_periph(struct scsipi_chann
uint32_t hash;
int s;
+ KASSERT(KERNEL_LOCKED_P());
+
if (target >= chan->chan_ntargets ||
lun >= chan->chan_nluns)
return (NULL);
@@ -1261,6 +1263,8 @@ scsipi_done(struct scsipi_xfer *xs)
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 @@ scsipi_execute_xs(struct scsipi_xfer *xs
int oasync, async, poll, error, s;
KASSERT(!cold);
+ KASSERT(KERNEL_LOCKED_P());
(chan->chan_bustype->bustype_cmd)(xs);
Index: src/sys/dev/usb/umass_scsipi.c
diff -u src/sys/dev/usb/umass_scsipi.c:1.38 src/sys/dev/usb/umass_scsipi.c:1.38.6.1
--- src/sys/dev/usb/umass_scsipi.c:1.38 Wed Aug 24 11:28:50 2011
+++ src/sys/dev/usb/umass_scsipi.c Mon Feb 20 20:35:40 2012
@@ -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.38.6.1 2012/02/20 20:35:40 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.38.6.1 2012/02/20 20:35:40 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_umass.h"
@@ -317,7 +317,9 @@ umass_scsipi_request(struct scsipi_chann
/* 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 @@ umass_scsipi_cb(struct umass_softc *sc,
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 @@ umass_scsipi_sense_cb(struct umass_softc
xs->resid));
s = splbio();
+ KERNEL_LOCK(1, curlwp);
scsipi_done(xs);
+ KERNEL_UNLOCK_ONE(curlwp);
splx(s);
}
@@ -510,12 +516,17 @@ umass_atapi_probe_device(struct atapibus
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 @@ umass_atapi_probe_device(struct atapibus
/* 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 @@ umass_atapi_probe_device(struct atapibus
"'%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
Index: src/sys/dev/usb/usscanner.c
diff -u src/sys/dev/usb/usscanner.c:1.30.12.1 src/sys/dev/usb/usscanner.c:1.30.12.2
--- src/sys/dev/usb/usscanner.c:1.30.12.1 Sat Feb 18 07:35:12 2012
+++ src/sys/dev/usb/usscanner.c Mon Feb 20 20:35:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: usscanner.c,v 1.30.12.1 2012/02/18 07:35:12 mrg Exp $ */
+/* $NetBSD: usscanner.c,v 1.30.12.2 2012/02/20 20:35:40 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.30.12.1 2012/02/18 07:35:12 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usscanner.c,v 1.30.12.2 2012/02/20 20:35:40 mrg Exp $");
#include "scsibus.h"
#include <sys/param.h>
@@ -482,7 +482,9 @@ usscanner_intr_cb(usbd_xfer_handle xfer,
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 @@ usscanner_scsipi_request(struct scsipi_c
done:
sc->sc_state = UAS_IDLE;
+ KERNEL_LOCK(1, curlwp);
scsipi_done(xs);
+ KERNEL_UNLOCK_ONE(curlwp);
return;
case ADAPTER_REQ_GROW_RESOURCES: