]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
blk-map: provide the bdev to bio if one exists
authorKeith Busch <kbusch@kernel.org>
Wed, 3 Sep 2025 20:27:46 +0000 (13:27 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 9 Sep 2025 16:35:28 +0000 (10:35 -0600)
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.

Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-map.c
drivers/nvme/host/ioctl.c

index ca4f5cf0003889228f12cd98289e89e3bda74d04..165f2234f00f4258244cc877301faf5fe6c9db2f 100644 (file)
@@ -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_inline(bio, NULL, nr_vecs, req_op(rq));
+               bio_init_inline(bio, bdev, nr_vecs, req_op(rq));
        }
        return bio;
 }
index 6b3ac8ae3f34b951fe99b4e0ecca7e250291e61a..f778f3b5214bd08175f47f7eb198a61116e29829 100644 (file)
@@ -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)