提交 1dd60f09 编写于 作者: P Pavel Begunkov 提交者: Joseph Qi

io_uring: hide uring_fd in ctx

to #26323588

commit b14cca0c84c760fbd39ad6bb7e1181e2df103d25 upstream.

req->ring_fd and req->ring_file are used only during the prep stage
during submission, which is is protected by mutex. There is no need
to store them per-request, place them in ctx.
Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Acked-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
上级 bdff4da9
...@@ -251,6 +251,8 @@ struct io_ring_ctx { ...@@ -251,6 +251,8 @@ struct io_ring_ctx {
*/ */
struct fixed_file_data *file_data; struct fixed_file_data *file_data;
unsigned nr_user_files; unsigned nr_user_files;
int ring_fd;
struct file *ring_file;
/* if used, fixed mapped user buffers */ /* if used, fixed mapped user buffers */
unsigned nr_user_bufs; unsigned nr_user_bufs;
...@@ -475,15 +477,10 @@ struct io_kiocb { ...@@ -475,15 +477,10 @@ struct io_kiocb {
}; };
struct io_async_ctx *io; struct io_async_ctx *io;
union { /*
/* * llist_node is only used for poll deferred completions
* ring_file is only used in the submission path, and */
* llist_node is only used for poll deferred completions struct llist_node llist_node;
*/
struct file *ring_file;
struct llist_node llist_node;
};
int ring_fd;
bool has_user; bool has_user;
bool in_async; bool in_async;
bool needs_fixed_file; bool needs_fixed_file;
...@@ -1141,7 +1138,6 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx, ...@@ -1141,7 +1138,6 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
got_it: got_it:
req->io = NULL; req->io = NULL;
req->ring_file = NULL;
req->file = NULL; req->file = NULL;
req->ctx = ctx; req->ctx = ctx;
req->flags = 0; req->flags = 0;
...@@ -2722,7 +2718,7 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -2722,7 +2718,7 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
req->close.fd = READ_ONCE(sqe->fd); req->close.fd = READ_ONCE(sqe->fd);
if (req->file->f_op == &io_uring_fops || if (req->file->f_op == &io_uring_fops ||
req->close.fd == req->ring_fd) req->close.fd == req->ctx->ring_fd)
return -EBADF; return -EBADF;
return 0; return 0;
...@@ -4392,7 +4388,7 @@ static int io_grab_files(struct io_kiocb *req) ...@@ -4392,7 +4388,7 @@ static int io_grab_files(struct io_kiocb *req)
int ret = -EBADF; int ret = -EBADF;
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
if (!req->ring_file) if (!ctx->ring_file)
return -EBADF; return -EBADF;
rcu_read_lock(); rcu_read_lock();
...@@ -4403,7 +4399,7 @@ static int io_grab_files(struct io_kiocb *req) ...@@ -4403,7 +4399,7 @@ static int io_grab_files(struct io_kiocb *req)
* the fd has changed since we started down this path, and disallow * the fd has changed since we started down this path, and disallow
* this operation if it has. * this operation if it has.
*/ */
if (fcheck(req->ring_fd) == req->ring_file) { if (fcheck(ctx->ring_fd) == ctx->ring_file) {
list_add(&req->inflight_entry, &ctx->inflight_list); list_add(&req->inflight_entry, &ctx->inflight_list);
req->flags |= REQ_F_INFLIGHT; req->flags |= REQ_F_INFLIGHT;
req->work.files = current->files; req->work.files = current->files;
...@@ -4775,6 +4771,9 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, ...@@ -4775,6 +4771,9 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
statep = &state; statep = &state;
} }
ctx->ring_fd = ring_fd;
ctx->ring_file = ring_file;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
const struct io_uring_sqe *sqe; const struct io_uring_sqe *sqe;
struct io_kiocb *req; struct io_kiocb *req;
...@@ -4807,8 +4806,6 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr, ...@@ -4807,8 +4806,6 @@ static int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr,
} }
} }
req->ring_file = ring_file;
req->ring_fd = ring_fd;
req->has_user = *mm != NULL; req->has_user = *mm != NULL;
req->in_async = async; req->in_async = async;
req->needs_fixed_file = async; req->needs_fixed_file = async;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册