Re: [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing

From: Anuj Gupta

Date: Thu Dec 03 2026 - 03:30:34 EST


On Mon, Nov 30, 2026 at 03:28:37PM +0800, Diangang Li wrote:
> On nonblocking issue, io_attach_dmabuf_map() returns -EAGAIN if no map is
> available. This happens before io_rw_init_file() sets REQ_F_NOWAIT, so
> an RWF_NOWAIT request is punted to io-wq and can block instead of
> completing with -EAGAIN.

RWF_NOWAIT is still ignored when the request is issued directly from
io-wq, for example with IOSQE_ASYNC. In that case, IO_URING_F_NONBLOCK
may not be set, so map creation can block.

One option is to pass a nowait argument to io_attach_dmabuf_map() that
takes both flags into account. Something like this, on top of this
patch [1]

Also, when the map is missing, an app doing only RWF_NOWAIT I/O would
keep getting -EAGAIN. It would need a blocking I/O to create the map,
including after invalidation.

[1]
diff --git a/io_uring/dma-buf.h b/io_uring/dma-buf.h
index d8d9b4f224d8..cb9c2d984ab5 100644
--- a/io_uring/dma-buf.h
+++ b/io_uring/dma-buf.h
@@ -28,9 +28,8 @@ static inline void io_detach_dmabuf_map(struct io_kiocb *req)

static inline int io_attach_dmabuf_map(struct io_kiocb *req,
struct iov_iter *iter,
- unsigned issue_flags)
+ bool nowait)
{
- bool nowait = issue_flags & IO_URING_F_NONBLOCK;
struct dma_buf_io_map *map;
struct io_buf_dma *bd;

diff --git a/io_uring/rw.c b/io_uring/rw.c
index 6e4e8fbc9ff1..cca27ab29c58 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -357,6 +357,8 @@ static int io_init_rw_fixed(struct io_kiocb *req, unsigned int issue_flags,
{
struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw);
struct io_async_rw *io = req->async_data;
+ bool nowait = (issue_flags & IO_URING_F_NONBLOCK) ||
+ (rw->flags & RWF_NOWAIT);
int ret;

if (!io->bytes_done) {
@@ -367,7 +369,7 @@ static int io_init_rw_fixed(struct io_kiocb *req, unsigned int issue_flags,
iov_iter_save_state(&io->iter, &io->iter_state);
}

- ret = io_attach_dmabuf_map(req, &io->iter, issue_flags);
+ ret = io_attach_dmabuf_map(req, &io->iter, nowait);
if (unlikely(ret)) {
/*
* This runs before io_rw_init_file() sets REQ_F_NOWAIT. Set it