summaryrefslogtreecommitdiff
path: root/io_uring/rsrc.c
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2024-10-27 09:08:31 -0600
committerJens Axboe <axboe@kernel.dk>2024-11-02 15:45:30 -0600
commitb54a14041ee6444692d95ff38c8b3d1af682aa17 (patch)
tree658c5839cb2eb6dd19429c5e4911ea9cd727d664 /io_uring/rsrc.c
parent3597f2786b687a7f26361ce00a805ea0af41b65f (diff)
io_uring/rsrc: add io_rsrc_node_lookup() helper
There are lots of spots open-coding this functionality, add a generic helper that does the node lookup in a speculation safe way. Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r--io_uring/rsrc.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
index 49a6ab5f3ae9..0380b2f4ed8d 100644
--- a/io_uring/rsrc.c
+++ b/io_uring/rsrc.c
@@ -181,6 +181,7 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
return -EINVAL;
for (done = 0; done < nr_args; done++) {
+ struct io_rsrc_node *node;
u64 tag = 0;
if ((tags && copy_from_user(&tag, &tags[done], sizeof(tag))) ||
@@ -195,9 +196,10 @@ static int __io_sqe_files_update(struct io_ring_ctx *ctx,
if (fd == IORING_REGISTER_FILES_SKIP)
continue;
- i = array_index_nospec(up->offset + done, ctx->file_table.data.nr);
- if (ctx->file_table.data.nodes[i]) {
- io_put_rsrc_node(ctx->file_table.data.nodes[i]);
+ i = up->offset + done;
+ node = io_rsrc_node_lookup(&ctx->file_table.data, i);
+ if (node) {
+ io_put_rsrc_node(node);
ctx->file_table.data.nodes[i] = NULL;
io_file_bitmap_clear(&ctx->file_table, i);
}
@@ -958,9 +960,9 @@ static int io_clone_buffers(struct io_ring_ctx *ctx, struct io_ring_ctx *src_ctx
goto out_unlock;
for (i = 0; i < nbufs; i++) {
- struct io_rsrc_node *src_node = src_ctx->buf_table.nodes[i];
- struct io_rsrc_node *dst_node;
+ struct io_rsrc_node *dst_node, *src_node;
+ src_node = io_rsrc_node_lookup(&src_ctx->buf_table, i);
if (src_node == rsrc_empty_node) {
dst_node = rsrc_empty_node;
} else {