Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2027533pxa; Mon, 24 Aug 2020 03:02:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1HcKBNvhVrbSSFfj7fxd6koFqqdQ3bJsJUBOBItBytkHX0EybJP1RX4XRfxDh2f51SqQM X-Received: by 2002:a05:6402:501:: with SMTP id m1mr4416289edv.99.1598263345681; Mon, 24 Aug 2020 03:02:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598263345; cv=none; d=google.com; s=arc-20160816; b=ERmm73WzXj7lhHR2PT5YvwPjvujNC/KP0nNjyLBo8vFZfrhYuK6Nxlo6qKVi4r53Ou zPceoSVLJKFb2PdxFKh/vj6tJ7yKM37JjiTzsMrTgX15LinEhrM1cpLlQjpGlqdkrxlE tJgSm4rYv6UegXfKvYWnYKpM53lhf3eHAaOO7cIyKPy1Nfx/+tB1DlYruqyZbTTsAvym MKBaT3Q6tYK06ucaHGVah4SK2uuHxrk0Iz5mxSidFT/9OjiHMKnMth0KDRKjBMt2Uw9s tIQcArHbdw2a+EBNf8tvov2+BuV8Yub/cj7fg40siyfylizQ0DjraGefIQIO5upVzUrr nlhA== 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=T3Q3Ji5M0rCcKtl5L687ZJbR3FFbWel+pQ7ZB3k6SiY=; b=P79KztTI32jnWt/UWPcF9YoJO287Uh6IADEjU4t3QQXGr55M1m1Wej78RahuicXtLm qXot3I+R3qWzzLFxKmkvlZx8wilVqDJqcr97XEKbA/EUhAiCRxCxDEqCnhPf/cRCOoL7 RevVo7iknqCokexrPHDmbkazrEkwRBL07NojiIT2cc5R2nL77cfgVNYY5YHY4LfFU9MG 2uFkoDyohL3jUwEX4nMDBaUyf8//cEpNksURDKE1LBPi9XaWvRtt51lyyFuKhGUruWwn uOTy2gzpLITMn4rIKE9+W65HkFNNaEOUDfIAM7fBT8g7jnUuGuBK5nVY4HYqwoQdBc/Y Wqvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o1T7Ckyk; 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=fail (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 b92si6287488edf.226.2020.08.24.03.02.02; Mon, 24 Aug 2020 03:02:25 -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=@kernel.org header.s=default header.b=o1T7Ckyk; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726585AbgHXIcQ (ORCPT + 99 others); Mon, 24 Aug 2020 04:32:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:38758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726037AbgHXIcJ (ORCPT ); Mon, 24 Aug 2020 04:32:09 -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 48F592074D; Mon, 24 Aug 2020 08:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598257928; bh=2FKLRsp/q4hCpwXTaY8+6NDt7k4ARIDqnPQJhxEo6BY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1T7CkykaxA0ieOGgtps0HycJ9sVwcKeUAh1hc/q/RPG5jHTgrkyEnaSImBkjKwxJ y/5WLOi7ENqGLqt5vxigla+7hnCiqTEoXPEix2PMRzl1f1o6uEx3dOof2N33h+I/IG jySxa8IId3oLNijzxcxhsZq2KylHK7+oHP72zO9U= 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.8 012/148] io_uring: find and cancel head link async work on files exit Date: Mon, 24 Aug 2020 10:28:30 +0200 Message-Id: <20200824082414.547922920@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824082413.900489417@linuxfoundation.org> References: <20200824082413.900489417@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: Jens Axboe commit b711d4eaf0c408a811311ee3e94d6e9e5a230a9a upstream. Commit f254ac04c874 ("io_uring: enable lookup of links holding inflight files") only handled 2 out of the three head link cases we have, we also need to lookup and cancel work that is blocked in io-wq if that work has a link that's holding a reference to the files structure. Put the "cancel head links that hold this request pending" logic into io_attempt_cancel(), which will to through the motions of finding and canceling head links that hold the current inflight files stable request pending. Cc: stable@vger.kernel.org Reported-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7609,6 +7609,33 @@ static bool io_timeout_remove_link(struc return found; } +static bool io_cancel_link_cb(struct io_wq_work *work, void *data) +{ + return io_match_link(container_of(work, struct io_kiocb, work), data); +} + +static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req) +{ + enum io_wq_cancel cret; + + /* cancel this particular work, if it's running */ + cret = io_wq_cancel_work(ctx->io_wq, &req->work); + if (cret != IO_WQ_CANCEL_NOTFOUND) + return; + + /* find links that hold this pending, cancel those */ + cret = io_wq_cancel_cb(ctx->io_wq, io_cancel_link_cb, req, true); + if (cret != IO_WQ_CANCEL_NOTFOUND) + return; + + /* if we have a poll link holding this pending, cancel that */ + if (io_poll_remove_link(ctx, req)) + return; + + /* final option, timeout link is holding this req pending */ + io_timeout_remove_link(ctx, req); +} + static void io_uring_cancel_files(struct io_ring_ctx *ctx, struct files_struct *files) { @@ -7665,10 +7692,8 @@ static void io_uring_cancel_files(struct continue; } } else { - io_wq_cancel_work(ctx->io_wq, &cancel_req->work); - /* could be a link, check and remove if it is */ - if (!io_poll_remove_link(ctx, cancel_req)) - io_timeout_remove_link(ctx, cancel_req); + /* cancel this request, or head link requests */ + io_attempt_cancel(ctx, cancel_req); io_put_req(cancel_req); }