Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src/sys/dev/scsipi Pull up following revision(s) (requested b...
details: https://anonhg.NetBSD.org/src/rev/6f056533c74a
branches: netbsd-8
changeset: 850749:6f056533c74a
user: snj <snj%NetBSD.org@localhost>
date: Wed Jun 21 18:18:55 2017 +0000
description:
Pull up following revision(s) (requested by mlelstv in ticket #53):
sys/dev/scsipi/atapiconf.c: revision 1.91
sys/dev/scsipi/cd.c: revision 1.341
sys/dev/scsipi/scsi_base.c: revision 1.92
sys/dev/scsipi/scsiconf.c: revision 1.280
sys/dev/scsipi/scsipi_base.c: revisions 1.176, 1.177
sys/dev/scsipi/sd.c: revision 1.325
sys/dev/scsipi/ss.c: revision 1.89
sys/dev/scsipi/st.c: revision 1.231
The atapibus detach path did hold the channel mutex while calling into autoconf,
which would trigger a panic when unplugging a USB ATAPI CDROM.
Align detach code for scsibus and atapibus to fix this.
Also avoid races when detaching devices by replacing callout_stop with
callout_halt.
--
pass config_detach error to caller.
diffstat:
sys/dev/scsipi/atapiconf.c | 43 +++++++++++++++----------------------------
sys/dev/scsipi/cd.c | 6 +++---
sys/dev/scsipi/scsi_base.c | 14 ++++++++++++--
sys/dev/scsipi/scsiconf.c | 34 +++++-----------------------------
sys/dev/scsipi/scsipi_base.c | 28 +++++++++++++++++++++-------
sys/dev/scsipi/sd.c | 6 +++---
sys/dev/scsipi/ss.c | 6 +++---
sys/dev/scsipi/st.c | 6 +++---
8 files changed, 65 insertions(+), 78 deletions(-)
diffs (truncated from 365 to 300 lines):
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/atapiconf.c
--- a/sys/dev/scsipi/atapiconf.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/atapiconf.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: atapiconf.c,v 1.90 2016/11/29 03:23:00 mlelstv Exp $ */
+/* $NetBSD: atapiconf.c,v 1.90.8.1 2017/06/21 18:18:55 snj Exp $ */
/*
* Copyright (c) 1996, 2001 Manuel Bouyer. All rights reserved.
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.90 2016/11/29 03:23:00 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.90.8.1 2017/06/21 18:18:55 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -147,6 +147,7 @@
sc->sc_dev = self;
chan->chan_name = device_xname(sc->sc_dev);
+ chan->chan_id = -1;
/* ATAPI has no LUNs. */
chan->chan_nluns = 1;
@@ -192,39 +193,28 @@
mutex_exit(chan_mtx(chan));
}
+/* same as scsibusdetach */
static int
atapibusdetach(device_t self, int flags)
{
struct atapibus_softc *sc = device_private(self);
struct scsipi_channel *chan = sc->sc_channel;
- struct scsipi_periph *periph;
- int target, error = 0;
+ int error = 0;
+
+ /*
+ * Detach all of the periphs.
+ */
+ error = scsipi_target_detach(chan, -1, -1, flags);
+ if (error)
+ return error;
+
+ pmf_device_deregister(self);
/*
* Shut down the channel.
*/
scsipi_channel_shutdown(chan);
- /* for config_detach() */
- KERNEL_LOCK(1, curlwp);
-
- /*
- * Now detach all of the periphs.
- */
- mutex_enter(chan_mtx(chan));
- for (target = 0; target < chan->chan_ntargets; target++) {
- periph = scsipi_lookup_periph_locked(chan, target, 0);
- if (periph == NULL)
- continue;
- error = config_detach(periph->periph_dev, flags);
- if (error) {
- mutex_exit(chan_mtx(chan));
- goto out;
- }
- KASSERT(scsipi_lookup_periph(chan, target, 0) == NULL);
- }
- mutex_exit(chan_mtx(chan));
-
cv_destroy(&chan->chan_cv_xs);
cv_destroy(&chan->chan_cv_comp);
cv_destroy(&chan->chan_cv_thr);
@@ -232,10 +222,7 @@
if (atomic_dec_uint_nv(&chan_running(chan)) == 0)
mutex_destroy(chan_mtx(chan));
-out:
- /* XXXSMP scsipi */
- KERNEL_UNLOCK_ONE(curlwp);
- return error;
+ return 0;
}
static int
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/cd.c
--- a/sys/dev/scsipi/cd.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/cd.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cd.c,v 1.340 2017/04/08 13:50:23 mlelstv Exp $ */
+/* $NetBSD: cd.c,v 1.340.6.1 2017/06/21 18:18:55 snj Exp $ */
/*-
* Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
@@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.340 2017/04/08 13:50:23 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.340.6.1 2017/06/21 18:18:55 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -354,7 +354,7 @@
}
/* kill any pending restart */
- callout_stop(&cd->sc_callout);
+ callout_halt(&cd->sc_callout, NULL);
dk_drain(dksc);
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/scsi_base.c
--- a/sys/dev/scsipi/scsi_base.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/scsi_base.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scsi_base.c,v 1.91 2016/11/20 15:37:19 mlelstv Exp $ */
+/* $NetBSD: scsi_base.c,v 1.91.8.1 2017/06/21 18:18:55 snj Exp $ */
/*-
* Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.91 2016/11/20 15:37:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsi_base.c,v 1.91.8.1 2017/06/21 18:18:55 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -116,6 +116,16 @@
void
scsi_kill_pending(struct scsipi_periph *periph)
{
+ struct scsipi_xfer *xs;
+
+ TAILQ_FOREACH(xs, &periph->periph_xferq, device_q) {
+ callout_stop(&xs->xs_callout);
+ scsi_print_addr(periph);
+ printf("killed ");
+ scsipi_print_cdb(xs->cmd);
+ xs->error = XS_DRIVER_STUFFUP;
+ scsipi_done(xs);
+ }
}
/*
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/scsiconf.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scsiconf.c,v 1.279 2017/03/18 08:05:40 tsutsui Exp $ */
+/* $NetBSD: scsiconf.c,v 1.279.6.1 2017/06/21 18:18:55 snj Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.279 2017/03/18 08:05:40 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.279.6.1 2017/06/21 18:18:55 snj Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -333,43 +333,19 @@
{
struct scsibus_softc *sc = device_private(self);
struct scsipi_channel *chan = sc->sc_channel;
- struct scsipi_periph *periph;
- int ctarget, clun;
- struct scsipi_xfer *xs;
int error;
/*
* Detach all of the periphs.
*/
- if ((error = scsipi_target_detach(chan, -1, -1, flags)) != 0)
+ error = scsipi_target_detach(chan, -1, -1, flags);
+ if (error)
return error;
pmf_device_deregister(self);
/*
- * Process outstanding commands (which will never complete as the
- * controller is gone).
- *
- * XXX Surely this is redundant? If we get this far, the
- * XXX peripherals have all been detached.
- */
- for (ctarget = 0; ctarget < chan->chan_ntargets; ctarget++) {
- if (ctarget == chan->chan_id)
- continue;
- for (clun = 0; clun < chan->chan_nluns; clun++) {
- periph = scsipi_lookup_periph(chan, ctarget, clun);
- if (periph == NULL)
- continue;
- TAILQ_FOREACH(xs, &periph->periph_xferq, device_q) {
- callout_stop(&xs->xs_callout);
- xs->error = XS_DRIVER_STUFFUP;
- scsipi_done(xs);
- }
- }
- }
-
- /*
- * Now shut down the channel.
+ * Shut down the channel.
*/
scsipi_channel_shutdown(chan);
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/scsipi_base.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scsipi_base.c,v 1.175 2016/12/22 11:19:21 mlelstv Exp $ */
+/* $NetBSD: scsipi_base.c,v 1.175.8.1 2017/06/21 18:18:55 snj 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.175 2016/12/22 11:19:21 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.175.8.1 2017/06/21 18:18:55 snj Exp $");
#ifdef _KERNEL_OPT
#include "opt_scsi.h"
@@ -2400,9 +2400,10 @@
int flags)
{
struct scsipi_periph *periph;
+ device_t tdev;
int ctarget, mintarget, maxtarget;
int clun, minlun, maxlun;
- int error;
+ int error = 0;
if (target == -1) {
mintarget = 0;
@@ -2426,20 +2427,33 @@
maxlun = lun + 1;
}
+ /* for config_detach */
+ KERNEL_LOCK(1, curlwp);
+
+ mutex_enter(chan_mtx(chan));
for (ctarget = mintarget; ctarget < maxtarget; ctarget++) {
if (ctarget == chan->chan_id)
continue;
for (clun = minlun; clun < maxlun; clun++) {
- periph = scsipi_lookup_periph(chan, ctarget, clun);
+ periph = scsipi_lookup_periph_locked(chan, ctarget, clun);
if (periph == NULL)
continue;
- error = config_detach(periph->periph_dev, flags);
+ tdev = periph->periph_dev;
+ mutex_exit(chan_mtx(chan));
+ error = config_detach(tdev, flags);
if (error)
- return error;
+ goto out;
+ mutex_enter(chan_mtx(chan));
+ KASSERT(scsipi_lookup_periph_locked(chan, ctarget, clun) == NULL);
}
}
- return 0;
+ mutex_exit(chan_mtx(chan));
+
+out:
+ KERNEL_UNLOCK_ONE(curlwp);
+
+ return error;
}
/*
diff -r 6a8ff4c8db7f -r 6f056533c74a sys/dev/scsipi/sd.c
--- a/sys/dev/scsipi/sd.c Wed Jun 21 18:16:13 2017 +0000
+++ b/sys/dev/scsipi/sd.c Wed Jun 21 18:18:55 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sd.c,v 1.324 2017/04/10 18:20:43 jdolecek Exp $ */
+/* $NetBSD: sd.c,v 1.324.6.1 2017/06/21 18:18:55 snj Exp $ */
/*-
* Copyright (c) 1998, 2003, 2004 The NetBSD Foundation, Inc.
@@ -47,7 +47,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.324 2017/04/10 18:20:43 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sd.c,v 1.324.6.1 2017/06/21 18:18:55 snj Exp $");
Home |
Main Index |
Thread Index |
Old Index