[PATCH 3/5] io_uring: fix reassigning work.task_pid from io-wq

From: Pavel Begunkov
Date: Tue Feb 11 2020 - 15:03:03 EST


If a request got into io-wq context, io_prep_async_work() has already
been called. Most of the stuff there is idempotent with an exception
that it'll set work.task_pid to task_pid_vnr() of an io_wq worker thread

Do only what's needed, that's io_prep_linked_timeout() and setting
IO_WQ_WORK_UNBOUND.

Signed-off-by: Pavel Begunkov <asml.silence@xxxxxxxxx>
---
fs/io_uring.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 04680d2c205c..f3108bce4afe 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -948,6 +948,17 @@ static inline void io_req_work_drop_env(struct io_kiocb *req)
}
}

+static inline void io_prep_next_work(struct io_kiocb *req,
+ struct io_kiocb **link)
+{
+ const struct io_op_def *def = &io_op_defs[req->opcode];
+
+ if (!(req->flags & REQ_F_ISREG) && def->unbound_nonreg_file)
+ req->work.flags |= IO_WQ_WORK_UNBOUND;
+
+ *link = io_prep_linked_timeout(req);
+}
+
static inline bool io_prep_async_work(struct io_kiocb *req,
struct io_kiocb **link)
{
@@ -2453,7 +2464,7 @@ static void io_wq_assign_next(struct io_wq_work **workptr, struct io_kiocb *nxt)
{
struct io_kiocb *link;

- io_prep_async_work(nxt, &link);
+ io_prep_next_work(nxt, &link);
*workptr = &nxt->work;
if (link) {
nxt->work.flags |= IO_WQ_WORK_CB;
--
2.24.0