Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2276975pxb; Thu, 11 Feb 2021 08:29:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkoSvbGgBPAEb5LOr9np5W3UieHotdVbd/v0Ko4AT2SHXIYUe4G5HjdiRJ4PlwkH2Jz3H7 X-Received: by 2002:a17:906:8507:: with SMTP id i7mr9285705ejx.175.1613060945697; Thu, 11 Feb 2021 08:29:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613060945; cv=none; d=google.com; s=arc-20160816; b=DR9ovTIknBfw4TitWdfYMu4/HvYK0XvYLkAYUXKXGH32xr35v7pvRNYe2RuGhKEdB9 VOt2BbLzPGa2Oe9p3OxBSjo7a/5wcECk9mYvI+KM+PmnjhFIUZ7b6AMXG+K5A5Ogv1TS z4vzbq+OEZh2UbPHvBYw2RP/aXu29tZi+88TDGlpKc7hO6UOClQUMzH3+uX9IIAkGKFp OfOdI04az3V8AiBsn+eGYlP0NWN7MIVWgbHHyIlsGNMrF49lcJAxrkVfdopE8k83Nh13 MTQEH/qeeP0BOZZ9qBPVkud0X8PMfnYRiKhIZo4llvjiLTjI9HZ/hMh41l75pX5zEG8X LKVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Uwg1tr0cJ0vDA62YnvUWI48Z9vAo4/5D8hVJfguuYcA=; b=m2EwflNM6satmh8evn14I31S0v8hhVMZ1L85votyLG4x1eoLEPY7ws4vPkhZTITC77 6VL3irJ46x257RFZN8bnrkrtbfQ89V+LVm5Zmm0b/K55pOaM5XAT3UdT49x4G53lXtsl XXQGxlpVr4EX1EjCYIFbiwpikNGNqrJLqRWifuvIAqt274QOdRTRMq/ylAprXnaLxxpP +iEVDHpQhP0xm310tNkz7D+vQkJ5sqCzoEtsO7rURS+deZlxO276aE9sBPdwT89Shys0 wwDS1BJbARSmJw+AQ5sp+fK79cKkGzQVM72NEcNRS4A3cIkiqmq+zo9mQEL9kn9pUcen Vlbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qdMLtLN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si3905344eju.170.2021.02.11.08.28.38; Thu, 11 Feb 2021 08:29:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qdMLtLN+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231950AbhBKQ1h (ORCPT + 99 others); Thu, 11 Feb 2021 11:27:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:53518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbhBKPYz (ORCPT ); Thu, 11 Feb 2021 10:24:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 88CEA64EE1; Thu, 11 Feb 2021 15:04:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055848; bh=6NcTRIFKk4unTxxNvkfJ3ULuqkv+plZ1Alue4N3L8Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qdMLtLN+PC0ufnv9CDCdfA1jy221qgkpY/NwnPeZUbgGn+6Lt76pf7VjfRoArS44V ENxRsn4vwW90nU6VsM/ULwQOL707BeZeV5mF9zjvUamXY2/jI+eaw//JnPbyyLHd49 WEQRFufXlS5QXHcpvt2OK07tcyw/HT57uAyv//6s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Jens Axboe , Pavel Begunkov Subject: [PATCH 5.10 03/54] io_uring: dont iterate io_uring_cancel_files() Date: Thu, 11 Feb 2021 16:01:47 +0100 Message-Id: <20210211150153.042590656@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210211150152.885701259@linuxfoundation.org> References: <20210211150152.885701259@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov [ Upstream commit b52fda00dd9df8b4a6de5784df94f9617f6133a1 ] io_uring_cancel_files() guarantees to cancel all matching requests, that's not necessary to do that in a loop. Move it up in the callchain into io_uring_cancel_task_requests(). Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8654,16 +8654,10 @@ static void io_cancel_defer_files(struct } } -/* - * Returns true if we found and killed one or more files pinning requests - */ -static bool io_uring_cancel_files(struct io_ring_ctx *ctx, +static void io_uring_cancel_files(struct io_ring_ctx *ctx, struct task_struct *task, struct files_struct *files) { - if (list_empty_careful(&ctx->inflight_list)) - return false; - while (!list_empty_careful(&ctx->inflight_list)) { struct io_kiocb *cancel_req = NULL, *req; DEFINE_WAIT(wait); @@ -8698,8 +8692,6 @@ static bool io_uring_cancel_files(struct schedule(); finish_wait(&ctx->inflight_wait, &wait); } - - return true; } static bool io_cancel_task_cb(struct io_wq_work *work, void *data) @@ -8710,15 +8702,12 @@ static bool io_cancel_task_cb(struct io_ return io_task_match(req, task); } -static bool __io_uring_cancel_task_requests(struct io_ring_ctx *ctx, - struct task_struct *task, - struct files_struct *files) +static void __io_uring_cancel_task_requests(struct io_ring_ctx *ctx, + struct task_struct *task) { - bool ret; - - ret = io_uring_cancel_files(ctx, task, files); - if (!files) { + while (1) { enum io_wq_cancel cret; + bool ret = false; cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_task_cb, task, true); if (cret != IO_WQ_CANCEL_NOTFOUND) @@ -8734,9 +8723,11 @@ static bool __io_uring_cancel_task_reque ret |= io_poll_remove_all(ctx, task); ret |= io_kill_timeouts(ctx, task); + if (!ret) + break; + io_run_task_work(); + cond_resched(); } - - return ret; } static void io_disable_sqo_submit(struct io_ring_ctx *ctx) @@ -8771,11 +8762,10 @@ static void io_uring_cancel_task_request io_cancel_defer_files(ctx, task, files); io_cqring_overflow_flush(ctx, true, task, files); + io_uring_cancel_files(ctx, task, files); - while (__io_uring_cancel_task_requests(ctx, task, files)) { - io_run_task_work(); - cond_resched(); - } + if (!files) + __io_uring_cancel_task_requests(ctx, task); if ((ctx->flags & IORING_SETUP_SQPOLL) && ctx->sq_data) { atomic_dec(&task->io_uring->in_idle);