From 66fe7abe9f956ed661d0f1064fd47ec517a03633 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 8 Sep 2026 17:03:12 +0000 Subject: [PATCH] io_uring: drop registered files and buffers at release time Registered file and buffer tables are only torn down from io_ring_ctx_free(), which only runs when all requests have completed and the ctx refs have hit zero. Before this, every registered file remains open. The resource nodes are reference counted and any request using a registered file or buffer holds its own reference to the node, so this only releases what is actually unused. The rest follow as those requests complete or get canceled. Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 3957d4f584a3..9b18ddb3c0de 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -2207,8 +2207,6 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx) io_sq_thread_finish(ctx); mutex_lock(&ctx->uring_lock); - io_sqe_buffers_unregister(ctx); - io_sqe_files_unregister(ctx); io_unregister_zcrx(ctx); io_cqring_overflow_kill(ctx); io_eventfd_unregister(ctx); @@ -2474,6 +2472,9 @@ static __cold void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx) xa_for_each(&ctx->personalities, index, creds) io_unregister_personality(ctx, index); io_terminate_zcrx(ctx); + /* Drop these now, rather than async, to unpin the files */ + io_sqe_buffers_unregister(ctx); + io_sqe_files_unregister(ctx); mutex_unlock(&ctx->uring_lock); /*