Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp388150pxk; Fri, 11 Sep 2020 09:33:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweAQXgm6Omwdvn3GrUvGJdmg2KUvWywj7ta8IUJdC5nbyWMaNIc+2nFRRYODKb+5dsbp77 X-Received: by 2002:a17:907:20d9:: with SMTP id qq25mr2730345ejb.382.1599842031812; Fri, 11 Sep 2020 09:33:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599842031; cv=none; d=google.com; s=arc-20160816; b=QobqF27QZ5KLxeVVJAAHX/Dz5lnqCZ8GQFuI0YFZxop70e0P40ZyNLbdhKd6wziFfy cSRyM1HNFortOOax7o/W7UQHI3P6LNyfRzd39jNppVy+iqPFRzXFD2QBma5454CZNYf+ XjRq61iCwueUYINEqA6RaBgC4jiPJ7DbQTls8+eYiZkoqljajhTDJ/xa11ts9lP/knfA fXs6q5fN/dkfLMINnHPM/G6O8+L0iLyrs4B+vsi3ommgzY2VkJSL8dRV73l1uI7D3O8/ BC86UngZlhVUfrXMxsFzek4n//3O+0GCKTfHDS2s1MysEgvDK/8P4NyCqsvVEWweIKAf Gpgg== 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=m3i8Yc+D8+nqe/+jDz11Tc7TqXrmAzlIDRXZN9nYkP8=; b=KspXrCSbfjEeA7BMwgZaF6a+G88VuxzAhGK3w1NNVM3WAGlGycW6dGDdw93TN5xSgc QJYymJh59E6a/tlbA8f1LxD8+S8WuTacqHpX6eU7Ped63yDL1xmccCa/ARlmyYwQQ1qo xYYU2xKNCfJpEP0D0XXNzigwMzUZJGXiROKe5VKXbaxDKVPYPggMCYeeOA7N6P+P1eUO VhlZ6oUgQsAk/uNxAgru4Kcc5sQaeU2cscDg0S3k8DYZHVKMn+6jLslslgtirBNrRZ0H Frc7/EZcls0CA4+rIiRlfI/issiZtWPA5ifIW7FAlVM+q5utdEJMDkb5a3zJHD0S4ji3 2o7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RwvKjBdU; 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 c15si1615330ejr.34.2020.09.11.09.33.28; Fri, 11 Sep 2020 09:33:51 -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=RwvKjBdU; 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 S1726626AbgIKQch (ORCPT + 99 others); Fri, 11 Sep 2020 12:32:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:53924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgIKPTI (ORCPT ); Fri, 11 Sep 2020 11:19:08 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 AF82322450; Fri, 11 Sep 2020 12:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599829168; bh=K6y/vHVqiosI8pfx5NYVW44msU10AvAKxSSUxgqbr2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RwvKjBdU6ymL2C81W+9TKUaVqsNyvX4iMZmx7eSwG6C/6hsT+NuMTnXxiw4jIoqph 95P2KAXBBVcOtRf2UJdMZtv97qvN8dRe8WWTFyL4Z9k85YkhT2gof6LISr1ax0Zzfx J2/3GSoB6/BcCM+FQUoqeoSAOptm4a05n2qyOfkk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe , Sasha Levin Subject: [PATCH 5.8 01/16] io_uring: fix cancel of deferred reqs with ->files Date: Fri, 11 Sep 2020 14:47:18 +0200 Message-Id: <20200911122459.664920183@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200911122459.585735377@linuxfoundation.org> References: <20200911122459.585735377@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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: Pavel Begunkov [ Upstream commit b7ddce3cbf010edbfac6c6d8cc708560a7bcd7a4 ] While trying to cancel requests with ->files, it also should look for requests in ->defer_list, otherwise it might end up hanging a thread. Cancel all requests in ->defer_list up to the last request there with matching ->files, that's needed to follow drain ordering semantics. Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/io_uring.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fs/io_uring.c b/fs/io_uring.c index 38f3ec15ba3b1..5f627194d0920 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -7675,12 +7675,38 @@ static void io_attempt_cancel(struct io_ring_ctx *ctx, struct io_kiocb *req) io_timeout_remove_link(ctx, req); } +static void io_cancel_defer_files(struct io_ring_ctx *ctx, + struct files_struct *files) +{ + struct io_kiocb *req = NULL; + LIST_HEAD(list); + + spin_lock_irq(&ctx->completion_lock); + list_for_each_entry_reverse(req, &ctx->defer_list, list) { + if ((req->flags & REQ_F_WORK_INITIALIZED) + && req->work.files == files) { + list_cut_position(&list, &ctx->defer_list, &req->list); + break; + } + } + spin_unlock_irq(&ctx->completion_lock); + + while (!list_empty(&list)) { + req = list_first_entry(&list, struct io_kiocb, list); + list_del_init(&req->list); + req_set_fail_links(req); + io_cqring_add_event(req, -ECANCELED); + io_double_put_req(req); + } +} + static void io_uring_cancel_files(struct io_ring_ctx *ctx, struct files_struct *files) { if (list_empty_careful(&ctx->inflight_list)) return; + io_cancel_defer_files(ctx, files); /* cancel all at once, should be faster than doing it one by one*/ io_wq_cancel_cb(ctx->io_wq, io_wq_files_match, files, true); -- 2.25.1