Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2686143ybl; Thu, 29 Aug 2019 11:27:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPrEMl9b2QFQRMo7ku0Zw28rhzXb70oAUJkQc5ARukZR66hEDjN0Len9uituDMtAmqrrGn X-Received: by 2002:a65:614a:: with SMTP id o10mr9399425pgv.407.1567103273933; Thu, 29 Aug 2019 11:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103273; cv=none; d=google.com; s=arc-20160816; b=ypjAn62PtsJNNqOMp2UWdH0S4mKM8YogNjwoy/Abc/gHqqQJwgKBUd2B6Ag308XrTA Th3q2wo0hb+SUDNdPA04TpwyAFjK00X6AaNumGk441TJS4ydToDFvTKDTarfxAUDuBIa qct7e6UaaKQJxQC6hyoSsZnMIPfRJELPguXlzFFsYD6gXMp139AQ/jvOVJetkQU8o2KD b8Rg/R0ANYTWkBFV+gS0x7YawNek3we+GgfofgHXDPi/cEfU361YtAI9MBxskUenjy1D 6gXvt2PZeh6F2mybu1tTdDR4JQuaevXHu1Zx7hk/Vg7H8YemHHHy3VmnkG3IdP1gyi5a i73g== 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=6hBOY8Nc5rzX81purPsUadI4RMyUEdDz0mc3OJX4wX4=; b=oLiqfYYSQMmfUX700OcmqmQJN4GPZ3JxJM56UtlHaT4c1Q122IdGpJl7WcNOEA7GS1 eZWfIzWIGL5+EI49dKhioHqcfPiasS/rk8IrhVY7ZRIuz0Go90lMyVL4I5W5g/VTbKKi TVpHroEeNhZMSqMCmlG7W8Fw4xHs4FOMQa4fG9mcDNQxggI09uAM2ArXla2dt8uy3A00 kJLxPGXlosc8GHQHl7TojeXu8W0DOFenxqQpxdfhkJ8HTHicg0ykr88blRw5h1lvhAGR h6OtxQq2EUI0T3FBqBGCe8dQhMcdV4PeYvYrvrbDiwQFnWoBSHJ8E8P/0yDZV3inETdh u66g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EWqzyOoP; 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 g13si2899495pgr.297.2019.08.29.11.27.38; Thu, 29 Aug 2019 11:27:53 -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=EWqzyOoP; 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 S1728673AbfH2SPo (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:57424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729392AbfH2SPk (ORCPT ); Thu, 29 Aug 2019 14:15:40 -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 1DE8623426; Thu, 29 Aug 2019 18:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102539; bh=loIvfXxJrf4NnIrQL+3Q5C5MQVuqdI6QAgWsWx7KpkI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EWqzyOoPT4goMXfx+Kt39TfL85PyvRwTuzy895mBm1fCv+ASCfadrEh1WTU6eSi6c dvjolowhRkaqITsxHIfHDpMCEkZaN8vOfveHLGzfEiH4Dbcr7jGithnIjib8fDm/X4 wEdoO0C8fDQ0o2bdhPu6GFhyAnSoy+tATPnisUVw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jens Axboe , Sagi Grimberg , Sasha Levin , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 74/76] io_uring: add need_resched() check in inner poll loop Date: Thu, 29 Aug 2019 14:13:09 -0400 Message-Id: <20190829181311.7562-74-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 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