* 5.4 backport of io_uring/io-wq fix
@ 2020-02-28 22:27 Jens Axboe
2020-02-29 3:04 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Jens Axboe @ 2020-02-28 22:27 UTC (permalink / raw)
To: stable; +Cc: Jann Horn, Sasha Levin
[-- Attachment #1: Type: text/plain, Size: 432 bytes --]
Hi,
We don't have these two commits in 5.4-stable:
ff002b30181d30cdfbca316dadd099c3ca0d739c
9392a27d88b9707145d713654eb26f0c29789e50
because they don't apply with the rework that was done in how io_uring
handles offload. Since there's no io-wq in 5.4, it doesn't make sense to
do two patches. I'm attaching my port of the two for 5.4-stable, it's
been tested. Please queue it up for the next 5.4-stable, thanks!
--
Jens Axboe
[-- Attachment #2: 0001-io_uring-grab-fs-as-part-of-async-offload.patch --]
[-- Type: text/x-patch, Size: 3345 bytes --]
From 343c693195f2424ed18be31b58d67d04df584429 Mon Sep 17 00:00:00 2001
From: Jens Axboe <axboe@kernel.dk>
Date: Fri, 28 Feb 2020 15:20:18 -0700
Subject: [PATCH] io_uring: grab ->fs as part of async offload
[ Upstream commits 9392a27d88b9 and ff002b30181d ]
Ensure that the async work grabs ->fs from the queueing task if the
punted commands needs to do lookups.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
fs/io_uring.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/fs/io_uring.c b/fs/io_uring.c
index 709671faaed6..607edaef5e71 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -71,6 +71,7 @@
#include <linux/sizes.h>
#include <linux/hugetlb.h>
#include <linux/highmem.h>
+#include <linux/fs_struct.h>
#include <uapi/linux/io_uring.h>
@@ -334,6 +335,8 @@ struct io_kiocb {
u32 result;
u32 sequence;
+ struct fs_struct *fs;
+
struct work_struct work;
};
@@ -651,6 +654,7 @@ static struct io_kiocb *io_get_req(struct io_ring_ctx *ctx,
/* one is dropped after submission, the other at completion */
refcount_set(&req->refs, 2);
req->result = 0;
+ req->fs = NULL;
return req;
out:
percpu_ref_put(&ctx->refs);
@@ -1672,6 +1676,16 @@ static int io_send_recvmsg(struct io_kiocb *req, const struct io_uring_sqe *sqe,
ret = -EINTR;
}
+ if (req->fs) {
+ struct fs_struct *fs = req->fs;
+
+ spin_lock(&req->fs->lock);
+ if (--fs->users)
+ fs = NULL;
+ spin_unlock(&req->fs->lock);
+ if (fs)
+ free_fs_struct(fs);
+ }
io_cqring_add_event(req->ctx, sqe->user_data, ret);
io_put_req(req);
return 0;
@@ -2168,6 +2182,7 @@ static inline bool io_sqe_needs_user(const struct io_uring_sqe *sqe)
static void io_sq_wq_submit_work(struct work_struct *work)
{
struct io_kiocb *req = container_of(work, struct io_kiocb, work);
+ struct fs_struct *old_fs_struct = current->fs;
struct io_ring_ctx *ctx = req->ctx;
struct mm_struct *cur_mm = NULL;
struct async_list *async_list;
@@ -2187,6 +2202,15 @@ static void io_sq_wq_submit_work(struct work_struct *work)
/* Ensure we clear previously set non-block flag */
req->rw.ki_flags &= ~IOCB_NOWAIT;
+ if (req->fs != current->fs && current->fs != old_fs_struct) {
+ task_lock(current);
+ if (req->fs)
+ current->fs = req->fs;
+ else
+ current->fs = old_fs_struct;
+ task_unlock(current);
+ }
+
ret = 0;
if (io_sqe_needs_user(sqe) && !cur_mm) {
if (!mmget_not_zero(ctx->sqo_mm)) {
@@ -2285,6 +2309,11 @@ static void io_sq_wq_submit_work(struct work_struct *work)
mmput(cur_mm);
}
revert_creds(old_cred);
+ if (old_fs_struct) {
+ task_lock(current);
+ current->fs = old_fs_struct;
+ task_unlock(current);
+ }
}
/*
@@ -2512,6 +2541,23 @@ static void io_submit_sqe(struct io_ring_ctx *ctx, struct sqe_submit *s,
req->user_data = s->sqe->user_data;
+#if defined(CONFIG_NET)
+ switch (READ_ONCE(s->sqe->opcode)) {
+ case IORING_OP_SENDMSG:
+ case IORING_OP_RECVMSG:
+ spin_lock(¤t->fs->lock);
+ if (!current->fs->in_exec) {
+ req->fs = current->fs;
+ req->fs->users++;
+ }
+ spin_unlock(¤t->fs->lock);
+ if (!req->fs) {
+ ret = -EAGAIN;
+ goto err_req;
+ }
+ }
+#endif
+
/*
* If we already have a head request, queue this one for async
* submittal once the head completes. If we don't have a head but
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: 5.4 backport of io_uring/io-wq fix
2020-02-28 22:27 5.4 backport of io_uring/io-wq fix Jens Axboe
@ 2020-02-29 3:04 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2020-02-29 3:04 UTC (permalink / raw)
To: Jens Axboe; +Cc: stable, Jann Horn
On Fri, Feb 28, 2020 at 03:27:17PM -0700, Jens Axboe wrote:
>Hi,
>
>We don't have these two commits in 5.4-stable:
>
>ff002b30181d30cdfbca316dadd099c3ca0d739c
>9392a27d88b9707145d713654eb26f0c29789e50
>
>because they don't apply with the rework that was done in how io_uring
>handles offload. Since there's no io-wq in 5.4, it doesn't make sense to
>do two patches. I'm attaching my port of the two for 5.4-stable, it's
>been tested. Please queue it up for the next 5.4-stable, thanks!
I've copied this explanation into the commit message and queued it for
5.4, thanks Jens!
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-29 3:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-02-28 22:27 5.4 backport of io_uring/io-wq fix Jens Axboe
2020-02-29 3:04 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).