]> www.infradead.org Git - users/hch/misc.git/commitdiff
io_uring: don't post tag CQEs on file/buffer registration failure
authorPavel Begunkov <asml.silence@gmail.com>
Fri, 4 Apr 2025 14:46:34 +0000 (15:46 +0100)
committerJens Axboe <axboe@kernel.dk>
Fri, 4 Apr 2025 15:40:44 +0000 (09:40 -0600)
Buffer / file table registration is all or nothing, if it fails all
resources we might have partially registered are dropped and the table
is killed. If that happens, it doesn't make sense to post any rsrc tag
CQEs. That would be confusing to the application, which should not need
to handle that case.

Cc: stable@vger.kernel.org
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Fixes: 7029acd8a9503 ("io_uring/rsrc: get rid of per-ring io_rsrc_node list")
Link: https://lore.kernel.org/r/c514446a8dcb0197cddd5d4ba8f6511da081cf1f.1743777957.git.asml.silence@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
io_uring/rsrc.c

index 5e64a8bb30a451c4e0b4ea9ccf56ecb20ce63e54..b36c8825550eff74a53667d7e45bfe9b5ba583ae 100644 (file)
@@ -175,6 +175,18 @@ void io_rsrc_cache_free(struct io_ring_ctx *ctx)
        io_alloc_cache_free(&ctx->imu_cache, kfree);
 }
 
+static void io_clear_table_tags(struct io_rsrc_data *data)
+{
+       int i;
+
+       for (i = 0; i < data->nr; i++) {
+               struct io_rsrc_node *node = data->nodes[i];
+
+               if (node)
+                       node->tag = 0;
+       }
+}
+
 __cold void io_rsrc_data_free(struct io_ring_ctx *ctx,
                              struct io_rsrc_data *data)
 {
@@ -583,6 +595,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
        io_file_table_set_alloc_range(ctx, 0, ctx->file_table.data.nr);
        return 0;
 fail:
+       io_clear_table_tags(&ctx->file_table.data);
        io_sqe_files_unregister(ctx);
        return ret;
 }
@@ -902,8 +915,10 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
        }
 
        ctx->buf_table = data;
-       if (ret)
+       if (ret) {
+               io_clear_table_tags(&ctx->buf_table);
                io_sqe_buffers_unregister(ctx);
+       }
        return ret;
 }