Skip to contentSkip to conversation

Five blk-mq-debugfs patches

PATCH In review Bart Van Assche 5 participants 24 messages May 25, 2017 – May 30, 2017 Block layer

lore
Share & tools
lore
#0 lore raw

cover Five blk-mq-debugfs patches

Hello Jens,

This series contains four patches that add new features to the blk-mq-debugfs code and that are intended for kernel v4.13 and one bug fix that is intended for kernel v4.12. The patches in this series are:

Bart Van Assche (5):
blk-mq: Only register debugfs attributes for blk-mq queues
blk-mq-debugfs: Show atomic request flags
blk-mq-debugfs: Show requeue list
blk-mq-debugfs: Show busy requests
blk-mq-debugfs: Add 'kick' operation

 block/blk-mq-debugfs.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-
 block/blk-sysfs.c      |  6 ++---
 2 files changed, 73 insertions(+), 4 deletions(-)
Signature · 1 line
2.12.2
#1 lore raw

PATCH 1/5 blk-mq: Only register debugfs attributes for blk-mq queues

The code in blk-mq-debugfs.c assumes that it is working on a blk-mq queue and is not intended to work on a blk-sq queue. Hence only register blk-mq debugfs attributes for blk-mq queues.

Fixes commit 9c1051aacde8 ("blk-mq: untangle debugfs and sysfs")
Cc Omar Sandoval <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-sysfs.c +3 -3
index 5e7b3924996c..0494baa743a3 100644
@@ -888,10 +888,10 @@ int blk_register_queue(struct gendisk *disk)
 		goto unlock;
 	}
 
-	if (q->mq_ops)
+	if (q->mq_ops) {
 		__blk_mq_register_dev(dev, q);
-
-	blk_mq_debugfs_register(q);
+		blk_mq_debugfs_register(q);
+	}
 
 	kobject_uevent(&q->kobj, KOBJ_ADD);
 
Signature · 1 line
2.12.2
#5 lore raw

PATCH 2/5 blk-mq-debugfs: Show atomic request flags

In reply to Bart Van Assche

When analyzing e.g. queue lockups it is important to know whether or not a request has already been started. Hence also show the atomic request flags.

Cc Omar Sandoval <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
block/blk-mq-debugfs.c +10 -0
index 803aed4d7221..d56ddd7a1285 100644
@@ -267,6 +267,14 @@ static const char *const rqf_name[] = {
 };
 #undef RQF_NAME
 
+#define RQAF_NAME(name) [REQ_ATOM_##name] = #name
+static const char *const rqaf_name[] = {
+	RQAF_NAME(COMPLETE),
+	RQAF_NAME(STARTED),
+	RQAF_NAME(POLL_SLEPT),
+};
+#undef RQAF_NAME
+
 int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
 {
 	const struct blk_mq_ops *const mq_ops = rq->q->mq_ops;
@@ -283,6 +291,8 @@ int __blk_mq_debugfs_rq_show(struct seq_file *m, struct request *rq)
 	seq_puts(m, ", .rq_flags=");
 	blk_flags_show(m, (__force unsigned int)rq->rq_flags, rqf_name,
 		       ARRAY_SIZE(rqf_name));
+	seq_puts(m, ", .atomic_flags=");
+	blk_flags_show(m, rq->atomic_flags, rqaf_name, ARRAY_SIZE(rqaf_name));
 	seq_printf(m, ", .tag=%d, .internal_tag=%d", rq->tag,
 		   rq->internal_tag);
 	if (mq_ops->show_rq)
Signature · 1 line
2.12.2
#7 lore raw

PATCH 3/5 blk-mq-debugfs: Show requeue list

In reply to Bart Van Assche

When verifying whether or not a blk-mq driver forgot to kick the requeue list after having requeued a request it is important to be able to verify the contents of the requeue list. Hence export that list through debugfs.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
block/blk-mq-debugfs.c +32 -0
index d56ddd7a1285..8b06a12c1461 100644
@@ -308,6 +308,37 @@ int blk_mq_debugfs_rq_show(struct seq_file *m, void *v)
 }
 EXPORT_SYMBOL_GPL(blk_mq_debugfs_rq_show);
 
+static void *queue_requeue_list_start(struct seq_file *m, loff_t *pos)
+	__acquires(&q->requeue_lock)
+{
+	struct request_queue *q = m->private;
+
+	spin_lock_irq(&q->requeue_lock);
+	return seq_list_start(&q->requeue_list, *pos);
+}
+
+static void *queue_requeue_list_next(struct seq_file *m, void *v, loff_t *pos)
+{
+	struct request_queue *q = m->private;
+
+	return seq_list_next(v, &q->requeue_list, pos);
+}
+
+static void queue_requeue_list_stop(struct seq_file *m, void *v)
+	__releases(&q->requeue_lock)
+{
+	struct request_queue *q = m->private;
+
+	spin_unlock_irq(&q->requeue_lock);
+}
+
+static const struct seq_operations queue_requeue_list_seq_ops = {
+	.start	= queue_requeue_list_start,
+	.next	= queue_requeue_list_next,
+	.stop	= queue_requeue_list_stop,
+	.show	= blk_mq_debugfs_rq_show,
+};
+
 static void *hctx_dispatch_start(struct seq_file *m, loff_t *pos)
 	__acquires(&hctx->lock)
 {
@@ -665,6 +696,7 @@ const struct file_operations blk_mq_debugfs_fops = {
 
 static const struct blk_mq_debugfs_attr blk_mq_debugfs_queue_attrs[] = {
 	{"poll_stat", 0400, queue_poll_stat_show},
+	{"requeue_list", 0400, .seq_ops = &queue_requeue_list_seq_ops},
 	{"state", 0600, queue_state_show, queue_state_write},
 	{},
 };
Signature · 1 line
2.12.2
#9 lore raw

PATCH 4/5 blk-mq-debugfs: Show busy requests

In reply to Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +25 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;
+
+	if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == ctx->hctx &&
+	    test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))
+		blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);
+}
+
+static int hctx_busy_show(void *data, struct seq_file *m)
+{
+	struct blk_mq_hw_ctx *hctx = data;
+	struct show_busy_ctx ctx = { .m = m, .hctx = hctx };
+
+	blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy, &ctx);
+
+	return 0;
+}
+
 static int hctx_ctx_map_show(void *data, struct seq_file *m)
 {
 	struct blk_mq_hw_ctx *hctx = data;
@@ -705,6 +729,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
 	{"state", 0400, hctx_state_show},
 	{"flags", 0400, hctx_flags_show},
 	{"dispatch", 0400, .seq_ops = &hctx_dispatch_seq_ops},
+	{"busy", 0400, hctx_busy_show},
 	{"ctx_map", 0400, hctx_ctx_map_show},
 	{"tags", 0400, hctx_tags_show},
 	{"tags_bitmap", 0400, hctx_tags_bitmap_show},
Signature · 1 line
2.12.2
#23 lore raw

PATCH 5/5 blk-mq-debugfs: Add 'kick' operation

In reply to Bart Van Assche

Running a queue causes the block layer to examine the per-CPU and hw queues but not the requeue list. Hence add a 'kick' operation that also examines the requeue list.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block/blk-mq-debugfs.c +3 -1
index 70a2b955afee..89277a888800 100644
@@ -114,10 +114,12 @@ static ssize_t queue_state_write(void *data, const char __user *buf,
 		blk_mq_run_hw_queues(q, true);
 	} else if (strcmp(op, "start") == 0) {
 		blk_mq_start_stopped_hw_queues(q, true);
+	} else if (strcmp(op, "kick") == 0) {
+		blk_mq_kick_requeue_list(q);
 	} else {
 		pr_err("%s: unsupported operation '%s'\n", __func__, op);
 inval:
-		pr_err("%s: use either 'run' or 'start'\n", __func__);
+		pr_err("%s: use 'run', 'start' or 'kick'\n", __func__);
 		return -EINVAL;
 	}
 	return count;
Signature · 1 line
2.12.2
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] blk-mq: Only register debugfs attributes for blk-mq queues

In reply to Bart Van Assche
Quoted 3 lines · Bart Van Assche

The code in blk-mq-debugfs.c assumes that it is working on a blk-mq queue and is not intended to work on a blk-sq queue. Hence only register blk-mq debugfs attributes for blk-mq queues.

Oops. This is probably what David reported here:
https://github.com/ddiss/rapido/pull/13#event-1093484761. Thanks, Bart.

Quoted 31 lines
Fixes commit 9c1051aacde8 ("blk-mq: untangle debugfs and sysfs")
Cc Omar Sandoval <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-sysfs.c +3 -3
index 5e7b3924996c..0494baa743a3 100644
@@ -888,10 +888,10 @@ int blk_register_queue(struct gendisk *disk)
 		goto unlock;
 	}
 
-	if (q->mq_ops)
+	if (q->mq_ops) {
 		__blk_mq_register_dev(dev, q);
-
-	blk_mq_debugfs_register(q);
+		blk_mq_debugfs_register(q);
+	}
 
 	kobject_uevent(&q->kobj, KOBJ_ADD);
 
Signature · 1 line
2.12.2
Reviewed-by on v1 1/5
#3 lore raw

Re: [PATCH 1/5] blk-mq: Only register debugfs attributes for blk-mq queues

In reply to Bart Van Assche
Quoted 23 lines · Bart Van Assche

The code in blk-mq-debugfs.c assumes that it is working on a blk-mq queue and is not intended to work on a blk-sq queue. Hence only register blk-mq debugfs attributes for blk-mq queues.

Fixes commit 9c1051aacde8 ("blk-mq: untangle debugfs and sysfs")
Cc Omar Sandoval <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-sysfs.c +0 -0
index 5e7b3924996c..0494baa743a3 100644
@@ -888,10 +888,10 @@ int blk_register_queue(struct gendisk *disk)
 		goto unlock;
 	}
 

block/blk-sysfs.c int blk_register_queue(struct gendisk *disk) · line 897

Quoted 10 lines
block/blk-sysfs.c +3 -3
-	if (q->mq_ops)
+	if (q->mq_ops) {
 		__blk_mq_register_dev(dev, q);
-
-	blk_mq_debugfs_register(q);
+		blk_mq_debugfs_register(q);
+	}
 
 	kobject_uevent(&q->kobj, KOBJ_ADD);
 

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
Reviewed-by on v1 2/5
#6 lore raw

Re: [PATCH 2/5] blk-mq-debugfs: Show atomic request flags

In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche

When analyzing e.g. queue lockups it is important to know whether or not a request has already been started. Hence also show the atomic request flags.

Quoted 9 lines
Cc Omar Sandoval <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
Reviewed-by on v1 3/5
#8 lore raw

Re: [PATCH 3/5] blk-mq-debugfs: Show requeue list

In reply to Bart Van Assche
Quoted 5 lines · Bart Van Assche

When verifying whether or not a blk-mq driver forgot to kick the requeue list after having requeued a request it is important to be able to verify the contents of the requeue list. Hence export that list through debugfs.

Quoted 9 lines
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
maintainer
#10 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Bart Van Assche
Quoted 19 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +0 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 380

Quoted 10 lines
block/blk-mq-debugfs.c +8 -0
 };
 
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;

Let's not call that variable 'ctx', in blk-mq that's pretty much reserved for the sw queues.

Signature · 1 line
Jens Axboe
maintainer
#4 lore raw

Re: [PATCH 1/5] blk-mq: Only register debugfs attributes for blk-mq queues

In reply to Bart Van Assche
Quoted 3 lines · Bart Van Assche

The code in blk-mq-debugfs.c assumes that it is working on a blk-mq queue and is not intended to work on a blk-sq queue. Hence only register blk-mq debugfs attributes for blk-mq queues.

Thanks Bart, I have queued this up for this series.

Signature · 1 line
Jens Axboe
#15 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Bart Van Assche
Quoted 50 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +24 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;
+
+	if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == ctx->hctx &&
+	    test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))
+		blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);
+}
+
+static int hctx_busy_show(void *data, struct seq_file *m)
+{
+	struct blk_mq_hw_ctx *hctx = data;
+	struct show_busy_ctx ctx = { .m = m, .hctx = hctx };
+
+	blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy, &ctx);
+
+	return 0;
+}
+
 static int hctx_ctx_map_show(void *data, struct seq_file *m)
 {
 	struct blk_mq_hw_ctx *hctx = data;

block/blk-mq-debugfs.c static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { · line 735

Quoted 7 lines
block/blk-mq-debugfs.c +1 -0
@@ -705,6 +729,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
 	{"state", 0400, hctx_state_show},
 	{"flags", 0400, hctx_flags_show},
 	{"dispatch", 0400, .seq_ops = &hctx_dispatch_seq_ops},
+	{"busy", 0400, hctx_busy_show},
 	{"ctx_map", 0400, hctx_ctx_map_show},
 	{"tags", 0400, hctx_tags_show},
 	{"tags_bitmap", 0400, hctx_tags_bitmap_show},

Hmm. I wonder if this is going to work as intended; 'busy' might be changing rapidly, so the busy_iter might be giving us unintended results. Have you checked?

Cheers,

Hannes

Signature · 5 lines
Dr. Hannes Reinecke		   Teamlead Storage & Networking
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
#11 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Jens Axboe
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute. =20

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>

---

Quoted 8 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_s=

Quoted 8 lines
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

=20

block/blk-mq-debugfs.c +0 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_s=

eq_ops =3D {

Quoted 9 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = {

Quoted 9 lines
block/blk-mq-debugfs.c +0 -0
 	.show	=3D blk_mq_debugfs_rq_show,
 };

=20

block/blk-mq-debugfs.c +6 -0
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserv=

ed)

Quoted 5 lines

block/blk-mq-debugfs.c

Quoted 2 lines
block/blk-mq-debugfs.c +2 -0
+{
+	const struct show_busy_ctx *ctx =3D data;

=20
Let's not call that variable 'ctx', in blk-mq that's pretty much reserved for the sw queues.

Hello Jens,

How about renaming show_busy_ctx into show_busy_params and ctx into params?

Bart.=

maintainer
#12 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

Quoted 35 lines · Bart Van Assche
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +0 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
Quoted 11 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 380

Quoted 8 lines
block/blk-mq-debugfs.c +8 -0
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;

Let's not call that variable 'ctx', in blk-mq that's pretty much reserved for the sw queues.

Quoted 3 lines

Hello Jens,

How about renaming show_busy_ctx into show_busy_params and ctx into params?

I think that would be an improvement. Also, this:

	blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);

doesn't look safe at all, as you are passing in a node instead of a head. I think you just want to use __blk_mq_debugfs_rq_show() here.

Signature · 1 line
Jens Axboe
maintainer
#13 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

Quoted 38 lines · Jens Axboe
Quoted 37 lines · Bart Van Assche
Quoted 22 lines · Jens Axboe
Quoted 21 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +0 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
Quoted 11 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 380

Quoted 8 lines
block/blk-mq-debugfs.c +8 -0
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;

Let's not call that variable 'ctx', in blk-mq that's pretty much reserved for the sw queues.

Hello Jens,

Quoted 8 lines
Quoted 1 line

How about renaming show_busy_ctx into show_busy_params and ctx into params?

I think that would be an improvement. Also, this:

	blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);

doesn't look safe at all, as you are passing in a node instead of a head. I think you just want to use __blk_mq_debugfs_rq_show() here.

I guess it's safe as we don't iterate the list, but it's pointless though. Just use __blk_mq_debugfs_rq_show().

Signature · 1 line
Jens Axboe
#14 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Jens Axboe
Quoted 13 lines · Jens Axboe
Quoted 12 lines · Bart Van Assche
Quoted 11 lines · Jens Axboe
Quoted 10 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute. =20

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>

---

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispat=

Quoted 8 lines
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

=20

block/blk-mq-debugfs.c +0 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispat=

ch_seq_ops =3D {

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = {

Quoted 9 lines
block/blk-mq-debugfs.c +0 -0
 	.show	=3D blk_mq_debugfs_rq_show,
 };

=20

block/blk-mq-debugfs.c +6 -0
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool re=

served)

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

block/blk-mq-debugfs.c

Quoted 2 lines
block/blk-mq-debugfs.c +2 -0
+{
+	const struct show_busy_ctx *ctx =3D data;

=20
Let's not call that variable 'ctx', in blk-mq that's pretty much reserved for the sw queues.

=20
Hello Jens,
=20
How about renaming show_busy_ctx into show_busy_params and ctx into par=

ams?

Quoted 7 lines

=20
I think that would be an improvement. Also, this:
=20

	blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);

=20
doesn't look safe at all, as you are passing in a node instead of a head. I think you just want to use __blk_mq_debugfs_rq_show() here.

Hello Jens,

That change will make the compiler perform type checking. I agree that's an improvement. I will make that change.

Bart.=

#16 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Hannes Reinecke
Quoted 3 lines · Hannes Reinecke

Hmm. I wonder if this is going to work as intended; 'busy' might be changing rapidly, so the busy_iter might be giving us unintended results. Have you checked?

Hello Hannes,

The intention is that this attribute is used by developers to figure out wh= ich
requests got stuck if one or more requests got stuck. Querying this attribu= te a
few times should help to see whether the requests shown are requests that complete quickly or whether these are requests that got stuck. The output I collected while testing this debugfs attribute looks fine to me:

# while true; do (cd /sys/kernel/debug/block && for f in */*/busy; do [ -e =
$f ] && grep -aH '' $f; done); done
[ ... ]
sde/hctx0/busy:ffff880267dcba00 {.op=3DWRITE, .cmd_flags=3DFAILFAST_TRANSPO=
RT|SYNC|META|PRIO|NOMERGE, .rq_flags=3DMQ_INFLIGHT|DONTPREP|IO_STAT|STATS, =
.atomic_flags=3DSTARTED, .tag=3D19, .internal_tag=3D-1,
.cmd=3DWrite(10) 2a 00 00 07 92 38 00 00 08 00}
sde/hctx0/busy:ffff880267dcd140 {.op=3DWRITE, .cmd_flags=3DFAILFAST_TRANSPO=
RT|SYNC|META|PRIO|NOMERGE, .rq_flags=3DMQ_INFLIGHT|DONTPREP|IO_STAT|STATS, =
.atomic_flags=3DSTARTED, .tag=3D20, .internal_tag=3D-1,
.cmd=3DWrite(10) 2a 00 00 07 92 80 00 00 08 00}
[ ... ]
sr0/hctx0/busy:ffff88046797d140 {.op=3DSCSI_IN, .cmd_flags=3D, .rq_flags=3D=
DONTPREP|PREEMPT|COPY_USER|QUIET|IO_STAT|STATS, .atomic_flags=3DSTARTED, .t=
ag=3D20, .internal_tag=3D-1, .cmd=3DGet event status
notification 4a 01 00 00 10 00 00 00 08 00}
[ ... ]

Bart.=

maintainer
#17 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Hannes Reinecke
Quoted 53 lines · Hannes Reinecke
Quoted 52 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +24 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
+struct show_busy_ctx {
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;
+
+	if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == ctx->hctx &&
+	    test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))
+		blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);
+}
+
+static int hctx_busy_show(void *data, struct seq_file *m)
+{
+	struct blk_mq_hw_ctx *hctx = data;
+	struct show_busy_ctx ctx = { .m = m, .hctx = hctx };
+
+	blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy, &ctx);
+
+	return 0;
+}
+
 static int hctx_ctx_map_show(void *data, struct seq_file *m)
 {
 	struct blk_mq_hw_ctx *hctx = data;
@@ -705,6 +729,7 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = {
 	{"state", 0400, hctx_state_show},
 	{"flags", 0400, hctx_flags_show},
 	{"dispatch", 0400, .seq_ops = &hctx_dispatch_seq_ops},
Quoted 8 lines

block/blk-mq-debugfs.c static const struct blk_mq_debugfs_attr blk_mq_debugfs_hctx_attrs[] = { · line 735

Quoted 5 lines
block/blk-mq-debugfs.c +1 -0
+	{"busy", 0400, hctx_busy_show},
 	{"ctx_map", 0400, hctx_ctx_map_show},
 	{"tags", 0400, hctx_tags_show},
 	{"tags_bitmap", 0400, hctx_tags_bitmap_show},

Hmm. I wonder if this is going to work as intended; 'busy' might be changing rapidly, so the busy_iter might be giving us unintended results. Have you checked?

That's true for _any_ of the debugfs exports for probing into internals that hold/store requests. All of them are just a snapshot in time, there's no intent (or posibility) for these to be stable in any way.

Signature · 1 line
Jens Axboe
#18 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Bart Van Assche
Quoted 3 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

The name of 'busy' isn't very explicit about this case, and I guess you mean the requests are dispatched to hardware, so 'dispatched' or sort of name may be more accurate.

Quoted 19 lines
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +1 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
+struct show_busy_ctx {

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 383

Quoted 10 lines
block/blk-mq-debugfs.c +10 -0
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;
+
+	if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == ctx->hctx &&
+	    test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))

During this small window, the request can be freed and reallocated in another I/O path, then use-after-free is caused.

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 392

Quoted 9 lines
block/blk-mq-debugfs.c +9 -0
+		blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);
+}
+
+static int hctx_busy_show(void *data, struct seq_file *m)
+{
+	struct blk_mq_hw_ctx *hctx = data;
+	struct show_busy_ctx ctx = { .m = m, .hctx = hctx };
+
+	blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy, &ctx);

This way is easy to cause use-after-free, so as a debug function, you can't affect the normal function.

But the new fixed blk_mq_quiesce_queue() can be used before calling blk_mq_tagset_busy_iter() to avoid the race.

http://marc.info/?l=linux-block&m=149578610419654&w=2

Thanks,
Ming

#19 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

Quoted 55 lines · Ming Lei
Quoted 3 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

The name of 'busy' isn't very explicit about this case, and I guess you mean the requests are dispatched to hardware, so 'dispatched' or sort of name may be more accurate.

Quoted 19 lines
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Ming Lei <[email protected]>
---
 block/blk-mq-debugfs.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
block/blk-mq-debugfs.c +1 -0
index 8b06a12c1461..70a2b955afee 100644
@@ -370,6 +370,30 @@ static const struct seq_operations hctx_dispatch_seq_ops = {
 	.show	= blk_mq_debugfs_rq_show,
 };
 
+struct show_busy_ctx {

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 383

Quoted 10 lines
block/blk-mq-debugfs.c +10 -0
+	struct seq_file		*m;
+	struct blk_mq_hw_ctx	*hctx;
+};
+
+static void hctx_show_busy(struct request *rq, void *data, bool reserved)
+{
+	const struct show_busy_ctx *ctx = data;
+
+	if (blk_mq_map_queue(rq->q, rq->mq_ctx->cpu) == ctx->hctx &&
+	    test_bit(REQ_ATOM_STARTED, &rq->atomic_flags))

During this small window, the request can be freed and reallocated in another I/O path, then use-after-free is caused.

block/blk-mq-debugfs.c static const struct seq_operations hctx_dispatch_seq_ops = { · line 392

Quoted 9 lines
block/blk-mq-debugfs.c +9 -0
+		blk_mq_debugfs_rq_show(ctx->m, &rq->queuelist);
+}
+
+static int hctx_busy_show(void *data, struct seq_file *m)
+{
+	struct blk_mq_hw_ctx *hctx = data;
+	struct show_busy_ctx ctx = { .m = m, .hctx = hctx };
+
+	blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy, &ctx);

This way is easy to cause use-after-free, so as a debug function, you can't affect the normal function.

Quoted 4 lines

But the new fixed blk_mq_quiesce_queue() can be used before calling blk_mq_tagset_busy_iter() to avoid the race.

http://marc.info/?l=linux-block&m=149578610419654&w=2

Actually blk_mq_quiesce_queue can make other cancel cases safe because blk_mark_rq_complete() is used before canceling.

For this case, we can't use blk_mark_rq_complete(), so there can't be a safe way to touch the request dispatched to hardware.

Given the dispatched request won't be touched by CPU, and its state shouldn't be changed, I am just wondering what is the real motivation for this debug interface, could Bart explain a bit?

Thanks,
Ming

#21 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Ming Lei
Quoted 8 lines · Ming Lei
Quoted 3 lines · Bart Van Assche

Requests that got stuck in a block driver are neither on blk_mq_ctx.rq_list nor on any hw dispatch queue. Make these visible in debugfs through the "busy" attribute.

=20
The name of 'busy' isn't very explicit about this case, and I guess you mean the requests are dispatched to hardware, so 'dispatched' or sort of name may be more accurate.

Hello Ming,

There is already a debugfs attribute with the name "dispatch". I'm afraid having one attribute with the name "dispatch" and another with the name "dispatched" would be confusing.

Quoted 3 lines

[ ... ]
During this small window, the request can be freed and reallocated in another I/O path, then use-after-free is caused.

A similar remark applies to all request queue debugfs attributes: the queue state can change immediately after having queried the state so that's not unique to this attribute. Regarding the "use-after-free": the memory that i= s
allocated for requests is only freed after the debugfs attributes have been removed so the code that implements this attribute will read the contents o= f
a struct request. It is up to the person who reads the contents of this attribute to decide how to interpret the contents.

Quoted 2 lines

But the new fixed blk_mq_quiesce_queue() can be used before calling blk_mq_tagset_busy_iter() to avoid the race.

That would be overkill. The "busy" attribute is intended as a debugging hel= p.
The implementation of this function should trigger any crashes. But it was not my intention to avoid data races when I implemented this function.

Bart.=

#20 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Ming Lei
Quoted 2 lines · Ming Lei

What is the real motivation for this debug interface, could Bart explain a bit?

As mentioned in the description of this patch, the purpose of this patch is to allow anyone who is working on a block driver to figure out whether or not a request got stuck in a block driver. This means that .queue_rq() got called for a request but the block driver did not trigger a call to .end_io().

Bart.=

maintainer
#22 lore raw

Re: [PATCH 4/5] blk-mq-debugfs: Show busy requests

In reply to Bart Van Assche
Quoted 4 lines · Bart Van Assche
Quoted 3 lines

[ ... ]
During this small window, the request can be freed and reallocated in another I/O path, then use-after-free is caused.

Quoted 8 lines

A similar remark applies to all request queue debugfs attributes: the queue state can change immediately after having queried the state so that's not unique to this attribute. Regarding the "use-after-free":
the memory that is allocated for requests is only freed after the debugfs attributes have been removed so the code that implements this attribute will read the contents of a struct request. It is up to the person who reads the contents of this attribute to decide how to interpret the contents.

I think it's important to stress that the memory is not going away, so it'll potentially just show a new state of the request. That's perfectly fine, and will happen all the time for the various debugfs exports. The useful aspect of them is when things have come to a halt, for whatever reason. The states will tend to stay stable when that happens, and provide a useful method of introspection to debug the issue.

The important part here is that the memory is perfectly valid, so we won't run into issues with that.

Signature · 1 line
Jens Axboe