public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] io_uring/futex: Recycle ifd on failure
@ 2026-09-02 17:27 Gabriel Krisman Bertazi
  2026-09-02 22:27 ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Krisman Bertazi @ 2026-09-02 17:27 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, Gabriel Krisman Bertazi

The failure path doesn't recycle the ifd on FUTEX_WAIT for no good
reason.  If we move the free above done_unlock, we are even already
holding the submit lock.  Recycle it.

Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
 io_uring/futex.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/io_uring/futex.c b/io_uring/futex.c
index eaee14242a3a..6389bd2f0399 100644
--- a/io_uring/futex.c
+++ b/io_uring/futex.c
@@ -321,20 +321,22 @@ int io_futex_wait(struct io_kiocb *req, unsigned int issue_flags)
 
 	ret = futex_wait_setup(iof->uaddr, iof->futex_val, iof->futex_flags,
 			       &ifd->q, NULL, NULL);
-	if (!ret) {
-		hlist_add_head(&req->hash_node, &ctx->futex_list);
-		io_ring_submit_unlock(ctx, issue_flags);
+	if (ret)
+		goto free_async;
 
-		return IOU_ISSUE_SKIP_COMPLETE;
-	}
+	hlist_add_head(&req->hash_node, &ctx->futex_list);
+	io_ring_submit_unlock(ctx, issue_flags);
 
+	return IOU_ISSUE_SKIP_COMPLETE;
+
+free_async:
+	io_cache_free(&ctx->futex_cache, ifd);
+	io_req_async_data_clear(req, 0);
 done_unlock:
 	io_ring_submit_unlock(ctx, issue_flags);
 done:
-	if (ret < 0)
-		req_set_fail(req);
+	req_set_fail(req);
 	io_req_set_res(req, ret, 0);
-	io_req_async_data_free(req);
 	return IOU_COMPLETE;
 }
 
-- 
2.55.0


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

end of thread, other threads:[~2026-09-02 22:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02 17:27 [PATCH] io_uring/futex: Recycle ifd on failure Gabriel Krisman Bertazi
2026-09-02 22:27 ` Jens Axboe
2026-09-02 22:41   ` Gabriel Krisman Bertazi
2026-09-02 22:41   ` Gabriel Krisman Bertazi

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