public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>,
	Christian Brauner <brauner@kernel.org>,
	Carlos Maiolino <cem@kernel.org>, Qu Wenruo <wqu@suse.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-block@vger.kernel.org, linux-xfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 13/14] iomap: add a flag to bounce buffer direct I/O
Date: Wed, 14 Jan 2026 14:59:44 -0800	[thread overview]
Message-ID: <20260114225944.GR15551@frogsfrogsfrogs> (raw)
In-Reply-To: <20260114074145.3396036-14-hch@lst.de>

On Wed, Jan 14, 2026 at 08:41:11AM +0100, Christoph Hellwig wrote:
> Add a new flag that request bounce buffering for direct I/O.  This is
> needed to provide the stable pages requirement requested by devices
> that need to calculate checksums or parity over the data and allows
> file systems to properly work with things like T10 protection
> information.  The implementation just calls out to the new bio bounce
> buffering helpers.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

This seems pretty sensible, assuming bio_iov_iter_bounce does what I
think it does (sets up the bio with the bounce buffer pages instead of
the user-backed pages for a zero-copy IO) right?

If so, then

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/iomap/direct-io.c  | 30 ++++++++++++++++++++----------
>  include/linux/iomap.h |  9 +++++++++
>  2 files changed, 29 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 3f552245ecc2..83fef3210e2b 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
> @@ -214,7 +214,11 @@ static void __iomap_dio_bio_end_io(struct bio *bio, bool inline_completion)
>  {
>  	struct iomap_dio *dio = bio->bi_private;
>  
> -	if (dio->flags & IOMAP_DIO_USER_BACKED) {
> +	if (dio->flags & IOMAP_DIO_BOUNCE) {
> +		bio_iov_iter_unbounce(bio, !!dio->error,
> +				dio->flags & IOMAP_DIO_USER_BACKED);
> +		bio_put(bio);
> +	} else if (dio->flags & IOMAP_DIO_USER_BACKED) {
>  		bio_check_pages_dirty(bio);
>  	} else {
>  		bio_release_pages(bio, false);
> @@ -300,12 +304,16 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
>  		struct iomap_dio *dio, loff_t pos, unsigned int alignment,
>  		blk_opf_t op)
>  {
> +	unsigned int nr_vecs;
>  	struct bio *bio;
>  	ssize_t ret;
>  
> -	bio = iomap_dio_alloc_bio(iter, dio,
> -			bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_VECS),
> -			op);
> +	if (dio->flags & IOMAP_DIO_BOUNCE)
> +		nr_vecs = bio_iov_bounce_nr_vecs(dio->submit.iter, op);
> +	else
> +		nr_vecs = bio_iov_vecs_to_alloc(dio->submit.iter, BIO_MAX_VECS);
> +
> +	bio = iomap_dio_alloc_bio(iter, dio, nr_vecs, op);
>  	fscrypt_set_bio_crypt_ctx(bio, iter->inode,
>  			pos >> iter->inode->i_blkbits, GFP_KERNEL);
>  	bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos);
> @@ -314,7 +322,11 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
>  	bio->bi_private = dio;
>  	bio->bi_end_io = iomap_dio_bio_end_io;
>  
> -	ret = bio_iov_iter_get_pages(bio, dio->submit.iter, alignment - 1);
> +	if (dio->flags & IOMAP_DIO_BOUNCE)
> +		ret = bio_iov_iter_bounce(bio, dio->submit.iter);
> +	else
> +		ret = bio_iov_iter_get_pages(bio, dio->submit.iter,
> +					     alignment - 1);
>  	if (unlikely(ret))
>  		goto out_put_bio;
>  	ret = bio->bi_iter.bi_size;
> @@ -330,7 +342,8 @@ static ssize_t iomap_dio_bio_iter_one(struct iomap_iter *iter,
>  
>  	if (dio->flags & IOMAP_DIO_WRITE)
>  		task_io_account_write(ret);
> -	else if (dio->flags & IOMAP_DIO_USER_BACKED)
> +	else if ((dio->flags & IOMAP_DIO_USER_BACKED) &&
> +		 !(dio->flags & IOMAP_DIO_BOUNCE))
>  		bio_set_pages_dirty(bio);
>  
>  	/*
> @@ -659,7 +672,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  	dio->i_size = i_size_read(inode);
>  	dio->dops = dops;
>  	dio->error = 0;
> -	dio->flags = 0;
> +	dio->flags = dio_flags & (IOMAP_DIO_FSBLOCK_ALIGNED | IOMAP_DIO_BOUNCE);
>  	dio->done_before = done_before;
>  
>  	dio->submit.iter = iter;
> @@ -668,9 +681,6 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  	if (iocb->ki_flags & IOCB_NOWAIT)
>  		iomi.flags |= IOMAP_NOWAIT;
>  
> -	if (dio_flags & IOMAP_DIO_FSBLOCK_ALIGNED)
> -		dio->flags |= IOMAP_DIO_FSBLOCK_ALIGNED;
> -
>  	if (iov_iter_rw(iter) == READ) {
>  		if (iomi.pos >= dio->i_size)
>  			goto out_free_dio;
> diff --git a/include/linux/iomap.h b/include/linux/iomap.h
> index 6bb941707d12..ea79ca9c2d6b 100644
> --- a/include/linux/iomap.h
> +++ b/include/linux/iomap.h
> @@ -566,6 +566,15 @@ struct iomap_dio_ops {
>   */
>  #define IOMAP_DIO_FSBLOCK_ALIGNED	(1 << 3)
>  
> +/*
> + * Bounce buffer instead of using zero copy access.
> + *
> + * This is needed if the device needs stable data to checksum or generate
> + * parity.  The file system must hook into the I/O submission and offload
> + * completions to user context for reads when this is set.
> + */
> +#define IOMAP_DIO_BOUNCE		(1 << 4)
> +
>  ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
>  		const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
>  		unsigned int dio_flags, void *private, size_t done_before);
> -- 
> 2.47.3
> 
> 

  reply	other threads:[~2026-01-14 22:59 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14  7:40 bounce buffer direct I/O when stable pages are required Christoph Hellwig
2026-01-14  7:40 ` [PATCH 01/14] block: refactor get_contig_folio_len Christoph Hellwig
2026-01-14  7:41 ` [PATCH 02/14] block: open code bio_add_page and fix handling of mismatching P2P ranges Christoph Hellwig
2026-01-14 12:46   ` Johannes Thumshirn
2026-01-14 13:01     ` hch
2026-01-14  7:41 ` [PATCH 03/14] iov_iter: extract a iov_iter_extract_bvecs helper from bio code Christoph Hellwig
2026-01-14  7:41 ` [PATCH 04/14] block: remove bio_release_page Christoph Hellwig
2026-01-14  7:41 ` [PATCH 05/14] block: add helpers to bounce buffer an iov_iter into bios Christoph Hellwig
2026-01-14 12:51   ` Johannes Thumshirn
2026-01-14  7:41 ` [PATCH 06/14] iomap: fix submission side handling of completion side errors Christoph Hellwig
2026-01-14 22:35   ` Darrick J. Wong
2026-01-15  6:17     ` Christoph Hellwig
2026-01-14  7:41 ` [PATCH 07/14] iomap: simplify iomap_dio_bio_iter Christoph Hellwig
2026-01-14 22:51   ` Darrick J. Wong
2026-01-15  6:20     ` Christoph Hellwig
2026-01-14  7:41 ` [PATCH 08/14] iomap: split out the per-bio logic from iomap_dio_bio_iter Christoph Hellwig
2026-01-14 22:53   ` Darrick J. Wong
2026-01-14  7:41 ` [PATCH 09/14] iomap: share code between iomap_dio_bio_end_io and iomap_finish_ioend_direct Christoph Hellwig
2026-01-14 22:54   ` Darrick J. Wong
2026-01-14  7:41 ` [PATCH 10/14] iomap: free the bio before completing the dio Christoph Hellwig
2026-01-14 22:55   ` Darrick J. Wong
2026-01-15  6:21     ` Christoph Hellwig
2026-01-14  7:41 ` [PATCH 11/14] iomap: rename IOMAP_DIO_DIRTY to IOMAP_DIO_USER_BACKED Christoph Hellwig
2026-01-14 22:56   ` Darrick J. Wong
2026-01-14  7:41 ` [PATCH 12/14] iomap: support ioends for direct reads Christoph Hellwig
2026-01-14 22:57   ` Darrick J. Wong
2026-01-15  6:21     ` Christoph Hellwig
2026-01-14  7:41 ` [PATCH 13/14] iomap: add a flag to bounce buffer direct I/O Christoph Hellwig
2026-01-14 22:59   ` Darrick J. Wong [this message]
2026-01-15  6:21     ` Christoph Hellwig
2026-01-14  7:41 ` [PATCH 14/14] xfs: use bounce buffering direct I/O when the device requires stable pages Christoph Hellwig
2026-01-14 23:07   ` Darrick J. Wong
2026-01-15  6:24     ` Christoph Hellwig
2026-01-14  9:52 ` bounce buffer direct I/O when stable pages are required Qu Wenruo
2026-01-14 12:39   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2026-01-19  7:44 bounce buffer direct I/O when stable pages are required v2 Christoph Hellwig
2026-01-19  7:44 ` [PATCH 13/14] iomap: add a flag to bounce buffer direct I/O Christoph Hellwig
2026-01-23  9:05   ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260114225944.GR15551@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cem@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox