Message ID | 20230608024159.1282953-2-yukuai1@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10262vqr; Wed, 7 Jun 2023 20:11:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+5NwVD7r5l/eJ915qE6jxPmVf2dubTAzhb+aVi5eRXHQYoQ31a6WgeB+Hca+FTOjpWILh X-Received: by 2002:a17:90a:191a:b0:255:949b:b50d with SMTP id 26-20020a17090a191a00b00255949bb50dmr4549336pjg.4.1686193881709; Wed, 07 Jun 2023 20:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686193881; cv=none; d=google.com; s=arc-20160816; b=FXlngwflg6jdSe8Hvun75raHZFivIuIQAkXk2etBXCTMwCceV7eKUJqoFPGJUonhUJ PhA80lVmh9N/2YSDid0m1gJ45ZSmh5xKK971Goo0dGYGVL4yX4jG0AVhWIpvrCZVTxAJ tSFF6sAo8tD73JozZE3eqqXvhCJ9BdK729cRa0Nmdg26JwaXhzcT9+9jnPospIOkxPp6 i6K/+AA7E4mM/PXLE2pTUj0WgB73iZOyIB1evkH2rzIS5g2PoOjqNFdqjX+Kvq4bbTtG Cev4LIu8Skh7Iudjvr9b/5saM4xG6PCR/7oAu3VSqinE9CiZ0/65LyNhCoPmSREUHMnV 3epg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=c5+bsc+5tuWYnng2VkaR0wWEp3eTqZTsqEBQU4QEx6c=; b=CUiXHJej0Wiy59ihZtoWAHWBpU2i8gjq84+aUeRhuLtj9FOVv222J1EuuXHKYdacid P5Oag9SBIBoUA+Nzgms1P2AzXcySr/3w7Zd9ihfv1S9/sYl1ngn6lx7R+ZJ9lIMQT6p1 ekaBj41IezDWI9/Wr922TW/fJXwI1lDLWfjvALHURLsf5nb1b8L0JF/rf5UdovepqY34 PVoLUye8bmunxAsO6ZrqSnApKGlRbsivb+KDsPl/EPy8SAid/Ake4l9ypJ1kY454TxAs KpxiqJ5KusalbxL7iskWVvVQ5foKpxOw7LT3SzMYy1dkPlSLxqRoaa4/jEYQfqhWRDBT m/Iw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020a17090a644200b0024e5ed38294si342554pjm.66.2023.06.07.20.11.09; Wed, 07 Jun 2023 20:11:21 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233689AbjFHCqS (ORCPT <rfc822;literming00@gmail.com> + 99 others); Wed, 7 Jun 2023 22:46:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbjFHCqP (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Jun 2023 22:46:15 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B9C3210C; Wed, 7 Jun 2023 19:46:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Qc7rK1lSCz4f3l7V; Thu, 8 Jun 2023 10:46:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgD3rLDwQIFkn13HLA--.37355S5; Thu, 08 Jun 2023 10:46:10 +0800 (CST) From: Yu Kuai <yukuai1@huaweicloud.com> To: hch@lst.de, axboe@kernel.dk, dgilbert@interlog.com, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com, yangerkun@huawei.com Subject: [PATCH v3 1/2] scsi: sg: fix blktrace debugfs entries leakage Date: Thu, 8 Jun 2023 10:41:58 +0800 Message-Id: <20230608024159.1282953-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608024159.1282953-1-yukuai1@huaweicloud.com> References: <20230608024159.1282953-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3rLDwQIFkn13HLA--.37355S5 X-Coremail-Antispam: 1UD129KBjvJXoW7Kry3Zr4kJrWxuFyxtr4ruFg_yoW8Ww4kpF WxXa90krWUWr4UGw1DZw1UZF1fCay09395GFW2gwn3WF4rJr90gF95tFyaqa45ArZ5uFZ8 GFW5KF95WFnrJaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JU4T5dUUUUU = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768102436102976121?= X-GMAIL-MSGID: =?utf-8?q?1768102436102976121?= |
Series |
fix blktrace debugfs entries leakage
|
|
Commit Message
Yu Kuai
June 8, 2023, 2:41 a.m. UTC
From: Yu Kuai <yukuai3@huawei.com> sg_ioctl() support to enable blktrace, which will create debugfs entries "/sys/kernel/debug/block/sgx/", however, there is no guarantee that user will remove these entries through ioctl, and deleting sg device doesn't cleanup these blktrace entries. This problem can be fixed by cleanup blktrace while releasing request_queue, however, it's not a good idea to do this special handling in common layer just for sg device. Fix this problem by shutdown bltkrace in sg_device_destroy(), where the device is deleted and all the users close the device, also grab a scsi_device reference from sg_add_device() to prevent scsi_device to be freed before sg_device_destroy(); Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/scsi/sg.c | 8 ++++++++ 1 file changed, 8 insertions(+)
Comments
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
Hi Yu,
kernel test robot noticed the following build warnings:
[auto build test WARNING on axboe-block/for-next]
[also build test WARNING on linus/master v6.4-rc5 next-20230608]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/scsi-sg-fix-blktrace-debugfs-entries-leakage/20230608-104735
base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
patch link: https://lore.kernel.org/r/20230608024159.1282953-2-yukuai1%40huaweicloud.com
patch subject: [PATCH v3 1/2] scsi: sg: fix blktrace debugfs entries leakage
config: i386-randconfig-r002-20230608 (https://download.01.org/0day-ci/archive/20230608/202306082353.o2lpbQcL-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build):
git remote add axboe-block https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git
git fetch axboe-block for-next
git checkout axboe-block/for-next
b4 shazam https://lore.kernel.org/r/20230608024159.1282953-2-yukuai1@huaweicloud.com
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202306082353.o2lpbQcL-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from drivers/scsi/sg.c:45:
drivers/scsi/sg.c: In function 'sg_device_destroy':
>> include/linux/blktrace_api.h:88:57: warning: statement with no effect [-Wunused-value]
88 | # define blk_trace_remove(q) (-ENOTTY)
| ^
drivers/scsi/sg.c:1575:9: note: in expansion of macro 'blk_trace_remove'
1575 | blk_trace_remove(sdp->device->request_queue);
| ^~~~~~~~~~~~~~~~
vim +88 include/linux/blktrace_api.h
157f9c00e88529 Arnaldo Carvalho de Melo 2009-01-26 81
2056a782f8e7e6 Jens Axboe 2006-03-23 82 #else /* !CONFIG_BLK_DEV_IO_TRACE */
2056a782f8e7e6 Jens Axboe 2006-03-23 83 # define blk_trace_ioctl(bdev, cmd, arg) (-ENOTTY)
2056a782f8e7e6 Jens Axboe 2006-03-23 84 # define blk_trace_shutdown(q) do { } while (0)
a54895fa057c67 Christoph Hellwig 2020-12-03 85 # define blk_add_driver_data(rq, data, len) do {} while (0)
d0deef5b14af7d Shawn Du 2009-04-14 86 # define blk_trace_setup(q, name, dev, bdev, arg) (-ENOTTY)
6da127ad0918f9 Christof Schmitt 2008-01-11 87 # define blk_trace_startstop(q, start) (-ENOTTY)
6da127ad0918f9 Christof Schmitt 2008-01-11 @88 # define blk_trace_remove(q) (-ENOTTY)
9d5f09a424a67d Alan D. Brunelle 2008-05-27 89 # define blk_add_trace_msg(q, fmt, ...) do { } while (0)
35fe6d763229e8 Shaohua Li 2017-07-12 90 # define blk_add_cgroup_trace_msg(q, cg, fmt, ...) do { } while (0)
59fa0224cfea31 Shaohua Li 2016-05-09 91 # define blk_trace_note_message_enabled(q) (false)
2056a782f8e7e6 Jens Axboe 2006-03-23 92 #endif /* CONFIG_BLK_DEV_IO_TRACE */
d0deef5b14af7d Shawn Du 2009-04-14 93
Hi, 在 2023/06/09 0:02, kernel test robot 写道: > Hi Yu, > > kernel test robot noticed the following build warnings: > > [auto build test WARNING on axboe-block/for-next] > [also build test WARNING on linus/master v6.4-rc5 next-20230608] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: https://github.com/intel-lab-lkp/linux/commits/Yu-Kuai/scsi-sg-fix-blktrace-debugfs-entries-leakage/20230608-104735 > base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next > patch link: https://lore.kernel.org/r/20230608024159.1282953-2-yukuai1%40huaweicloud.com > patch subject: [PATCH v3 1/2] scsi: sg: fix blktrace debugfs entries leakage > config: i386-randconfig-r002-20230608 (https://download.01.org/0day-ci/archive/20230608/202306082353.o2lpbQcL-lkp@intel.com/config) > compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 > reproduce (this is a W=1 build): > git remote add axboe-block https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git > git fetch axboe-block for-next > git checkout axboe-block/for-next > b4 shazam https://lore.kernel.org/r/20230608024159.1282953-2-yukuai1@huaweicloud.com > # save the config file > mkdir build_dir && cp config build_dir/.config > make W=1 O=build_dir ARCH=i386 olddefconfig > make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: https://lore.kernel.org/oe-kbuild-all/202306082353.o2lpbQcL-lkp@intel.com/ > > All warnings (new ones prefixed by >>): > > In file included from drivers/scsi/sg.c:45: > drivers/scsi/sg.c: In function 'sg_device_destroy': >>> include/linux/blktrace_api.h:88:57: warning: statement with no effect [-Wunused-value] > 88 | # define blk_trace_remove(q) (-ENOTTY) > | So, this warning happens in all the caller of blk_trace_remove() when CONFIG_BLK_DEV_IO_TRACE is disabled that doesn't handle the return value. I'll use blk_trace_shutdown() instead to avoid this warning. ^ Thanks, Kuai > drivers/scsi/sg.c:1575:9: note: in expansion of macro 'blk_trace_remove' > 1575 | blk_trace_remove(sdp->device->request_queue); > | ^~~~~~~~~~~~~~~~ > > > vim +88 include/linux/blktrace_api.h > > 157f9c00e88529 Arnaldo Carvalho de Melo 2009-01-26 81 > 2056a782f8e7e6 Jens Axboe 2006-03-23 82 #else /* !CONFIG_BLK_DEV_IO_TRACE */ > 2056a782f8e7e6 Jens Axboe 2006-03-23 83 # define blk_trace_ioctl(bdev, cmd, arg) (-ENOTTY) > 2056a782f8e7e6 Jens Axboe 2006-03-23 84 # define blk_trace_shutdown(q) do { } while (0) > a54895fa057c67 Christoph Hellwig 2020-12-03 85 # define blk_add_driver_data(rq, data, len) do {} while (0) > d0deef5b14af7d Shawn Du 2009-04-14 86 # define blk_trace_setup(q, name, dev, bdev, arg) (-ENOTTY) > 6da127ad0918f9 Christof Schmitt 2008-01-11 87 # define blk_trace_startstop(q, start) (-ENOTTY) > 6da127ad0918f9 Christof Schmitt 2008-01-11 @88 # define blk_trace_remove(q) (-ENOTTY) > 9d5f09a424a67d Alan D. Brunelle 2008-05-27 89 # define blk_add_trace_msg(q, fmt, ...) do { } while (0) > 35fe6d763229e8 Shaohua Li 2017-07-12 90 # define blk_add_cgroup_trace_msg(q, cg, fmt, ...) do { } while (0) > 59fa0224cfea31 Shaohua Li 2016-05-09 91 # define blk_trace_note_message_enabled(q) (false) > 2056a782f8e7e6 Jens Axboe 2006-03-23 92 #endif /* CONFIG_BLK_DEV_IO_TRACE */ > d0deef5b14af7d Shawn Du 2009-04-14 93 >
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 037f8c98a6d3..ed4e2f9b3d64 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1496,6 +1496,10 @@ sg_add_device(struct device *cl_dev) int error; unsigned long iflags; + error = scsi_device_get(scsidp); + if (error) + return error; + error = -ENOMEM; cdev = cdev_alloc(); if (!cdev) { @@ -1553,6 +1557,7 @@ sg_add_device(struct device *cl_dev) out: if (cdev) cdev_del(cdev); + scsi_device_put(scsidp); return error; } @@ -1567,6 +1572,9 @@ sg_device_destroy(struct kref *kref) * any other cleanup. */ + blk_trace_remove(sdp->device->request_queue); + scsi_device_put(sdp->device); + write_lock_irqsave(&sg_index_lock, flags); idr_remove(&sg_index_idr, sdp->index); write_unlock_irqrestore(&sg_index_lock, flags);