This passes it in to io-wq, so it assumes the right fs_struct when executing async work that may need to do lookups.
Cc: stable@vger.kernel.org # 5.3+ Signed-off-by: Jens Axboe axboe@kernel.dk --- fs/io_uring.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c index 1a3ca6577a10..2a7bb178986e 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -75,6 +75,7 @@ #include <linux/fsnotify.h> #include <linux/fadvise.h> #include <linux/eventpoll.h> +#include <linux/fs_struct.h>
#define CREATE_TRACE_POINTS #include <trace/events/io_uring.h> @@ -611,6 +612,8 @@ struct io_op_def { unsigned not_supported : 1; /* needs file table */ unsigned file_table : 1; + /* needs ->fs */ + unsigned needs_fs : 1; };
static const struct io_op_def io_op_defs[] = { @@ -653,12 +656,14 @@ static const struct io_op_def io_op_defs[] = { .needs_mm = 1, .needs_file = 1, .unbound_nonreg_file = 1, + .needs_fs = 1, }, [IORING_OP_RECVMSG] = { .async_ctx = 1, .needs_mm = 1, .needs_file = 1, .unbound_nonreg_file = 1, + .needs_fs = 1, }, [IORING_OP_TIMEOUT] = { .async_ctx = 1, @@ -689,6 +694,7 @@ static const struct io_op_def io_op_defs[] = { .needs_file = 1, .fd_non_neg = 1, .file_table = 1, + .needs_fs = 1, }, [IORING_OP_CLOSE] = { .needs_file = 1, @@ -702,6 +708,7 @@ static const struct io_op_def io_op_defs[] = { .needs_mm = 1, .needs_file = 1, .fd_non_neg = 1, + .needs_fs = 1, }, [IORING_OP_READ] = { .needs_mm = 1, @@ -733,6 +740,7 @@ static const struct io_op_def io_op_defs[] = { .needs_file = 1, .fd_non_neg = 1, .file_table = 1, + .needs_fs = 1, }, [IORING_OP_EPOLL_CTL] = { .unbound_nonreg_file = 1, @@ -907,6 +915,16 @@ static inline void io_req_work_grab_env(struct io_kiocb *req, } if (!req->work.creds) req->work.creds = get_current_cred(); + if (!req->work.fs && def->needs_fs) { + spin_lock(¤t->fs->lock); + if (!current->fs->in_exec) { + req->work.fs = current->fs; + req->work.fs->users++; + } else { + req->work.flags |= IO_WQ_WORK_CANCEL; + } + spin_unlock(¤t->fs->lock); + } }
static inline void io_req_work_drop_env(struct io_kiocb *req) @@ -919,6 +937,16 @@ static inline void io_req_work_drop_env(struct io_kiocb *req) put_cred(req->work.creds); req->work.creds = NULL; } + if (req->work.fs) { + struct fs_struct *fs = req->work.fs; + + spin_lock(&req->work.fs->lock); + if (--fs->users) + fs = NULL; + spin_unlock(&req->work.fs->lock); + if (fs) + free_fs_struct(fs); + } }
static inline bool io_prep_async_work(struct io_kiocb *req,
Hi,
[This is an automated email]
This commit has been processed because it contains a -stable tag. The stable tag indicates that it's relevant for the following trees: 5.3+
The bot has tested the following trees: v5.5.2, v5.4.18.
v5.5.2: Failed to apply! Possible dependencies: 05f3fb3c5397 ("io_uring: avoid ring quiesce for fixed file set unregister and update") 15b71abe7b52 ("io_uring: add support for IORING_OP_OPENAT") 3a6820f2bb8a ("io_uring: add non-vectored read/write commands") 3e4827b05d2a ("io_uring: add support for epoll_ctl(2)") 4840e418c2fc ("io_uring: add IORING_OP_FADVISE") b5dba59e0cf7 ("io_uring: add support for IORING_OP_CLOSE") d3656344fea0 ("io_uring: add lookup table for various opcode needs") d63d1b5edb7b ("io_uring: add support for fallocate()") eddc7ef52a6b ("io_uring: add support for IORING_OP_STATX")
v5.4.18: Failed to apply! Possible dependencies: 15b71abe7b52 ("io_uring: add support for IORING_OP_OPENAT") 2665abfd757f ("io_uring: add support for linked SQE timeouts") 3e4827b05d2a ("io_uring: add support for epoll_ctl(2)") 3fbb51c18f5c ("io_uring: move all prep state for IORING_OP_CONNECT to prep handler") 4840e418c2fc ("io_uring: add IORING_OP_FADVISE") 561fb04a6a22 ("io_uring: replace workqueue usage with io-wq") 771b53d033e8 ("io-wq: small threadpool implementation for io_uring") 8ed8d3c3bc32 ("io_uring: any deferred command must have stable sqe data") 9adbd45d6d32 ("io_uring: add and use struct io_rw for read/writes") ad8a48acc23c ("io_uring: make req->timeout be dynamically allocated") b29472ee7b53 ("io_uring: make IORING_OP_TIMEOUT_REMOVE deferrable") ba5290ccb6b5 ("io_uring: replace s->needs_lock with s->in_async") ba816ad61fdf ("io_uring: run dependent links inline if possible") c826bd7a743f ("io_uring: add set of tracing events") e47293fdf989 ("io_uring: move all prep state for IORING_OP_{SEND,RECV}_MGS to prep handler") fbf23849b172 ("io_uring: make IORING_OP_CANCEL_ASYNC deferrable") fcb323cc53e2 ("io_uring: io_uring: add support for async work inheriting files")
NOTE: The patch will not be queued to stable trees until it is upstream.
How should we proceed with this patch?
linux-stable-mirror@lists.linaro.org