Commit 17ab4994 authored by Luis Chamberlain's avatar Luis Chamberlain Committed by Yu Kuai
Browse files

block: create the request_queue debugfs_dir on registration

mainline inclusion
from mainline-v5.9-rc1
commit 85e0cbbb
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAGRKP
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=85e0cbbb8a79537dbc465e9deb449a08b2b092a6



--------------------------------

We were only creating the request_queue debugfs_dir only
for make_request block drivers (multiqueue), but never for
request-based block drivers. We did this as we were only
creating non-blktrace additional debugfs files on that directory
for make_request drivers. However, since blktrace *always* creates
that directory anyway, we special-case the use of that directory
on blktrace. Other than this being an eye-sore, this exposes
request-based block drivers to the same debugfs fragile
race that used to exist with make_request block drivers
where if we start adding files onto that directory we can later
run a race with a double removal of dentries on the directory
if we don't deal with this carefully on blktrace.

Instead, just simplify things by always creating the request_queue
debugfs_dir on request_queue registration. Rename the mutex also to
reflect the fact that this is used outside of the blktrace context.

Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Conflicts:
	block/blk-core.c
	block/blk-sysfs.c
	block/blk.h
	include/linux/blkdev.h
	kernel/trace/blktrace.c
[Context conflicts]
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
parent 2b7f7767
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -45,9 +45,7 @@
#include "blk-rq-qos.h"
#include "blk-io-hierarchy/stats.h"

#ifdef CONFIG_DEBUG_FS
struct dentry *blk_debugfs_root;
#endif

EXPORT_TRACEPOINT_SYMBOL_GPL(block_bio_remap);
EXPORT_TRACEPOINT_SYMBOL_GPL(block_rq_remap);
@@ -1346,9 +1344,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id,

	kobject_init(&q->kobj, &blk_queue_ktype);

#ifdef CONFIG_BLK_DEV_IO_TRACE
	mutex_init(&q->blk_trace_mutex);
#endif
	mutex_init(&q->debugfs_mutex);
	mutex_init(&q->sysfs_lock);
	mutex_init(&q_wrapper->sysfs_dir_lock);
	spin_lock_init(&q->__queue_lock);
@@ -4307,9 +4303,7 @@ int __init blk_dev_init(void)

	init_blk_queue_async_dispatch();

#ifdef CONFIG_DEBUG_FS
	blk_debugfs_root = debugfs_create_dir("block", NULL);
#endif

	return 0;
}
+0 −5
Original line number Diff line number Diff line
@@ -841,9 +841,6 @@ void blk_mq_debugfs_register(struct request_queue *q)
	struct blk_mq_hw_ctx *hctx;
	int i;

	q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
					    blk_debugfs_root);

	debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs);

	/*
@@ -867,9 +864,7 @@ void blk_mq_debugfs_register(struct request_queue *q)

void blk_mq_debugfs_unregister(struct request_queue *q)
{
	debugfs_remove_recursive(q->debugfs_dir);
	q->sched_debugfs_dir = NULL;
	q->debugfs_dir = NULL;
}

static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx,
+9 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <linux/blktrace_api.h>
#include <linux/blk-mq.h>
#include <linux/blk-cgroup.h>
#include <linux/debugfs.h>
#include <linux/atomic.h>

#include "blk.h"
@@ -895,6 +896,9 @@ static void __blk_release_queue(struct work_struct *work)
	}

	blk_trace_shutdown(q);
	mutex_lock(&q->debugfs_mutex);
	debugfs_remove_recursive(q->debugfs_dir);
	mutex_unlock(&q->debugfs_mutex);

	if (q->mq_ops)
		blk_mq_debugfs_unregister(q);
@@ -968,6 +972,11 @@ int blk_register_queue(struct gendisk *disk)
		goto unlock;
	}

	mutex_lock(&q->debugfs_mutex);
	q->debugfs_dir = debugfs_create_dir(kobject_name(q->kobj.parent),
					    blk_debugfs_root);
	mutex_unlock(&q->debugfs_mutex);

	if (q->mq_ops) {
		__blk_mq_register_dev(dev, q);
		blk_mq_debugfs_register(q);
+0 −2
Original line number Diff line number Diff line
@@ -15,9 +15,7 @@
/* Max future timer expiry for timeouts */
#define BLK_MAX_TIMEOUT		(5 * HZ)

#ifdef CONFIG_DEBUG_FS
extern struct dentry *blk_debugfs_root;
#endif

struct blk_flush_queue {
	unsigned int		flush_queue_delayed:1;
+2 −2
Original line number Diff line number Diff line
@@ -641,9 +641,9 @@ struct request_queue {
	unsigned int		sg_timeout;
	unsigned int		sg_reserved_size;
	int			node;
	struct mutex		debugfs_mutex;
#ifdef CONFIG_BLK_DEV_IO_TRACE
	struct blk_trace __rcu	*blk_trace;
	struct mutex		blk_trace_mutex;
#endif
	/*
	 * for flush operations
@@ -689,8 +689,8 @@ struct request_queue {
	struct list_head	tag_set_list;
	struct bio_set		bio_split;

#ifdef CONFIG_BLK_DEBUG_FS
	struct dentry		*debugfs_dir;
#ifdef CONFIG_BLK_DEBUG_FS
	struct dentry		*sched_debugfs_dir;
#endif

Loading