Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2690270ybl; Thu, 29 Aug 2019 11:31:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzB+ywuTci2sz5THRlWTnaVjdYMc74v0AYrrrU7/ic8cR5jcefc6IrXb7wNDhPbXJ5f91/ X-Received: by 2002:a65:62cd:: with SMTP id m13mr9516961pgv.437.1567103485706; Thu, 29 Aug 2019 11:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103485; cv=none; d=google.com; s=arc-20160816; b=oXcn5HQ5oVqJDQs3l2s37czd6eRlkBArAqNgyB8MIz1c6WqROmupJm6HaTBKW4DwYp YRFwzcTsESNL3JfSowSjlVdNUutip0gpi3CIjtAvGqcsnMfvC0faJw2L9ZjKTgYoSW96 5eIwpR8B6UdG32Y9bZYeyunqW1DVtPFuaxTl6q/CB27+Z7CAu0YOrx/frxilH5TyZnCR haesIV6FTbY7yCvpG2/jM7w9lcNvaxpoZGQVrE/3l2bRWcrKHRMZSd7O9MIg/qAwUppk LjW6gZTDAWlB85LvUX7Pv7BFNnFZrS+v5FHETWyYog9c4zIAu6LSKXatd+xVzB5uYHSB tllg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mMQo1LZE4XgqelapJb3m6yEVybGGGmhfXz9UkGV1dSw=; b=WNNGdr0WbCaBB0EnHehQQFgTzZb5xmN7/GUJKlkhz/iDnRD8sDbEUtIqYAV0/3j2bS 1FJOc9Pppa7UoSJMeLbJjzBA3hWEw4AFAF8w6+PJxeJJ2ZUt6c2o+MQv95GbZQn3lIim XPtHLtxl8ZzrTm1s1JvKJZIeCqm+h4PxkrNOSa0sFK2diDqySFIXFEg4fCxg7zugSrw5 Kf/89nq9Ns3a5sxO57p16JI9Xb32huPoKTMGRQI5bNa19uKP71dig7l+dtz2YuxNYyLr jUr1YibEVyvp7hp3c02Dm3bfXW0fit3zWY9PUX8HFB3jeP3jRBexWI9UWC5zMosFdVFM K3Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i5QQ9ubK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si2667416pgq.586.2019.08.29.11.31.10; Thu, 29 Aug 2019 11:31:25 -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=i5QQ9ubK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729196AbfH2S3G (ORCPT + 99 others); Thu, 29 Aug 2019 14:29:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:56778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728293AbfH2SPI (ORCPT ); Thu, 29 Aug 2019 14:15:08 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 75BFF2189D; Thu, 29 Aug 2019 18:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102508; bh=5GRht+bIAa0hz22+5MeBH34xCjSsB4QkhPYcDHuiw80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5QQ9ubKlBOvZqQV5UvFpfDzIU0eDuoaHG0BqF9UzHr/3f2m1seoD5jETrNHaAxKr RxzaNnfHtGrIP0i02WYOXzQ6xGsO2Ag/MFFgSEroKvGGf6g4eJP5VxSNroacC6JSLW cDK1C40y/Exeq/E498rbNeQvPXy1MLwaeBeNgtyE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jens Axboe , Sasha Levin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 58/76] io_uring: don't enter poll loop if we have CQEs pending Date: Thu, 29 Aug 2019 14:12:53 -0400 Message-Id: <20190829181311.7562-58-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe [ 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