On Tue, Dec 01, 2026 at 05:16:50PM +0000, [email protected] wrote:
> 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 <[email protected]>
> 
> 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.

Correct, maybe just return original error when the iter is dmabuf 
without the EAGAIN convertion. Will send a new patch soon. 

> 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.
> 
IOPOLL can't be used with dma-buf, there is check in __io_register_dmabuf
and return -EOPNOTSUPP.
> -- 
> Sashiko AI review ยท 
> https://sashiko.dev/#/patchset/[email protected]?part=9

Reply via email to