Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7BF2B7F9 for ; Thu, 15 Jun 2023 05:09:52 +0000 (UTC) Received: by verein.lst.de (Postfix, from userid 2407) id 7450167373; Thu, 15 Jun 2023 07:09:47 +0200 (CEST) Date: Thu, 15 Jun 2023 07:09:47 +0200 From: Christoph Hellwig To: Damien Le Moal Cc: Christoph Hellwig , Alan Stern , Hannes Reinecke , Joe Breuer , Bart Van Assche , Bagas Sanjaya , Pavel Machek , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Thorsten Leemhuis , "James E.J. Bottomley" , "Martin K. Petersen" , Phillip Potter , Linux Power Management , Linux Kernel Mailing List , Linux Hardening , Linux Regressions , Linux SCSI , Dan Williams , Hannes Reinecke , Adrian Hunter , Martin Kepplinger , Kai-Heng Feng Subject: Re: Fwd: Waking up from resume locks up on sr device Message-ID: <20230615050947.GA5053@lst.de> References: <07d6e2e7-a50a-8cf4-5c5d-200551bd6687@gmail.com> <02e4f87a-80e8-dc5d-0d6e-46939f2c74ac@acm.org> <84f1c51c-86f9-04b3-0cd1-f685ebee7592@kernel.org> <37ed36f0-6f72-115c-85fb-62ef5ad72e76@suse.de> <859f0eda-4984-4489-9851-c9f6ec454a88@rowland.harvard.edu> <41b069c7-8723-4507-3e5a-1d1878db9002@kernel.org> <20230615044015.GA4720@lst.de> <9633f1a6-2e33-4a40-3fdb-0c1c4e4cd720@kernel.org> Precedence: bulk X-Mailing-List: regressions@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9633f1a6-2e33-4a40-3fdb-0c1c4e4cd720@kernel.org> User-Agent: Mutt/1.5.17 (2007-11-01) On Thu, Jun 15, 2023 at 01:57:37PM +0900, Damien Le Moal wrote: > > No. scsi_device_get just increments a reference count, and thus > > prevents ->release from beeing called. ->remove is not in any way > > affected by the refcount. > > What ->remove cb are you talking about ? The gendev one ? The one for the device locked. > I am trying to understand why the use of device_lock() helps in any way given > that this is not used by any other functions in scsi. And given that The device model locks the device before calling ->remove. > scsi_rescan_device() should always be called with a ref on the scsi device (and > so on the gendev as well) held, why would this function be racy with device remove ? Because ->remove ould otherwise be called at the same time as ->rescan. > Note that I did find a couple of places where scsi_rescan_device() seems to not > be called with a reference to the scsi dev held, e.g. store_rescan_field() and > store_state_field(). You need both a valid reference and ensure ->remove is not called at the same time.