Skip to contentSkip to conversation

make the blk-mq stacking interface optional

PATCH New Christoph Hellwig 3 participants 8 messages Feb 15, 2022 – Feb 17, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi Jens,

this series requires an explicit select to use the blk-mq stacking interfaces. This means they don't get build without dm support, and thus the buildbot should catch abuses like the one we had in the ufs driver more easily. And while I touched this code I also ended up cleaning up various loose ends.

Diffstat:

 block/Kconfig          |    3 +++
 block/blk-mq.c         |   45 +++++++++------------------------------------
 drivers/md/Kconfig     |    1 +
 drivers/md/dm-rq.c     |   26 +++++++++-----------------
 include/linux/blk-mq.h |    3 +--
 5 files changed, 23 insertions(+), 55 deletions(-)
#1 lore raw

PATCH 1/5 blk-mq: make the blk-mq stacking code optional

The code to stack blk-mq drivers is only used by dm-multipath, and will preferably stay that way. Make it optional and only selected by device mapper, so that the buildbots more easily catch abuses like the one that slipped in in the ufs driver in the last merged window. Another positive side effects is that kernel builds without device mapper shrink a little bit as well.

---
 block/Kconfig      | 3 +++
 block/blk-mq.c     | 2 ++
 drivers/md/Kconfig | 1 +
 3 files changed, 6 insertions(+)
block/Kconfig +3 -0
index 205f8d01c6952..168b873eb666d 100644
@@ -230,6 +230,9 @@ config BLK_PM
 config BLOCK_HOLDER_DEPRECATED
 	bool
 
+config BLK_MQ_STACKING
+	bool
+
 source "block/Kconfig.iosched"
 
 endif # BLOCK
block/blk-mq.c +2 -0
index 6c59ffe765fde..db62d34afb637 100644
@@ -2840,6 +2840,7 @@ void blk_mq_submit_bio(struct bio *bio)
 				blk_mq_try_issue_directly(rq->mq_hctx, rq));
 }
 
+#ifdef CONFIG_BLK_MQ_STACKING
 /**
  * blk_cloned_rq_check_limits - Helper function to check a cloned request
  *                              for the new queue limits
@@ -3017,6 +3018,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
 	return -ENOMEM;
 }
 EXPORT_SYMBOL_GPL(blk_rq_prep_clone);
+#endif /* CONFIG_BLK_MQ_STACKING */
 
 /*
  * Steal bios from a request and add them to a bio list.
drivers/md/Kconfig +1 -0
index b5ea378e66cb1..998a5cfdbc4e9 100644
@@ -204,6 +204,7 @@ config BLK_DEV_DM
 	tristate "Device mapper support"
 	select BLOCK_HOLDER_DEPRECATED if SYSFS
 	select BLK_DEV_DM_BUILTIN
+	select BLK_MQ_STACKING
 	depends on DAX || DAX=n
 	help
 	  Device-mapper is a low level volume manager.  It works by allowing
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/5 blk-mq: fold blk_cloned_rq_check_limits into blk_insert_cloned_request

In reply to Christoph Hellwig

Fold blk_cloned_rq_check_limits into its only caller.

---
 block/blk-mq.c | 38 +++++---------------------------------
 1 file changed, 5 insertions(+), 33 deletions(-)
block/blk-mq.c +5 -33
index db62d34afb637..fc132933397fb 100644
@@ -2842,26 +2842,14 @@ void blk_mq_submit_bio(struct bio *bio)
 
 #ifdef CONFIG_BLK_MQ_STACKING
 /**
- * blk_cloned_rq_check_limits - Helper function to check a cloned request
- *                              for the new queue limits
- * @q:  the queue
- * @rq: the request being checked
- *
- * Description:
- *    @rq may have been made based on weaker limitations of upper-level queues
- *    in request stacking drivers, and it may violate the limitation of @q.
- *    Since the block layer and the underlying device driver trust @rq
- *    after it is inserted to @q, it should be checked against @q before
- *    the insertion using this generic function.
- *
- *    Request stacking drivers like request-based dm may change the queue
- *    limits when retrying requests on other queues. Those requests need
- *    to be checked against the new queue limits again during dispatch.
+ * blk_insert_cloned_request - Helper for stacking drivers to submit a request
+ * @q:  the queue to submit the request
+ * @rq: the request being queued
  */
-static blk_status_t blk_cloned_rq_check_limits(struct request_queue *q,
-				      struct request *rq)
+blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq)
 {
 	unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
+	blk_status_t ret;
 
 	if (blk_rq_sectors(rq) > max_sectors) {
 		/*
@@ -2893,22 +2881,6 @@ static blk_status_t blk_cloned_rq_check_limits(struct request_queue *q,
 		return BLK_STS_IOERR;
 	}
 
-	return BLK_STS_OK;
-}
-
-/**
- * blk_insert_cloned_request - Helper for stacking drivers to submit a request
- * @q:  the queue to submit the request
- * @rq: the request being queued
- */
-blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq)
-{
-	blk_status_t ret;
-
-	ret = blk_cloned_rq_check_limits(q, rq);
-	if (ret != BLK_STS_OK)
-		return ret;
-
 	if (rq->q->disk &&
 	    should_fail_request(rq->q->disk->part0, blk_rq_bytes(rq)))
 		return BLK_STS_IOERR;
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/5 blk-mq: remove the request_queue argument to blk_insert_cloned_request

In reply to Christoph Hellwig

The request must be submitted to the queue it was allocated for, so remove the extra request_queue argument.

---
 block/blk-mq.c         | 9 ++++-----
 drivers/md/dm-rq.c     | 2 +-
 include/linux/blk-mq.h | 3 +--
 3 files changed, 6 insertions(+), 8 deletions(-)
block/blk-mq.c +4 -5
index fc132933397fb..886836a54064c 100644
@@ -2843,11 +2843,11 @@ void blk_mq_submit_bio(struct bio *bio)
 #ifdef CONFIG_BLK_MQ_STACKING
 /**
  * blk_insert_cloned_request - Helper for stacking drivers to submit a request
- * @q:  the queue to submit the request
  * @rq: the request being queued
  */
-blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *rq)
+blk_status_t blk_insert_cloned_request(struct request *rq)
 {
+	struct request_queue *q = rq->q;
 	unsigned int max_sectors = blk_queue_get_max_sectors(q, req_op(rq));
 	blk_status_t ret;
 
@@ -2881,8 +2881,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
 		return BLK_STS_IOERR;
 	}
 
-	if (rq->q->disk &&
-	    should_fail_request(rq->q->disk->part0, blk_rq_bytes(rq)))
+	if (q->disk && should_fail_request(q->disk->part0, blk_rq_bytes(rq)))
 		return BLK_STS_IOERR;
 
 	if (blk_crypto_insert_cloned_request(rq))
@@ -2895,7 +2894,7 @@ blk_status_t blk_insert_cloned_request(struct request_queue *q, struct request *
 	 * bypass a potential scheduler on the bottom device for
 	 * insert.
 	 */
-	blk_mq_run_dispatch_ops(rq->q,
+	blk_mq_run_dispatch_ops(q,
 			ret = blk_mq_request_issue_directly(rq, true));
 	if (ret)
 		blk_account_io_done(rq, ktime_get_ns());
drivers/md/dm-rq.c +1 -1
index 579ab6183d4d8..2fcc9b7f391b3 100644
@@ -311,7 +311,7 @@ static blk_status_t dm_dispatch_clone_request(struct request *clone, struct requ
 		clone->rq_flags |= RQF_IO_STAT;
 
 	clone->start_time_ns = ktime_get_ns();
-	r = blk_insert_cloned_request(clone->q, clone);
+	r = blk_insert_cloned_request(clone);
 	if (r != BLK_STS_OK && r != BLK_STS_RESOURCE && r != BLK_STS_DEV_RESOURCE)
 		/* must complete clone in terms of original request */
 		dm_complete_request(rq, r);
include/linux/blk-mq.h +1 -2
index d319ffa59354a..3a41d50b85d3a 100644
@@ -952,8 +952,7 @@ int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
 		struct bio_set *bs, gfp_t gfp_mask,
 		int (*bio_ctr)(struct bio *, struct bio *, void *), void *data);
 void blk_rq_unprep_clone(struct request *rq);
-blk_status_t blk_insert_cloned_request(struct request_queue *q,
-		struct request *rq);
+blk_status_t blk_insert_cloned_request(struct request *rq);
 
 struct rq_map_data {
 	struct page **pages;
Signature · 1 line
2.30.2
#4 lore raw

PATCH 4/5 dm: remove useless code from dm_dispatch_clone_request

In reply to Christoph Hellwig

Both ->start_time_ns and the RQF_IO_STAT are set when the request is allocated using blk_mq_alloc_request by dm-mpath in blk_mq_rq_ctx_init. The block layer also ensures ->start_time_ns is only set when actually needed.

---
 drivers/md/dm-rq.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/md/dm-rq.c +0 -4
index 2fcc9b7f391b3..8f6117342d322 100644
@@ -307,10 +307,6 @@ static blk_status_t dm_dispatch_clone_request(struct request *clone, struct requ
 {
 	blk_status_t r;
 
-	if (blk_queue_io_stat(clone->q))
-		clone->rq_flags |= RQF_IO_STAT;
-
-	clone->start_time_ns = ktime_get_ns();
 	r = blk_insert_cloned_request(clone);
 	if (r != BLK_STS_OK && r != BLK_STS_RESOURCE && r != BLK_STS_DEV_RESOURCE)
 		/* must complete clone in terms of original request */
Signature · 1 line
2.30.2
#5 lore raw

PATCH 5/5 dm: remove dm_dispatch_clone_request

In reply to Christoph Hellwig

Fold dm_dispatch_clone_request into it's only caller, and use a switch statement to single dispatch for the handling of the different return values from blk_insert_cloned_request.

---
 drivers/md/dm-rq.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/md/dm-rq.c +9 -13
index 8f6117342d322..6948d5db90925 100644
@@ -303,17 +303,6 @@ static void end_clone_request(struct request *clone, blk_status_t error)
 	dm_complete_request(tio->orig, error);
 }
 
-static blk_status_t dm_dispatch_clone_request(struct request *clone, struct request *rq)
-{
-	blk_status_t r;
-
-	r = blk_insert_cloned_request(clone);
-	if (r != BLK_STS_OK && r != BLK_STS_RESOURCE && r != BLK_STS_DEV_RESOURCE)
-		/* must complete clone in terms of original request */
-		dm_complete_request(rq, r);
-	return r;
-}
-
 static int dm_rq_bio_constructor(struct bio *bio, struct bio *bio_orig,
 				 void *data)
 {
@@ -394,13 +383,20 @@ static int map_request(struct dm_rq_target_io *tio)
 		/* The target has remapped the I/O so dispatch it */
 		trace_block_rq_remap(clone, disk_devt(dm_disk(md)),
 				     blk_rq_pos(rq));
-		ret = dm_dispatch_clone_request(clone, rq);
-		if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE) {
+		ret = blk_insert_cloned_request(clone);
+		switch (ret) {
+		case BLK_STS_OK:
+			break;
+		case BLK_STS_RESOURCE:
+		case BLK_STS_DEV_RESOURCE:
 			blk_rq_unprep_clone(clone);
 			blk_mq_cleanup_rq(clone);
 			tio->ti->type->release_clone_rq(clone, &tio->info);
 			tio->clone = NULL;
 			return DM_MAPIO_REQUEUE;
+		default:
+			/* must complete clone in terms of original request */
+			dm_complete_request(rq, ret);
 		}
 		break;
 	case DM_MAPIO_REQUEUE:
Signature · 1 line
2.30.2
Reviewed-by
#6 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

Hi Jens,

this series requires an explicit select to use the blk-mq stacking interfaces. This means they don't get build without dm support, and thus the buildbot should catch abuses like the one we had in the ufs driver more easily. And while I touched this code I also ended up cleaning up various loose ends.

All look good to me, thanks, for series:

maintainer Applied
#7 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

this series requires an explicit select to use the blk-mq stacking interfaces. This means they don't get build without dm support, and thus the buildbot should catch abuses like the one we had in the ufs driver more easily. And while I touched this code I also ended up cleaning up various loose ends.

Diffstat:

Quoted 8 lines
 block/Kconfig          |    3 +++
 block/blk-mq.c         |   45 +++++++++------------------------------------
 drivers/md/Kconfig     |    1 +
 drivers/md/dm-rq.c     |   26 +++++++++-----------------
 include/linux/blk-mq.h |    3 +--
 5 files changed, 23 insertions(+), 55 deletions(-)

[...]

Applied, thanks!

[1/5] blk-mq: make the blk-mq stacking code optional
(no commit info)
[2/5] blk-mq: fold blk_cloned_rq_check_limits into blk_insert_cloned_request
(no commit info)
[3/5] blk-mq: remove the request_queue argument to blk_insert_cloned_request
(no commit info)
[4/5] dm: remove useless code from dm_dispatch_clone_request
(no commit info)
[5/5] dm: remove dm_dispatch_clone_request
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe