Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp337280pxk; Wed, 23 Sep 2020 04:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwF0+iduSIF3LKzWZ6om8P93KKNJ+gxmNo15VXP5MUb3XvhvNAjAd40GShP4xnpjdYkJCro X-Received: by 2002:a05:6402:17b5:: with SMTP id j21mr8959155edy.276.1600861607205; Wed, 23 Sep 2020 04:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600861607; cv=none; d=google.com; s=arc-20160816; b=Ki88C+J1H1bmoCLH803mPsjveptVraskFdCBO/CIo9LtGnDQMl9DaSSjfv+DjBSKXD bIYKMyMSeKbwtaAzNyeQi7821wc80Z438HkMARRLVb7BGDOHGDKnNeHLyKtkkp4+cCwl n3M43cpKxjvSTipokAKhlJ7MuuLQG9s8FefZYiX9CZTln65jpCDiqN24IfJ50aL3IUSW 9Y7sxPoREDIqg99PJVz/bv4guHFbMfLQl6rdFRhJziYXVrptSdHbLdizuu9dkdbFlmor e2zYQ+j5guMxQ6eNECiZtDEVuTlP7aYViSWYPHqczM+6c7kMiPPLH07MZlMTeNO+hjgk VQ3w== 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=9itEseAD+a+MBY3AfvJv+oRl5Fh7iHmbspsMNgiBQ8I=; b=rnrM4amoN3UH1AfFf40CuqcsqwLmoePtX1pQ+giphZ92b4SrlxfGWSGLbzDl+8RupP dn/bCK4At8O4f4CDpLchhBwwC2Pl2F+rR5QPP76PyTiWCd8Az+gPWsNH4V4HJarqcedM Va1R5Qv9wXw5ijkEsKR8a5mMpjqZBohPcpQ8t8NDA4M9IrriLhvayg5R1S4041N2DBdb bQkTixc3o4WbVJ44uk0vD45HSpSd+Im3NaCMfzOrYs+HLGzcAhGIiGpNooqS1KM5xi8b zddiUnDL23UuUhKC7LXZ9HTIjfRZpfjNyBTGL8sbqjndzcUDkoWaVSgtteFxrK4cLdBm cXlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=YvKeBCRW; 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 bx24si735488ejb.449.2020.09.23.04.46.23; Wed, 23 Sep 2020 04:46:47 -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=YvKeBCRW; 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 S1726716AbgIWLpB (ORCPT + 99 others); Wed, 23 Sep 2020 07:45:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726636AbgIWLox (ORCPT ); Wed, 23 Sep 2020 07:44:53 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 380BEC0613D2 for ; Wed, 23 Sep 2020 04:44:53 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id y6so6692394plt.9 for ; Wed, 23 Sep 2020 04:44:53 -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=9itEseAD+a+MBY3AfvJv+oRl5Fh7iHmbspsMNgiBQ8I=; b=YvKeBCRWp8yZc41o0eMSB8UggT0lNlhX9n/s6kiLonLBDwzHc1vJjz799Jatl8GLLC 6N1DNrlPQCsphlq3gd5f9HDgeOmTUAWDWDjOLOAgtCK7Kzry1XXCNk8IlsmRg93vGW7E 5tg2AH7Dv++QCOAHINDuQAhNHlgXO45E41R9aUboCHc55TNusZ/gnDiUxZQGy4M1+nA9 br3CU5TT1DDHHx48gH1KIlgAVPITQTtSfhF8WoSMq3NDAlgmR7yMz8LiS+/p9O34Y03F HPUXGlFZmGeEf5+vWD7vIprFInNSnie+66zDIOAKeKkNp536kIo00KLzPN76oJb4a2hs Z4mA== 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=9itEseAD+a+MBY3AfvJv+oRl5Fh7iHmbspsMNgiBQ8I=; b=jWaEGp7FEhoQpcrdjneqra7TpurL7whLenjDUkrfsP29TK/pxlWVlhTG223LVe0osB j520InmkcHzni0dwNP6UoointqGljPF5gqrwyBOMBPz97EEtDuyTL6ml0Qsi28BZCx5t BHU7pkmTMbP78lgXcoWLb2MMdaG6nDbZAL2IHXBszvD8j3WvbVDGIfnrqCG2kQ3q3+xZ ueX7Gmaix3jre4cnEAQpuqoTP9J862VCL/m+xXTzDEzsQ+yCXHWNvP4kydj5Jd71Ny92 KYXZoF5chuSQ5ZfsPhcE8R9CT4o1llRKL6fCyCYnS20RuoQgSr3vyxezO7YNquQGohCh VirQ== X-Gm-Message-State: AOAM532UCpNJSOVG0Yi4wZ6lphm615tL2HD4JpNBqIuSy6Ag6cGm02wg MC9uWODGCd9L6h/Zwr5+YECr6w== X-Received: by 2002:a17:90a:e2cc:: with SMTP id fr12mr7955245pjb.125.1600861492822; Wed, 23 Sep 2020 04:44:52 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.72]) by smtp.gmail.com with ESMTPSA id a13sm17632155pfl.184.2020.09.23.04.44.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Sep 2020 04:44:52 -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 v2 3/5] io_uring: Fix remove irrelevant req from the task_list Date: Wed, 23 Sep 2020 19:44:17 +0800 Message-Id: <20200923114419.71218-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20200923114419.71218-1-songmuchun@bytedance.com> References: <20200923114419.71218-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 c80c37ef38513..12e68ea00a543 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); @@ -3725,15 +3723,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 @@ -3743,7 +3742,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