Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp98759pxu; Tue, 6 Oct 2020 20:21:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXHFuk0oFm5akBTI7FQIWwkJMcxXhgQiVTzYVQ8lDFFJQbzbNBLV9M/qS7SnK1REA14QT7 X-Received: by 2002:a50:c34a:: with SMTP id q10mr1422167edb.36.1602040919045; Tue, 06 Oct 2020 20:21:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602040919; cv=none; d=google.com; s=arc-20160816; b=nJFUWZEwiXitICkGIP+spQ3CGoOyFrtm6cuMgqm9M0/wJeNnOpaoj06z92UG/VI3X5 IZBuWSPBV7rY7f9kQyy8ZoFGIWv1MPUUTKpMjevU/yDeI9g6JQ8soK/iZBWTfh7XuiR6 IGbELhMhFJ8nDoOGOzvIKqyGmrNZW4AJ2I8I6nZT51ogIhWki9NE+cpyAGExCTDWsJkZ tJMP+2W9Q3N/S8Oc8cUbyj0QYTIbg5WvvIySJL0uEqB3dNEs/CORgtQyJ8hasv833vmT arUnVNAWzf0yWrTvMplooMrmZS95x9IYMob/REC05h91DfafQMlOMqvsCl1dWG0UYUQB r6mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GeVbov0xNPxL4pvkkmxnDNiMOHPiM/FJbyQtEEMpPQc=; b=purpEOoloPOGGDNNmunD9kUDG7cjvaj8U4yuGiLtrxS5XVnyy3FiGcO7esnQb1+BiO tEGt3f71ShOxejfZKUTHkGL7d/iojGu0K+wbPcYaLvRrVG1+hRDtTTrOC45SxZEQzvx8 tEJ+I5tpXGUnCKPNR9fcBLar9z7nEEwwikLPF00IuDU87Fk5iBYilufgs59DMLs14Dtl aufbi2Wh22ThZQxXNI1Uyhi8AqVVYgjlIjoVmLYMtO+yoia0VtuFBqTSYnCkQCiABCRV lw+IjhwjRvfDcLS1Yuye3s6Z27L492+e9w0pQEl81+9REjwg1OmcRQiu7+9VFPW8JPWf 9AXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=fwSdbZZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si659183ejr.221.2020.10.06.20.21.36; Tue, 06 Oct 2020 20:21:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=fwSdbZZl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727333AbgJGDRL (ORCPT + 99 others); Tue, 6 Oct 2020 23:17:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727262AbgJGDRH (ORCPT ); Tue, 6 Oct 2020 23:17:07 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7EAAC0613D2 for ; Tue, 6 Oct 2020 20:17:05 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id az3so337745pjb.4 for ; Tue, 06 Oct 2020 20:17:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GeVbov0xNPxL4pvkkmxnDNiMOHPiM/FJbyQtEEMpPQc=; b=fwSdbZZlK5Q7h7g2nyZsoFvVzwIWW97I/PVzJbBd1xKj5L7sttS7jiyZ1oDvU7CUjm J3OK1fVORdZq5/vFvFMrPi8CJilG1lsTE1AHbpLDjp5Kr3iNKNuG3XX4vrsbmfM1A0is 4WVaiR91B6d3pbYyY5End0VaHMSfEHaU9DnjoCBOmIWo7+ZtIhfiHwm9o2SiTSxfamMF qUNI7nsNxAMfs8cuRunI2BSh7kbkT1dd75fgD9f78gp/4XqgEPn50nhrIbOcrDvn0imO jL4Tw2320znVzyDvKnSBEN+W6CWZdfXIPvOIIDrtpzD66fRCYM4hUnMvK06RAcr9fk74 o9vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GeVbov0xNPxL4pvkkmxnDNiMOHPiM/FJbyQtEEMpPQc=; b=nA0b8QbE+384Go48pwpHCBmnEblWkhSSecqV94WCr/tDDlU2tA4SWLayOZEuSF2yvU 6amaEeoxakJA1d1uFNg+xjXThg2TkmTJM8KtxXmYV2cg6Oev1lBWvZKTNQPWpNxF/RI5 Lq7fx+cir0FkdLieFDxTdKRxQWf4qdWLd5iGZnmqsUZ9y+3M81IROgnK5tO1yYY1cFXT JE751DcM7xBUU7c1IT8Wxg98TbF7qgspKHZqyTpoe/tHa85oWmGltK7lPpOSc6bQzwNM +FHa/aAwWbWIfa4tBEXm6Ecvy2uRA2SwWGxUgHRMa3YxVpxE8hBAh0LdSywn+fHPl319 E0Cw== X-Gm-Message-State: AOAM5338uDIGmbhL98dv73rWbhtONmbgMv5mojo50tam2tod02iP2/4L Ytw0pmHbYdHm2GfHIJcZLWhgzg== X-Received: by 2002:a17:902:8d96:b029:d2:8cdd:db9d with SMTP id v22-20020a1709028d96b02900d28cdddb9dmr1138671plo.79.1602040625464; Tue, 06 Oct 2020 20:17:05 -0700 (PDT) Received: from localhost.localdomain ([103.136.221.72]) by smtp.gmail.com with ESMTPSA id e1sm729094pfd.198.2020.10.06.20.17.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Oct 2020 20:17:04 -0700 (PDT) From: Muchun Song To: axboe@kernel.dk, viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhuyinyin@bytedance.com, Muchun Song Subject: [PATCH v3 3/4] io_uring: Fix remove irrelevant req from the task_list Date: Wed, 7 Oct 2020 11:16:34 +0800 Message-Id: <20201007031635.65295-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201007031635.65295-1-songmuchun@bytedance.com> References: <20201007031635.65295-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the process 0 has been initialized io_uring is complete, and then fork process 1. If process 1 exits and it leads to delete all reqs from the task_list. If we kill process 0. We will not send SIGINT signal to the kworker. So we can not remove the req from the task_list. The io_sq_wq_submit_work() can do that for us. Fixes: 1c4404efcf2c ("io_uring: make sure async workqueue is canceled on exit") Signed-off-by: Muchun Song --- fs/io_uring.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5d9583e3d0d25..c65f78f395655 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2277,13 +2277,11 @@ static void io_sq_wq_submit_work(struct work_struct *work) break; cond_resched(); } while (1); -end_req: - if (!list_empty(&req->task_list)) { - spin_lock_irq(&ctx->task_lock); - list_del_init(&req->task_list); - spin_unlock_irq(&ctx->task_lock); - } } +end_req: + spin_lock_irq(&ctx->task_lock); + list_del_init(&req->task_list); + spin_unlock_irq(&ctx->task_lock); /* drop submission reference */ io_put_req(req); @@ -3727,15 +3725,16 @@ static int io_uring_fasync(int fd, struct file *file, int on) static void io_cancel_async_work(struct io_ring_ctx *ctx, struct files_struct *files) { + struct io_kiocb *req; + if (list_empty(&ctx->task_list)) return; spin_lock_irq(&ctx->task_lock); - while (!list_empty(&ctx->task_list)) { - struct io_kiocb *req; - req = list_first_entry(&ctx->task_list, struct io_kiocb, task_list); - list_del_init(&req->task_list); + list_for_each_entry(req, &ctx->task_list, task_list) { + if (files && req->files != files) + continue; /* * The below executes an smp_mb(), which matches with the @@ -3745,7 +3744,7 @@ static void io_cancel_async_work(struct io_ring_ctx *ctx, */ smp_store_mb(req->flags, req->flags | REQ_F_CANCEL); /* B */ - if (req->work_task && (!files || req->files == files)) + if (req->work_task) send_sig(SIGINT, req->work_task, 1); } spin_unlock_irq(&ctx->task_lock); -- 2.11.0