Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5228249ybl; Tue, 27 Aug 2019 01:09:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9mbRTECpz83nkvIgG4x2M22VC6L23uMVzJLvPVgDvCDAl5hRDs+pZ0sX2pgTHwT9uy6Re X-Received: by 2002:a17:90a:30ad:: with SMTP id h42mr23762387pjb.31.1566893362490; Tue, 27 Aug 2019 01:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893362; cv=none; d=google.com; s=arc-20160816; b=ySHfHh0E+snRFdlwtM4KcACopJ2NOYFOcvkcY2uXgvNSv0NBBYHW37v7lt8MHFMDbh 2AEqRtHiGeE49v6/GTWHZPOuVw94SWckPIpk3lXHLGVwMjytPsoHJkBklvsGQlpYtvdQ hc2i3TpPSsegTTuEN3Cv7YI/PDawRG7MtSUDYLwbxWJd9SsTwxXEKe3CA/L5QUPawEI9 OPnPzru235lexIvHELsoPuuGuEY+8YDknMDErHAYgsE1JbkSoLSHmw3+oG7xWm1Fu61p Navdt9zIyu8+BqFtN+AV4lSXjhWURCBqxg+8Rhvf0y6IjZvs+l2RDkq4oXS8W1HQYimx ThDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Afbqx1hzda4twsUExi97cPNvjRhshnS2r4rJB6IeKVg=; b=tgwMS/QsF5mJ8yxH5OyDvROfu+Yq8zsQYGHIVXI7iGACF9JFi3Ek7/DzRb58akiehR snHVdAUertHyKfU3TqG6k4X101sPU8qjThaZ79PidmeT+/cLkJk8SXnUHXsHLRXtMXUm 3Np1Y9kWvMbLKruFGG1n/lMU2m8/ZqLYDRFwiftD+8+RaOeqZ1klBz+ItncQH1abcV82 sIF7GcNTX6mjVBQO/ikpj6MT6wy4OPCExoW2I16YV3meNE6wUE7ylCSTxNRJmWZGDWxD 29/7W+8szCPsYSEEXzh0FiWj7ZYZfUSFNSgLYqGor2EKhZ8eUKfWnTijhwRrgScq84M6 YiZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xzP6dXSS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m22si11087791pgh.190.2019.08.27.01.09.06; Tue, 27 Aug 2019 01:09:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xzP6dXSS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732135AbfH0IGv (ORCPT + 99 others); Tue, 27 Aug 2019 04:06:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:36808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733060AbfH0IGr (ORCPT ); Tue, 27 Aug 2019 04:06:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6F77206BA; Tue, 27 Aug 2019 08:06:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893206; bh=PTH5gf3qMAjBZYotzW2/KcVVswrMaCW1ki+HabsApLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xzP6dXSSFkheKTyPfgnVEg0CellGG223vVTr9YHPqCE1ER9cpV97qkGU/LT4oS7TG oq+n7HDwOBV8ROsCi6puwhzGXr3rKdLpSjEXxAGorVQjsWdxd2HgFvFCvorRB+VoT4 tYZRrhsagSNRLems0JxSSiyhz2DUVpTESsQbHh0U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , Sasha Levin Subject: [PATCH 5.2 158/162] io_uring: dont enter poll loop if we have CQEs pending Date: Tue, 27 Aug 2019 09:51:26 +0200 Message-Id: <20190827072744.323251684@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072738.093683223@linuxfoundation.org> References: <20190827072738.093683223@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit a3a0e43fd77013819e4b6f55e37e0efe8e35d805 ] We need to check if we have CQEs pending before starting a poll loop, as those could be the events we will be spinning for (and hence we'll find none). This can happen if a CQE triggers an error, or if it is found by eg an IRQ before we get a chance to find it through polling. Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 5bb01d84f38d3..83e3cede11220 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -618,6 +618,13 @@ static void io_put_req(struct io_kiocb *req) io_free_req(req); } +static unsigned io_cqring_events(struct io_cq_ring *ring) +{ + /* See comment at the top of this file */ + smp_rmb(); + return READ_ONCE(ring->r.tail) - READ_ONCE(ring->r.head); +} + /* * Find and free completed poll iocbs */ @@ -756,6 +763,14 @@ static int io_iopoll_check(struct io_ring_ctx *ctx, unsigned *nr_events, do { int tmin = 0; + /* + * Don't enter poll loop if we already have events pending. + * If we do, we can potentially be spinning for commands that + * already triggered a CQE (eg in error). + */ + if (io_cqring_events(ctx->cq_ring)) + break; + /* * If a submit got punted to a workqueue, we can have the * application entering polling for a command before it gets @@ -2232,13 +2247,6 @@ static int io_ring_submit(struct io_ring_ctx *ctx, unsigned int to_submit) return submit; } -static unsigned io_cqring_events(struct io_cq_ring *ring) -{ - /* See comment at the top of this file */ - smp_rmb(); - return READ_ONCE(ring->r.tail) - READ_ONCE(ring->r.head); -} - /* * Wait until events become available, if we don't already have some. The * application must reap them itself, as they reside on the shared cq ring. -- 2.20.1