From patchwork Thu May 11 06:56:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 13237532 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 82EF5C7EE22 for ; Thu, 11 May 2023 07:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbjEKHAq (ORCPT ); Thu, 11 May 2023 03:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237161AbjEKHAV (ORCPT ); Thu, 11 May 2023 03:00:21 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D38277AA1; Wed, 10 May 2023 23:59:39 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QH2n84qzqz4f3vdV; Thu, 11 May 2023 14:59:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgD3rLA7klxkxW3WJA--.19279S4; Thu, 11 May 2023 14:59:09 +0800 (CST) From: Yu Kuai To: hch@lst.de, ming.lei@redhat.com, axboe@kernel.dk Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH -next] block: fix blktrace debugfs entries leak Date: Thu, 11 May 2023 14:56:33 +0800 Message-Id: <20230511065633.710045-1-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CM-TRANSID: gCh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vhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yu Kuai Commit 99d055b4fd4b ("block: remove per-disk debugfs files in blk_unregister_queue") moves blk_trace_shutdown() from blk_release_queue() to blk_unregister_queue(), this is safe if blktrace is created through sysfs, however, there are some regression in corner cases: 1) for scsi, passthrough io can still be issued after del_gendisk, and blktrace debugfs entries will be removed immediately after del_gendisk(), therefor passthrough io can't be tracked and blktrace will complain: failed read of /sys/kernel/debug/block/sdb/trace0: 5/Input/output error 2) blktrace can still be enabled after del_gendisk() through ioctl if the disk is opened before del_gendisk(), and if blktrace is not shutdown through ioctl before closing the disk, debugfs entries will be leaked. It seems 1) is not important, while 2) needs to be fixed apparently. Fix this problem by shutdown blktrace in blk_free_queue(), disk_release() is not used because scsi sg support blktrace without gendisk, and this is safe because queue is not freed yet, and blk_trace_shutdown() is reentrant. Fixes: 99d055b4fd4b ("block: remove per-disk debugfs files in blk_unregister_queue") Signed-off-by: Yu Kuai --- block/blk-core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index 00c74330fa92..a0c949533a5d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -263,6 +263,10 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head) static void blk_free_queue(struct request_queue *q) { + mutex_lock(&q->debugfs_mutex); + blk_trace_shutdown(q); + mutex_unlock(&q->debugfs_mutex); + blk_free_queue_stats(q->stats); if (queue_is_mq(q)) blk_mq_release(q);