From owner-freebsd-arch@FreeBSD.ORG Wed Aug 31 14:24:49 2011 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C9FF0106566B; Wed, 31 Aug 2011 14:24:49 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id A18048FC08; Wed, 31 Aug 2011 14:24:49 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 430D346B06; Wed, 31 Aug 2011 10:24:49 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id CB3768A02E; Wed, 31 Aug 2011 10:24:48 -0400 (EDT) From: John Baldwin To: freebsd-arch@freebsd.org Date: Wed, 31 Aug 2011 09:43:24 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110617; KDE/4.5.5; amd64; ; ) References: <4E53986B.5000804@FreeBSD.org> <4E5A099F.4060903@FreeBSD.org> <201108281127.44696.hselasky@freebsd.org> In-Reply-To: <201108281127.44696.hselasky@freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201108310943.24476.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Wed, 31 Aug 2011 10:24:48 -0400 (EDT) Cc: Hans Petter Selasky , Andriy Gapon Subject: Re: skipping locks, mutex_owned, usb X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Aug 2011 14:24:49 -0000 On Sunday, August 28, 2011 5:27:44 am Hans Petter Selasky wrote: > On Sunday 28 August 2011 11:25:51 Andriy Gapon wrote: > > on 23/08/2011 15:09 Andriy Gapon said the following: > > > This "XXX cludge" [sic] pattern is scattered around a few functions in > > > the ukbd code and perhaps other usb code: > > > func() > > > { > > > > > > if (!mtx_owned(&Giant)) { > > > > > > mtx_lock(&Giant); > > > > > > func(); > > > mtx_unlock(&Giant); > > > > > > return; > > > > > > } > > > > > > // etc ... > > > > > > } > > > > Ohhh, nothing seems simple with the USB code: > > > > /* make sure that the BUS mutex is not locked */ > > drop_bus = 0; > > while (mtx_owned(&xroot->udev->bus->bus_mtx)) { > > mtx_unlock(&xroot->udev->bus->bus_mtx); > > drop_bus++; > > } > > > > /* make sure that the transfer mutex is not locked */ > > drop_xfer = 0; > > while (mtx_owned(xroot->xfer_mtx)) { > > mtx_unlock(xroot->xfer_mtx); > > drop_xfer++; > > } > > > > So many unconventional tricks. > > Similar code is used in the DROP_GIANT and PICKUP_GIANT macros. You might want > to check all references to mtx_owned() in the kernel, and make a set of > exceptions for post-panic code execution. Giant is special because it is a hack to let us run non-MPSAFE code. Other locks should not follow its model. -- John Baldwin