* [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4
[not found] <CGME20261201160117epcas5p2ec8720e93d2041c09b70d41eed40efd1@epcas5p2.samsung.com>
@ 2026-12-01 15:59 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 01/13] block: factor out bdev_init_dma_buf_io_ctx() Nitesh Shetty
` (13 more replies)
0 siblings, 14 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, linux-xfs, linux-fsdevel,
linux-doc, linux-kernel, linux-block, linux-media, dri-devel,
linaro-mm-sig, nvdimm, linux-ext4, io-uring
This series extends io_uring dma-buf registered buffers from block
devices to direct I/O on XFS and ext4 files.
It combines the XFS [1] and ext4 [3] series and builds on Pavel's work
to share a registration across files [2].
A new dma_buf_io_tag() file operation returns a tag for the device a
file does I/O to, or 0 if it can't do dma-buf I/O.
One registration serves all files with the same tag.
Block devices use the disk sequence number.
ext4 and XFS use the tag of the device holding the file's data, namely
s_bdev for ext4, and the data or realtime device for XFS.
Paths that copy data through the CPU refuse dma-buf iterators, namely
buffered fallbacks, DAX, holes inside the file, inline data, bounce
buffers, the blk-crypto fallback and integrity metadata.
Changes since [1], [2] and [3]:
- Merge the XFS and ext4 series.
- Replace the struct file field of [2] and FMODE_CAN_DMABUF_IO of [3]
with a dma_buf_io_tag() file operation.
- Refuse I/O to another device with the tag, instead of one context
per device.
- Use the disk sequence number as the block device tag instead of the
gendisk pointer.
- Step over holes past EOF in iomap (Yun Wang).
[1] https://lore.kernel.org/linux-xfs/20261016091919.971295-1-anuj1072538@gmail.com/
[2] https://lore.kernel.org/all/7165ab453cc680276b88f47f9ae89bc4967543cd.1793751001.git.asml.silence@gmail.com/
[3] https://lore.kernel.org/all/20261113070621.273953-1-mengmeng.zhao@linux.dev/
Mengmeng Zhao (4):
iomap: don't ask for a buffered fallback for dma-buf iterators
blk-crypto: refuse dma-buf bios in the fallback path
dax: refuse dma-buf iterators in dax_iomap_rw()
ext4: support dma-buf registered buffers for direct I/O
Nitesh Shetty (6):
block: factor out bdev_init_dma_buf_io_ctx()
dma-buf-io: add tags to share a context between files
block: set dma-buf-io tag for block files
dma-buf-io: require O_DIRECT and a tag in dma_buf_io_ctx_create()
iomap: add dma-buf direct I/O guards
xfs: support dma-buf registered buffers for direct I/O
Pavel Begunkov (3):
io_uring: add data to dma-buf conversion helpers
io_uring/dma-buf: switch to tag file filtering
io_uring/dma-buf: get rid of struct io_buf_dma
.../filesystems/iomap/operations.rst | 3 ++
block/bdev.c | 28 +++++++++++
block/blk-crypto.c | 8 +++
block/fops.c | 16 +++---
drivers/dma-buf/dma-buf-io.c | 16 ++++--
fs/dax.c | 4 ++
fs/ext4/ext4.h | 10 ++++
fs/ext4/file.c | 45 +++++++++++++++--
fs/iomap/direct-io.c | 49 +++++++++++++++++--
fs/xfs/xfs_file.c | 40 +++++++++++++++
include/linux/blkdev.h | 18 +++++++
include/linux/dma-buf-io.h | 19 +++++++
include/linux/fs.h | 1 +
io_uring/dma-buf.c | 19 ++-----
io_uring/dma-buf.h | 24 +++++----
15 files changed, 257 insertions(+), 43 deletions(-)
base-commit: 71da94f340e4edf35a3995f38d47bc754aeb6819
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread
* [RFC PATCH v3 01/13] block: factor out bdev_init_dma_buf_io_ctx()
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 ` 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
` (12 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Dan Williams, Matthew Wilcox, Jan Kara, Alexander Viro,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Anuj Gupta, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
Move the block device setup into bdev_init_dma_buf_io_ctx(), so file
systems can use it for the device backing a file.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
block/bdev.c | 24 ++++++++++++++++++++++++
block/fops.c | 10 +---------
include/linux/blkdev.h | 3 +++
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c
index f20f91b3176e..a949b3d0d97e 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -17,6 +17,7 @@
#include <linux/blkpg.h>
#include <linux/magic.h>
#include <linux/buffer_head.h>
+#include <linux/dma-buf-io.h>
#include <linux/swap.h>
#include <linux/writeback.h>
#include <linux/mount.h>
@@ -60,6 +61,29 @@ struct block_device *file_bdev(struct file *bdev_file)
}
EXPORT_SYMBOL(file_bdev);
+/**
+ * bdev_init_dma_buf_io_ctx - set up a dma-buf I/O context for a block device
+ * @bdev: block device the context is set up for
+ * @ctx: context to initialise
+ *
+ * Used by block device files, and by file systems for the device holding
+ * a file's data.
+ *
+ * Return: On success zero is returned, negative error code on failure.
+ */
+int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
+ struct dma_buf_io_ctx *ctx)
+{
+ struct gendisk *disk = bdev->bd_disk;
+
+ if (ctx->dmabuf->size > UINT_MAX)
+ return -EINVAL;
+ if (!disk->fops->init_dma_buf_io_ctx)
+ return -EOPNOTSUPP;
+ return disk->fops->init_dma_buf_io_ctx(bdev, ctx);
+}
+EXPORT_SYMBOL_GPL(bdev_init_dma_buf_io_ctx);
+
static void bdev_write_inode(struct block_device *bdev)
{
struct inode *inode = BD_INODE(bdev);
diff --git a/block/fops.c b/block/fops.c
index 084379778413..f017bd1e01b2 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -19,7 +19,6 @@
#include <linux/iomap.h>
#include <linux/module.h>
#include <linux/io_uring/cmd.h>
-#include <linux/dma-buf-io.h>
#include "blk.h"
static inline struct inode *bdev_file_inode(struct file *file)
@@ -1005,16 +1004,9 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc)
static int blkdev_init_dma_buf_io_ctx(struct file *file,
struct dma_buf_io_ctx *ctx)
{
- struct block_device *bdev = file_bdev(file);
- struct gendisk *disk = bdev->bd_disk;
-
if (!(file->f_flags & O_DIRECT))
return -EINVAL;
- if (ctx->dmabuf->size > UINT_MAX)
- return -EINVAL;
- if (!disk->fops->init_dma_buf_io_ctx)
- return -EOPNOTSUPP;
- return disk->fops->init_dma_buf_io_ctx(bdev, ctx);
+ return bdev_init_dma_buf_io_ctx(file_bdev(file), ctx);
}
const struct file_operations def_blk_fops = {
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 63c6e43ecdda..8b69a66b67df 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1674,6 +1674,9 @@ struct block_device_operations {
int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
};
+int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
+ struct dma_buf_io_ctx *ctx);
+
#ifdef CONFIG_COMPAT
extern int blkdev_compat_ptr_ioctl(struct block_device *, blk_mode_t,
unsigned int, unsigned long);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 02/13] dma-buf-io: add tags to share a context between files
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 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 03/13] block: set dma-buf-io tag for block files Nitesh Shetty
` (11 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Anuj Gupta, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
A dma-buf I/O context can only be used with the file it was created on.
File systems need to share it between files on the same device.
Add a dma_buf_io_tag() file operation.
It returns a tag for the device a file does I/O to, or 0 if the file
can't do dma-buf I/O.
The context stores the tag of the creating file and can be used with
any file with the same tag.
A file's tag can change after open, e.g. when O_DIRECT is cleared, so
compare it on every I/O.
Based on a patch by Pavel Begunkov:
https://lore.kernel.org/all/7165ab453cc680276b88f47f9ae89bc4967543cd.1793751001.git.asml.silence@gmail.com/
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
include/linux/dma-buf-io.h | 19 +++++++++++++++++++
include/linux/fs.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/include/linux/dma-buf-io.h b/include/linux/dma-buf-io.h
index d9f27650a851..0f5d391706cf 100644
--- a/include/linux/dma-buf-io.h
+++ b/include/linux/dma-buf-io.h
@@ -48,10 +48,29 @@ struct dma_buf_io_ctx {
enum dma_data_direction dir;
bool is_dead;
+ /* set by the importer, matched against ->dma_buf_io_tag() */
+ u64 importer_tag;
+
void *dev_priv;
const struct dma_buf_io_ops *dev_ops;
};
+/* The tag can change after open, so check it for every I/O. */
+static inline u64 dma_buf_io_file_tag(struct file *file)
+{
+ if (!file->f_op->dma_buf_io_tag || !(file->f_flags & O_DIRECT))
+ return 0;
+ return file->f_op->dma_buf_io_tag(file);
+}
+
+static inline bool dma_buf_io_file_compatible(const struct dma_buf_io_ctx *ctx,
+ struct file *file)
+{
+ u64 tag = dma_buf_io_file_tag(file);
+
+ return tag && tag == ctx->importer_tag;
+}
+
int dma_buf_io_ctx_create(struct file *file,
struct dma_buf *dmabuf,
enum dma_data_direction dir,
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 5b3a100aba77..48c1a2c95ba8 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1965,6 +1965,7 @@ struct file_operations {
unsigned int poll_flags);
int (*mmap_prepare)(struct vm_area_desc *);
int (*init_dma_buf_io_ctx)(struct file *, struct dma_buf_io_ctx *);
+ u64 (*dma_buf_io_tag)(struct file *file);
} __randomize_layout;
/* Supports async buffered reads */
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 03/13] block: set dma-buf-io tag for block files
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 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 04/13] io_uring: add data to dma-buf conversion helpers Nitesh Shetty
` (10 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Dan Williams, Matthew Wilcox, Jan Kara, Alexander Viro,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Anuj Gupta, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
Use the disk sequence number as the tag of block device files.
It is never reused, so a new disk can't match an old registration.
Based on a patch by Pavel Begunkov:
https://lore.kernel.org/all/7165ab453cc680276b88f47f9ae89bc4967543cd.1793751001.git.asml.silence@gmail.com/
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
block/bdev.c | 6 +++++-
block/fops.c | 6 ++++++
include/linux/blkdev.h | 15 +++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/block/bdev.c b/block/bdev.c
index a949b3d0d97e..d5ea32a6217c 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -75,12 +75,16 @@ int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
struct dma_buf_io_ctx *ctx)
{
struct gendisk *disk = bdev->bd_disk;
+ int ret;
if (ctx->dmabuf->size > UINT_MAX)
return -EINVAL;
if (!disk->fops->init_dma_buf_io_ctx)
return -EOPNOTSUPP;
- return disk->fops->init_dma_buf_io_ctx(bdev, ctx);
+ ret = disk->fops->init_dma_buf_io_ctx(bdev, ctx);
+ if (!ret)
+ ctx->importer_tag = bdev_dma_buf_io_tag(bdev);
+ return ret;
}
EXPORT_SYMBOL_GPL(bdev_init_dma_buf_io_ctx);
diff --git a/block/fops.c b/block/fops.c
index f017bd1e01b2..f723220194a4 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -1009,6 +1009,11 @@ static int blkdev_init_dma_buf_io_ctx(struct file *file,
return bdev_init_dma_buf_io_ctx(file_bdev(file), ctx);
}
+static u64 blkdev_dma_buf_io_tag(struct file *file)
+{
+ return bdev_dma_buf_io_tag(file_bdev(file));
+}
+
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_release,
@@ -1028,6 +1033,7 @@ const struct file_operations def_blk_fops = {
.uring_cmd = blkdev_uring_cmd,
.fop_flags = FOP_BUFFER_RASYNC | FOP_DONTCACHE,
.init_dma_buf_io_ctx = blkdev_init_dma_buf_io_ctx,
+ .dma_buf_io_tag = blkdev_dma_buf_io_tag,
};
static __init int blkdev_init(void)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 8b69a66b67df..a9a3bc618266 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1677,6 +1677,21 @@ struct block_device_operations {
int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
struct dma_buf_io_ctx *ctx);
+/**
+ * bdev_dma_buf_io_tag - get the dma-buf I/O tag of a block device
+ * @bdev: block device to query
+ *
+ * The tag is the disk sequence number, which is never reused.
+ *
+ * Return: the tag, or 0 if the disk doesn't support dma-buf I/O.
+ */
+static inline u64 bdev_dma_buf_io_tag(struct block_device *bdev)
+{
+ if (!bdev->bd_disk->fops->init_dma_buf_io_ctx)
+ return 0;
+ return bdev->bd_disk->diskseq;
+}
+
#ifdef CONFIG_COMPAT
extern int blkdev_compat_ptr_ioctl(struct block_device *, blk_mode_t,
unsigned int, unsigned long);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 04/13] io_uring: add data to dma-buf conversion helpers
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (2 preceding siblings ...)
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 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering Nitesh Shetty
` (9 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Dan Williams, Matthew Wilcox, Jan Kara, Alexander Viro,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Anuj Gupta, Nitesh Shetty, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
From: Pavel Begunkov <asml.silence@gmail.com>
struct io_buf_dma is stored as void * in registered buffers and cast in
several places.
Casts from void * aren't type checked, so wrap them in helpers.
No functional changes.
Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
io_uring/dma-buf.c | 2 +-
io_uring/dma-buf.h | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index 61825d59e384..fd9b8769818a 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -2,7 +2,7 @@
static inline void io_release_dmabuf(void *priv)
{
- struct io_buf_dma *bd = priv;
+ struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
fput(bd->target_file);
dma_buf_io_ctx_release(bd->ctx);
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index d8d9b4f224d8..051483991090 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -12,6 +12,16 @@ struct io_buf_dma {
struct file *target_file;
};
+static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
+{
+ return data;
+}
+
+static inline struct io_buf_dma *io_buf_to_dmabuf(struct io_mapped_ubuf *imu)
+{
+ return io_priv_to_dmabuf(imu->priv);
+}
+
int __io_register_dmabuf(struct io_ring_ctx *ctx,
struct io_uring_regbuf_desc *desc,
struct io_mapped_ubuf *imu);
@@ -39,7 +49,7 @@ static inline int io_attach_dmabuf_map(struct io_kiocb *req,
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
- bd = req->buf_node->buf->priv;
+ bd = io_buf_to_dmabuf(req->buf_node->buf);
map = dma_buf_io_get_map(bd->ctx, nowait);
if (unlikely(IS_ERR(map)))
return PTR_ERR(map);
@@ -53,7 +63,7 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
struct io_mapped_ubuf *imu,
size_t len, size_t offset)
{
- struct io_buf_dma *bd = imu->priv;
+ struct io_buf_dma *bd = io_buf_to_dmabuf(imu);
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (3 preceding siblings ...)
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 ` 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
` (8 subsequent siblings)
13 siblings, 1 reply; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Anuj Gupta, Nitesh Shetty, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
From: Pavel Begunkov <asml.silence@gmail.com>
Instead of enforcing that a dma-buf-io context is used only with the
registered file, allow sharing it between files with the same tag.
Drop the reference to that file, so it can be closed while the buffer
stays registered.
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
io_uring/dma-buf.c | 3 +--
io_uring/dma-buf.h | 6 ++----
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index fd9b8769818a..fe735a8773b7 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -4,7 +4,6 @@ static inline void io_release_dmabuf(void *priv)
{
struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
- fput(bd->target_file);
dma_buf_io_ctx_release(bd->ctx);
kfree(bd);
}
@@ -52,13 +51,13 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
if (ret)
goto err;
- bd->target_file = target_file;
imu->len = dmabuf->size;
imu->release = io_release_dmabuf;
imu->priv = bd;
imu->flags = IO_REGBUF_F_DMABUF;
imu->dir = IO_BUF_DEST | IO_BUF_SOURCE;
dma_buf_put(dmabuf);
+ fput(target_file);
return 0;
err:
kfree(bd);
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index 051483991090..eb4ce2348be2 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -9,7 +9,6 @@
struct io_buf_dma {
struct dma_buf_io_ctx *ctx;
- struct file *target_file;
};
static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
@@ -63,11 +62,10 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
struct io_mapped_ubuf *imu,
size_t len, size_t offset)
{
- struct io_buf_dma *bd = io_buf_to_dmabuf(imu);
-
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
- if (req->file != bd->target_file)
+ if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu)->ctx,
+ req->file)))
return -EBADF;
io_req_set_flags(req, REQ_F_DMABUF);
iov_iter_dmabuf_map(iter, ddir, NULL, offset, len);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 06/13] dma-buf-io: require O_DIRECT and a tag in dma_buf_io_ctx_create()
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (4 preceding siblings ...)
2026-12-01 15:59 ` [RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering Nitesh Shetty
@ 2026-12-01 15:59 ` 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
` (7 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Anuj Gupta, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
Move the O_DIRECT check from blkdev_init_dma_buf_io_ctx() into
dma_buf_io_ctx_create(), so it covers every file type.
Also refuse files without a tag, as the context could not be used
with them.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
block/fops.c | 2 --
drivers/dma-buf/dma-buf-io.c | 16 +++++++++++++---
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/block/fops.c b/block/fops.c
index f723220194a4..5c38db558f2d 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -1004,8 +1004,6 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc)
static int blkdev_init_dma_buf_io_ctx(struct file *file,
struct dma_buf_io_ctx *ctx)
{
- if (!(file->f_flags & O_DIRECT))
- return -EINVAL;
return bdev_init_dma_buf_io_ctx(file_bdev(file), ctx);
}
diff --git a/drivers/dma-buf/dma-buf-io.c b/drivers/dma-buf/dma-buf-io.c
index 8440151de860..020a998e305f 100644
--- a/drivers/dma-buf/dma-buf-io.c
+++ b/drivers/dma-buf/dma-buf-io.c
@@ -152,9 +152,9 @@ static void dma_buf_io_ctx_shutdown(struct dma_buf_io_ctx *ctx)
* @out_ctx: [out] resulting ctx
*
* Create a new I/O context from the given DMA buffer for the given file.
- * It only works with files implementing ->init_dma_buf_io_ctx and fails
- * with -EOPNOTSUPP otherwise. Once created, the user can create a map
- * and use it to issue I/O, such as read/write requests, to @file.
+ * The file must be opened with O_DIRECT and have a non-zero dma-buf I/O
+ * tag. Once created, the user can create a map and use it to issue I/O to
+ * any file with the same tag.
*/
int dma_buf_io_ctx_create(struct file *file,
struct dma_buf *dmabuf,
@@ -166,6 +166,10 @@ int dma_buf_io_ctx_create(struct file *file,
if (!file->f_op->init_dma_buf_io_ctx)
return -EOPNOTSUPP;
+ if (!(file->f_flags & O_DIRECT))
+ return -EINVAL;
+ if (!dma_buf_io_file_tag(file))
+ return -EOPNOTSUPP;
ctx = kzalloc_obj(*ctx);
if (!ctx)
@@ -186,6 +190,12 @@ int dma_buf_io_ctx_create(struct file *file,
!ctx->dev_ops->unmap ||
!ctx->dev_ops->release))
return -EINVAL;
+ if (WARN_ON_ONCE(!ctx->importer_tag)) {
+ ctx->dev_ops->release(ctx);
+ dma_buf_put(dmabuf);
+ kfree(ctx);
+ return -EINVAL;
+ }
*out_ctx = ctx;
return 0;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 07/13] io_uring/dma-buf: get rid of struct io_buf_dma
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (5 preceding siblings ...)
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 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 08/13] iomap: add dma-buf direct I/O guards Nitesh Shetty
` (6 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Anuj Gupta, Nitesh Shetty, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
From: Pavel Begunkov <asml.silence@gmail.com>
After the previous patch, struct io_buf_dma only holds the
dma_buf_io_ctx, so use the context directly.
Fixes: 62e4bf5b25d44 ("io_uring/rsrc: add dmabuf backed registered buffers")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
io_uring/dma-buf.c | 16 ++++------------
io_uring/dma-buf.h | 16 ++++++----------
2 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index fe735a8773b7..a1fc34c0c044 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -2,17 +2,14 @@
static inline void io_release_dmabuf(void *priv)
{
- struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
-
- dma_buf_io_ctx_release(bd->ctx);
- kfree(bd);
+ dma_buf_io_ctx_release(io_priv_to_dmabuf(priv));
}
int __io_register_dmabuf(struct io_ring_ctx *ctx,
struct io_uring_regbuf_desc *desc,
struct io_mapped_ubuf *imu)
{
- struct io_buf_dma *bd = NULL;
+ struct dma_buf_io_ctx *dmabuf_ctx;
struct file *target_file = NULL;
struct dma_buf *dmabuf = NULL;
int ret;
@@ -27,10 +24,6 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
if (desc->uaddr || desc->size)
return -EINVAL;
- bd = kzalloc_obj(*bd);
- if (!bd)
- return -ENOMEM;
-
target_file = fget(desc->target_fd);
if (!target_file) {
ret = -EBADF;
@@ -47,20 +40,19 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
goto err;
ret = dma_buf_io_ctx_create(target_file, dmabuf, DMA_BIDIRECTIONAL,
- &bd->ctx);
+ &dmabuf_ctx);
if (ret)
goto err;
imu->len = dmabuf->size;
imu->release = io_release_dmabuf;
- imu->priv = bd;
+ imu->priv = dmabuf_ctx;
imu->flags = IO_REGBUF_F_DMABUF;
imu->dir = IO_BUF_DEST | IO_BUF_SOURCE;
dma_buf_put(dmabuf);
fput(target_file);
return 0;
err:
- kfree(bd);
if (target_file)
fput(target_file);
if (dmabuf)
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index eb4ce2348be2..952e254034bf 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -7,16 +7,12 @@
#include "rsrc.h"
-struct io_buf_dma {
- struct dma_buf_io_ctx *ctx;
-};
-
-static inline struct io_buf_dma *io_priv_to_dmabuf(void *data)
+static inline struct dma_buf_io_ctx *io_priv_to_dmabuf(void *data)
{
return data;
}
-static inline struct io_buf_dma *io_buf_to_dmabuf(struct io_mapped_ubuf *imu)
+static inline struct dma_buf_io_ctx *io_buf_to_dmabuf(struct io_mapped_ubuf *imu)
{
return io_priv_to_dmabuf(imu->priv);
}
@@ -40,16 +36,16 @@ static inline int io_attach_dmabuf_map(struct io_kiocb *req,
unsigned issue_flags)
{
bool nowait = issue_flags & IO_URING_F_NONBLOCK;
+ struct io_mapped_ubuf *imu;
struct dma_buf_io_map *map;
- struct io_buf_dma *bd;
if (!(req->flags & REQ_F_DMABUF))
return 0;
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
- bd = io_buf_to_dmabuf(req->buf_node->buf);
- map = dma_buf_io_get_map(bd->ctx, nowait);
+ imu = req->buf_node->buf;
+ map = dma_buf_io_get_map(io_buf_to_dmabuf(imu), nowait);
if (unlikely(IS_ERR(map)))
return PTR_ERR(map);
req->dmabuf_map = map;
@@ -64,7 +60,7 @@ static inline int io_import_dmabuf_map(struct io_kiocb *req,
{
if (!IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
return -EOPNOTSUPP;
- if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu)->ctx,
+ if (unlikely(!dma_buf_io_file_compatible(io_buf_to_dmabuf(imu),
req->file)))
return -EBADF;
io_req_set_flags(req, REQ_F_DMABUF);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 08/13] iomap: add dma-buf direct I/O guards
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (6 preceding siblings ...)
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 ` 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
` (5 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Mengmeng Zhao, Li Wang,
Yun Wang, Anuj Gupta, linux-xfs, linux-fsdevel, linux-doc,
linux-kernel, linux-block, linux-media, dri-devel, linaro-mm-sig,
nvdimm, linux-ext4, io-uring
Direct I/O copies data from the CPU in four places, namely zero-filling
holes, inline data, bounce pages and integrity metadata.
A dma-buf iterator has no pages, so refuse it there.
A read that hits a hole or unwritten extent before i_size fails with
-EOPNOTSUPP, even if I/O for an earlier extent was already submitted.
Holes at or beyond i_size are skipped, as reads are truncated to i_size
on completion.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
Co-developed-by: Yun Wang <arsenova@a7snv.com>
Signed-off-by: Yun Wang <arsenova@a7snv.com>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
fs/iomap/direct-io.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index f00b0841fdd0..1cd907204501 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -425,6 +425,11 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
unsigned int alignment;
ssize_t ret = 0;
+ /* integrity metadata is generated from the data pages */
+ if (iov_iter_is_dmabuf_map(dio->submit.iter) &&
+ (iomap->flags & IOMAP_F_INTEGRITY))
+ return -EOPNOTSUPP;
+
/*
* File systems that write out of place and always allocate new blocks
* need each bio to be block aligned as that's the unit of allocation.
@@ -589,7 +594,25 @@ static int iomap_dio_bio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
static int iomap_dio_hole_iter(struct iomap_iter *iter, struct iomap_dio *dio)
{
- loff_t copied = iov_iter_zero(iomap_length(iter), dio->submit.iter);
+ loff_t copied;
+
+ if (iov_iter_is_dmabuf_map(dio->submit.iter)) {
+ u64 length = iomap_length(iter);
+
+ /* zero-filling walks the data pages */
+ if (iter->pos < dio->i_size)
+ return -EOPNOTSUPP;
+ /*
+ * Past EOF there is nothing to zero.
+ * The read is truncated to i_size before it is reported, so
+ * step over the hole.
+ */
+ iov_iter_advance(dio->submit.iter, length);
+ dio->size += length;
+ return iomap_iter_advance(iter, length);
+ }
+
+ copied = iov_iter_zero(iomap_length(iter), dio->submit.iter);
if (dio->flags & IOMAP_DIO_FSBLOCK_ALIGNED) {
loff_t aligned_copied = round_down(copied,
@@ -619,6 +642,10 @@ static int iomap_dio_inline_iter(struct iomap_iter *iomi, struct iomap_dio *dio)
loff_t pos = iomi->pos;
u64 copied;
+ /* inline data is copied from the CPU */
+ if (iov_iter_is_dmabuf_map(iter))
+ return -EOPNOTSUPP;
+
if (WARN_ON_ONCE(!inline_data))
return -EIO;
@@ -717,6 +744,10 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
if (!iomi.len)
return NULL;
+ /* bouncing copies the data from the CPU */
+ if (iov_iter_is_dmabuf_map(iter) && (dio_flags & IOMAP_DIO_BOUNCE))
+ return ERR_PTR(-EOPNOTSUPP);
+
dio = kmalloc_obj(*dio);
if (!dio)
return ERR_PTR(-ENOMEM);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 09/13] iomap: don't ask for a buffered fallback for dma-buf iterators
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (7 preceding siblings ...)
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 ` 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
` (4 subsequent siblings)
13 siblings, 1 reply; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Mengmeng Zhao, Li Wang, Anuj Gupta,
Nitesh Shetty, linux-xfs, linux-fsdevel, linux-doc, linux-kernel,
linux-block, linux-media, dri-devel, linaro-mm-sig, nvdimm,
linux-ext4, io-uring
From: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
-ENOTBLK tells the file system to retry the write as buffered I/O.
A dma-buf iterator has no pages, so it can't, and the write would end
as a zero-byte success.
Return a real error instead. A busy folio becomes -EAGAIN.
Other invalidation errors are returned as is.
-ENOTBLK from the file system's iomap_iter_next_fn callback becomes
-EOPNOTSUPP if nothing was transferred, while a partial transfer still
returns its progress.
Only files with a dma-buf I/O tag reach these branches.
XFS and ext4 add the tag in the last two patches.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
Documentation/filesystems/iomap/operations.rst | 3 +++
fs/iomap/direct-io.c | 16 ++++++++++++++--
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/Documentation/filesystems/iomap/operations.rst b/Documentation/filesystems/iomap/operations.rst
index a5784dee0850..1760021183e1 100644
--- a/Documentation/filesystems/iomap/operations.rst
+++ b/Documentation/filesystems/iomap/operations.rst
@@ -519,6 +519,9 @@ Return Values
cache before issuing the I/O to storage.
The ``begin`` or ``end`` functions may also return
this value.
+ A dma-buf iterator cannot fall back to buffered I/O, so it gets
+ ``-EAGAIN`` when the failure is retryable and ``-EOPNOTSUPP`` when no
+ data could be transferred.
* ``-EIOCBQUEUED``: The asynchronous direct I/O request has been
queued and will be completed separately.
diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index 1cd907204501..be7f3ef57d8a 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -718,7 +718,9 @@ static int iomap_dio_iter(struct iomap_iter *iter, struct iomap_dio *dio)
* completing partial requests asynchronously.
*
* Returns -ENOTBLK In case of a page invalidation invalidation failure for
- * writes. The callers needs to fall back to buffered I/O in this case.
+ * writes. The callers needs to fall back to buffered I/O in this case. A
+ * dma-buf iterator cannot use that fallback, so it gets -EAGAIN when the
+ * failure is retryable and -EOPNOTSUPP when nothing was transferred.
*/
struct iomap_dio *
__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
@@ -818,7 +820,7 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
/*
* Try to invalidate cache pages for the range we are writing.
* If this invalidation fails, let the caller fall back to
- * buffered I/O.
+ * buffered I/O unless the iterator cannot be handled there.
*/
ret = kiocb_invalidate_pages(iocb, iomi.len);
if (ret) {
@@ -832,6 +834,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
* the caller tries again.
*/
ret = -EAGAIN;
+ } else if (iov_iter_is_dmabuf_map(iter)) {
+ /*
+ * a busy folio is transient, let the
+ * caller retry the direct write
+ */
+ if (ret == -EBUSY)
+ ret = -EAGAIN;
} else {
/* fall back to buffered write */
ret = -ENOTBLK;
@@ -879,6 +888,9 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
if (ret == -ENOTBLK) {
wait_for_completion = true;
ret = 0;
+ /* a partial transfer is still reported as a short I/O */
+ if (!dio->size && iov_iter_is_dmabuf_map(iter))
+ ret = -EOPNOTSUPP;
}
if (ret < 0)
iomap_dio_set_error(dio, ret);
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 10/13] blk-crypto: refuse dma-buf bios in the fallback path
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (8 preceding siblings ...)
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 15:59 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 11/13] dax: refuse dma-buf iterators in dax_iomap_rw() Nitesh Shetty
` (3 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Mengmeng Zhao, Li Wang, Anuj Gupta,
Nitesh Shetty, linux-xfs, linux-fsdevel, linux-doc, linux-kernel,
linux-block, linux-media, dri-devel, linaro-mm-sig, nvdimm,
linux-ext4, io-uring
From: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Without native inline encryption, blk-crypto encrypts through the
bio's data pages.
A dma-buf bio has none, so fail it before the fallback runs.
Devices with native support are not affected.
The check can't wait for blk_mq_submit_bio(), as submitters reach the
fallback before the bio is queued.
No in-tree user submits such a bio today.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
block/blk-crypto.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/block/blk-crypto.c b/block/blk-crypto.c
index bc3a9f59574b..01b8d26040dc 100644
--- a/block/blk-crypto.c
+++ b/block/blk-crypto.c
@@ -271,6 +271,14 @@ bool __blk_crypto_submit_bio(struct bio *bio)
bio_endio_status(bio, BLK_STS_NOTSUPP);
return false;
}
+ /*
+ * The fallback encrypts from the data pages, which a dma-buf
+ * bio does not have.
+ */
+ if (op_is_dmabuf(bio->bi_opf)) {
+ bio_endio_status(bio, BLK_STS_NOTSUPP);
+ return false;
+ }
return blk_crypto_fallback_bio_prep(bio);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 11/13] dax: refuse dma-buf iterators in dax_iomap_rw()
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (9 preceding siblings ...)
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 ` Nitesh Shetty
2026-12-01 15:59 ` [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O Nitesh Shetty
` (2 subsequent siblings)
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Mengmeng Zhao, Li Wang, Anuj Gupta,
Nitesh Shetty, linux-xfs, linux-fsdevel, linux-doc, linux-kernel,
linux-block, linux-media, dri-devel, linaro-mm-sig, nvdimm,
linux-ext4, io-uring
From: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
DAX copies data through the CPU, so it can't use a dma-buf iterator.
XFS and ext4 give DAX inodes no tag, so this is a safety net for other
callers.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
fs/dax.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/dax.c b/fs/dax.c
index 9d161d7ef3ef..feea8eae52c1 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1753,6 +1753,10 @@ dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,
if (!iomi.len)
return 0;
+ /* a dma-buf iterator has no CPU-visible pages to copy through */
+ if (iov_iter_is_dmabuf_map(iter))
+ return -EOPNOTSUPP;
+
if (iov_iter_rw(iter) == WRITE) {
lockdep_assert_held_write(&iomi.inode->i_rwsem);
iomi.flags |= IOMAP_WRITE;
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (10 preceding siblings ...)
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 ` Nitesh Shetty
2026-12-01 17:20 ` sashiko-bot
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
13 siblings, 1 reply; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Alexander Viro, Jan Kara, Dan Williams, Matthew Wilcox,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Nitesh Shetty, Anuj Gupta, linux-xfs,
linux-fsdevel, linux-doc, linux-kernel, linux-block, linux-media,
dri-devel, linaro-mm-sig, nvdimm, linux-ext4, io-uring
Implement init_dma_buf_io_ctx and dma_buf_io_tag for XFS, using the
inode's data or realtime device.
DAX inodes get no tag, nor do devices needing stable pages, as their
direct writes bounce through the CPU.
Zoned inodes are not supported yet.
Refuse dma-buf iterators in the buffered and DAX paths.
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
fs/xfs/xfs_file.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index ad1ce4f99ad8..a8440663d5e9 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -252,6 +252,9 @@ xfs_file_buffered_read(
struct xfs_inode *ip = XFS_I(file_inode(iocb->ki_filp));
ssize_t ret;
+ if (iov_iter_is_dmabuf_map(to))
+ return -EOPNOTSUPP;
+
trace_xfs_file_buffered_read(iocb, to);
ret = xfs_ilock_iocb(iocb, XFS_IOLOCK_SHARED);
@@ -964,6 +967,9 @@ xfs_file_dax_write(
ssize_t ret, error = 0;
loff_t pos;
+ if (iov_iter_is_dmabuf_map(from))
+ return -EOPNOTSUPP;
+
ret = xfs_ilock_iocb(iocb, iolock);
if (ret)
return ret;
@@ -1005,6 +1011,9 @@ xfs_file_buffered_write(
bool cleared_space = false;
unsigned int iolock;
+ if (iov_iter_is_dmabuf_map(from))
+ return -EOPNOTSUPP;
+
write_retry:
iolock = XFS_IOLOCK_EXCL;
ret = xfs_ilock_iocb(iocb, iolock);
@@ -1071,6 +1080,9 @@ xfs_file_buffered_write_zoned(
struct xfs_zone_alloc_ctx ac = { };
ssize_t ret;
+ if (iov_iter_is_dmabuf_map(from))
+ return -EOPNOTSUPP;
+
ret = xfs_zoned_write_space_reserve(mp, iocb, from, XFS_ZR_GREEDY, &ac);
if (ret < 0)
return ret;
@@ -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);
+}
+
const struct file_operations xfs_file_operations = {
.llseek = xfs_file_llseek,
.read_iter = xfs_file_read_iter,
.write_iter = xfs_file_write_iter,
+ .init_dma_buf_io_ctx = xfs_file_init_dma_buf_io_ctx,
+ .dma_buf_io_tag = xfs_file_dma_buf_io_tag,
.splice_read = xfs_file_splice_read,
.splice_write = iter_file_splice_write,
.iopoll = iocb_bio_iopoll,
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [RFC PATCH v3 13/13] ext4: support dma-buf registered buffers for direct I/O
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (11 preceding siblings ...)
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 15:59 ` Nitesh Shetty
2026-12-01 17:20 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 sashiko-bot
13 siblings, 0 replies; 18+ messages in thread
From: Nitesh Shetty @ 2026-12-01 15:59 UTC (permalink / raw)
To: Christian Brauner, Darrick J. Wong, Jonathan Corbet, Shuah Khan,
Randy Dunlap, Jens Axboe, Sumit Semwal, Christian König,
Dan Williams, Matthew Wilcox, Jan Kara, Alexander Viro,
Theodore Ts'o, Andreas Dilger, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, Carlos Maiolino, Pavel Begunkov
Cc: gost.dev, nitheshshetty, Mengmeng Zhao, Li Wang, Anuj Gupta,
Nitesh Shetty, linux-xfs, linux-fsdevel, linux-doc, linux-kernel,
linux-block, linux-media, dri-devel, linaro-mm-sig, nvdimm,
linux-ext4, io-uring
From: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Implement init_dma_buf_io_ctx and dma_buf_io_tag for ext4, using s_bdev.
Inodes that can't do direct I/O without the page cache get no tag,
namely DAX, encryption, verity, inline data and data=journal.
Refuse dma-buf iterators in the buffered and DAX paths.
A short direct write is returned as is instead of falling back to
buffered I/O.
Signed-off-by: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
Signed-off-by: Li Wang <liwang@kylinos.cn>
Signed-off-by: Anuj Gupta <anuj20.g@samsung.com>
Signed-off-by: Nitesh Shetty <nj.shetty@samsung.com>
---
fs/ext4/ext4.h | 10 ++++++++++
fs/ext4/file.c | 45 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 52 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index dc2c181337a1..5e622175df97 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -4402,6 +4402,16 @@ static inline bool ext4_inode_can_atomic_write(struct inode *inode)
ext4_dio_alignment(inode) != 0;
}
+/*
+ * Encrypted inodes can do direct I/O, but it may go through the blk-crypto
+ * fallback, which copies the data through the CPU.
+ */
+static inline bool ext4_inode_can_dmabuf_io(struct inode *inode)
+{
+ return !IS_DAX(inode) && !IS_ENCRYPTED(inode) &&
+ ext4_dio_alignment(inode) != 0;
+}
+
extern int ext4_block_write_begin(handle_t *handle, struct folio *folio,
loff_t pos, unsigned len,
get_block_t *get_block);
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index cfb22d0d5728..c35ce9eecd39 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -30,6 +30,7 @@
#include <linux/uio.h>
#include <linux/mman.h>
#include <linux/backing-dev.h>
+#include <linux/blkdev.h>
#include "ext4.h"
#include "ext4_jbd2.h"
#include "xattr.h"
@@ -66,6 +67,14 @@ static bool ext4_should_use_dio(struct kiocb *iocb, struct iov_iter *iter)
return IS_ALIGNED(iocb->ki_pos | iov_iter_alignment(iter), dio_align);
}
+static ssize_t ext4_buffered_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+ if (iov_iter_is_dmabuf_map(to))
+ return -EOPNOTSUPP;
+
+ return generic_file_read_iter(iocb, to);
+}
+
static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
{
ssize_t ret;
@@ -88,7 +97,7 @@ static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
* taken.
*/
iocb->ki_flags &= ~IOCB_DIRECT;
- return generic_file_read_iter(iocb, to);
+ return ext4_buffered_read_iter(iocb, to);
}
ret = iomap_dio_read_simple(iocb, to, ext4_iomap_begin);
@@ -119,7 +128,7 @@ static ssize_t ext4_dax_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (!IS_DAX(inode)) {
inode_unlock_shared(inode);
/* Fallback to buffered IO in case we cannot support DAX */
- return generic_file_read_iter(iocb, to);
+ return ext4_buffered_read_iter(iocb, to);
}
ret = dax_iomap_rw(iocb, to, ext4_iomap_next);
inode_unlock_shared(inode);
@@ -146,7 +155,7 @@ static ssize_t ext4_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (iocb->ki_flags & IOCB_DIRECT)
return ext4_dio_read_iter(iocb, to);
- return generic_file_read_iter(iocb, to);
+ return ext4_buffered_read_iter(iocb, to);
}
static ssize_t ext4_file_splice_read(struct file *in, loff_t *ppos,
@@ -362,6 +371,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
if (iocb->ki_flags & IOCB_ATOMIC)
return -EOPNOTSUPP;
+ if (iov_iter_is_dmabuf_map(from))
+ return -EOPNOTSUPP;
+
inode_lock(inode);
/*
@@ -696,6 +708,13 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
ssize_t err;
loff_t endbyte;
+ /*
+ * A dma-buf iterator can't go through the page cache, so return
+ * the short write instead of falling back to buffered I/O.
+ */
+ if (iov_iter_is_dmabuf_map(from))
+ return ret;
+
/*
* Buffered I/O provides no torn-write protection, so never
* finish an atomic write through the page cache. iomap must
@@ -740,6 +759,9 @@ ext4_dax_write_iter(struct kiocb *iocb, struct iov_iter *from)
bool extend = false;
struct inode *inode = file_inode(iocb->ki_filp);
+ if (iov_iter_is_dmabuf_map(from))
+ return -EOPNOTSUPP;
+
if (iocb->ki_flags & IOCB_NOWAIT) {
if (!inode_trylock(inode))
return -EAGAIN;
@@ -1059,10 +1081,27 @@ loff_t ext4_llseek(struct file *file, loff_t offset, int whence)
return vfs_setpos(file, offset, maxbytes);
}
+static u64 ext4_file_dma_buf_io_tag(struct file *file)
+{
+ struct inode *inode = file_inode(file);
+
+ if (!ext4_inode_can_dmabuf_io(inode))
+ return 0;
+ return bdev_dma_buf_io_tag(inode->i_sb->s_bdev);
+}
+
+static int ext4_file_init_dma_buf_io_ctx(struct file *file,
+ struct dma_buf_io_ctx *ctx)
+{
+ return bdev_init_dma_buf_io_ctx(file_inode(file)->i_sb->s_bdev, ctx);
+}
+
const struct file_operations ext4_file_operations = {
.llseek = ext4_llseek,
.read_iter = ext4_file_read_iter,
.write_iter = ext4_file_write_iter,
+ .init_dma_buf_io_ctx = ext4_file_init_dma_buf_io_ctx,
+ .dma_buf_io_tag = ext4_file_dma_buf_io_tag,
.iopoll = iocb_bio_iopoll,
.unlocked_ioctl = ext4_ioctl,
#ifdef CONFIG_COMPAT
--
2.47.3
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [RFC PATCH v3 05/13] io_uring/dma-buf: switch to tag file filtering
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
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01 17:10 UTC (permalink / raw)
To: Nitesh Shetty; +Cc: dri-devel, nvdimm, linux-ext4, tytso, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] io_uring/dma-buf: fput() in __io_register_dmabuf() unpins
importer module
--
commit 2e02bfbc83fd62e0046f2d9e78bfc97e418c5fff
Author: Pavel Begunkov <asml.silence@gmail.com>
io_uring/dma-buf: switch to tag file filtering
This commit replaces the exact target_file check on registered dma-bufs
with tag-based file compatibility checking via dma_buf_io_file_compatible()
and drops the target_file reference at the end of __io_register_dmabuf().
> diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
> index fd9b8769818ad..fe735a8773b73 100644
> --- a/io_uring/dma-buf.c
> +++ b/io_uring/dma-buf.c
> @@ -4,7 +4,6 @@ static inline void io_release_dmabuf(void *priv)
> {
> struct io_buf_dma *bd = io_priv_to_dmabuf(priv);
>
> - fput(bd->target_file);
> dma_buf_io_ctx_release(bd->ctx);
> kfree(bd);
> }
> @@ -52,13 +51,13 @@ int __io_register_dmabuf(struct io_ring_ctx *ctx,
> if (ret)
> goto err;
>
> - bd->target_file = target_file;
> imu->len = dmabuf->size;
> imu->release = io_release_dmabuf;
> imu->priv = bd;
> imu->flags = IO_REGBUF_F_DMABUF;
> imu->dir = IO_BUF_DEST | IO_BUF_SOURCE;
> dma_buf_put(dmabuf);
> + fput(target_file);
> return 0;
[Severity: High]
Can dropping target_file in __io_register_dmabuf() allow the importer
driver module to be unloaded while bd->ctx is still registered?
When userspace closes target_fd and no other files remain open on the
device (such as an NVMe namespace), nvme_ns_release() and bdev_release()
drop the module references on nvme.ko and nvme-core.ko. Neither
dma_buf_io_ctx_create() nor nvme_init_io_ctx_locked() pins the importer
module; nvme_init_io_ctx_locked() only takes a kobject reference via
nvme_get_ctrl(ctrl) and sets ctx->dev_ops = &nvme_dma_buf_io_ops.
If nvme.ko is then unloaded while the buffer stays registered,
nvme_remove() detaches the dma-buf and drops the driver's ctrl reference,
and the later io_release_dmabuf() -> dma_buf_io_ctx_release() call invokes
ctx->dev_ops->release(ctx) and ctrl->ops->free_ctrl(ctrl) in unmapped
module memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201155938.3028275-1-nj.shetty@samsung.com?part=5
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFC PATCH v3 09/13] iomap: don't ask for a buffered fallback for dma-buf iterators
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
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01 17:16 UTC (permalink / raw)
To: Nitesh Shetty; +Cc: dri-devel, nvdimm, linux-ext4, tytso, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] iomap: blocking -EAGAIN on -EBUSY in __iomap_dio_rw() breaks
XFS and IOPOLL
--
commit e6c38297f83152550306506a0aa0d60de11399b1
Author: Mengmeng Zhao <zhaomengmeng@kylinos.cn>
iomap: don't ask for a buffered fallback for dma-buf iterators
This commit updates __iomap_dio_rw() so that dma-buf iterators do not
return -ENOTBLK to request a buffered I/O fallback, instead mapping page
invalidation -EBUSY failures to -EAGAIN and zero-progress -ENOTBLK
callbacks to -EOPNOTSUPP.
> diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
> index 1cd907204501f..be7f3ef57d8a4 100644
> --- a/fs/iomap/direct-io.c
> +++ b/fs/iomap/direct-io.c
[ ... ]
> @@ -832,6 +834,13 @@ __iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
> * the caller tries again.
> */
> ret = -EAGAIN;
> + } else if (iov_iter_is_dmabuf_map(iter)) {
> + /*
> + * a busy folio is transient, let the
> + * caller retry the direct write
> + */
> + if (ret == -EBUSY)
> + ret = -EAGAIN;
> } else {
> /* fall back to buffered write */
> ret = -ENOTBLK;
[Severity: High]
Can mapping -EBUSY to -EAGAIN when IOCB_NOWAIT is clear trigger an
ASSERT failure and an infinite loop in xfs_file_dio_write_unaligned()?
When IOCB_NOWAIT is not set, kiocb_invalidate_pages() blocks on
writeback and returns -EBUSY from invalidate_inode_pages2_range() if a
folio in the target range remains pinned or dirty. For a sector-aligned
but block-unaligned blocking direct write in XFS, the exclusive retry
pass clears IOMAP_DIO_OVERWRITE_ONLY and assumes -EAGAIN can only come
from the initial overwrite-only attempt:
fs/xfs/xfs_file.c:xfs_file_dio_write_unaligned() {
...
retry_exclusive:
iolock = XFS_IOLOCK_EXCL;
flags = IOMAP_DIO_FORCE_WAIT;
...
ret = iomap_dio_rw(iocb, from, &xfs_direct_write_iomap_ops,
&xfs_dio_write_ops, flags, NULL, 0);
/*
* Retry unaligned I/O with exclusive blocking semantics if the
*DIO layer rejected it for mapping or locking reasons. If we are
* doing nonblocking user I/O, propagate the error.
*/
if (ret == -EAGAIN && !(iocb->ki_flags & IOCB_NOWAIT)) {
ASSERT(flags & IOMAP_DIO_OVERWRITE_ONLY);
xfs_iunlock(ip, iolock);
goto retry_exclusive;
}
...
}
Returning -EAGAIN on the retry_exclusive pass trips this ASSERT and
loops back to retry_exclusive indefinitely while the folio stays busy.
On an io_uring ring configured with IORING_SETUP_IOPOLL, returning
-EAGAIN to a blocking io-wq worker similarly causes io_write() and
io_wq_submit_work() to spin retrying io_issue_sqe(). Leaving ret as
-EBUSY returns the invalidation failure directly to the caller.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201155938.3028275-1-nj.shetty@samsung.com?part=9
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O
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
0 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01 17:20 UTC (permalink / raw)
To: Nitesh Shetty; +Cc: dri-devel, nvdimm, linux-ext4, tytso, media-ci
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
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4
2026-12-01 15:59 ` [RFC PATCH v3 00/13] fs: dma-buf direct I/O for XFS and ext4 Nitesh Shetty
` (12 preceding siblings ...)
2026-12-01 15:59 ` [RFC PATCH v3 13/13] ext4: " Nitesh Shetty
@ 2026-12-01 17:20 ` sashiko-bot
13 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-12-01 17:20 UTC (permalink / raw)
To: Nitesh Shetty; +Cc: linux-ext4, tytso
Sashiko has finished reviewing this 13-patch series:
- Patches 1-4, 6-8, 10, 11, and 13: no issues found.
- Patch 5 ("io_uring/dma-buf: switch to tag file filtering"): 1
potential issue (1 High)
- Patch 9 ("iomap: don't ask for a buffered fallback for dma-buf..."): 1
potential issue (1 High)
- Patch 12 ("xfs: support dma-buf registered buffers for direct I/O"): 1
potential issue (1 High)
Detailed reviews have been sent as separate replies to patches 5, 9, and
12.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201155938.3028275-1-nj.shetty@samsung.com
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-12-01 17:20 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox