summaryrefslogtreecommitdiff
path: root/io_uring/uring_cmd.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/uring_cmd.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/uring_cmd.c')
-rw-r--r--io_uring/uring_cmd.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c
index 17d5f5004702..535909a38e76 100644
--- a/io_uring/uring_cmd.c
+++ b/io_uring/uring_cmd.c
@@ -209,18 +209,17 @@ int io_uring_cmd_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
if (ioucmd->flags & IORING_URING_CMD_FIXED) {
struct io_ring_ctx *ctx = req->ctx;
- u16 index;
+ struct io_rsrc_node *node;
- index = READ_ONCE(sqe->buf_index);
- if (unlikely(index >= ctx->buf_table.nr))
+ node = io_rsrc_node_lookup(&ctx->buf_table, req->buf_index);
+ if (unlikely(!node))
return -EFAULT;
- req->buf_index = array_index_nospec(index, ctx->buf_table.nr);
/*
* Pi node upfront, prior to io_uring_cmd_import_fixed()
* being called. This prevents destruction of the mapped buffer
* we'll need at actual import time.
*/
- io_req_assign_rsrc_node(req, ctx->buf_table.nodes[req->buf_index]);
+ io_req_assign_rsrc_node(req, node);
}
ioucmd->cmd_op = READ_ONCE(sqe->cmd_op);