From: sashiko-bot@kernel.org
To: "Nitesh Shetty" <nj.shetty@samsung.com>
Cc: dri-devel@lists.freedesktop.org, nvdimm@lists.linux.dev,
linux-ext4@vger.kernel.org, tytso@mit.edu, media-ci@linuxtv.org
Subject: Re: [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O
Date: Tue, 01 Dec 2026 17:20:49 +0000 [thread overview]
Message-ID: <sashiko-outbox-243809@kernel.org> (raw)
In-Reply-To: <20261201155938.3028275-13-nj.shetty@samsung.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] xfs: TOCTOU race and missing dma-buf checks on RT flag and
stable writes
--
commit 08914e910a1ba46188577502e908fd31c6bc3a3f
Author: Nitesh Shetty <nj.shetty@samsung.com>
xfs: support dma-buf registered buffers for direct I/O
This commit adds dma-buf direct I/O support to XFS via init_dma_buf_io_ctx
and dma_buf_io_tag callbacks, while rejecting dma-buf iterators in the
buffered and DAX paths.
> diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
> index ad1ce4f99ad88..a8440663d5e95 100644
> --- a/fs/xfs/xfs_file.c
> +++ b/fs/xfs/xfs_file.c
[ ... ]
> @@ -2187,10 +2199,38 @@ xfs_file_mmap_prepare(
> return 0;
> }
>
> +/*
> + * Direct I/O to devices that need stable pages bounces through the CPU,
> + * so they can't do dma-buf I/O. Zoned inodes are not supported yet.
> + */
> +static u64
> +xfs_file_dma_buf_io_tag(
> + struct file *file)
> +{
> + struct xfs_inode *ip = XFS_I(file_inode(file));
> +
> + if (IS_DAX(VFS_I(ip)) || xfs_is_zoned_inode(ip) ||
> + mapping_stable_writes(file->f_mapping))
> + return 0;
> + return bdev_dma_buf_io_tag(xfs_inode_buftarg(ip)->bt_bdev);
> +}
> +
> +static int
> +xfs_file_init_dma_buf_io_ctx(
> + struct file *file,
> + struct dma_buf_io_ctx *ctx)
> +{
> + struct xfs_inode *ip = XFS_I(file_inode(file));
> +
> + return bdev_init_dma_buf_io_ctx(xfs_inode_buftarg(ip)->bt_bdev, ctx);
> +}
[Severity: High]
Can a concurrent FS_IOC_FSSETXATTR ioctl change the inode's target block
device, zoned status, or stable-writes state after the unlocked
xfs_file_dma_buf_io_tag() check?
xfs_ioctl_setattr_xflags() can toggle XFS_DIFLAG_REALTIME on an open regular
file without allocated data extents, which switches xfs_inode_buftarg(ip)
between m_ddev_targp and m_rtdev_targp, changes xfs_is_zoned_inode(ip) on
zoned mounts, and updates AS_STABLE_WRITES via xfs_update_stable_writes():
CPU0 CPU1
io_init_rw_fixed()
io_import_dmabuf_map()
dma_buf_io_file_compatible()
xfs_file_dma_buf_io_tag()
/* tag matches m_ddev_targp */
xfs_fileattr_set()
xfs_ilock(ip, XFS_IOLOCK_EXCL)
xfs_ioctl_setattr_xflags()
/* flips XFS_DIFLAG_REALTIME
* and AS_STABLE_WRITES */
xfs_iunlock(ip, XFS_IOLOCK_EXCL)
xfs_file_write_iter() / xfs_file_read_iter()
xfs_ilock_iocb()
/* proceeds with ITER_DMABUF_MAP on new device/state */
The direct I/O paths never re-validate the dma-buf tag or reject
ITER_DMABUF_MAP after acquiring XFS_IOLOCK:
- On a non-zoned mount with an external realtime device, xfs_bmbt_to_iomap()
binds iomap->bdev to the newly selected device and iomap_dio_rw() submits
REQ_DMABUF bioscarrying a dma_buf_io_map mapped for the old device to the
new one (causing bio->bi_io_vec / bio->bi_dmabuf_map union type confusion
if the new driver does not support REQ_DMABUF, or invalid DMA addresses
across devices).
- On a zoned mount, if XFS_DIFLAG_REALTIME is set before xfs_file_dio_write()
checks xfs_is_zoned_inode(ip), it dispatches to
xfs_file_dio_write_zoned(), which (unlike xfs_file_buffered_write_zoned())
does not reject iov_iter_is_dmabuf_map(from).
- In xfs_file_dio_read(), if mapping_stable_writes() becomes true, it calls
iomap_dio_rw() with xfs_dio_read_bounce_ops and dio_flags = 0 (without
IOMAP_DIO_BOUNCE or an iov_iter_is_dmabuf_map(to) check), so
iomap_bounce_read() and iomap_ioend_unbounce() dereference
orig_bio->bi_io_vec (aliased with orig_bio->bi_dmabuf_map) as a bio_vec
array.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201155938.3028275-1-nj.shetty@samsung.com?part=12
next prev parent reply other threads:[~2026-12-01 17:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20261201160117epcas5p2ec8720e93d2041c09b70d41eed40efd1@epcas5p2.samsung.com>
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 01/13] block: factor out bdev_init_dma_buf_io_ctx() Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 02/13] dma-buf-io: add tags to share a context between files Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 03/13] block: set dma-buf-io tag for block files Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 04/13] io_uring: add data to dma-buf conversion helpers Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering Nitesh Shetty
2026-12-01 17:10 ` sashiko-bot
2026-12-01 15:59 ` [RFC PATCH v3 06/13] dma-buf-io: require O_DIRECT and a tag in dma_buf_io_ctx_create() Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 07/13] io_uring/dma-buf: get rid of struct io_buf_dma Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 08/13] iomap: add dma-buf direct I/O guards Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 09/13] iomap: don't ask for a buffered fallback for dma-buf iterators Nitesh Shetty
2026-12-01 17:16 ` sashiko-bot
2026-12-01 15:59 ` [RFC PATCH v3 10/13] blk-crypto: refuse dma-buf bios in the fallback path Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 11/13] dax: refuse dma-buf iterators in dax_iomap_rw() Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O Nitesh Shetty
2026-12-01 17:20 ` sashiko-bot [this message]
2026-12-01 15:59 ` [RFC PATCH v3 13/13] ext4: " Nitesh Shetty
2026-12-01 17:20 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 sashiko-bot
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=sashiko-outbox-243809@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-ext4@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=nj.shetty@samsung.com \
--cc=nvdimm@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tytso@mit.edu \
/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