From owner-freebsd-drivers@freebsd.org Sun Jun 18 10:11:10 2017 Return-Path: Delivered-To: freebsd-drivers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 96D89D8DC48 for ; Sun, 18 Jun 2017 10:11:10 +0000 (UTC) (envelope-from njm@njm.me.uk) Received: from smtp002.apm-internet.net (smtp002.apm-internet.net [85.119.248.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F2E65669EE for ; Sun, 18 Jun 2017 10:11:09 +0000 (UTC) (envelope-from njm@njm.me.uk) Received: (qmail 80154 invoked from network); 18 Jun 2017 10:04:26 -0000 X-APM-Authkey: 18389/1 2 Received: from unknown (HELO meld.njm.me.uk) (90.194.167.105) by smtp002.apm-internet.net with SMTP; 18 Jun 2017 10:04:26 -0000 Received: from triton.njm.me.uk (triton.njm.me.uk [192.168.144.133]) by meld.njm.me.uk (8.15.2/8.15.2) with ESMTP id v5IA4P3c002078; Sun, 18 Jun 2017 11:04:26 +0100 (BST) (envelope-from njm@njm.me.uk) Received: from localhost (localhost [127.0.0.1]) by triton.njm.me.uk (8.15.2/8.15.2) with ESMTP id v5IA4P6b072619; Sun, 18 Jun 2017 11:04:25 +0100 (BST) (envelope-from njm@njm.me.uk) Date: Sun, 18 Jun 2017 11:04:25 +0100 From: "N.J. Mann" To: Jia-Ju Bai cc: freebsd-drivers@freebsd.org Subject: Re: [Bug 220095][PATCH] dpt_scsi: Fix a possible sleep-under-mutex bug in dpt_init Message-ID: <7D8CD40C6A8CDF922B1E15A8@triton.njm.me.uk> In-Reply-To: <20170618094601.40636-1-baijiaju1990@163.com> References: <20170618094601.40636-1-baijiaju1990@163.com> X-Mailer: Mulberry/4.0.8 (Linux/x86) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Jun 2017 10:11:10 -0000 Hi, On Sunday, June 18, 2017 17:46:01 +0800 Jia-Ju Bai wrote: > The driver may sleep under a mutex, and the function call path is: > dpt_init [acquire the mutex] > dptallocsgmap > bus_dmamap_load(BUS_DMA_WAITOK) --> may sleep > > The possible fix of this bug is to set the last parameter in > bus_dmamap_load to "BUS_DMA_NOWAIT". Have you read the manual page for bus_dmamap_load() ? bus_dmamap_load(dmat, map, buf, buflen, *callback, callback_arg, flags) Creates a mapping in device visible address space of buflen bytes of buf, associated with the DMA map map. This call will always return immediately and will not block for any reason. I am not saying that your change should not be made, just that your analysis may be wrong. Cheers, Nick. --