diff options
author | Jens Axboe <axboe@kernel.dk> | 2024-10-27 16:08:31 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-11-02 22:45:30 +0100 |
commit | b54a14041ee6444692d95ff38c8b3d1af682aa17 (patch) | |
tree | 658c5839cb2eb6dd19429c5e4911ea9cd727d664 /io_uring/filetable.c | |
parent | io_uring/rsrc: unify file and buffer resource tables (diff) | |
download | linux-b54a14041ee6444692d95ff38c8b3d1af682aa17.tar.xz linux-b54a14041ee6444692d95ff38c8b3d1af682aa17.zip |
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/filetable.c')
-rw-r--r-- | io_uring/filetable.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/io_uring/filetable.c b/io_uring/filetable.c index c1f9f9550446..7a9de6718b8a 100644 --- a/io_uring/filetable.c +++ b/io_uring/filetable.c @@ -58,7 +58,7 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file, u32 slot_index) __must_hold(&req->ctx->uring_lock) { - struct io_rsrc_node *node; + struct io_rsrc_node *node, *old_node; if (io_is_uring_fops(file)) return -EBADF; @@ -71,9 +71,9 @@ static int io_install_fixed_file(struct io_ring_ctx *ctx, struct file *file, if (!node) return -ENOMEM; - slot_index = array_index_nospec(slot_index, ctx->file_table.data.nr); - if (ctx->file_table.data.nodes[slot_index]) - io_put_rsrc_node(ctx->file_table.data.nodes[slot_index]); + old_node = io_rsrc_node_lookup(&ctx->file_table.data, slot_index); + if (old_node) + io_put_rsrc_node(old_node); else io_file_bitmap_set(&ctx->file_table, slot_index); @@ -123,15 +123,17 @@ int io_fixed_fd_install(struct io_kiocb *req, unsigned int issue_flags, int io_fixed_fd_remove(struct io_ring_ctx *ctx, unsigned int offset) { + struct io_rsrc_node *node; + if (unlikely(!ctx->file_table.data.nr)) return -ENXIO; if (offset >= ctx->file_table.data.nr) return -EINVAL; - offset = array_index_nospec(offset, ctx->file_table.data.nr); - if (!ctx->file_table.data.nodes[offset]) + node = io_rsrc_node_lookup(&ctx->file_table.data, offset); + if (!node) return -EBADF; - io_put_rsrc_node(ctx->file_table.data.nodes[offset]); + io_put_rsrc_node(node); ctx->file_table.data.nodes[offset] = NULL; io_file_bitmap_clear(&ctx->file_table, offset); return 0; |