NetBSD Problem Report #51129
From www@NetBSD.org Tue May 10 06:32:12 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 72D6F7AA95
for <gnats-bugs@gnats.NetBSD.org>; Tue, 10 May 2016 06:32:12 +0000 (UTC)
Message-Id: <20160510063211.7EB367AAAF@mollari.NetBSD.org>
Date: Tue, 10 May 2016 06:32:11 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: Disconnecting USB SD card without umount causes file operations to hang
X-Send-Pr-Version: www-1.0
>Number: 51129
>Category: kern
>Synopsis: Disconnecting USB SD card without umount causes file operations to hang
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: skrll
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue May 10 06:35:00 +0000 2016
>Closed-Date: Sat Feb 20 09:18:44 +0000 2021
>Last-Modified: Sat Feb 20 09:18:44 +0000 2021
>Originator: coypu
>Release: NetBSD 7.99.29
>Organization:
>Environment:
NetBSD net.Home 7.99.29 NetBSD 7.99.29 (GENERIC) #1: Tue May 10 07:40:15 IDT 2016 fly@net.Home:/usr/obj/sys/arch/amd64/compile/GENERIC amd64
>Description:
attach SD card reader with rpi.img on it
mount /dev/sd0a /new
detach SD card reader
any operation will hang. ls, umount (even umount -f), etc.
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
From: coypu@SDF.ORG
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Tue, 10 May 2016 06:37:29 +0000
Clarifying, not *any* file operation.
Examples of file operations that hang:
mount -v
umount -f /new
ls /new
etc.
Examples of file operations that do not hang:
ls /
From: coypu@SDF.ORG
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Tue, 10 May 2016 06:43:52 +0000
From dmesg after trying to plug it back in a few times:
umass0 at uhub0 port 1 configuration 1 interface 0
umass0: USB FLASH DISK USB FLASH DISK, rev 2.00/2.01, addr 5
umass0: using SCSI over Bulk-Only
scsibus0 at umass0: 2 targets, 1 lun per target
sd0 at scsibus0 target 0 lun 0: <USB Mass, Storage Device,
\001\000\000\001> disk removable
sd0: fabricating a geometry
sd0: 15193 MB, 15193 cyl, 64 head, 32 sec, 512 bytes/sect x 31116288
sectors
sd0: fabricating a geometry
/dev/sd0a: file system not clean (fs_clean=0x10); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
umass0: BBB reset failed, TIMEOUT
umass0: BBB bulk-in clear stall failed, TIMEOUT
umass0: BBB bulk-out clear stall failed, TIMEOUT
umass0: BBB reset failed, TIMEOUT
umass0: BBB bulk-in clear stall failed, TIMEOUT
umass0: BBB bulk-out clear stall failed, TIMEOUT
umass0: BBB reset failed, TIMEOUT
umass0: BBB bulk-in clear stall failed, TIMEOUT
umass0: BBB bulk-out clear stall failed, TIMEOUT
...
From: coypu@SDF.ORG
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Tue, 10 May 2016 07:17:51 +0000
Bonus:
if you umount /new, you can now execute the following:
mv /new /new/a/b
whereas normally it would say device busy.
if you run umount -f instead, this operation will also hang.
normal umount is stuck in biowait
umount -f is stuck in vcache
mv after umount -f is stuck in vcache
Maybe bonus:
I could lock my system, not sure which scenario is needed because
I can't always make it happen (placing a lock on /, can't execute
new programs).
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Sat, 14 May 2016 18:05:40 +0000
On Tue, May 10, 2016 at 07:20:00AM +0000, coypu@SDF.ORG wrote:
> Bonus:
>
> if you umount /new, you can now execute the following:
> mv /new /new/a/b
>
> whereas normally it would say device busy.
>
> if you run umount -f instead, this operation will also hang.
>
> normal umount is stuck in biowait
> umount -f is stuck in vcache
> mv after umount -f is stuck in vcache
So, just to make sure I understand:
mkdir /new [so it's empty]
attach device
mount /dev/sd0a /new
pull device
umount /new & [hangs in background]
mv /new /new/a/b [succeeds and *doesn't* hang?]
and a/b is a subdirectory on the device? That is ... odd.
and also
mkdir /new [so it's empty]
attach device
mount /dev/sd0a /new
pull device
umount -f /new [hangs]
? (which is still a bug, but less surprising)
--
David A. Holland
dholland@netbsd.org
State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sun, 26 Feb 2017 02:42:21 +0000
State-Changed-Why:
same as 51127 which is mine too.
State-Changed-From-To: closed->open
State-Changed-By: jdolecek@NetBSD.org
State-Changed-When: Thu, 20 Apr 2017 17:18:20 +0000
State-Changed-Why:
Somebody should fix this. Better keep it open.
From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: jdolecek@NetBSD.org
Subject: Re: kern/51129 (Disconnecting USB SD card without umount causes file
operations to hang)
Date: Thu, 20 Apr 2017 17:34:49 +0000
Plug USB
mount
disconnect, reconnect USB
umount
660 1 3 10 0 fffffe8475baaaa0 umount biowait
crash> bt/a fffffe8475baaaa0
trace: pid 660 lid 1 at 0xfffffe811d942880
sleepq_block() at sleepq_block+0x97
cv_wait() at cv_wait+0x9e
biowait() at biowait+0x42
bread() at bread+0x2e
ffs_init_vnode() at ffs_init_vnode+0xa7
ffs_loadvnode() at ffs_loadvnode+0x43
vcache_get() at vcache_get+0x293
ufs_vget() at ufs_vget+0x23
ufs_root() at ufs_root+0x1c
VFS_ROOT() at VFS_ROOT+0x1c
lookup_once() at lookup_once+0x250
namei_tryemulroot.constprop.9() at namei_tryemulroot.constprop.9+0x3a9
namei() at namei+0x43
fd_nameiat.isra.2() at fd_nameiat.isra.2+0x54
do_sys_statat() at do_sys_statat+0x77
sys___lstat50() at sys___lstat50+0x25
syscall() at syscall+0x1bc
--- syscall (number 441) ---
785bb70ae67a:
Idea that may not be sensible: using cv_timedwait instead in biowait and
setting an error on EWOULDBLOCK.
Alternatively using this time to cv_broadcast failures (???)
umass0: BBB reset failed, TIMEOUT
umass0: BBB bulk-in clear stall failed, TIMEOUT
umass0: BBB bulk-out clear stall failed, TIMEOUT
Responsible-Changed-From-To: kern-bug-people->skrll
Responsible-Changed-By: skrll@NetBSD.org
Responsible-Changed-When: Fri, 21 Apr 2017 15:43:13 +0000
Responsible-Changed-Why:
Take
From: Nick Hudson <skrll@netbsd.org>
To: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc:
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Sat, 22 Apr 2017 06:37:50 +0100
This is a multi-part message in MIME format.
--------------050605020508030409040902
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Does this patch fix things for you?
Thanks,
Nick
--------------050605020508030409040902
Content-Type: text/x-patch;
name="pr51129.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="pr51129.diff"
Index: sys/dev/usb/umass.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/umass.c,v
retrieving revision 1.157
diff -u -p -w -b -r1.157 umass.c
--- sys/dev/usb/umass.c 21 Nov 2016 08:27:30 -0000 1.157
+++ sys/dev/usb/umass.c 22 Apr 2017 05:34:54 -0000
@@ -796,6 +796,10 @@ umass_detach(device_t self, int flags)
DPRINTFM(UDMASS_USB, "sc %p detached", sc, 0, 0, 0);
+ mutex_enter(&sc->sc_lock);
+ sc->sc_dying = true;
+ mutex_exit(&sc->sc_lock);
+
pmf_device_deregister(self);
/* Abort the pipes to wake up any waiting processes. */
@@ -1156,9 +1160,6 @@ umass_bbb_state(struct usbd_xfer *xfer,
"sc->sc_wire == 0x%02x wrong for umass_bbb_state\n",
sc->sc_wire);
- if (sc->sc_dying)
- return;
-
/*
* State handling for BBB transfers.
*
@@ -1173,6 +1174,18 @@ umass_bbb_state(struct usbd_xfer *xfer,
DPRINTFM(UDMASS_BBB, "sc %p xfer %p, transfer_state %d dir %d", sc,
xfer, sc->transfer_state, sc->transfer_dir);
+ if (err == USBD_CANCELLED) {
+ DPRINTFM(UDMASS_BBB, "sc %p xfer %p cancelled", sc,
+ xfer, 0, 0);
+
+ sc->transfer_state = TSTATE_IDLE;
+ sc->transfer_cb(sc, sc->transfer_priv, 0, STATUS_TIMEOUT);
+ return;
+ }
+
+ if (sc->sc_dying)
+ return;
+
switch (sc->transfer_state) {
/***** Bulk Transfer *****/
@@ -1609,6 +1622,13 @@ umass_cbi_state(struct usbd_xfer *xfer,
"sc->sc_wire == 0x%02x wrong for umass_cbi_state\n",
sc->sc_wire);
+ if (err == USBD_CANCELLED) {
+ DPRINTFM(UDMASS_BBB, "sc %p xfer %p cancelled", sc, xfer, 0, 0);
+ sc->transfer_state = TSTATE_IDLE;
+ sc->transfer_cb(sc, sc->transfer_priv, 0, STATUS_TIMEOUT);
+ return;
+ }
+
if (sc->sc_dying)
return;
Index: sys/dev/usb/umass_scsipi.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/umass_scsipi.c,v
retrieving revision 1.54
diff -u -p -w -b -r1.54 umass_scsipi.c
--- sys/dev/usb/umass_scsipi.c 21 Nov 2016 08:27:30 -0000 1.54
+++ sys/dev/usb/umass_scsipi.c 22 Apr 2017 05:34:54 -0000
@@ -444,6 +444,10 @@ umass_scsipi_cb(struct umass_softc *sc,
xs->error = XS_RESET;
break;
+ case STATUS_TIMEOUT:
+ xs->error = XS_TIMEOUT;
+ break;
+
default:
panic("%s: Unknown status %d in umass_scsipi_cb",
device_xname(sc->sc_dev), status);
Index: sys/dev/usb/umassvar.h
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/umassvar.h,v
retrieving revision 1.38
diff -u -p -w -b -r1.38 umassvar.h
--- sys/dev/usb/umassvar.h 3 Jul 2016 07:27:37 -0000 1.38
+++ sys/dev/usb/umassvar.h 22 Apr 2017 05:34:54 -0000
@@ -135,6 +135,7 @@ typedef void (*umass_callback)(struct um
#define STATUS_CMD_UNKNOWN 1 /* will have to fetch sense */
#define STATUS_CMD_FAILED 2 /* transfer was ok, command failed */
#define STATUS_WIRE_FAILED 3 /* couldn't even get command across */
+#define STATUS_TIMEOUT 4 /* transfer aborted */
typedef void (*umass_wire_xfer)(struct umass_softc *, int, void *, int, void *,
int, int, u_int, int, umass_callback, void *);
--------------050605020508030409040902--
From: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Cc: skrll@NetBSD.org
Subject: Re: kern/51129: Disconnecting USB SD card without umount causes file
operations to hang
Date: Sat, 22 Apr 2017 08:43:09 +0000
On Sat, Apr 22, 2017 at 05:40:01AM +0000, Nick Hudson wrote:
> Does this patch fix things for you?
>
> Thanks,
> Nick
It works, thanks!
Now 'cd /mnt' and 'umount /mnt' fail with EIO
From: "Nick Hudson" <skrll@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/51129 CVS commit: src/sys/dev/usb
Date: Tue, 25 Apr 2017 05:36:03 +0000
Module Name: src
Committed By: skrll
Date: Tue Apr 25 05:36:03 UTC 2017
Modified Files:
src/sys/dev/usb: umass.c
Log Message:
In umass_detach set sc_dyring so that further attempts at transfers will
fail. This fixes part of
PR/51129 (Disconnecting USB SD card without umount causes file operations to hang)
To generate a diff of this commit:
cvs rdiff -u -r1.157 -r1.158 src/sys/dev/usb/umass.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->feedback
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Sun, 16 Feb 2020 20:47:44 +0000
State-Changed-Why:
Is it fixed now?
State-Changed-From-To: feedback->closed
State-Changed-By: skrll@NetBSD.org
State-Changed-When: Sat, 20 Feb 2021 09:18:44 +0000
State-Changed-Why:
assume fixed. please raise a new PR if you stil have problems.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.