From patchwork Tue Feb 22 14:14:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 546626 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 94D8EC4167D for ; Tue, 22 Feb 2022 14:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232823AbiBVOPw (ORCPT ); Tue, 22 Feb 2022 09:15:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230349AbiBVOPs (ORCPT ); Tue, 22 Feb 2022 09:15:48 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CF8D160423; Tue, 22 Feb 2022 06:15:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kUzycC9K9fsPTd/sxe/S3aq/1ZdpTJdGU3r+NLtSIt0=; b=iCq6fEazeP/5hh+SD/Noah9MlB 8MHBu2/T+ByXvimv4Cu0qRFbaxAvG6MeWf7pITG2bSAxHdH0mDfKJSxXqIvQBY0dPOHgca2IPFo6z xDTNMYcY7RTEMXG1CLCH/DloWp1gPK1kMQk8DnloFDfa3NEKckMGNVY6jUQqbDsutOf/+2FbR7HHw q5YPbARRjH+4ALgvAxnU7lMjDmKEwp3LAQRwwV2EU/c2EKa1pveFAa1KRrPOnYTU6r9r90RcXJKlL CgUjj6H+bqZoVyfYNdEVKKbCIaPZc26y6p/RBDYO8lRg3x6UFTcXrA6SseyujL1OLwJRqDdJlIbTj VPCGe02w==; Received: from [2001:4bb8:198:f8fc:c22a:ebfc:be8d:63c2] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMVwi-009qMF-Tv; Tue, 22 Feb 2022 14:15:17 +0000 From: Christoph Hellwig To: Jens Axboe Cc: "Martin K. Petersen" , Ming Lei , linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, Bart Van Assche Subject: [PATCH 09/12] block: move q_usage_counter release into blk_queue_release Date: Tue, 22 Feb 2022 15:14:47 +0100 Message-Id: <20220222141450.591193-10-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220222141450.591193-1-hch@lst.de> References: <20220222141450.591193-1-hch@lst.de> MIME-Version: 1.0 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-scsi@vger.kernel.org From: Ming Lei After blk_cleanup_queue() returns, disk may not be released yet, so probably bio may still be submitted and ->q_usage_counter may be touched, so far this way seems safe, but not good from API's viewpoint. Move the release q_usage_counter into blk_queue_release(). Signed-off-by: Ming Lei Reviewed-by: Bart Van Assche Signed-off-by: Christoph Hellwig --- block/blk-core.c | 2 -- block/blk-sysfs.c | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index b2f2c65774812..a8c59913dd78d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -342,8 +342,6 @@ void blk_cleanup_queue(struct request_queue *q) blk_mq_sched_free_rqs(q); mutex_unlock(&q->sysfs_lock); - percpu_ref_exit(&q->q_usage_counter); - /* @q is and will stay empty, shutdown and put */ blk_put_queue(q); } diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 5f723d2ff8948..4ea22169b5186 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -780,6 +780,8 @@ static void blk_release_queue(struct kobject *kobj) might_sleep(); + percpu_ref_exit(&q->q_usage_counter); + if (q->poll_stat) blk_stat_remove_callback(q, q->poll_cb); blk_stat_free_callback(q->poll_cb);