提交 eaebfba5 编写于 作者: Z Zhengyuan Liu 提交者: Shile Zhang

io_uring: fix counter inc/dec mismatch in async_list

commit f7b76ac9d17e16e44feebb6d2749fec92bfd6dd4 upstream.

We could queue a work for each req in defer and link list without
increasing async_list->cnt, so we shouldn't decrease it while exiting
from workqueue as well if we didn't process the req in async list.

Thanks to Jens Axboe <axboe@kernel.dk> for his guidance.

Fixes: 31b515106428 ("io_uring: allow workqueue item to handle multiple buffered requests")
Signed-off-by: NZhengyuan Liu <liuzhengyuan@kylinos.cn>
Signed-off-by: NJens Axboe <axboe@kernel.dk>
Signed-off-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
Reviewed-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
上级 8bc3afd8
...@@ -333,7 +333,8 @@ struct io_kiocb { ...@@ -333,7 +333,8 @@ struct io_kiocb {
#define REQ_F_IO_DRAIN 16 /* drain existing IO first */ #define REQ_F_IO_DRAIN 16 /* drain existing IO first */
#define REQ_F_IO_DRAINED 32 /* drain done */ #define REQ_F_IO_DRAINED 32 /* drain done */
#define REQ_F_LINK 64 /* linked sqes */ #define REQ_F_LINK 64 /* linked sqes */
#define REQ_F_FAIL_LINK 128 /* fail rest of links */ #define REQ_F_LINK_DONE 128 /* linked sqes done */
#define REQ_F_FAIL_LINK 256 /* fail rest of links */
u64 user_data; u64 user_data;
u32 result; u32 result;
u32 sequence; u32 sequence;
...@@ -631,6 +632,7 @@ static void io_req_link_next(struct io_kiocb *req) ...@@ -631,6 +632,7 @@ static void io_req_link_next(struct io_kiocb *req)
nxt->flags |= REQ_F_LINK; nxt->flags |= REQ_F_LINK;
} }
nxt->flags |= REQ_F_LINK_DONE;
INIT_WORK(&nxt->work, io_sq_wq_submit_work); INIT_WORK(&nxt->work, io_sq_wq_submit_work);
queue_work(req->ctx->sqo_wq, &nxt->work); queue_work(req->ctx->sqo_wq, &nxt->work);
} }
...@@ -1843,6 +1845,10 @@ static void io_sq_wq_submit_work(struct work_struct *work) ...@@ -1843,6 +1845,10 @@ static void io_sq_wq_submit_work(struct work_struct *work)
/* async context always use a copy of the sqe */ /* async context always use a copy of the sqe */
kfree(sqe); kfree(sqe);
/* req from defer and link list needn't decrease async cnt */
if (req->flags & (REQ_F_IO_DRAINED | REQ_F_LINK_DONE))
goto out;
if (!async_list) if (!async_list)
break; break;
if (!list_empty(&req_list)) { if (!list_empty(&req_list)) {
...@@ -1890,6 +1896,7 @@ static void io_sq_wq_submit_work(struct work_struct *work) ...@@ -1890,6 +1896,7 @@ static void io_sq_wq_submit_work(struct work_struct *work)
} }
} }
out:
if (cur_mm) { if (cur_mm) {
set_fs(old_fs); set_fs(old_fs);
unuse_mm(cur_mm); unuse_mm(cur_mm);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册