Commit d3101fc
Xiaoguang Wang
io_uring: fix io_kiocb.flags modification race in IOPOLL mode
to #28736503
commit 65a6543 upstream
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.
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Xiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
Acked-by: Joseph Qi <joseph.qi@linux.alibaba.com>1 parent 9c90c6a commit d3101fc
1 file changed
+6
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
522 | | - | |
523 | 522 | | |
524 | 523 | | |
525 | 524 | | |
| |||
564 | 563 | | |
565 | 564 | | |
566 | 565 | | |
567 | | - | |
568 | | - | |
569 | 566 | | |
570 | 567 | | |
571 | 568 | | |
| |||
630 | 627 | | |
631 | 628 | | |
632 | 629 | | |
| 630 | + | |
| 631 | + | |
633 | 632 | | |
634 | 633 | | |
635 | 634 | | |
| |||
1789 | 1788 | | |
1790 | 1789 | | |
1791 | 1790 | | |
1792 | | - | |
| 1791 | + | |
1793 | 1792 | | |
1794 | 1793 | | |
1795 | 1794 | | |
| |||
1970 | 1969 | | |
1971 | 1970 | | |
1972 | 1971 | | |
1973 | | - | |
| 1972 | + | |
1974 | 1973 | | |
1975 | 1974 | | |
1976 | 1975 | | |
| |||
2003 | 2002 | | |
2004 | 2003 | | |
2005 | 2004 | | |
2006 | | - | |
| 2005 | + | |
2007 | 2006 | | |
2008 | 2007 | | |
2009 | 2008 | | |
| |||
2131 | 2130 | | |
2132 | 2131 | | |
2133 | 2132 | | |
| 2133 | + | |
2134 | 2134 | | |
2135 | 2135 | | |
2136 | 2136 | | |
| |||
0 commit comments