From owner-freebsd-current@FreeBSD.ORG Mon Apr 28 16:39:33 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0401837B404; Mon, 28 Apr 2003 16:39:33 -0700 (PDT) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 00BB243FE0; Mon, 28 Apr 2003 16:39:32 -0700 (PDT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.8/8.12.3) with ESMTP id h3SNdUA7084654; Mon, 28 Apr 2003 17:39:30 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Mon, 28 Apr 2003 17:39:25 -0600 (MDT) Message-Id: <20030428.173925.21929852.imp@bsdimp.com> To: hsu@FreeBSD.org From: "M. Warner Losh" In-Reply-To: <200304282255.h3SMtuPi008021@mta4.rcsntx.swbell.net> References: <200304282255.h3SMtuPi008021@mta4.rcsntx.swbell.net> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: current@FreeBSD.org cc: jhb@FreeBSD.org Subject: Re: panic: sleeping thread owns a mutex X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Apr 2003 23:39:33 -0000 In message: <200304282255.h3SMtuPi008021@mta4.rcsntx.swbell.net> Jeffrey Hsu writes: : > Set a flag in your driver before you drop the wi lock that the : > wiintr() function can check and bail out immediately if it is set. : > For example: : : > foo_detach() : > { : > ... : > sc->sc_dead = 1; : > FOO_UNLOCK(sc); <--- Race 1 : > bus_teardown_intr(...) We can't get an interrupt after this returns, and we're guaranteed that the interrupt has terminated. : > ... : mtx_destroy(&sc->sc_mtx); <--- note this : > } : : > foo_intr() : > { : > FOO_LOCK(sc); : > if (sc->sc_dead) { : > FOO_UNLOCK(sc); : > return; : > } : > ... : > } : : The sc_dead flag doesn't protect against foo_intr() attempting to : lock a mutex that has been destroyed. fxp has the same problem : and is one of the reasons, among others, I wasn't too happy with : the fxp softc locks introduced there. Since this race isn't possible, the dead solution is sufficient to guard against the Race 1 above. : The solution I have in mind involves using the DEAD flag in the interrupt : handler to defer destroying the mutex if the interrupt handler is active. bus_teardown_inter already assures that. Warner