2020-02-11 21:40:51

by Pavel Begunkov

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

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 <[email protected]>
---
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


2020-02-11 21:41:44

by Jens Axboe

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

On 2/11/20 1:01 PM, Pavel Begunkov wrote:
> 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.

Rest of the series aside, I'm going to fix-up the pid addition to
only set if it's zero like the others.

--
Jens Axboe

2020-02-11 21:42:26

by Pavel Begunkov

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

On 11/02/2020 23:21, Jens Axboe wrote:
> On 2/11/20 1:01 PM, Pavel Begunkov wrote:
>> 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.
>
> Rest of the series aside, I'm going to fix-up the pid addition to
> only set if it's zero like the others.

IMO, io_req_work_grab_env() should never be called from io-wq. It'd do nothing
good but open space for subtle bugs. And if that's enforced (as done in this
patch), it's safe to set @pid multiple times.

Probably, it worth to add the check just to not go through task_pid_vnr()
several times.

--
Pavel Begunkov


Attachments:
signature.asc (849.00 B)
OpenPGP digital signature

2020-02-11 21:43:26

by Jens Axboe

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

On 2/11/20 1:57 PM, Pavel Begunkov wrote:
> On 11/02/2020 23:21, Jens Axboe wrote:
>> On 2/11/20 1:01 PM, Pavel Begunkov wrote:
>>> 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.
>>
>> Rest of the series aside, I'm going to fix-up the pid addition to
>> only set if it's zero like the others.
>
> IMO, io_req_work_grab_env() should never be called from io-wq. It'd do nothing
> good but open space for subtle bugs. And if that's enforced (as done in this
> patch), it's safe to set @pid multiple times.

I agree, it'd be an issue if we ever did the first iteration through the
worker. And it'd be nice to make the flow self explanatory in that
regard.

> Probably, it worth to add the check just to not go through task_pid_vnr()
> several times.

Good point, that is worth it on its own.

--
Jens Axboe