Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1766359rwb; Tue, 27 Sep 2022 18:50:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Sk/XDatag8vLFwTv5bRVs2rq/TG6cQ7IugJCJ9dVWqQbRb9sg5JRs2c4qwubAAHSlZaiV X-Received: by 2002:a63:1954:0:b0:438:79da:7849 with SMTP id 20-20020a631954000000b0043879da7849mr26435307pgz.527.1664329822855; Tue, 27 Sep 2022 18:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664329822; cv=none; d=google.com; s=arc-20160816; b=lSyzXFRvWtiwxd4QjDL/kAFQmC1sxnzvYuLccjE9vBEnEqmyNQt6x27sR1x5mvZXd1 x4X2atTnRuX01F6t30Orferp4T5YB6HmzrPr2ZIjhPIA5FaOYBSiu79pryoGlgP4konj gBUUPPlW2glsWcW9NlJoOiWZ5KRB8D9lpA6j+xEPUK8Bpi0nBgCokKS7DUT/n3klfV5b 0BZwOpixST2BBRUAc0Kg3SCKNwcNQvmV1pFMghUZh6Xm3XKLuPRQdablI3hK/n8OEMe+ ZG/3cmPOpoev3NpN0u8q0Gyjo+h7eUOIXycjY/r4fQRUx2ZxZJ/WPuSX4lqmn6K/Ojcl dUjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yuhYrI3O2et4AQDqfdAc7XVomQ7XZIW92EUt5M6cRFY=; b=KJ+VJzHzH7K0QdtB2i+opOFx43EGt5+8hKziFYEctVSGQvcI8pYadwb0wy1iCx9RiK tF0bAJoxc9KqDl7OtZdynmPm5jXlFYUJvu8zHpok8NZaMKYg0tupFC4MiLnEP1oQ5h6/ KIpdeGgYAHQWCeUPJLrmagwwe7tC1DJVPCMDIWaMxFZkOw4bhhTLnJdlfhDlJeenjtkq qlndE3Gp25eTtDd1Mney7Fhepmb/0Q0cAnURkeFQq0CZK6UZq3V1u1kriKJ9pGlGi0XJ livE9TK0F6z9Ns7iX1WMnUW38WDEk3BiEwFiHatT6C+ADVUswOjzCQa6s3IDFKYGI7MA kSuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bSfDT5vr; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 20-20020a631054000000b0042f1afb8cf9si3708830pgq.477.2022.09.27.18.50.10; Tue, 27 Sep 2022 18:50:22 -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=@redhat.com header.s=mimecast20190719 header.b=bSfDT5vr; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231269AbiI1BKW (ORCPT + 99 others); Tue, 27 Sep 2022 21:10:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231759AbiI1BKS (ORCPT ); Tue, 27 Sep 2022 21:10:18 -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 E3FCA5E66B for ; Tue, 27 Sep 2022 18:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664327407; 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=bSfDT5vrDpi0thvhRS5vBXsZX5BiB9+peCrLMKnokv4z9C9iOhr9ZHK01Xn9HwfWwRhqGZ 63cFKyYI054sBdi2U29KvylJXIMHCSnXCKNaqetULAaWLmW/3Aznze9LBuh/sAAbqKsME7 gkE7mqkk97qsq18WHmqAGDAc30zP5b0= 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 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 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