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 Signed-off-by: Nitesh Shetty --- 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