From patchwork Mon Aug 17 15:16:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 266043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88F6CC433DF for ; Mon, 17 Aug 2020 19:14:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67A76204EC for ; Mon, 17 Aug 2020 19:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597691696; bh=Pp+vN7qB4/2ERCceyOTqwYXEP0XhOyD+YA3d2GFVuFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mxJZso9S/vjbxPKZS616fhkbKQb7zszXkiSsBk7DpcKaigjXoNQg/7opZoqsU0g1G gDwYuGwoxsjcDqD9aUSWPWnCGumgpVfgQkkVNv3xaA+XhLh7hxhERTTQv69wN5sqKI P1W7g35BU5uYJ/Fh0iJQOARxgCXl1/u/7jDnaN9o= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731899AbgHQTOe (ORCPT ); Mon, 17 Aug 2020 15:14:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:48846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730355AbgHQPkM (ORCPT ); Mon, 17 Aug 2020 11:40:12 -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 677CA23105; Mon, 17 Aug 2020 15:40:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678809; bh=Pp+vN7qB4/2ERCceyOTqwYXEP0XhOyD+YA3d2GFVuFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MJRlFvRWep+x8nsvpeCdxnN7gpfOTZSGYk9uUsfn2qdieIG+DpWtQVnqeAgxiECtt JXLKAtxKp7p/yrZqJWAWD3hxrydrYqS6ek+6PEZNFCyshbMgNmuqWtKR2CGb0Ewyk3 B/N4PcHr5z56FTl3yRMBL5u5bK3hLuPr7vk+gzOw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe Subject: [PATCH 5.8 462/464] io_uring: add missing REQ_F_COMP_LOCKED for nested requests Date: Mon, 17 Aug 2020 17:16:55 +0200 Message-Id: <20200817143855.909267241@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jens Axboe commit 9b7adba9eaec28e0e4343c96d0dbeb9578802f5f upstream. When we traverse into failing links or timeouts, we need to ensure we propagate the REQ_F_COMP_LOCKED flag to ensure that we correctly signal to the completion side that we already hold the completion lock. Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1549,12 +1549,9 @@ static void io_req_link_next(struct io_k /* * Called if REQ_F_LINK_HEAD is set, and we fail the head request */ -static void io_fail_links(struct io_kiocb *req) +static void __io_fail_links(struct io_kiocb *req) { struct io_ring_ctx *ctx = req->ctx; - unsigned long flags; - - spin_lock_irqsave(&ctx->completion_lock, flags); while (!list_empty(&req->link_list)) { struct io_kiocb *link = list_first_entry(&req->link_list, @@ -1568,13 +1565,29 @@ static void io_fail_links(struct io_kioc io_link_cancel_timeout(link); } else { io_cqring_fill_event(link, -ECANCELED); + link->flags |= REQ_F_COMP_LOCKED; __io_double_put_req(link); } req->flags &= ~REQ_F_LINK_TIMEOUT; } io_commit_cqring(ctx); - spin_unlock_irqrestore(&ctx->completion_lock, flags); +} + +static void io_fail_links(struct io_kiocb *req) +{ + struct io_ring_ctx *ctx = req->ctx; + + if (!(req->flags & REQ_F_COMP_LOCKED)) { + unsigned long flags; + + spin_lock_irqsave(&ctx->completion_lock, flags); + __io_fail_links(req); + spin_unlock_irqrestore(&ctx->completion_lock, flags); + } else { + __io_fail_links(req); + } + io_cqring_ev_posted(ctx); } @@ -4767,6 +4780,7 @@ static int io_timeout_cancel(struct io_r return -EALREADY; req_set_fail_links(req); + req->flags |= REQ_F_COMP_LOCKED; io_cqring_fill_event(req, -ECANCELED); io_put_req(req); return 0;