Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3558660rwb; Mon, 3 Oct 2022 17:33:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM51r0BYyBZRo42ta8uaWMe4E7gMk9GGAwp/TyaHC7uyD3n3AGF0JhGooiNnup+NuVocqEYO X-Received: by 2002:a05:6402:c81:b0:458:c428:173a with SMTP id cm1-20020a0564020c8100b00458c428173amr10800976edb.298.1664843639692; Mon, 03 Oct 2022 17:33:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664843639; cv=none; d=google.com; s=arc-20160816; b=M9Kff0uhlm8sxo84e4WY21ttyqYeOTmB3M4n5LsRb38jIVDzfqx1Dgj55BX19RNaGv /vjmiLxI5rH9bydfI7NC8NtWFdsEXe8CvELSJUY4QPTrKFaTX+h7J/UVGCYjUWyZzScM ZWFaYd7UsRCUubrQWnBj0CvIQzGcm4u8oMJZXRD9f3LBtRF/Xc1rBghB0usWrtkCdA4N vcMAt0mmwAsOe1B3ABHW1NNTx3YkRiKrK/UzhKrnLJb13nVdD6+FcN+v9qJidagrvwIv EnbFVobq3pgnebDkRHLiIPFAUeJrZZyz2H+IO7UcONk9/hcoruEoIXXePSJMw2VbA7W7 4Feg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=G37LnXkC8VTdsMvruTDa2+n50xVxzxAz9mNwqVDycIY=; b=Hmx40MPkIZszvukVBB7UN8k6rUSS7IDlZICRudz5brVUhic3QINTsEABuVV0cxrGxj cHePq/I5A1LLR5zZ8GAr1OqY9Sh1JsFIG1iIOlhXAJXdSgNjfe1X46dI6hGuq8nsdFQD 0RqDrhUffy/qRxJvJ6QJtLzz4XhiN6pAzn8g6qdTZ4wgbJSUScdWDQjM7/4/MvjEIsgH q+dxKJ1W6yhP18Mc7uqfR7zR6mvCBDdstdUJVDvPh5AflrXcLK9JnQLrwi3c2CSomA4w 2Q9bb1rgYrQuwaafXEYcPJ1UgH/6A5xDVhE4+H9NU3ul4j01j0DnW/A5CFFp/nXKtIBQ cioA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=XTOqMBWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg35-20020a170907a42300b00780d58a6ac8si10615743ejc.804.2022.10.03.17.33.34; Mon, 03 Oct 2022 17:33:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=XTOqMBWM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbiJCX5G (ORCPT + 99 others); Mon, 3 Oct 2022 19:57:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbiJCX4u (ORCPT ); Mon, 3 Oct 2022 19:56:50 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6077F27CDB; Mon, 3 Oct 2022 16:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=G37LnXkC8VTdsMvruTDa2+n50xVxzxAz9mNwqVDycIY=; b=XTOqMBWME2UGab0kwjo1gzrMRW gB+DuURn9NS4zcZSmoeMs18rQmqAsTNNa6uuhzopJE7oJUzHFGX+qVY7cdxQlfhPuwqLeXoDvetBs CcsdjMo+/vbb/SNGM9xa8ArXmcyHMYiLJbgqoh53RFxan4Zh6rxIM0KwecTCGmVw7g/2QE2XOPexA zmbGEaVvP9cKgoIuClztMdTyR+b3wnCwudN9YEIqi1v33/NbiEad2VssWmt64gBQQnGlv4v+/ejDr cvjhjQ2lZjbHT91+3gOMqh0aGmftMrWfQC/SD1FT/gQY7QqVITbhlMYVu9rTYP2v6z59AYKycxcnF 095W7VAA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ofVIh-0086q0-0V; Mon, 03 Oct 2022 23:56:43 +0000 Date: Mon, 3 Oct 2022 16:56:42 -0700 From: Luis Chamberlain To: Bart Van Assche Cc: Mauro Carvalho Chehab , "Martin K . Petersen" , linux-scsi@vger.kernel.org, Christoph Hellwig , Ming Lei , Hannes Reinecke , John Garry , Mike Christie , Krzysztof Kozlowski , Greg Kroah-Hartman , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, "James E.J. Bottomley" , Tejun Heo Subject: Re: [PATCH v5 6/7] module: Improve support for asynchronous module exit code Message-ID: References: <20220914225621.415631-1-bvanassche@acm.org> <20220914225621.415631-7-bvanassche@acm.org> <33ee1c3a-d37a-b81f-68be-d1901c7dd6e8@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Luis Chamberlain X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 30, 2022 at 12:39:27PM -0700, Luis Chamberlain wrote: > On Wed, Sep 28, 2022 at 11:17:02AM -0700, Bart Van Assche wrote: > > On 9/27/22 17:02, Luis Chamberlain wrote: > > > On Tue, Sep 20, 2022 at 10:13:40AM -0700, Bart Van Assche wrote: > > > > On 9/14/22 15:56, Bart Van Assche wrote: > > > > > Some kernel modules call device_del() from their module exit code and > > > > > schedule asynchronous work from inside the .release callback without waiting > > > > > until that callback has finished. As an example, many SCSI LLD drivers call > > > > > scsi_remove_host() from their module exit code. scsi_remove_host() may > > > > > invoke scsi_device_dev_release_usercontext() asynchronously. > > > > > scsi_device_dev_release_usercontext() uses the host template pointer and > > > > > that pointer usually exists in static storage in the SCSI LLD. Support > > > > > using the module reference count to keep the module around until > > > > > asynchronous module exiting has completed by waiting in the delete_module() > > > > > system call until the module reference count drops to zero. > > > > > > > > Hi Luis, > > > > > > > > I'd like to know your opinion about this patch since you are the maintainer > > > > of the kernel module system. > > > > > > See this patch which extends the documentation of try_module_get(): > > > > > > https://lkml.kernel.org/r/20211029184500.2821444-7-mcgrof@kernel.org > > > > > > You can ignore discussion around the thread as sadly it is just > > > irrelevant stuff not about that patch. But the logic it spells out > > > is still true. > > > > > > So, in short, using try_module_get() on exit is actually the wrong > > > thing to do and it is no surprise it would fail. I haven't gotten > > > yet around to reviewing Mauro's driver API which let's you unbind > > > drivers, but it sounds related so I CC'd you on that. > > > > > > So I'd like to ask instead if an alternative to using try_module_get() > > > on exit would be better here and for the future. > > > > Hi Luis, > > > > The extended documentation of try_module_get() is very helpful. But please > > note that this patch is not related to try_module_get() at all. See also > > patch 7/7 in this series (https://lore.kernel.org/linux-scsi/20220914225621.415631-8-bvanassche@acm.org/). > > I cannot see how this patch set is no way related to try_module_get() > given the 7/7 patch you posted replaces try_module_get() with __module_get(). > My point, and hint, is that the original construct that added try_module_get() > on removal was flawed and I'm not sure trying to expand on that idea would > or even *should* be fruitful given the issues / tribal knowledge I tried > extending documentation for. > > It would beg the question if instead re-evaluating the goal could be > done in such a way that the new documentation I suggested on try_module_get() > would be seriously taken into account. Yeah I've gone ahead and re-read your original patch again the issue with that is it waits *once* for the refcnt to go to 0, but that does not forbit it from going back up, at which point you have a race which can still create the situation. Every subsystem is different, but for instance simply running a loop opening a device block file should suffice to bump the refcnt of a respective block driver module. So at least the patch itself won't ultimately address this issue I'm afraid. Luis