Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1167723ybf; Thu, 27 Feb 2020 06:14:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxhShhoRmnYUiQNzf990l289W/+JPXgI05AoQOu8rsX/QsYje3FxSa5wueYihxwbT9RKg7y X-Received: by 2002:a05:6830:2015:: with SMTP id e21mr3457013otp.106.1582812840607; Thu, 27 Feb 2020 06:14:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582812840; cv=none; d=google.com; s=arc-20160816; b=M3Mcycekx3wDWG8NXJdulgUdjQuGGjrTowpujgevcFxyLDcM+bMLajTTdJ02af4+Nx u5NpBd/XTpcCQ3aTpDh6lD1Qody0z5IdY1XcnYTcdAzd3m1QnEGas+mKeNxiyFGgp1sX J/kY7lVRyL8jotO5HYIOGZoIrw4lTSifIlzFs+IITU01m5IcrFclkTKQz/UYI58EdjYu +HssEnFK9xnmJ5KzwIg8aFRaiEH800oNHfpM8EjxB9hBziVno/mBg6GBhUvIRKFsO5B3 x1N+pOP+DqibgndqpOq/fMl4/fufvJT3F1AXPrhNUMdw/58Xpyd09eGDzTZNQlsCYumm 4z6Q== 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=IZ7Povv+2a07oOdp7nRhh+eGBJGwFvG57N/wIBLggCE=; b=NPSpK52Irf5900q8NFDvBPDWljFWlpiaqJPfe6la/sXbwrl/mVexTFJhhPQTKK77L9 z5vIbaX3aheoX6rUwQZ5P5ywZ0Rw9ihXDq/HXj3QOTVbNd9Wtl6qG/yfHduifU2yhN+l E8fcyzVszGeszV/lq1omfpjzyuGezK0MfIKBU0n0RZMXbYN4nDZW4YDEvjW/0bVSUZwS IH+a/zxQ2xhBYMBO2jDyeYPAofT6us5UfhkPSXyPYVR+uFQvRNwz3kVeEnXIliQcOpqR qmlggsWqz5DzoyoEegomxnjhipTQl141yKRTczVosdVPtzURd34pEhpTtJKLYrvuuRpo +AYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="0/SFMx1m"; 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 a4si1494335otq.98.2020.02.27.06.13.32; Thu, 27 Feb 2020 06:14:00 -0800 (PST) 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="0/SFMx1m"; 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 S2388794AbgB0OMK (ORCPT + 99 others); Thu, 27 Feb 2020 09:12:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:50720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387743AbgB0OME (ORCPT ); Thu, 27 Feb 2020 09:12:04 -0500 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 87B3120578; Thu, 27 Feb 2020 14:12:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812724; bh=hzIUODltB8CaaldLAxlIk6S4sMoGiLxfeP47cHNFmO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0/SFMx1m/0sdcti6gDBEWb3rPVoyf9vLFLU2cWajpvnKiTKm4ARXxWuIhzVQceGqn nb4oCZt8YZkP3krG6sGXAGAXhVbSjR41A+1Y14cNPTNcDeOymoQfLFWDXxfJRiFIsL +YytcUUAzw6tmMJXH/TpVrDH2t6HRZc31SI1quYA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , Jens Axboe Subject: [PATCH 5.4 127/135] io_uring: prevent sq_thread from spinning when it should stop Date: Thu, 27 Feb 2020 14:37:47 +0100 Message-Id: <20200227132248.126675153@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@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 From: Stefano Garzarella commit 7143b5ac5750f404ff3a594b34fdf3fc2f99f828 upstream. This patch drops 'cur_mm' before calling cond_resched(), to prevent the sq_thread from spinning even when the user process is finished. Before this patch, if the user process ended without closing the io_uring fd, the sq_thread continues to spin until the 'sq_thread_idle' timeout ends. In the worst case where the 'sq_thread_idle' parameter is bigger than INT_MAX, the sq_thread will spin forever. Fixes: 6c271ce2f1d5 ("io_uring: add submission polling") Signed-off-by: Stefano Garzarella Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2732,16 +2732,6 @@ static int io_sq_thread(void *data) to_submit = io_sqring_entries(ctx); if (!to_submit) { /* - * We're polling. If we're within the defined idle - * period, then let us spin without work before going - * to sleep. - */ - if (inflight || !time_after(jiffies, timeout)) { - cond_resched(); - continue; - } - - /* * Drop cur_mm before scheduling, we can't hold it for * long periods (or over schedule()). Do this before * adding ourselves to the waitqueue, as the unuse/drop @@ -2753,6 +2743,16 @@ static int io_sq_thread(void *data) cur_mm = NULL; } + /* + * We're polling. If we're within the defined idle + * period, then let us spin without work before going + * to sleep. + */ + if (inflight || !time_after(jiffies, timeout)) { + cond_resched(); + continue; + } + prepare_to_wait(&ctx->sqo_wait, &wait, TASK_INTERRUPTIBLE);