Skip to contentSkip to conversation

blk-map: provide the bdev to bio if one exists

PATCH Applied Keith Busch 3 participants 3 messages Sep 3, 2025 – Sep 9, 2025

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

PATCH 1/1 blk-map: provide the bdev to bio if one exists

From: Keith Busch <[email protected]>

We can now safely provide a block device when extracting user pages for driver and user passthrough commands. Set the bdev so the caller doesn't have to do that later. This has an additional benefit of being able to extract P2P pages in the passthrough path.

---
Note, this absolutely requires this patch series to be successful:

https://lore.kernel.org/linux-block/[email protected]/

Otherwise DRV_IN/OUT commands may fail because the interface assumes logical block size, which is not a valid assumption for passthrough commands, but we're not relying on the logical block size with the above patch series, so it's fine.

The ability to test P2P data payloads with the passthrough interface is the real goal of this path.

 block/blk-map.c           | 5 +++--
 drivers/nvme/host/ioctl.c | 5 -----
 2 files changed, 3 insertions(+), 7 deletions(-)
block/blk-map.c +3 -2
index 6d1268aa82715..1098162c09393 100644
@@ -253,10 +253,11 @@ static void blk_mq_map_bio_put(struct bio *bio)
 static struct bio *blk_rq_map_bio_alloc(struct request *rq,
 		unsigned int nr_vecs, gfp_t gfp_mask)
 {
+	struct block_device *bdev = rq->q->disk ? rq->q->disk->part0 : NULL;
 	struct bio *bio;
 
 	if (rq->cmd_flags & REQ_ALLOC_CACHE && (nr_vecs <= BIO_INLINE_VECS)) {
-		bio = bio_alloc_bioset(NULL, nr_vecs, rq->cmd_flags, gfp_mask,
+		bio = bio_alloc_bioset(bdev, nr_vecs, rq->cmd_flags, gfp_mask,
 					&fs_bio_set);
 		if (!bio)
 			return NULL;
@@ -264,7 +265,7 @@ static struct bio *blk_rq_map_bio_alloc(struct request *rq,
 		bio = bio_kmalloc(nr_vecs, gfp_mask);
 		if (!bio)
 			return NULL;
-		bio_init(bio, NULL, bio->bi_inline_vecs, nr_vecs, req_op(rq));
+		bio_init(bio, bdev, bio->bi_inline_vecs, nr_vecs, req_op(rq));
 	}
 	return bio;
 }
drivers/nvme/host/ioctl.c +0 -5
index 6b3ac8ae3f34b..f778f3b5214bd 100644
@@ -142,14 +142,9 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
 		ret = blk_rq_map_user_io(req, NULL, nvme_to_user_ptr(ubuffer),
 				bufflen, GFP_KERNEL, flags & NVME_IOCTL_VEC, 0,
 				0, rq_data_dir(req));
-
 	if (ret)
 		return ret;
 
-	bio = req->bio;
-	if (bdev)
-		bio_set_dev(bio, bdev);
-
 	if (has_metadata) {
 		ret = blk_rq_integrity_map_user(req, meta_buffer, meta_len);
 		if (ret)
Signature · 1 line
2.47.3
maintainer Applied
#2 lore raw
In reply to Keith Busch
Quoted 6 lines · Keith Busch

We can now safely provide a block device when extracting user pages for driver and user passthrough commands. Set the bdev so the caller doesn't have to do that later. This has an additional benefit of being able to extract P2P pages in the passthrough path.

Applied, thanks!

[1/1] blk-map: provide the bdev to bio if one exists

      commit: d0d1d522316e91f2b935a78bbf962b8e529d8c4f

Best regards,

Signature · 1 line
Jens Axboe