From patchwork Sat Jul 13 03:58:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengyuan Liu X-Patchwork-Id: 11042863 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A8FB13BD for ; Sat, 13 Jul 2019 03:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78AF72835B for ; Sat, 13 Jul 2019 03:59:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CFD528389; Sat, 13 Jul 2019 03:59:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D89282836F for ; Sat, 13 Jul 2019 03:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727474AbfGMD7A (ORCPT ); Fri, 12 Jul 2019 23:59:00 -0400 Received: from smtpbguseast2.qq.com ([54.204.34.130]:42774 "EHLO smtpbguseast2.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727466AbfGMD7A (ORCPT ); Fri, 12 Jul 2019 23:59:00 -0400 X-QQ-mid: bizesmtp21t1562990329twuqv0la Received: from localhost.localdomain (unknown [113.240.168.78]) by esmtp6.qq.com (ESMTP) with id ; Sat, 13 Jul 2019 11:58:43 +0800 (CST) X-QQ-SSF: 01400000002000H0ZG31B00A0000000 X-QQ-FEAT: F6eslHfxP6otbQDg1Ha2cTCgOTwLjTi0TR1A/EDVDYE6I7JyO1NLqxvOxWPog 6sdKvZStQTmC0UVBMl2GoG5fDjrTcYh0IQ+a07mOOYui6IzVcZAhiXzjKxaCVnUcHR+5/fG gN+PwjrypHb2vt2LXKWK+tzjwiVsEFdWa7tBo2Tj4lR0Ug/Di7+5+esTkdnK4saz7dpmOYU fYih7bGvJmEiLO1Zzq2s3QDkCPDjEGpdHsWV1nvO9b8+5jSwssZloJf9YzJcPlShHKPkfYC nUz/XghAWiH9Hpjv5+bPez5UyuiXVpkZOfUg/Rj/XnoM+YfIEELFgBajCTO/lHooaLloiOI KNpoEfF X-QQ-GoodBg: 2 From: Zhengyuan Liu To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, Zhengyuan Liu Subject: [PATCH 1/2] io_uring: make req from defer and link list not touch async list Date: Sat, 13 Jul 2019 11:58:25 +0800 Message-Id: <20190713035826.2987-1-liuzhengyuan@kylinos.cn> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:kylinos.cn:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We would queue a work for each req in defer and link list without increasing async->cnt, so we shouldn't decrease it while exiting from workqueue as well as shouldn't process the req in async list. Signed-off-by: Zhengyuan Liu --- 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..3e48fd7cd08f 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_LINKED 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_LINKED; 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 dec async_list->cnt */ + if (req->flags & (REQ_F_IO_DRAINED | REQ_F_LINKED)) + 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); From patchwork Sat Jul 13 03:58:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengyuan Liu X-Patchwork-Id: 11042861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC8B01395 for ; Sat, 13 Jul 2019 03:59:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF5862835B for ; Sat, 13 Jul 2019 03:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF0A728553; Sat, 13 Jul 2019 03:59:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B81362835B for ; Sat, 13 Jul 2019 03:59:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727547AbfGMD7A (ORCPT ); Fri, 12 Jul 2019 23:59:00 -0400 Received: from smtpbguseast2.qq.com ([54.204.34.130]:42753 "EHLO smtpbguseast2.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbfGMD7A (ORCPT ); Fri, 12 Jul 2019 23:59:00 -0400 X-QQ-mid: bizesmtp21t1562990331txpxhzya Received: from localhost.localdomain (unknown [113.240.168.78]) by esmtp6.qq.com (ESMTP) with id ; Sat, 13 Jul 2019 11:58:50 +0800 (CST) X-QQ-SSF: 01400000002000H0ZG31B00A0000000 X-QQ-FEAT: vvh+TVF7+rVoEP4+Rm3xc9ceJjlvXatM5gNN8+RBmzlLxAXv6UNttlgp8kO6g CGrcef0Qtcv+lwqvZMVYj8NPQHORGA/RuMyi9MWJOTN6tYwtNtaEQ6jw9G8HB1UJgm5zZin oDVoir6Hs5/5pEhMpSJdBD5f3eC+3yuE/yOEmCmlDC3KuAHOCi1cqyKXQ/0xDNh1i/ShbQB WyS5lUVJdzwKXSmfvOKU2WhK1SqUz5ndTGPBSyyKjuxAtuGTcp5uqQrnUQ78bDavyxtiXJr himHEvwt7MZmwWyymne2pCcvhgtRvJvW14ABwRKTcSn/8QOaAYhx50CgkUNYeyI7LyYth6e RgHBSA7WRsy7NJh9mE= X-QQ-GoodBg: 2 From: Zhengyuan Liu To: axboe@kernel.dk Cc: linux-block@vger.kernel.org, Zhengyuan Liu Subject: [PATCH 2/2] io_uring: fix the judging condition in io_sequence_defer Date: Sat, 13 Jul 2019 11:58:26 +0800 Message-Id: <20190713035826.2987-2-liuzhengyuan@kylinos.cn> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190713035826.2987-1-liuzhengyuan@kylinos.cn> References: <20190713035826.2987-1-liuzhengyuan@kylinos.cn> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:kylinos.cn:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sq->cached_sq_head and cq->cached_cq_tail are both unsigned int. if cached_sq_head gets overflowed before cached_cq_tail, then we may miss a barrier req. As cached_cq_tail moved always following cached_sq_head, the NQ should be enough. Signed-off-by: Zhengyuan Liu --- fs/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 3e48fd7cd08f..55294ef82102 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -429,7 +429,7 @@ static inline bool io_sequence_defer(struct io_ring_ctx *ctx, if ((req->flags & (REQ_F_IO_DRAIN|REQ_F_IO_DRAINED)) != REQ_F_IO_DRAIN) return false; - return req->sequence > ctx->cached_cq_tail + ctx->sq_ring->dropped; + return req->sequence != ctx->cached_cq_tail + ctx->sq_ring->dropped; } static struct io_kiocb *io_get_deferred_req(struct io_ring_ctx *ctx)