Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp502164pxt; Fri, 6 Aug 2021 07:11:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrvWaaPAEXOOr9PuYlQW6oGVwEdWX6Mnzbwi9Cwf/iK8KO6Cz1nAizay6WSjloaTUHy+yO X-Received: by 2002:a5d:91c2:: with SMTP id k2mr2795346ior.117.1628259085557; Fri, 06 Aug 2021 07:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628259085; cv=none; d=google.com; s=arc-20160816; b=ACJiju2ZytOSv9AD+R0s13OcY4sXAknFRw3K0izNpRsOUR+9FgDT/H8XFvQWUZ3PWY vOc63PhbmL9Nxkte1zFAQBhDlRY8qwapFZC9aDV2RPuLR5y/vyGwe9qduvQJWoOwZ112 kdFjGJFLIaDA05KZcceyMS+1dxToM5SkrDckf/di8sMXOxQUm9ACa4HGYrj39r+/Gxjd yA+cxZyargYnjm2Fd3MAq7N7Pr8fA8PLAVcxXv/vr94trFLeuM4yJn8UlabkSr27VShW mze20SL54VKUaDJLL0QJo3/VIQpBTA4XH4m9xw0ezAulwN/rsCVudfTThW4DApipNkF3 qYCw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VxDbJkWcMl12DjJW4IXspjRgQMkDGT332tNMSZJfvEI=; b=qFOcM4zYTs9l7u6NUvWrLjxXm/xZfacRdzQ1J/sxvSINFCVvtpnBud+xzkA6Z61X2E mYHU5aycSsEojIsroEV8NWJem9cTSypMnsLapwV3Vi/urom2sBqs32ghsluhyipBHj7V n3FLdyIrSYmIgM4LNjTLbaBESAQA9fLVtlUfEuWAFgwbp/WdD9lbqJO0+OCG/60gjv5u JHEmIPHQLe8PdKwrtVgg6p6HlMYWzbajTUm8RugJDPLQN3NdfrKn1WVtYtvsdaKGxYgV ptHM11lpwTAJhe10iv+MHHzEpNVzq8AZgnBq9zH6bDL6nR0iA6gT45h3lIrcS+R24j0t ns6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="B/58NJY5"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s9si8573056ilq.115.2021.08.06.07.11.12; Fri, 06 Aug 2021 07:11:25 -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=@linuxfoundation.org header.s=korg header.b="B/58NJY5"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245053AbhHFIYg (ORCPT + 99 others); Fri, 6 Aug 2021 04:24:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:53272 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244317AbhHFIVC (ORCPT ); Fri, 6 Aug 2021 04:21:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 84CA2611F0; Fri, 6 Aug 2021 08:20:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628238047; bh=iZNNAozg/6jwFOgDG0HAn/Bsks/1S6gkhjtd3zl6Yuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B/58NJY5YWarCR/LYV7M01NMegEpfK/z4DwL11qFGPQkIb+cpFzcpZON9CetRiFSn Wh5FJCrmxYEWl3Ps6g1LM6xbscRyoIQNCEBpvFmpcU2ivsQf1R5gs8STz2b+h91Qn1 vRFotsX5OAUlKTOIeb+4wVR3i6SLi3oMy60MqiGw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Al Viro , Jens Axboe , Sasha Levin Subject: [PATCH 5.13 30/35] io_uring: never attempt iopoll reissue from release path Date: Fri, 6 Aug 2021 10:17:13 +0200 Message-Id: <20210806081114.717223967@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210806081113.718626745@linuxfoundation.org> References: <20210806081113.718626745@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe [ Upstream commit 3c30ef0f78cfb36fdb13753794b0384cf7e37cc9 ] There are two reasons why this shouldn't be done: 1) Ring is exiting, and we're canceling requests anyway. Any request should be canceled anyway. In theory, this could iterate for a number of times if someone else is also driving the target block queue into request starvation, however the likelihood of this happening is miniscule. 2) If the original task decided to pass the ring to another task, then we don't want to be reissuing from this context as it may be an unrelated task or context. No assumptions should be made about the context in which ->release() is run. This can only happen for pure read/write, and we'll get -EFAULT on them anyway. Link: https://lore.kernel.org/io-uring/YPr4OaHv0iv0KTOc@zeniv-ca.linux.org.uk/ Reported-by: Al Viro Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index d465e9997157..86f609fa761c 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2252,7 +2252,7 @@ static inline bool io_run_task_work(void) * Find and free completed poll iocbs */ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events, - struct list_head *done) + struct list_head *done, bool resubmit) { struct req_batch rb; struct io_kiocb *req; @@ -2267,7 +2267,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events, req = list_first_entry(done, struct io_kiocb, inflight_entry); list_del(&req->inflight_entry); - if (READ_ONCE(req->result) == -EAGAIN && + if (READ_ONCE(req->result) == -EAGAIN && resubmit && !(req->flags & REQ_F_DONT_REISSUE)) { req->iopoll_completed = 0; req_ref_get(req); @@ -2291,7 +2291,7 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events, } static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events, - long min) + long min, bool resubmit) { struct io_kiocb *req, *tmp; LIST_HEAD(done); @@ -2334,7 +2334,7 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events, } if (!list_empty(&done)) - io_iopoll_complete(ctx, nr_events, &done); + io_iopoll_complete(ctx, nr_events, &done, resubmit); return ret; } @@ -2352,7 +2352,7 @@ static void io_iopoll_try_reap_events(struct io_ring_ctx *ctx) while (!list_empty(&ctx->iopoll_list)) { unsigned int nr_events = 0; - io_do_iopoll(ctx, &nr_events, 0); + io_do_iopoll(ctx, &nr_events, 0, false); /* let it sleep and repeat later if can't complete a request */ if (nr_events == 0) @@ -2410,7 +2410,7 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, long min) if (list_empty(&ctx->iopoll_list)) break; } - ret = io_do_iopoll(ctx, &nr_events, min); + ret = io_do_iopoll(ctx, &nr_events, min, true); } while (!ret && nr_events < min && !need_resched()); out: mutex_unlock(&ctx->uring_lock); @@ -6804,7 +6804,7 @@ static int __io_sq_thread(struct io_ring_ctx *ctx, bool cap_entries) mutex_lock(&ctx->uring_lock); if (!list_empty(&ctx->iopoll_list)) - io_do_iopoll(ctx, &nr_events, 0); + io_do_iopoll(ctx, &nr_events, 0, true); /* * Don't submit if refs are dying, good for io_uring_register(), -- 2.30.2