Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2554427pxj; Mon, 10 May 2021 05:49:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwow0ftBkVfHnSz+9xDFSzHjry/69F0iV0wWGFTybh7y/KmrKJv8SC1JVUeb4y0ILYFHN/V X-Received: by 2002:a92:da8c:: with SMTP id u12mr21231817iln.19.1620650974847; Mon, 10 May 2021 05:49:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620650974; cv=none; d=google.com; s=arc-20160816; b=QkXlX5kqhKA3FLlfZoovn+1Ufyk9fpb8l56X1W/2g+2QqBG5g/SQEcxsSqGLk9u2Hr wB6Vs+U+8QksJhnat8RVCO3yHjcGqP0Cb1MBjCUIzPybmMLnN+rlTH3NYVVLZps3gMiB HFc6ItzWwV/6yO45c5WgTkzlq0vSfCs87MM+Y8pXMnqTppB978DPxKj5shb1OLrgp4nW ItRWxOAxqFAZwOpBamv4/w+XpEUxQ3eapCO2zXX6ezI+hLzMYv8DYCc4nvVvMVlT2wr1 /cvdYZU8FkUUt2f9x0LY5bsxGUDvC9eptccmpktOguVDBBF4yU1JpEL1kjMgG9G1E8Yo D78g== 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=bqe7khCkeDmKDhNo4slASY5wHahg47AOOvMboZSL3QI=; b=RUOQKpE9SSCbaxQt+AWOtFZ/CpzpjdcEJ3LbU7YHhi+9yX4Is1Y3ehaDgZX4lQAcb2 jBPyylCE2JjXoR/oxIxBDs9KOYI1gxmKx2aF7ZvXRKhXgHCDTM/Za/YE7qMimbbJhCOm ndU2ZNfKoInnUWwkJGyVuVP5RYH9mels+vlsq4myrr6GG/me7l6sFlA95pBlX3/a6k7V 8SC/2k0CQE7MTtXZZttTM09sXTGZia5Mum4ZmiQsqFqmztHyEBFzUUUIvAhj80BtJ9oL DcoQKLatkUKK7/4eSjOyh/1lf5Oa32cc8+MKYWcFjeGnPLYYPjTjjG3K0qQ2AQpcCTxA +sfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uf+VcRez; 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 q16si16406228iow.52.2021.05.10.05.49.15; Mon, 10 May 2021 05:49:34 -0700 (PDT) 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=uf+VcRez; 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 S1348082AbhEJMj7 (ORCPT + 99 others); Mon, 10 May 2021 08:39:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:34962 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238013AbhEJLQs (ORCPT ); Mon, 10 May 2021 07:16:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2AFA46144F; Mon, 10 May 2021 11:12:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620645122; bh=jjJPwdS8K1D01ETOZNuduVhSxI+zxPORR2wf5Nv5kbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uf+VcRez0m32IM+k9PoWVsbSSYjnsbAXuse+ZV8Li4ZL4S8I4KZIr51KZ9x1nRIBT GEawFwxSK845c47IDuPraRt2UG1RdNSRXgmifOW1IhFnmyD2hQ5IvNchN/dQDMXnhV Sio3+6covTicO5uqTcH4WiEmhMnZGbgiNeuhmVWQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.12 361/384] io_uring: fix work_exit sqpoll cancellations Date: Mon, 10 May 2021 12:22:30 +0200 Message-Id: <20210510102026.656004341@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102014.849075526@linuxfoundation.org> References: <20210510102014.849075526@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 commit 28090c133869b461c5366195a856d73469ab87d9 upstream. After closing an SQPOLL ring, io_ring_exit_work() kicks in and starts doing cancellations via io_uring_try_cancel_requests(). It will go through io_uring_try_cancel_iowq(), which uses ctx->tctx_list, but as SQPOLL task don't have a ctx note, its io-wq won't be reachable and so is left not cancelled. It will eventually cancelled when one of the tasks dies, but if a thread group survives for long and changes rings, it will spawn lots of unreclaimed resources and live locked works. Cancel SQPOLL task's io-wq separately in io_ring_exit_work(). Cc: stable@vger.kernel.org Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/a71a7fe345135d684025bb529d5cb1d8d6b46e10.1619389911.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -8571,6 +8571,13 @@ static void io_tctx_exit_cb(struct callb complete(&work->completion); } +static bool io_cancel_ctx_cb(struct io_wq_work *work, void *data) +{ + struct io_kiocb *req = container_of(work, struct io_kiocb, work); + + return req->ctx == data; +} + static void io_ring_exit_work(struct work_struct *work) { struct io_ring_ctx *ctx = container_of(work, struct io_ring_ctx, exit_work); @@ -8587,6 +8594,17 @@ static void io_ring_exit_work(struct wor */ do { io_uring_try_cancel_requests(ctx, NULL, NULL); + if (ctx->sq_data) { + struct io_sq_data *sqd = ctx->sq_data; + struct task_struct *tsk; + + io_sq_thread_park(sqd); + tsk = sqd->thread; + if (tsk && tsk->io_uring && tsk->io_uring->io_wq) + io_wq_cancel_cb(tsk->io_uring->io_wq, + io_cancel_ctx_cb, ctx, true); + io_sq_thread_unpark(sqd); + } WARN_ON_ONCE(time_after(jiffies, timeout)); } while (!wait_for_completion_timeout(&ctx->ref_comp, HZ/20)); @@ -8731,13 +8749,6 @@ static bool io_cancel_defer_files(struct return true; } -static bool io_cancel_ctx_cb(struct io_wq_work *work, void *data) -{ - struct io_kiocb *req = container_of(work, struct io_kiocb, work); - - return req->ctx == data; -} - static bool io_uring_try_cancel_iowq(struct io_ring_ctx *ctx) { struct io_tctx_node *node;