Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2278853pxb; Thu, 11 Feb 2021 08:31:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJz41+i16e6N5M5jhs54THIi0XH9LLTVFGCJtcRkXQ2fueICYgHco5kmIyqCb/l8OQorbOQ+ X-Received: by 2002:a17:907:b16:: with SMTP id h22mr8950637ejl.393.1613061090564; Thu, 11 Feb 2021 08:31:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613061090; cv=none; d=google.com; s=arc-20160816; b=L6qZWLOW3qcMs0Bw+k+aHOKD31XYgNiybijII6El35P+swO9AizMH7bI/Xa0/pK8K+ WlmSvhxx0euL80d9P6WSlObJ2BcPHcBF9IH870w015BURPxxg3btUsKkUS6BvsKsVaQq JQg2MQgDQpGqEJ0OqDmQmS53safozUkWRu+TnuoI8Q2F6FC9YP4/9d3pAY1TP7RH9siy vRuzx8+l/0odd0JPisF33yn4GCLepkfvRoQoR/MZSIAY3TzHIKb/SODLoRSDgvzqAH7I qWqB6TY18j6OhAEf3mGo3JXDgkxVvSkCPt8E8BrXJ36RnrlmLtjzA4iiQa+UWuDxIsEV iz2A== 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=s/6cf3uHtI4NnM9YgXza1dD4V4jBfqZ+R8PdOwmL6l0=; b=K9EXrdY+VLWUspapLyzc9W9tKWqt/ndyHBfLtaOa+RbhiHOJkNOzl25jYcbfIt6ffK oxFmVCBb6U1J9Mg2h3DEsRR27eKcATWfsmKOJXHjMsK/35eL1gJBtXcrVehKGBpImsdr X9G5KxWL13TWB9dUXxWKAYZuS3ZB99BmXb6Fel7kFKjXyY8eTgzFhm4Fa4MB+i6BGm2u /NFwGh8F+H2kcbdJMb32Bjd5I/RSFUvppF41grIwvYyXAH/ibRyH0t3MRFjk7uf9JGsE gkKmYZtvFd7hGDBk6LQl7+ayeRgSpGwN8RENHTZWREiwAhH0gHWM/EzZiL3+0qasdjTW 7IXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d5t4HZAe; 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 u22si4020225ejf.705.2021.02.11.08.30.39; Thu, 11 Feb 2021 08:31:30 -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=d5t4HZAe; 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 S232025AbhBKQ2G (ORCPT + 99 others); Thu, 11 Feb 2021 11:28:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:53526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231152AbhBKPYz (ORCPT ); Thu, 11 Feb 2021 10:24:55 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6047A64EC7; Thu, 11 Feb 2021 15:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613055820; bh=yszjSzXdxmaj7BeEVp5rgPBW+T0Qmzy+mNIOCv68f/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d5t4HZAeA5G0c0tHr3F+w2MrOhXzrdCk8cQnuiSqf+xjEo1Fzio4F1skeJeJVj9Rs EwGIk42Zragr3t+HTjUYQXKzYqgTNGU8E9HgTpH10Wc8dkJ591bNgyeG96i22o5esS 85xHsXRihViG7nOfyvnZ/GIz9OxWeGHkANFALzts= 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 02/54] io_uring: add a {task,files} pair matching helper Date: Thu, 11 Feb 2021 16:01:46 +0100 Message-Id: <20210211150152.999277924@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: Pavel Begunkov [ Upstream commit 08d23634643c239ddae706758f54d3a8e0c24962 ] Add io_match_task() that matches both task and files. Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 63 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -997,6 +997,36 @@ static inline void io_clean_op(struct io __io_clean_op(req); } +static inline bool __io_match_files(struct io_kiocb *req, + struct files_struct *files) +{ + return ((req->flags & REQ_F_WORK_INITIALIZED) && + (req->work.flags & IO_WQ_WORK_FILES)) && + req->work.identity->files == files; +} + +static bool io_match_task(struct io_kiocb *head, + struct task_struct *task, + struct files_struct *files) +{ + struct io_kiocb *link; + + if (task && head->task != task) + return false; + if (!files) + return true; + if (__io_match_files(head, files)) + return true; + if (head->flags & REQ_F_LINK_HEAD) { + list_for_each_entry(link, &head->link_list, link_list) { + if (__io_match_files(link, files)) + return true; + } + } + return false; +} + + static void io_sq_thread_drop_mm(void) { struct mm_struct *mm = current->mm; @@ -1612,32 +1642,6 @@ static void io_cqring_mark_overflow(stru } } -static inline bool __io_match_files(struct io_kiocb *req, - struct files_struct *files) -{ - return ((req->flags & REQ_F_WORK_INITIALIZED) && - (req->work.flags & IO_WQ_WORK_FILES)) && - req->work.identity->files == files; -} - -static bool io_match_files(struct io_kiocb *req, - struct files_struct *files) -{ - struct io_kiocb *link; - - if (!files) - return true; - if (__io_match_files(req, files)) - return true; - if (req->flags & REQ_F_LINK_HEAD) { - list_for_each_entry(link, &req->link_list, link_list) { - if (__io_match_files(link, files)) - return true; - } - } - return false; -} - /* Returns true if there are no backlogged entries after the flush */ static bool __io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force, struct task_struct *tsk, @@ -1659,9 +1663,7 @@ static bool __io_cqring_overflow_flush(s cqe = NULL; list_for_each_entry_safe(req, tmp, &ctx->cq_overflow_list, compl.list) { - if (tsk && req->task != tsk) - continue; - if (!io_match_files(req, files)) + if (!io_match_task(req, tsk, files)) continue; cqe = io_get_cqring(ctx); @@ -8635,8 +8637,7 @@ static void io_cancel_defer_files(struct spin_lock_irq(&ctx->completion_lock); list_for_each_entry_reverse(de, &ctx->defer_list, list) { - if (io_task_match(de->req, task) && - io_match_files(de->req, files)) { + if (io_match_task(de->req, task, files)) { list_cut_position(&list, &ctx->defer_list, &de->list); break; }