linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] io_uring: fix the wrong counter in async_list
@ 2019-07-16 15:26 Zhengyuan Liu
  2019-07-16 15:56 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Zhengyuan Liu @ 2019-07-16 15:26 UTC (permalink / raw)
  To: axboe; +Cc: linux-block

We would 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 as shouldn't process the req in async list.

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

Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn>
---
 fs/io_uring.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 7e932c572f26..e554091c713c 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -333,7 +333,8 @@ struct io_kiocb {
 #define REQ_F_IO_DRAIN		16	/* drain existing IO first */
 #define REQ_F_IO_DRAINED	32	/* drain done */
 #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;
 	u32			result;
 	u32			sequence;
@@ -630,6 +631,7 @@ static void io_req_link_next(struct io_kiocb *req)
 			nxt->flags |= REQ_F_LINK;
 		}
 
+		nxt->flags |= REQ_F_LINK_DONE;
 		INIT_WORK(&nxt->work, io_sq_wq_submit_work);
 		queue_work(req->ctx->sqo_wq, &nxt->work);
 	}
@@ -1845,6 +1847,10 @@ static void io_sq_wq_submit_work(struct work_struct *work)
 		/* async context always use a copy of the 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)
 			break;
 		if (!list_empty(&req_list)) {
@@ -1892,6 +1898,7 @@ static void io_sq_wq_submit_work(struct work_struct *work)
 		}
 	}
 
+out:
 	if (cur_mm) {
 		set_fs(old_fs);
 		unuse_mm(cur_mm);
-- 
2.19.1




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] io_uring: fix the wrong counter in async_list
  2019-07-16 15:26 [PATCH v2] io_uring: fix the wrong counter in async_list Zhengyuan Liu
@ 2019-07-16 15:56 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2019-07-16 15:56 UTC (permalink / raw)
  To: Zhengyuan Liu; +Cc: linux-block

On 7/16/19 9:26 AM, Zhengyuan Liu wrote:
> We would 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 as shouldn't process the req in async list.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-16 15:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 15:26 [PATCH v2] io_uring: fix the wrong counter in async_list Zhengyuan Liu
2019-07-16 15:56 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).