Skip to contentSkip to conversation

blk-mq: enable IO poll if .nr_queues of type poll > 0

PATCH In review Ming Lei 3 participants 5 messages Dec 18, 2018 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-mq: enable IO poll if .nr_queues of type poll > 0

The queue mapping of type poll only exists when set->map[HCTX_TYPE_POLL].nr_queues is bigger than zero, so enhance the constraint by checking .nr_queues of type poll before enabling IO poll.

Otherwise IO race & timeout can be observed when running block/007.

Cc Jeff Moyer <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 block/blk-mq.c    | 3 ++-
 block/blk-sysfs.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
block/blk-mq.c +2 -1
index 6847f014606b..e45400da4180 100644
@@ -2833,7 +2833,8 @@ struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
 	q->tag_set = set;
 
 	q->queue_flags |= QUEUE_FLAG_MQ_DEFAULT;
-	if (set->nr_maps > HCTX_TYPE_POLL)
+	if (set->nr_maps > HCTX_TYPE_POLL &&
+	    set->map[HCTX_TYPE_POLL].nr_queues)
 		blk_queue_flag_set(QUEUE_FLAG_POLL, q);
 
 	if (!(set->flags & BLK_MQ_F_SG_MERGE))
block/blk-sysfs.c +2 -1
index bb7c642ffefa..0619c8922893 100644
@@ -402,7 +402,8 @@ static ssize_t queue_poll_store(struct request_queue *q, const char *page,
 	unsigned long poll_on;
 	ssize_t ret;
 
-	if (!q->tag_set || q->tag_set->nr_maps <= HCTX_TYPE_POLL)
+	if (!q->tag_set || q->tag_set->nr_maps <= HCTX_TYPE_POLL ||
+	    !q->tag_set->map[HCTX_TYPE_POLL].nr_queues)
 		return -EINVAL;
 
 	ret = queue_var_store(&poll_on, page, count);
Signature · 1 line
2.9.5
maintainer
#1 lore raw
Quoted 5 lines · Ming Lei

The queue mapping of type poll only exists when set->map[HCTX_TYPE_POLL].nr_queues is bigger than zero, so enhance the constraint by checking .nr_queues of type poll before enabling IO poll.

Otherwise IO race & timeout can be observed when running block/007.

Looks good to me, but we might consider having a helper for this, since we have this check in 3 places now. But for now this is good, thanks Ming.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 10 lines · Jens Axboe
Quoted 5 lines · Ming Lei

The queue mapping of type poll only exists when set->map[HCTX_TYPE_POLL].nr_queues is bigger than zero, so enhance the constraint by checking .nr_queues of type poll before enabling IO poll.

Otherwise IO race & timeout can be observed when running block/007.

Looks good to me, but we might consider having a helper for this, since we have this check in 3 places now. But for now this is good, thanks Ming.

Jens, if you want this I can drop the nvme patch to set nr_maps to 2 as it wouldn't be needed. Not sure which one is more elegant, but I guess Mings version is a little more fool proof.

author
#3 lore raw
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jens Axboe
Quoted 5 lines · Ming Lei

The queue mapping of type poll only exists when set->map[HCTX_TYPE_POLL].nr_queues is bigger than zero, so enhance the constraint by checking .nr_queues of type poll before enabling IO poll.

Otherwise IO race & timeout can be observed when running block/007.

Quoted 7 lines
Quoted 3 lines

Looks good to me, but we might consider having a helper for this, since we have this check in 3 places now. But for now this is good, thanks Ming.

Jens, if you want this I can drop the nvme patch to set nr_maps to 2 as it wouldn't be needed. Not sure which one is more elegant, but I guess Mings version is a little more fool proof.

For READ queue type, its .nr_maps can be 3 and .nr_queues is zero, so if check on the two queue type is kept as consistent, we may get good code readability, IMO.

As Jens mentioned, we may introduce blk_mq_queue_type_supported() helper to cover both.

Thanks,
Ming

maintainer
#4 lore raw
Quoted 17 lines · Ming Lei
Quoted 8 lines · Christoph Hellwig
Quoted 7 lines · Jens Axboe
Quoted 5 lines · Ming Lei

The queue mapping of type poll only exists when set->map[HCTX_TYPE_POLL].nr_queues is bigger than zero, so enhance the constraint by checking .nr_queues of type poll before enabling IO poll.

Otherwise IO race & timeout can be observed when running block/007.

Quoted 7 lines
Quoted 3 lines

Looks good to me, but we might consider having a helper for this, since we have this check in 3 places now. But for now this is good, thanks Ming.

Jens, if you want this I can drop the nvme patch to set nr_maps to 2 as it wouldn't be needed. Not sure which one is more elegant, but I guess Mings version is a little more fool proof.

Quoted 6 lines

For READ queue type, its .nr_maps can be 3 and .nr_queues is zero, so if check on the two queue type is kept as consistent, we may get good code readability, IMO.

As Jens mentioned, we may introduce blk_mq_queue_type_supported() helper to cover both.

I think that would be preferable.

Signature · 1 line
Jens Axboe