]> git.hungrycats.org Git - linux/commitdiff
io_uring: free XArray nodes left by a failed store
authorChris Mason <mason@kernel.org>
Wed, 4 Nov 2026 18:44:08 +0000 (11:44 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 6 Nov 2026 17:06:12 +0000 (12:06 -0500)
Commit 51bab09b7ca1a9a6dd9303a3b7ee346f8128c963 upstream.

A failed xa_store() can leave nodes without entries in the tree, and
erasing every entry doesn't free those. An XArray needs xa_destroy()
before it goes away, even an empty one. That was dropped for tctx->xa in
commit ca6484cd308a ("io_uring: no need to call xa_destroy() on empty
xarray") over a lockdep report from freeing the tctx in softirq context,
and ctx->personalities never had it.

Now that the nodes are charged, a store can fail at memory.max and the
leaked nodes stay charged. Call xa_destroy() in io_uring_clean_tctx(),
which the task runs itself in process context before the tctx is freed,
in the error path of __io_uring_add_tctx_node(), and for
ctx->personalities in io_ring_ctx_free().

Fixes: ca6484cd308a ("io_uring: no need to call xa_destroy() on empty xarray")
Signed-off-by: Chris Mason <mason@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
[axboe: 6.18 installs the tctx before adding the node and has no error
path that frees it, drop that hunk. There's no ctx->hpage_acct either]
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
io_uring/io_uring.c
io_uring/tctx.c

index f1cd0e2b5b68d0dfb6b78242359f3de2e780c17a..ac097a9ac8c06849fe5c45e8b609cadc6dea2143 100644 (file)
@@ -3039,6 +3039,7 @@ static __cold void io_ring_ctx_free(struct io_ring_ctx *ctx)
        io_napi_free(ctx);
        kvfree(ctx->cancel_table.hbs);
        xa_destroy(&ctx->io_bl_xa);
+       xa_destroy(&ctx->personalities);
        kfree(ctx);
 }
 
index bf851ba5ca1a365dcdb63bcd0c580e595cd1288b..0e4445d3a83c9e0d4c15cf75edbe2cbe5c69f814 100644 (file)
@@ -206,6 +206,8 @@ __cold void io_uring_clean_tctx(struct io_uring_task *tctx)
                io_uring_del_tctx_node(index);
                cond_resched();
        }
+       /* A failed xa_store() leaves nodes with no entry behind. */
+       xa_destroy(&tctx->xa);
        if (wq) {
                /*
                 * Must be after io_uring_del_tctx_node() (removes nodes under