From frank@lap.exit.com  Fri Oct 29 22:33:24 2004
Return-Path: <frank@lap.exit.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B6AC516A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Oct 2004 22:33:24 +0000 (GMT)
Received: from tinker.exit.com (tinker.exit.com [206.223.0.1])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 310BE43D2D
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Oct 2004 22:33:24 +0000 (GMT)
	(envelope-from frank@lap.exit.com)
Received: from lap.exit.com (lap.exit.com [206.223.0.35])
	by tinker.exit.com (8.13.1/8.12.9) with ESMTP id i9TMawFj079503
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Oct 2004 15:36:58 -0700 (PDT)
	(envelope-from frank@lap.exit.com)
Received: from lap.exit.com (localhost [127.0.0.1])
	by lap.exit.com (8.13.1/8.13.1) with ESMTP id i9TMWcSf000748
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 29 Oct 2004 15:32:38 -0700 (PDT)
	(envelope-from frank@lap.exit.com)
Received: (from frank@localhost)
	by lap.exit.com (8.13.1/8.13.1/Submit) id i9TMWcZr000747;
	Fri, 29 Oct 2004 15:32:38 -0700 (PDT)
	(envelope-from frank)
Message-Id: <200410292232.i9TMWcZr000747@lap.exit.com>
Date: Fri, 29 Oct 2004 15:32:38 -0700 (PDT)
From: Frank Mayhar <frank@lap.exit.com>
Reply-To: Frank Mayhar <frank@exit.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Lock order reversal in USB code.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         73295
>Category:       kern
>Synopsis:       Lock order reversal in USB code.
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    iedowse
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Oct 29 22:40:29 GMT 2004
>Closed-Date:    Sun Apr 17 03:01:12 GMT 2005
>Last-Modified:  Sun Apr 17 03:01:12 GMT 2005
>Originator:     Frank Mayhar
>Release:        FreeBSD 5.3-STABLE i386
>Organization:
Exit Consulting
>Environment:
System: FreeBSD lap 5.3-STABLE FreeBSD 5.3-STABLE #6: Wed Oct 27 18:08:57 PDT 2004 frank@lap:/home/obj/usr/src/sys/AUTON i386


	This is with a kernel built with INVARIANTS, WITNESS and DIAGNOSTIC.
	I just plugged in the USB device (a SanDisk CF reader) and got the
	LOR:

usb3: handing over full speed device on port 3 to usb1
uhub3: port 3, device disappeared after reset
usb3: handing over full speed device on port 3 to usb1
uhub3: port 3, device disappeared after reset
umass0: SanDisk Corporation ImageMate CompactFlash USB, rev 1.10/0.09, addr 2
umass0: Get Max Lun not supported (STALLED)
malloc(M_WAITOK) of "1024", forcing M_NOWAIT with the following non-sleepable locks held:
exclusive sleep mutex dont_sleep_in_callout r = 0 (0xc06c90c0) locked @ /usr/src/sys/kern/kern_timeout.c:257
KDB: enter: witness_warn
[thread 100032]
Stopped at      kdb_enter+0x2b: nop
db> trace
kdb_enter(c0642e36) at kdb_enter+0x2b
witness_warn(5,0,c06788ac,c066347d,c0665fbd) at witness_warn+0x181
uma_zalloc_arg(c1433b00,0,2) at uma_zalloc_arg+0x41
malloc(260,c0693360,2,101,0) at malloc+0xb2
umass_cam_rescan(c218eb00,c06c90c0,0,c0665fbd,101) at umass_cam_rescan+0x1c
softclock(0) at softclock+0x1af
ithread_loop(c1d8fc80,d55e8d48,c1d8fc80,c04e6160,0) at ithread_loop+0x124
fork_exit(c04e6160,c1d8fc80,d55e8d48) at fork_exit+0xa4
fork_trampoline() at fork_trampoline+0x8
--- trap 0x1, eip = 0, esp = 0xd55e8d7c, ebp = 0 ---

It's pretty clear that umass_cam_rescan should be calling malloc with M_NOWAIT
rather than M_WAITOK (and, of course, handling the potential error return), or
alternatively that the rescan should happen in a sleepable context.
>Description:
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-usb 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 4 07:13:41 GMT 2004 
Responsible-Changed-Why:  
Reassign to appropriate mailing list. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73295 
State-Changed-From-To: open->patched 
State-Changed-By: iedowse 
State-Changed-When: Fri Mar 25 00:39:16 GMT 2005 
State-Changed-Why:  

Fixed in -CURRENT by revision 1.120 of umass.c. 


Responsible-Changed-From-To: freebsd-usb->iedowse 
Responsible-Changed-By: iedowse 
Responsible-Changed-When: Fri Mar 25 00:39:16 GMT 2005 
Responsible-Changed-Why:  

My MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73295 
State-Changed-From-To: patched->closed 
State-Changed-By: iedowse 
State-Changed-When: Sun Apr 17 02:59:43 GMT 2005 
State-Changed-Why:  

This has been merged into RELENG_5 

http://www.freebsd.org/cgi/query-pr.cgi?pr=73295 
>Unformatted:
