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 98FEEC54EE9 for ; Wed, 28 Sep 2022 01:10:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbiI1BKW (ORCPT ); Tue, 27 Sep 2022 21:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231804AbiI1BKT (ORCPT ); Tue, 27 Sep 2022 21:10:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 436AB5F22D for ; Tue, 27 Sep 2022 18:10:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664327409; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yuhYrI3O2et4AQDqfdAc7XVomQ7XZIW92EUt5M6cRFY=; b=NhSx1CSg7wa/QETmbkSR3WGIhJ8dUxlfg8y9C14aIsOtd6Qu4KLBwmZSPkSQJBwILYEW9O 3rSd8vW6niic0UjV8XGEX7BbRZgh/ustKPLJXL0ahss6vQKf7olJEHqanBbEPAKtMbsXBN 0yC3gnxwoh/579CWRK5E0T/cO7QqrWc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-434-53R5vA26MeOJJtwaB5DeVw-1; Tue, 27 Sep 2022 21:10:06 -0400 X-MC-Unique: 53R5vA26MeOJJtwaB5DeVw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8801A185A78F; Wed, 28 Sep 2022 01:10:05 +0000 (UTC) Received: from T590 (ovpn-8-16.pek2.redhat.com [10.72.8.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 350B1C15BA4; Wed, 28 Sep 2022 01:09:55 +0000 (UTC) Date: Wed, 28 Sep 2022 09:09:50 +0800 From: Ming Lei To: Bart Van Assche Cc: "Martin K . Petersen" , linux-scsi@vger.kernel.org, Luis Chamberlain , Christoph Hellwig , 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 , ming.lei@redhat.com 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220914225621.415631-7-bvanassche@acm.org> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: On Wed, Sep 14, 2022 at 03:56:20PM -0700, 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 It isn't only related with device, any kobject has such issue, or any reference counter usage has similar potential risk, see previous discussion: https://lore.kernel.org/lkml/YsZm7lSXYAHT14ui@T590/ IMO, it is one fundamental problem wrt. module vs. reference counting or kobject uses at least, since the callback depends on module code segment. > 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. The issue can't be addressed by the normal mod->refcnt, since user need to unload module when the device isn't used. thanks, Ming