Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5229041ybl; Tue, 27 Aug 2019 01:10:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxNSsSujm61pjB6Q+DA4c8N/HTQdX/L0668nX20sVYMdph5NVWsRqhj8jPZ45DbhIzQKP1 X-Received: by 2002:a17:90a:7783:: with SMTP id v3mr23372410pjk.109.1566893413695; Tue, 27 Aug 2019 01:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893413; cv=none; d=google.com; s=arc-20160816; b=ZqQXpzRrGHRdmKlA6ReA9JIk/pNhiWyX2+t2TViVYLAa0hJsGN9HEakOJY74hNBVHD 2MLqUy4iFAjdeOw3594BfJiw7PcdkdaIPYMftobhbJpe6ux8+lHhthHffc0Q9M/M1N8e sbzQqzMqAoCp+uXM+Un1I30lyjH5aQitS1DKJFmzxXXzCp9L7v7fYHJnELhb7sevwQK0 dI8cYRy0I4NPj8LgUYYVYj8m0ZQUvGmnldyGm9dbf7XGfHQ1ZBsBz72iN1jmk/0MOG5c Du3k9g7odKA09XIjKc5+JhrCfeoG2qOoNqjNrGNMdagPWTyMDLChX2iy0wou/CnQcGmM E/Nw== 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=NHi5cI60zGgV9iw9ksiv/2CC6oiPOfEZzUyBn96tpPU=; b=JRvTHAas9nEaqIiFBkR/QMREt31ydRBApX653Ajz4sCgVdksPT5QvwCzahiA7GraTs RJ+yTUyBpio8mscw5fizTO7QZ6TO/ZCVHOItv2oqD30Vl6irEUvs7pl4NB8l8b60P/Yw NXt9Q2/b9YoBLttGR8fcj17Msbh7AyPYouCrCcHqyDkzrT6JBGo3yJnO+fg1aHx44UNz kgQRmc6Q4EcBhpYMPYynu8tBwIDBCEUDEcGYusewWnXJV8M+PttU+gEUIbAis+neBda/ ykBPeT0G39sLOHNsi0R85e73rhVkwhqKW7Mip5yodILgYsypUi/daugIDIyWonVYqrPv 6yIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=O232IVRt; 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 x21si7493354plm.432.2019.08.27.01.09.58; Tue, 27 Aug 2019 01:10:13 -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=O232IVRt; 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 S1733094AbfH0IGx (ORCPT + 99 others); Tue, 27 Aug 2019 04:06:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:36854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733073AbfH0IGu (ORCPT ); Tue, 27 Aug 2019 04:06:50 -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 98DF3206BA; Tue, 27 Aug 2019 08:06:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566893209; bh=HvmvIsrVqVKebI1YvpNqor93rKIy6ruroAlxsG4/1Y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O232IVRtGoQasLYdPfFYM1cC4yBtRI2h/obn8lrRonRaKiN2sobjapyt59hTxTiPa CMC+n9vnLPfP6kqO1cBgQnLc7QfBKTy2pUva1eCrg4h7HLuTpSlrM1evkuWhQchD2J VhKrp70uNpHxF8OhRL0SmZoddRhQoXEuLEr4Kmi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sagi Grimberg , Jens Axboe , Sasha Levin Subject: [PATCH 5.2 159/162] io_uring: add need_resched() check in inner poll loop Date: Tue, 27 Aug 2019 09:51:27 +0200 Message-Id: <20190827072744.365607802@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 08f5439f1df25a6cf6cf4c72cf6c13025599ce67 ] The outer poll loop checks for whether we need to reschedule, and returns to userspace if we do. However, it's possible to get stuck in the inner loop as well, if the CPU we are running on needs to reschedule to finish the IO work. Add the need_resched() check in the inner loop as well. This fixes a potential hang if the kernel is configured with CONFIG_PREEMPT_VOLUNTARY=y. Reported-by: Sagi Grimberg Reviewed-by: Sagi Grimberg Tested-by: Sagi Grimberg Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 83e3cede11220..03cd8f5bba850 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -716,7 +716,7 @@ static int io_do_iopoll(struct io_ring_ctx *ctx, unsigned int *nr_events, static int io_iopoll_getevents(struct io_ring_ctx *ctx, unsigned int *nr_events, long min) { - while (!list_empty(&ctx->poll_list)) { + while (!list_empty(&ctx->poll_list) && !need_resched()) { int ret; ret = io_do_iopoll(ctx, nr_events, min); @@ -743,6 +743,12 @@ static void io_iopoll_reap_events(struct io_ring_ctx *ctx) unsigned int nr_events = 0; io_iopoll_getevents(ctx, &nr_events, 1); + + /* + * Ensure we allow local-to-the-cpu processing to take place, + * in this case we need to ensure that we reap all events. + */ + cond_resched(); } mutex_unlock(&ctx->uring_lock); } -- 2.20.1