[PATCH v4 07/14] block: forward init_dma_buf_io_ctx to drivers

From: Pavel Begunkov

Date: Tue Jul 28 2026 - 17:38:26 EST


Add a simple proxy implementation of init_dma_buf_io_ctx() forwarding
the call to a new struct block_device_operations operation.

Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
---
block/fops.c | 14 ++++++++++++++
include/linux/blkdev.h | 2 ++
2 files changed, 16 insertions(+)

diff --git a/block/fops.c b/block/fops.c
index 37d491f45015..d83cdbab65a6 100644
--- a/block/fops.c
+++ b/block/fops.c
@@ -926,6 +926,19 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc)
return generic_file_mmap_prepare(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 (!disk->fops->init_dma_buf_io_ctx)
+ return -EINVAL;
+ return disk->fops->init_dma_buf_io_ctx(bdev, ctx);
+}
+
const struct file_operations def_blk_fops = {
.open = blkdev_open,
.release = blkdev_release,
@@ -944,6 +957,7 @@ const struct file_operations def_blk_fops = {
.fallocate = blkdev_fallocate,
.uring_cmd = blkdev_uring_cmd,
.fop_flags = FOP_BUFFER_RASYNC,
+ .init_dma_buf_io_ctx = blkdev_init_dma_buf_io_ctx,
};

static __init int blkdev_init(void)
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 9213a5716f95..9f4c92e51dc9 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1682,6 +1682,8 @@ struct block_device_operations {
/* returns the length of the identifier or a negative errno: */
int (*get_unique_id)(struct gendisk *disk, u8 id[16],
enum blk_unique_id id_type);
+ int (*init_dma_buf_io_ctx)(struct block_device *,
+ struct dma_buf_io_ctx *);
struct module *owner;
const struct pr_ops *pr_ops;

--
2.54.0