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 14/14] xfs: use bounce buffering direct I/O when the device requires stable pages
Date: Wed, 14 Jan 2026 15:07:28 -0800 [thread overview]
Message-ID: <20260114230728.GS15551@frogsfrogsfrogs> (raw)
In-Reply-To: <20260114074145.3396036-15-hch@lst.de>
On Wed, Jan 14, 2026 at 08:41:12AM +0100, Christoph Hellwig wrote:
> Fix direct I/O on devices that require stable pages by asking iomap
> to bounce buffer. To support this, ioends are used for direct reads
> in this case to provide a user context for copying data back from the
> bounce buffer.
>
> This fixes qemu when used on devices using T10 protection information
> and probably other cases like iSCSI using data digests.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/xfs_aops.c | 8 ++++++--
> fs/xfs/xfs_file.c | 41 ++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 44 insertions(+), 5 deletions(-)
>
> diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> index 56a544638491..c3c1e149fff4 100644
> --- a/fs/xfs/xfs_aops.c
> +++ b/fs/xfs/xfs_aops.c
> @@ -103,7 +103,7 @@ xfs_ioend_put_open_zones(
> * IO write completion.
> */
> STATIC void
> -xfs_end_ioend(
> +xfs_end_ioend_write(
> struct iomap_ioend *ioend)
> {
> struct xfs_inode *ip = XFS_I(ioend->io_inode);
> @@ -202,7 +202,11 @@ xfs_end_io(
> io_list))) {
> list_del_init(&ioend->io_list);
> iomap_ioend_try_merge(ioend, &tmp);
> - xfs_end_ioend(ioend);
> + if (bio_op(&ioend->io_bio) == REQ_OP_READ)
> + iomap_finish_ioends(ioend,
> + blk_status_to_errno(ioend->io_bio.bi_status));
> + else
> + xfs_end_ioend_write(ioend);
> cond_resched();
> }
> }
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index 7874cf745af3..f6cc63dcf961 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
> @@ -224,12 +224,34 @@ xfs_ilock_iocb_for_write(
> return 0;
> }
>
> +/*
> + * Bounce buffering dio reads need a user context to copy back the data.
> + * Use an ioend to provide that.
> + */
> +static void
> +xfs_dio_read_bounce_submit_io(
> + const struct iomap_iter *iter,
> + struct bio *bio,
> + loff_t file_offset)
> +{
> + iomap_init_ioend(iter->inode, bio, file_offset, IOMAP_IOEND_DIRECT);
> + bio->bi_end_io = xfs_end_bio;
> + submit_bio(bio);
> +}
> +
> +static const struct iomap_dio_ops xfs_dio_read_bounce_ops = {
> + .submit_io = xfs_dio_read_bounce_submit_io,
> + .bio_set = &iomap_ioend_bioset,
> +};
> +
> STATIC ssize_t
> xfs_file_dio_read(
> struct kiocb *iocb,
> struct iov_iter *to)
> {
> struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
> + unsigned int dio_flags = 0;
> + const struct iomap_dio_ops *dio_ops = NULL;
> ssize_t ret;
>
> trace_xfs_file_direct_read(iocb, to);
> @@ -242,7 +264,12 @@ xfs_file_dio_read(
> ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
> if (ret)
> return ret;
> - ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, NULL, 0, NULL, 0);
> + if (mapping_stable_writes(iocb->ki_filp->f_mapping)) {
> + dio_ops = &xfs_dio_read_bounce_ops;
> + dio_flags |= IOMAP_DIO_BOUNCE;
> + }
> + ret = iomap_dio_rw(iocb, to, &xfs_read_iomap_ops, dio_ops, dio_flags,
Now that I've gotten to the final patch, one thing strikes me as a
little strange -- we pass the iocb to iomap_dio_rw, which means that in
theory iomap could set IOMAP_DIO_BOUNCE for us, instead of XFS having to
do that on its own.
I think the only barrier to that is the little bit with
xfs_dio_read_bounce_submit_io where we have to kick the direct read
completion to a place where we can copy the bounce buffer contents to
the pages that the caller gave us in the iov_iter, right?
Directio already has a mechanism for doing completions from
s_dio_done_wq, so can't we reuse that? Or is the gamble here that
things like btrfs might want to do something further with the bounce
buffer (like verifying checksums before copying to the caller's pages)
so we might as well make the fs responsible for setting IOMAP_DIO_BOUNCE
and taking control of the bio completion?
--D
> + NULL, 0);
> xfs_iunlock(ip, XFS_IOLOCK_SHARED);
>
> return ret;
> @@ -703,6 +730,8 @@ xfs_file_dio_write_aligned(
> xfs_ilock_demote(ip, XFS_IOLOCK_EXCL);
> iolock = XFS_IOLOCK_SHARED;
> }
> + if (mapping_stable_writes(iocb->ki_filp->f_mapping))
> + dio_flags |= IOMAP_DIO_BOUNCE;
> trace_xfs_file_direct_write(iocb, from);
> ret = iomap_dio_rw(iocb, from, ops, dops, dio_flags, ac, 0);
> out_unlock:
> @@ -750,6 +779,7 @@ xfs_file_dio_write_atomic(
> {
> unsigned int iolock = XFS_IOLOCK_SHARED;
> ssize_t ret, ocount = iov_iter_count(from);
> + unsigned int dio_flags = 0;
> const struct iomap_ops *dops;
>
> /*
> @@ -777,8 +807,10 @@ xfs_file_dio_write_atomic(
> }
>
> trace_xfs_file_direct_write(iocb, from);
> - ret = iomap_dio_rw(iocb, from, dops, &xfs_dio_write_ops,
> - 0, NULL, 0);
> + if (mapping_stable_writes(iocb->ki_filp->f_mapping))
> + dio_flags |= IOMAP_DIO_BOUNCE;
> + ret = iomap_dio_rw(iocb, from, dops, &xfs_dio_write_ops, dio_flags,
> + NULL, 0);
>
> /*
> * The retry mechanism is based on the ->iomap_begin method returning
> @@ -867,6 +899,9 @@ xfs_file_dio_write_unaligned(
> if (flags & IOMAP_DIO_FORCE_WAIT)
> inode_dio_wait(VFS_I(ip));
>
> + if (mapping_stable_writes(iocb->ki_filp->f_mapping))
> + flags |= IOMAP_DIO_BOUNCE;
> +
> trace_xfs_file_direct_write(iocb, from);
> ret = iomap_dio_rw(iocb, from, &xfs_direct_write_iomap_ops,
> &xfs_dio_write_ops, flags, NULL, 0);
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2026-01-14 23:07 UTC|newest]
Thread overview: 38+ 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
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 [this message]
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 14/14] xfs: use bounce buffering direct I/O when the device requires stable pages Christoph Hellwig
2026-01-19 17:45 ` Darrick J. Wong
2026-01-23 9:08 ` 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=20260114230728.GS15551@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