From: Xiaoguang Wang <[email protected]>
To: Jens Axboe <[email protected]>, [email protected]
Cc: [email protected], [email protected]
Subject: Re: [PATCH] io_uring: fix io_kiocb.flags modification race in IOPOLL mode
Date: Thu, 11 Jun 2020 23:20:43 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
hi,
> On 6/11/20 3:25 AM, Xiaoguang Wang wrote:
>> While testing io_uring in arm, we found sometimes io_sq_thread() keeps
>> polling io requests even though there are not inflight io requests in
>> block layer. After some investigations, found a possible race about
>> io_kiocb.flags, see below race codes:
>> 1) in the end of io_write() or io_read()
>> req->flags &= ~REQ_F_NEED_CLEANUP;
>> kfree(iovec);
>> return ret;
>>
>> 2) in io_complete_rw_iopoll()
>> if (res != -EAGAIN)
>> req->flags |= REQ_F_IOPOLL_COMPLETED;
>>
>> In IOPOLL mode, io requests still maybe completed by interrupt, then
>> above codes are not safe, concurrent modifications to req->flags, which
>> is not protected by lock or is not atomic modifications. I also had
>> disassemble io_complete_rw_iopoll() in arm:
>> req->flags |= REQ_F_IOPOLL_COMPLETED;
>> 0xffff000008387b18 <+76>: ldr w0, [x19,#104]
>> 0xffff000008387b1c <+80>: orr w0, w0, #0x1000
>> 0xffff000008387b20 <+84>: str w0, [x19,#104]
>>
>> Seems that the "req->flags |= REQ_F_IOPOLL_COMPLETED;" is load and
>> modification, two instructions, which obviously is not atomic.
>>
>> To fix this issue, add a new iopoll_completed in io_kiocb to indicate
>> whether io request is completed.
>
> Long term, I want to ensure that IOPOLL irq completions are illegal, it
> should not be enabled (or possible) if the driver doesn't do pure polled
> completions.
Yes, agree.
>
> Short term, I think your fix is fine, but should be turned into using
> READ_ONCE/WRITE_ONCE for the reading/setting of ->iopoll_completed.
> Can you resend it with that?
OK, I'll prepare one now.
Regards,
Xiaoguang Wang
>
prev parent reply other threads:[~2020-06-11 15:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 9:25 [PATCH] io_uring: fix io_kiocb.flags modification race in IOPOLL mode Xiaoguang Wang
2020-06-11 15:05 ` Jens Axboe
2020-06-11 15:20 ` Xiaoguang Wang [this message]
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=3b5f1d1a-0a39-c277-6460-f35da4600200@linux.alibaba.com \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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