Skip to contentSkip to conversation

cleanup for the recent bio_iov_iter_get_pages changes

PATCH In review Christoph Hellwig 7 participants 13 messages Oct 7, 2025 – Oct 8, 2025

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

Hi all,

while looking over the bio splitting issue reported by Qu, I noticed that some of the recent changes to bio_iov_iter_get_pages lead to more indirections than really needed, especially with the bcachefs abuse now removed in 6.18-rc. This small series cleans this up an prepares for the file system block size splitting needed by btrfs bs > PAGE_SIZE support.

Diffstat:

 block/bio.c            |    5 ++---
 block/blk-map.c        |    6 +++++-
 block/fops.c           |   13 ++++++++++---
 fs/iomap/direct-io.c   |    3 ++-
 include/linux/bio.h    |    7 +------
 include/linux/blkdev.h |    7 -------
 6 files changed, 20 insertions(+), 21 deletions(-)
#1 lore raw

PATCH 1/4 block: remove bio_iov_iter_get_pages

Switch the only caller to bio_iov_iter_get_pages, and explain why it does not have any alignment requirements.

---
 block/blk-map.c     | 6 +++++-
 include/linux/bio.h | 5 -----
 2 files changed, 5 insertions(+), 6 deletions(-)
block/blk-map.c +5 -1
index 165f2234f00f..6cce652c7fa6 100644
@@ -283,7 +283,11 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
 	bio = blk_rq_map_bio_alloc(rq, nr_vecs, gfp_mask);
 	if (!bio)
 		return -ENOMEM;
-	ret = bio_iov_iter_get_pages(bio, iter);
+	/*
+	 * No alignment requirements on our part to support arbitrary
+	 * passthrough commands.
+	 */
+	ret = bio_iov_iter_get_pages_aligned(bio, iter, 0);
 	if (ret)
 		goto out_put;
 	ret = blk_rq_append_bio(rq, bio);
include/linux/bio.h +0 -5
index a64a30131031..b01dae9506de 100644
@@ -449,11 +449,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
 int bio_iov_iter_get_pages_aligned(struct bio *bio, struct iov_iter *iter,
 		unsigned len_align_mask);
 
-static inline int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
-{
-	return bio_iov_iter_get_pages_aligned(bio, iter, 0);
-}
-
 void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter);
 void __bio_release_pages(struct bio *bio, bool mark_dirty);
 extern void bio_set_pages_dirty(struct bio *bio);
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/4 block: rename bio_iov_iter_get_pages_aligned to bio_iov_iter_get_pages

In reply to Christoph Hellwig

Now that the bio_iov_iter_get_pages is free again, use it instead of the more complicated now. Also drop the unused export.

---
 block/bio.c            | 5 ++---
 block/blk-map.c        | 2 +-
 include/linux/bio.h    | 2 +-
 include/linux/blkdev.h | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
block/bio.c +2 -3
index 3a1a848940dd..b3a79285c278 100644
@@ -1316,7 +1316,7 @@ static int bio_iov_iter_align_down(struct bio *bio, struct iov_iter *iter,
 }
 
 /**
- * bio_iov_iter_get_pages_aligned - add user or kernel pages to a bio
+ * bio_iov_iter_get_pages - add user or kernel pages to a bio
  * @bio: bio to add pages to
  * @iter: iov iterator describing the region to be added
  * @len_align_mask: the mask to align the total size to, 0 for any length
@@ -1336,7 +1336,7 @@ static int bio_iov_iter_align_down(struct bio *bio, struct iov_iter *iter,
  * MM encounters an error pinning the requested pages, it stops. Error
  * is returned only if 0 pages could be pinned.
  */
-int bio_iov_iter_get_pages_aligned(struct bio *bio, struct iov_iter *iter,
+int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
 			   unsigned len_align_mask)
 {
 	int ret = 0;
@@ -1360,7 +1360,6 @@ int bio_iov_iter_get_pages_aligned(struct bio *bio, struct iov_iter *iter,
 		return bio_iov_iter_align_down(bio, iter, len_align_mask);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(bio_iov_iter_get_pages_aligned);
 
 static void submit_bio_wait_endio(struct bio *bio)
 {
block/blk-map.c +1 -1
index 6cce652c7fa6..60faf036fb6e 100644
@@ -287,7 +287,7 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
 	 * No alignment requirements on our part to support arbitrary
 	 * passthrough commands.
 	 */
-	ret = bio_iov_iter_get_pages_aligned(bio, iter, 0);
+	ret = bio_iov_iter_get_pages(bio, iter, 0);
 	if (ret)
 		goto out_put;
 	ret = blk_rq_append_bio(rq, bio);
include/linux/bio.h +1 -1
index b01dae9506de..16c1c85613b7 100644
@@ -446,7 +446,7 @@ int submit_bio_wait(struct bio *bio);
 int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
 		size_t len, enum req_op op);
 
-int bio_iov_iter_get_pages_aligned(struct bio *bio, struct iov_iter *iter,
+int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter,
 		unsigned len_align_mask);
 
 void bio_iov_bvec_set(struct bio *bio, const struct iov_iter *iter);
include/linux/blkdev.h +1 -1
index dad5cb5b3812..134f974ac92d 100644
@@ -1876,7 +1876,7 @@ static inline int bio_split_rw_at(struct bio *bio,
 static inline int bio_iov_iter_get_bdev_pages(struct bio *bio,
 		struct iov_iter *iter, struct block_device *bdev)
 {
-	return bio_iov_iter_get_pages_aligned(bio, iter,
+	return bio_iov_iter_get_pages(bio, iter,
 					bdev_logical_block_size(bdev) - 1);
 }
 
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/4 iomap: open code bio_iov_iter_get_bdev_pages

In reply to Christoph Hellwig

Prepare for passing different alignments, and to retired bio_iov_iter_get_bdev_pages as a global helper.

---
 fs/iomap/direct-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/iomap/direct-io.c +2 -1
index 9802b2cc29bb..5d5d63efbd57 100644
@@ -433,7 +433,8 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
 		bio->bi_private = dio;
 		bio->bi_end_io = iomap_dio_bio_end_io;
 
-		ret = bio_iov_iter_get_bdev_pages(bio, dio->submit.iter, iomap->bdev);
+		ret = bio_iov_iter_get_pages(bio, dio->submit.iter,
+				bdev_logical_block_size(iomap->bdev) - 1);
 		if (unlikely(ret)) {
 			/*
 			 * We have to stop part way through an IO. We must fall
Signature · 1 line
2.47.3
#4 lore raw

PATCH 4/4 block: move bio_iov_iter_get_bdev_pages to block/fops.c

In reply to Christoph Hellwig

Keep bio_iov_iter_get_bdev_pages local with the callers, as blindly looking at the bdev logical block size is often not the best idea unless on a block device.

---
 block/fops.c           | 13 ++++++++++---
 include/linux/blkdev.h |  7 -------
 2 files changed, 10 insertions(+), 10 deletions(-)
block/fops.c +10 -3
index c2c0396ea9ee..5e3db9fead77 100644
@@ -43,6 +43,13 @@ static bool blkdev_dio_invalid(struct block_device *bdev, struct kiocb *iocb,
 			(bdev_logical_block_size(bdev) - 1);
 }
 
+static inline int blkdev_iov_iter_get_pages(struct bio *bio,
+		struct iov_iter *iter, struct block_device *bdev)
+{
+	return bio_iov_iter_get_pages(bio, iter,
+			bdev_logical_block_size(bdev) - 1);
+}
+
 #define DIO_INLINE_BIO_VECS 4
 
 static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
@@ -78,7 +85,7 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,
 	if (iocb->ki_flags & IOCB_ATOMIC)
 		bio.bi_opf |= REQ_ATOMIC;
 
-	ret = bio_iov_iter_get_bdev_pages(&bio, iter, bdev);
+	ret = blkdev_iov_iter_get_pages(&bio, iter, bdev);
 	if (unlikely(ret))
 		goto out;
 	ret = bio.bi_iter.bi_size;
@@ -212,7 +219,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
 		bio->bi_end_io = blkdev_bio_end_io;
 		bio->bi_ioprio = iocb->ki_ioprio;
 
-		ret = bio_iov_iter_get_bdev_pages(bio, iter, bdev);
+		ret = blkdev_iov_iter_get_pages(bio, iter, bdev);
 		if (unlikely(ret)) {
 			bio->bi_status = BLK_STS_IOERR;
 			bio_endio(bio);
@@ -348,7 +355,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb,
 		 */
 		bio_iov_bvec_set(bio, iter);
 	} else {
-		ret = bio_iov_iter_get_bdev_pages(bio, iter, bdev);
+		ret = blkdev_iov_iter_get_pages(bio, iter, bdev);
 		if (unlikely(ret))
 			goto out_bio_put;
 	}
include/linux/blkdev.h +0 -7
index 134f974ac92d..70b671a9a7f7 100644
@@ -1873,13 +1873,6 @@ static inline int bio_split_rw_at(struct bio *bio,
 	return bio_split_io_at(bio, lim, segs, max_bytes, lim->dma_alignment);
 }
 
-static inline int bio_iov_iter_get_bdev_pages(struct bio *bio,
-		struct iov_iter *iter, struct block_device *bdev)
-{
-	return bio_iov_iter_get_pages(bio, iter,
-					bdev_logical_block_size(bdev) - 1);
-}
-
 #define DEFINE_IO_COMP_BATCH(name)	struct io_comp_batch name = { }
 
 #endif /* _LINUX_BLKDEV_H */
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH 4/4] block: move bio_iov_iter_get_bdev_pages to block/fops.c

Quoted 2 lines · On Tue, Oct 07, 2025 at 04:57:40AM -0700, [email protected] wrote:

Blktests CI has tested the following submission:
Status: FAILURE

...

Quoted 1 line

No failure

o_O

#7 lore raw

Re: [PATCH 4/4] block: move bio_iov_iter_get_bdev_pages to block/fops.c

Quoted 9 lines · Keith Busch
Quoted 2 lines · On Tue, Oct 07, 2025 at 04:57:40AM -0700, [email protected] wrote:

Blktests CI has tested the following submission:
Status: FAILURE

...

Quoted 1 line

No failure

o_O

Sorry about the noise and the confusing report. I enabled the blktests CI automated testing system, but it didn't go well. I have stopped the system, and will work on the fix.

Reviewed-by
#8 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

Hi all,

while looking over the bio splitting issue reported by Qu, I noticed that some of the recent changes to bio_iov_iter_get_pages lead to more indirections than really needed, especially with the bcachefs abuse now removed in 6.18-rc. This small series cleans this up an prepares for the file system block size splitting needed by btrfs bs > PAGE_SIZE support.

Looks good to me, and makes my later changes much easier.

Thanks,
Qu

Quoted 9 lines

Diffstat:

  block/bio.c            |    5 ++---
  block/blk-map.c        |    6 +++++-
  block/fops.c           |   13 ++++++++++---
  fs/iomap/direct-io.c   |    3 ++-
  include/linux/bio.h    |    7 +------
  include/linux/blkdev.h |    7 -------
  6 files changed, 20 insertions(+), 21 deletions(-)
Reviewed-by
#9 lore raw
In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

while looking over the bio splitting issue reported by Qu, I noticed that some of the recent changes to bio_iov_iter_get_pages lead to more indirections than really needed, especially with the bcachefs abuse now removed in 6.18-rc. This small series cleans this up an prepares for the file system block size splitting needed by btrfs bs > PAGE_SIZE support.

Looks good to me.

Reviewed-by
#11 lore raw
In reply to Christoph Hellwig

Christoph,

Quoted 6 lines

while looking over the bio splitting issue reported by Qu, I noticed that some of the recent changes to bio_iov_iter_get_pages lead to more indirections than really needed, especially with the bcachefs abuse now removed in 6.18-rc. This small series cleans this up an prepares for the file system block size splitting needed by btrfs bs > PAGE_SIZE support.

Looks fine.

Signature · 1 line
Martin K. Petersen
maintainer Applied
#12 lore raw
In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig

while looking over the bio splitting issue reported by Qu, I noticed that some of the recent changes to bio_iov_iter_get_pages lead to more indirections than really needed, especially with the bcachefs abuse now removed in 6.18-rc. This small series cleans this up an prepares for the file system block size splitting needed by btrfs bs > PAGE_SIZE support.

[...]

Applied, thanks!

[1/4] block: remove bio_iov_iter_get_pages

      commit: 1ed06c83506ecaaf1836ddeb7c65772ff86d8d53
[2/4] block: rename bio_iov_iter_get_pages_aligned to bio_iov_iter_get_pages
      commit: 82dd5d763c9b718e2d655b9565e0a06a91bb83dc
[3/4] iomap: open code bio_iov_iter_get_bdev_pages
      commit: cb6d51a4115781fd9de6108932e866a332e38406
[4/4] block: move bio_iov_iter_get_bdev_pages to block/fops.c
      commit: 506aa235f6e0baa00bf792df82a5e9f618b7a5d8

Best regards,

Signature · 1 line
Jens Axboe