mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file
@ 2026-11-30  7:28 Diangang Li
  2026-11-30  7:28 ` [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing Diangang Li
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Diangang Li @ 2026-11-30  7:28 UTC (permalink / raw)
  To: axboe, asml.silence; +Cc: io-uring, linux-kernel, Diangang Li

From: Diangang Li <lidiangang@bytedance.com>

io_release_dmabuf() drops the target file before destroying the I/O
context. If the final file release runs via delayed_fput_work, it can
drop the importer's module reference before the ->unmap() and ->release()
callbacks have completed.

Release the context first so the target file pins the module throughout
teardown.

Fixes: 62e4bf5b25d4 ("io_uring/rsrc: add dmabuf backed registered buffers")
Assisted-by: LLM
Signed-off-by: Diangang Li <lidiangang@bytedance.com>
---
 io_uring/dma-buf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
index 61825d59e384..255767cdb1ca 100644
--- a/io_uring/dma-buf.c
+++ b/io_uring/dma-buf.c
@@ -4,8 +4,9 @@ static inline void io_release_dmabuf(void *priv)
 {
 	struct io_buf_dma *bd = priv;
 
-	fput(bd->target_file);
+	/* the open target file keeps the importer's module loaded */
 	dma_buf_io_ctx_release(bd->ctx);
+	fput(bd->target_file);
 	kfree(bd);
 }
 
-- 
2.39.5



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing
  2026-11-30  7:28 [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Diangang Li
@ 2026-11-30  7:28 ` Diangang Li
       [not found]   ` <CGME20261203082933epcas5p1bfb229c6feb82b6722133923a9ff3de0@epcas5p1.samsung.com>
  2026-12-03 12:10 ` [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Pavel Begunkov
  2026-12-03 12:53 ` Anuj gupta
  2 siblings, 1 reply; 5+ messages in thread
From: Diangang Li @ 2026-11-30  7:28 UTC (permalink / raw)
  To: axboe, asml.silence; +Cc: io-uring, linux-kernel, Diangang Li

From: Diangang Li <lidiangang@bytedance.com>

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.

Set REQ_F_NOWAIT on this path to prevent the retry. Requests issued
directly from io-wq can still create the map in blocking mode.

Fixes: 62e4bf5b25d4 ("io_uring/rsrc: add dmabuf backed registered buffers")
Assisted-by: LLM
Signed-off-by: Diangang Li <lidiangang@bytedance.com>
---
 io_uring/rw.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3ecb842147a4..6e4e8fbc9ff1 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -368,8 +368,16 @@ static int io_init_rw_fixed(struct io_kiocb *req, unsigned int issue_flags,
 	}
 
 	ret = io_attach_dmabuf_map(req, &io->iter, issue_flags);
-	if (ret)
+	if (unlikely(ret)) {
+		/*
+		 * This runs before io_rw_init_file() sets REQ_F_NOWAIT. Set it
+		 * here for RWF_NOWAIT, or -EAGAIN for a map that doesn't exist
+		 * yet punts the request to io-wq, where it will block.
+		 */
+		if (ret == -EAGAIN && (rw->flags & RWF_NOWAIT))
+			io_req_set_flags(req, REQ_F_NOWAIT);
 		return ret;
+	}
 	return 0;
 }
 
-- 
2.39.5



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing
       [not found]   ` <CGME20261203082933epcas5p1bfb229c6feb82b6722133923a9ff3de0@epcas5p1.samsung.com>
@ 2026-12-03  8:28     ` Anuj Gupta
  0 siblings, 0 replies; 5+ messages in thread
From: Anuj Gupta @ 2026-12-03  8:28 UTC (permalink / raw)
  To: Diangang Li; +Cc: axboe, asml.silence, io-uring, linux-kernel, Diangang Li

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file
  2026-11-30  7:28 [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Diangang Li
  2026-11-30  7:28 ` [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing Diangang Li
@ 2026-12-03 12:10 ` Pavel Begunkov
  2026-12-03 12:53 ` Anuj gupta
  2 siblings, 0 replies; 5+ messages in thread
From: Pavel Begunkov @ 2026-12-03 12:10 UTC (permalink / raw)
  To: Diangang Li, axboe; +Cc: io-uring, linux-kernel, Diangang Li

On 11/30/26 07:28, Diangang Li wrote:
> From: Diangang Li <lidiangang@bytedance.com>
> 
> io_release_dmabuf() drops the target file before destroying the I/O
> context. If the final file release runs via delayed_fput_work, it can
> drop the importer's module reference before the ->unmap() and ->release()
> callbacks have completed.

Looks good. There is a discussion for 2/2, but I'd merge this
one first.

Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>

> Release the context first so the target file pins the module throughout
> teardown.
> 
> Fixes: 62e4bf5b25d4 ("io_uring/rsrc: add dmabuf backed registered buffers")
> Assisted-by: LLM
> Signed-off-by: Diangang Li <lidiangang@bytedance.com>
> ---
>   io_uring/dma-buf.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/io_uring/dma-buf.c b/io_uring/dma-buf.c
> index 61825d59e384..255767cdb1ca 100644
> --- a/io_uring/dma-buf.c
> +++ b/io_uring/dma-buf.c
> @@ -4,8 +4,9 @@ static inline void io_release_dmabuf(void *priv)
>   {
>   	struct io_buf_dma *bd = priv;
>   
> -	fput(bd->target_file);
> +	/* the open target file keeps the importer's module loaded */
>   	dma_buf_io_ctx_release(bd->ctx);
> +	fput(bd->target_file);
>   	kfree(bd);
>   }
>   

-- 
Pavel Begunkov


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file
  2026-11-30  7:28 [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Diangang Li
  2026-11-30  7:28 ` [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing Diangang Li
  2026-12-03 12:10 ` [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Pavel Begunkov
@ 2026-12-03 12:53 ` Anuj gupta
  2 siblings, 0 replies; 5+ messages in thread
From: Anuj gupta @ 2026-12-03 12:53 UTC (permalink / raw)
  To: Diangang Li; +Cc: axboe, asml.silence, io-uring, linux-kernel, Diangang Li

Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-03 12:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  7:28 [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Diangang Li
2026-11-30  7:28 ` [PATCH 2/2] io_uring/rw: honour RWF_NOWAIT when a dma-buf map is missing Diangang Li
     [not found]   ` <CGME20261203082933epcas5p1bfb229c6feb82b6722133923a9ff3de0@epcas5p1.samsung.com>
2026-12-03  8:28     ` Anuj Gupta
2026-12-03 12:10 ` [PATCH 1/2] io_uring/dma-buf: release the I/O context before the target file Pavel Begunkov
2026-12-03 12:53 ` Anuj gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®