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 E09FAC433EF for ; Wed, 11 May 2022 08:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243981AbiEKIdS (ORCPT ); Wed, 11 May 2022 04:33:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243779AbiEKIbw (ORCPT ); Wed, 11 May 2022 04:31:52 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D14273190F; Wed, 11 May 2022 01:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=v6LTVQjeDFrw6vdK4w8luloTEFL+fsitDmR6W5fFJig=; b=IZ8CZmlPJlqOJneX1ygZtZH9XC 3O4wLrlBJTUiSsQ7Wn4piNtq66RatOWmjhgxOKeLdSi/UU/ygJU2swRImRifc+taFT25hqRbjQX4Z oWxPzaMZOEUW6AYTlQ5v+wNTWmgeUfQvPh6nyxty8+fhr7S5FCw7n5qtRCWwtHpWC1mXbm/HwSjld ODjjNirmL4WaUSW+odUmMSpD2S3wa+stlWW94jiP+O6lgW0ixEbsQ8p2YgPFaCPIwwNSVSpmgkqV1 ox4chKK7R/t5IycO3qu+lPIw1m+Opdn73RKY2cRGTuOMnM4qOIMqFuGnMMdE8ruXVY/iJdsxH+/kb 9ytKpZlQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nohku-005xEt-Te; Wed, 11 May 2022 08:31:36 +0000 Date: Wed, 11 May 2022 01:31:36 -0700 From: Christoph Hellwig To: John Garry Cc: Krzysztof Kozlowski , Christoph Hellwig , "Ewan D. Milne" , "James E.J. Bottomley" , "Martin K. Petersen" , Alim Akhtar , Avri Altman , Doug Gilbert , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, james.smart@broadcom.com Subject: Re: [PATCH 1/4] scsi: core: constify pointer to scsi_host_template Message-ID: References: <24bfb681-faec-3567-3089-9cd5ee182710@linaro.org> <1bb53912-c5c3-7690-e82f-cf356ca87404@huawei.com> <6f28acde-2177-0bc7-b06d-c704153489c0@linaro.org> <4510c5dc-3d7d-fc5f-cb80-34da7dbaaa8e@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 09, 2022 at 03:50:33PM +0100, John Garry wrote: > If you check scsi_device_dev_release(), we try to do a 'get' - if it fails, > then we nullify hostt->module. I think that is important as then we call > execute_in_process_context(), whose worker does the 'put'. However, the > 'put' will get upset if the refcnt was 0, which it would be if the earlier > 'get' fails - hence the nullify is to avoid that possibility. So whatever > you do needs to handle that. Details are in f2b85040 Yikes, that code is completely and utterly buggy and does not account for all the cases why try_module_get can fail. I think we always have a reference here and could use __module_get, but what we have is certainly unsafe and a good reason why the host template should be constifyed.