Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2241731pxb; Thu, 11 Feb 2021 07:45:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyGTpPDMxmov2+KgAfFA1su1KI4yel1ma8Vx3sC+mi3iLgwI4DJ7KYaESHsUTvyOgi3F+Tb X-Received: by 2002:a05:6402:208:: with SMTP id t8mr8846030edv.189.1613058338091; Thu, 11 Feb 2021 07:45:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613058338; cv=none; d=google.com; s=arc-20160816; b=PXpY4hjFdHF/7NaoBqW0GR/tHTKXJvZIoGHN0HR0kN8btG5n3tZaT9F9XVXeqRBnKi sPToGl5qJ2Bi0Jm/3blKa1raSJFwNthwZ6BefnM/t7OSzOdtQhYmoLjO/j6xuoNIH04I X+ZYqg/g7a34aQk4e2JpMpoHHT7kOGo6YN+4m0kYAHDqhfdevoRRQnvV38tW3Rs2c7Y7 OA499lFACl2Oo/Y77cYr95qACiHDQMw+aAcU2dAYoUWBYAWYM96jbhTD8UaRgdSTgSCv a7MnBSkv7kKGNdPJdU+jqbJEzKl6yVPGgNqvIRHXr+7enql5K5CXjX0HhhszIEJ46ulE gneQ== 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=UlfIuXU7fcjojuV6/28DKjjXcZRDCJzukPwEV7iE018=; b=FNGWzJud7ceuDBROujVQccALx1et/oeNPqd+7W+agq8mi5rZs4z6rtJPy5U2+f9gns 4qUSkHnldCNwqVg8PTuFhtlKlOcZz0Yygf99WEbD7aKar4thamJJSR8UXGnnA9EXCF9T it1ZedN1e3khjLeaFQe2eIrxJ3SSOIzApYFfKW5rDfS/toCCSitwc2V7CE5NlevISVLq iMI6RXp5ZENHIvSWq9luAza3aqW5wjVX9uxeMnUjySi0+8SZ2eLGxsWvnwbRINOWqVaO Wgi6ARU3Q7UJzfWG9Ni3MkrtBkqQOZn4hzREWWL19Jci7jNAeaixlBb0kzayUCyxmu4i WJEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T6FdbuhD; 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 p26si3951296edt.29.2021.02.11.07.45.03; Thu, 11 Feb 2021 07:45:38 -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=T6FdbuhD; 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 S230285AbhBKPoM (ORCPT + 99 others); Thu, 11 Feb 2021 10:44:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:52054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbhBKPNT (ORCPT ); Thu, 11 Feb 2021 10:13:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D99E864EE7; Thu, 11 Feb 2021 15:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055857; bh=AWEhQnvD4wbd7vUfesoDm4gdZDGusryI5Q9W95K/Owo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T6FdbuhDPVL3gwKhnvM+D1EUoPRhxqyrixlcyWoxUK2tzBSjGNxOOkBKsrUD+6nX+ rQ0shrmn7HsTslrum6buT1WHuyF2CtoAvO4ajZ/s5n1Oj/1rTb3wfLHofGO/7wqJvo idfYgz0EfRpgREukbQuh5VrX58j+nbNRiuVWZjhg= 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 07/54] io_uring: account io_uring internal files as REQ_F_INFLIGHT Date: Thu, 11 Feb 2021 16:01:51 +0100 Message-Id: <20210211150153.199303516@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: Jens Axboe [ Upstream commit 02a13674fa0e8dd326de8b9f4514b41b03d99003 ] We need to actively cancel anything that introduces a potential circular loop, where io_uring holds a reference to itself. If the file in question is an io_uring file, then add the request to the inflight list. Cc: stable@vger.kernel.org # 5.9+ Signed-off-by: Jens Axboe Signed-off-by: Pavel Begunkov Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1000,6 +1000,9 @@ static inline void io_clean_op(struct io static inline bool __io_match_files(struct io_kiocb *req, struct files_struct *files) { + if (req->file && req->file->f_op == &io_uring_fops) + return true; + return ((req->flags & REQ_F_WORK_INITIALIZED) && (req->work.flags & IO_WQ_WORK_FILES)) && req->work.identity->files == files; @@ -1398,11 +1401,14 @@ static bool io_grab_identity(struct io_k return false; atomic_inc(&id->files->count); get_nsproxy(id->nsproxy); - req->flags |= REQ_F_INFLIGHT; - spin_lock_irq(&ctx->inflight_lock); - list_add(&req->inflight_entry, &ctx->inflight_list); - spin_unlock_irq(&ctx->inflight_lock); + if (!(req->flags & REQ_F_INFLIGHT)) { + req->flags |= REQ_F_INFLIGHT; + + spin_lock_irq(&ctx->inflight_lock); + list_add(&req->inflight_entry, &ctx->inflight_list); + spin_unlock_irq(&ctx->inflight_lock); + } req->work.flags |= IO_WQ_WORK_FILES; } if (!(req->work.flags & IO_WQ_WORK_MM) && @@ -5886,8 +5892,10 @@ static void io_req_drop_files(struct io_ struct io_ring_ctx *ctx = req->ctx; unsigned long flags; - put_files_struct(req->work.identity->files); - put_nsproxy(req->work.identity->nsproxy); + if (req->work.flags & IO_WQ_WORK_FILES) { + put_files_struct(req->work.identity->files); + put_nsproxy(req->work.identity->nsproxy); + } spin_lock_irqsave(&ctx->inflight_lock, flags); list_del(&req->inflight_entry); spin_unlock_irqrestore(&ctx->inflight_lock, flags); @@ -6159,6 +6167,15 @@ static struct file *io_file_get(struct i file = __io_file_get(state, fd); } + if (file && file->f_op == &io_uring_fops) { + io_req_init_async(req); + req->flags |= REQ_F_INFLIGHT; + + spin_lock_irq(&ctx->inflight_lock); + list_add(&req->inflight_entry, &ctx->inflight_list); + spin_unlock_irq(&ctx->inflight_lock); + } + return file; } @@ -8578,8 +8595,7 @@ static void io_uring_cancel_files(struct spin_lock_irq(&ctx->inflight_lock); list_for_each_entry(req, &ctx->inflight_list, inflight_entry) { - if (req->task != task || - req->work.identity->files != files) + if (!io_match_task(req, task, files)) continue; found = true; break;