From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1610DEB64DB for ; Thu, 15 Jun 2023 05:10:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243086AbjFOFKJ (ORCPT ); Thu, 15 Jun 2023 01:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243096AbjFOFKA (ORCPT ); Thu, 15 Jun 2023 01:10:00 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1272697; Wed, 14 Jun 2023 22:09:53 -0700 (PDT) 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> 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) Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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.