NetBSD Problem Report #9703

Received: (qmail 18861 invoked from network); 29 Mar 2000 23:54:16 -0000
Message-Id: <200003292354.BAA01054@opus.augustsson.net>
Date: Thu, 30 Mar 2000 01:54:05 +0200 (CEST)
From: Lennart Augustsson <augustss@augustsson.net>
Reply-To: augustss@augustsson.net
To: gnats-bugs@gnats.netbsd.org
Subject: Detaching an sd device can hang the system
X-Send-Pr-Version: 3.95

>Number:         9703
>Category:       kern
>Synopsis:       Detaching an sd device can hang the system
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    enami
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Mar 29 15:57:00 +0000 2000
>Closed-Date:    Thu Apr 20 02:23:01 +0000 2000
>Last-Modified:  Thu Apr 20 02:23:01 +0000 2000
>Originator:     Lennart Augustsson
>Release:        NetBSD-current 2000-03-30
>Organization:
Department of Computing Science, Chalmers University
>Environment:
System: NetBSD opus 1.4X NetBSD 1.4X (OPUS) #103: Wed Mar 29 02:25:17 CEST 2000 augustss@opus:/usr/src/sys/arch/i386/compile/OPUS i386


>Description:
	If an sd device is detached and has pending I/O operations the
	function scsi_kill_pending() is called to kill them off.
	But this function does not seem to make any progress, it just
	sits in its while loop calling scsipi_done for the first
	scsipi_xer over and over again.
>How-To-Repeat:
	Detach a disk that is doing I/O.  Watch it die.
>Fix:
	Dunno.
>Release-Note:
>Audit-Trail:

From: enami tsugutomo <enami@sm.sony.co.jp>
To: augustss@augustsson.net
Cc: thorpej@netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: 30 Mar 2000 10:30:10 +0900

 Lennart Augustsson <augustss@augustsson.net> writes:

 > 	But this function does not seem to make any progress, it just
 > 	sits in its while loop calling scsipi_done for the first
 > 	scsipi_xer over and over again.

 Hmm, looks like if there is a xfer without XS_CTL_ASYNC is set on the
 pending queue, it loops infinitly.  Since the device is being
 detached, no new xfer request shouldn't come (right?), so, we just
 loop over all xfers?

 enami.

From: Lennart Augustsson <lennart@augustsson.net>
To: enami tsugutomo <enami@sm.sony.co.jp>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: Thu, 30 Mar 2000 10:55:09 +0200

 enami tsugutomo wrote:

 > Lennart Augustsson <augustss@augustsson.net> writes:
 >
 > >       But this function does not seem to make any progress, it just
 > >       sits in its while loop calling scsipi_done for the first
 > >       scsipi_xer over and over again.
 >
 > Hmm, looks like if there is a xfer without XS_CTL_ASYNC is set on the
 > pending queue, it loops infinitly.  Since the device is being
 > detached, no new xfer request shouldn't come (right?), so, we just
 > loop over all xfers?

 I can't promise that no new requests are coming in (since they come
 from the upper layers), but the hardware is gone so we can't execute them
 anymore.


 --

         -- Lennart




From: enami tsugutomo <enami@sm.sony.co.jp>
To: Lennart Augustsson <lennart@augustsson.net>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: 30 Mar 2000 18:11:10 +0900

 Lennart Augustsson <lennart@augustsson.net> writes:

 > I can't promise that no new requests are coming in (since they come
 > from the upper layers), but the hardware is gone so we can't execute them
 > anymore.

 At this point (i.e., when xxdetach is called), we know that the device
 is already deactivated.  So, we {can,should} reject the request for
 it.

 Hmm, but we should move such xfers somewhere else than that pending
 queue (which will deallocated after xxdetach returns).

 enami.

From: Lennart Augustsson <lennart@augustsson.net>
To: enami tsugutomo <enami@sm.sony.co.jp>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: Thu, 30 Mar 2000 11:42:36 +0200

 enami tsugutomo wrote:

 > Lennart Augustsson <lennart@augustsson.net> writes:
 >
 > > I can't promise that no new requests are coming in (since they come
 > > from the upper layers), but the hardware is gone so we can't execute them
 > > anymore.
 >
 > At this point (i.e., when xxdetach is called), we know that the device
 > is already deactivated.  So, we {can,should} reject the request for
 > it.

 They should absolutely be rejected, I just don't know if this happens.


 > Hmm, but we should move such xfers somewhere else than that pending
 > queue (which will deallocated after xxdetach returns).

 Which xfers are you talking about?  Those that were already pending
 when the detach happens?
 I think the code we have is almost right, it just have to make sure that
 the queue drains.

 --

         -- Lennart




From: enami tsugutomo <enami@sm.sony.co.jp>
To: Lennart Augustsson <lennart@augustsson.net>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org, enami@but-b.or.jp
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: Thu, 30 Mar 2000 20:03:32 +0900 (JST)

 # From oomiya soccur studium...

 In the train, I read the scsi code a bit more.

 > Message-ID: <38E3218B.5BD83536@augustsson.net>
 > Date: Thu, 30 Mar 2000 11:42:36 +0200
 > From: Lennart Augustsson <lennart@augustsson.net>
 > Subject: Re: kern/9703: Detaching an sd device can hang the system
 > 
 > They should absolutely be rejected, I just don't know if this happens.

 I remember that it has been done in send_cmd in each driver.

 > I think the code we have is almost right, it just have to make sure that
 > the queue drains.

 Yah, so we should do:

 	In the scsipi_kill_xfer,
 		- call scsipi_done for all xfers in the pending queue.
 		- then sleep until the queue become empty.

 	In the scsipi_free_xs, wakeup if the pending queue become
 	empty.

 I'll continue read the code...

 enami.

From: enami tsugutomo <enami@sm.sony.co.jp>
To: Lennart Augustsson <lennart@augustsson.net>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: 31 Mar 2000 13:17:45 +0900

 Lennart Augustsson <lennart@augustsson.net> writes:

 > I think the code we have is almost right, it just have to make sure that
 > the queue drains.

 Ok.  Is this fix your problem?  Just now I can't test by myself since
 I don't have access to detachable scsi (and atapi) controller.  I'll
 test this by myself tomorrow.

 enami.

 Index: scsi_base.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsi_base.c,v
 retrieving revision 1.72
 diff -u -r1.72 scsi_base.c
 --- scsi_base.c	2000/03/17 11:45:50	1.72
 +++ scsi_base.c	2000/03/31 03:31:31
 @@ -164,9 +164,11 @@
  scsi_kill_pending(sc_link)
  	struct scsipi_link *sc_link;
  {
 -	struct scsipi_xfer *xs;
 +	struct scsipi_xfer *xs, *xs_next;

 -	while ((xs = TAILQ_FIRST(&sc_link->pending_xfers)) != NULL) {
 +	for (xs = TAILQ_FIRST(&sc_link->pending_xfers); xs != NULL;
 +	    xs = xs_next) {
 +		xs_next = TAILQ_NEXT(xs, device_q);
  		xs->xs_status |= XS_STS_DONE;
  		xs->error = XS_DRIVER_STUFFUP;
  		scsipi_done(xs);
 Index: scsipi_base.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsipi_base.c,v
 retrieving revision 1.30
 diff -u -r1.30 scsipi_base.c
 --- scsipi_base.c	2000/03/23 07:01:44	1.30
 +++ scsipi_base.c	2000/03/31 03:31:33
 @@ -204,6 +204,7 @@
  {

  	(*sc_link->scsipi_kill_pending)(sc_link);
 +	scsipi_wait_drain(sc_link);
  #ifdef DIAGNOSTIC
  	if (TAILQ_FIRST(&sc_link->pending_xfers) != NULL)
  		panic("scsipi_kill_pending");

From: enami tsugutomo <enami@sm.sony.co.jp>
To: Lennart Augustsson <lennart@augustsson.net>
Cc: thorpej@netbsd.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/9703: Detaching an sd device can hang the system
Date: 31 Mar 2000 13:17:45 +0900

 Lennart Augustsson <lennart@augustsson.net> writes:

 > I think the code we have is almost right, it just have to make sure that
 > the queue drains.

 Ok.  Is this fix your problem?  Just now I can't test by myself since
 I don't have access to detachable scsi (and atapi) controller.  I'll
 test this by myself tomorrow.

 enami.

 Index: scsi_base.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsi_base.c,v
 retrieving revision 1.72
 diff -u -r1.72 scsi_base.c
 --- scsi_base.c	2000/03/17 11:45:50	1.72
 +++ scsi_base.c	2000/03/31 03:31:31
 @@ -164,9 +164,11 @@
  scsi_kill_pending(sc_link)
  	struct scsipi_link *sc_link;
  {
 -	struct scsipi_xfer *xs;
 +	struct scsipi_xfer *xs, *xs_next;

 -	while ((xs = TAILQ_FIRST(&sc_link->pending_xfers)) != NULL) {
 +	for (xs = TAILQ_FIRST(&sc_link->pending_xfers); xs != NULL;
 +	    xs = xs_next) {
 +		xs_next = TAILQ_NEXT(xs, device_q);
  		xs->xs_status |= XS_STS_DONE;
  		xs->error = XS_DRIVER_STUFFUP;
  		scsipi_done(xs);
 Index: scsipi_base.c
 ===================================================================
 RCS file: /cvsroot/syssrc/sys/dev/scsipi/scsipi_base.c,v
 retrieving revision 1.30
 diff -u -r1.30 scsipi_base.c
 --- scsipi_base.c	2000/03/23 07:01:44	1.30
 +++ scsipi_base.c	2000/03/31 03:31:33
 @@ -204,6 +204,7 @@
  {

  	(*sc_link->scsipi_kill_pending)(sc_link);
 +	scsipi_wait_drain(sc_link);
  #ifdef DIAGNOSTIC
  	if (TAILQ_FIRST(&sc_link->pending_xfers) != NULL)
  		panic("scsipi_kill_pending");
State-Changed-From-To: open->feedback 
State-Changed-By: enami 
State-Changed-When: Sun Apr 2 20:27:44 PDT 2000 
State-Changed-Why:  
I've send possible fix (which works for me) to lennart. 


Responsible-Changed-From-To: kern-bug-people->enami 
Responsible-Changed-By: enami 
Responsible-Changed-When: Sun Apr 2 20:27:44 PDT 2000 
Responsible-Changed-Why:  
I'll take care of this PR. 
State-Changed-From-To: feedback->closed 
State-Changed-By: enami 
State-Changed-When: Wed Apr 19 19:20:52 PDT 2000 
State-Changed-Why:  
Fix is commited in the tree and got ack to closed this PR from lennart. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.