From: Pavel Begunkov <asml.silence@gmail.com>
To: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>,
io-uring@vger.kernel.org
Cc: axboe@kernel.dk, joseph.qi@linux.alibaba.com
Subject: Re: [PATCH] io_uring: hold uring_lock to complete faild polled io in io_wq_submit_work()
Date: Sun, 20 Dec 2020 19:36:06 +0000 [thread overview]
Message-ID: <27952c41-111c-b505-e7f1-78b299f4b786@gmail.com> (raw)
In-Reply-To: <b82a6652-4895-4669-fb8f-167e5150e9e8@gmail.com>
On 20/12/2020 19:34, Pavel Begunkov wrote:
> On 14/12/2020 15:49, Xiaoguang Wang wrote:
>> io_iopoll_complete() does not hold completion_lock to complete polled
>> io, so in io_wq_submit_work(), we can not call io_req_complete() directly,
>> to complete polled io, otherwise there maybe concurrent access to cqring,
>> defer_list, etc, which is not safe. Commit dad1b1242fd5 ("io_uring: always
>> let io_iopoll_complete() complete polled io") has fixed this issue, but
>> Pavel reported that IOPOLL apart from rw can do buf reg/unreg requests(
>> IORING_OP_PROVIDE_BUFFERS or IORING_OP_REMOVE_BUFFERS), so the fix is
>> not good.
>>
>> Given that io_iopoll_complete() is always called under uring_lock, so here
>> for polled io, we can also get uring_lock to fix this issue.
>
> This returns it to the state it was before fixing + mutex locking for
> IOPOLL, and it's much better than having it half-broken as it is now.
btw, comments are over 80, but that's minor.
>
> Cc: <stable@vger.kernel.org> # 5.5+
> Reviewed-by: Pavel Begunkov <asml.silence@gmail.com>
>
>>
>> Fixes: dad1b1242fd5 ("io_uring: always let io_iopoll_complete() complete polled io")
>> Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
>> ---
>> fs/io_uring.c | 25 +++++++++++++++----------
>> 1 file changed, 15 insertions(+), 10 deletions(-)
>>
>> diff --git a/fs/io_uring.c b/fs/io_uring.c
>> index f53356ced5ab..eab3d2b7d232 100644
>> --- a/fs/io_uring.c
>> +++ b/fs/io_uring.c
>> @@ -6354,19 +6354,24 @@ static struct io_wq_work *io_wq_submit_work(struct io_wq_work *work)
>> }
>>
>> if (ret) {
>> + bool iopoll_enabled = req->ctx->flags & IORING_SETUP_IOPOLL;
>> +
>> /*
>> - * io_iopoll_complete() does not hold completion_lock to complete
>> - * polled io, so here for polled io, just mark it done and still let
>> - * io_iopoll_complete() complete it.
>> + * io_iopoll_complete() does not hold completion_lock to complete polled
>> + * io, so here for polled io, we can not call io_req_complete() directly,
>> + * otherwise there maybe concurrent access to cqring, defer_list, etc,
>> + * which is not safe. Given that io_iopoll_complete() is always called
>> + * under uring_lock, so here for polled io, we also get uring_lock to
>> + * complete it.
>> */
>> - if (req->ctx->flags & IORING_SETUP_IOPOLL) {
>> - struct kiocb *kiocb = &req->rw.kiocb;
>> + if (iopoll_enabled)
>> + mutex_lock(&req->ctx->uring_lock);
>>
>> - kiocb_done(kiocb, ret, NULL);
>> - } else {
>> - req_set_fail_links(req);
>> - io_req_complete(req, ret);
>> - }
>> + req_set_fail_links(req);
>> + io_req_complete(req, ret);
>> +
>> + if (iopoll_enabled)
>> + mutex_unlock(&req->ctx->uring_lock);
>> }
>>
>> return io_steal_work(req);
>>
>
--
Pavel Begunkov
next prev parent reply other threads:[~2020-12-21 4:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-14 15:49 [PATCH] io_uring: hold uring_lock to complete faild polled io in io_wq_submit_work() Xiaoguang Wang
2020-12-14 17:48 ` Pavel Begunkov
2020-12-15 2:28 ` Xiaoguang Wang
2020-12-15 11:08 ` Pavel Begunkov
2020-12-20 19:34 ` Pavel Begunkov
2020-12-20 19:36 ` Pavel Begunkov [this message]
2020-12-22 23:41 ` Jens Axboe
2020-12-23 2:12 ` Xiaoguang Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=27952c41-111c-b505-e7f1-78b299f4b786@gmail.com \
--to=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=joseph.qi@linux.alibaba.com \
--cc=xiaoguang.wang@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox