Skip to content

Commit ab6005f

Browse files
isilenceaxboe
authored andcommitted
io_uring: don't post tag CQEs on file/buffer registration failure
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: [email protected] Signed-off-by: Pavel Begunkov <[email protected]> Fixes: 7029acd ("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 <[email protected]>
1 parent e48e99b commit ab6005f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

io_uring/rsrc.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ void io_rsrc_cache_free(struct io_ring_ctx *ctx)
175175
io_alloc_cache_free(&ctx->imu_cache, kfree);
176176
}
177177

178+
static void io_clear_table_tags(struct io_rsrc_data *data)
179+
{
180+
int i;
181+
182+
for (i = 0; i < data->nr; i++) {
183+
struct io_rsrc_node *node = data->nodes[i];
184+
185+
if (node)
186+
node->tag = 0;
187+
}
188+
}
189+
178190
__cold void io_rsrc_data_free(struct io_ring_ctx *ctx,
179191
struct io_rsrc_data *data)
180192
{
@@ -583,6 +595,7 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
583595
io_file_table_set_alloc_range(ctx, 0, ctx->file_table.data.nr);
584596
return 0;
585597
fail:
598+
io_clear_table_tags(&ctx->file_table.data);
586599
io_sqe_files_unregister(ctx);
587600
return ret;
588601
}
@@ -902,8 +915,10 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
902915
}
903916

904917
ctx->buf_table = data;
905-
if (ret)
918+
if (ret) {
919+
io_clear_table_tags(&ctx->buf_table);
906920
io_sqe_buffers_unregister(ctx);
921+
}
907922
return ret;
908923
}
909924

0 commit comments

Comments
 (0)