Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2475853pxb; Mon, 18 Jan 2021 20:29:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJygU9Z7L2Wdkdw/v3XNnRBPIUX27kibpAZsT5IEuklQBhR5W106pF+e1nMB7UFotkYF/5bp X-Received: by 2002:a17:906:3553:: with SMTP id s19mr1732576eja.95.1611030562175; Mon, 18 Jan 2021 20:29:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611030562; cv=none; d=google.com; s=arc-20160816; b=J5aSw7o5Bk7Rll3mAVewYaZSt3hCZ1GzjnDRnNrUiHutZQzTMS1H1ONbcHXkphqE7Z QZAYTff2X709rqlkdpLOzbnCuD2IIYBQDXjXiOZ9S2YhE7w1ls7Pllnzeyd2YvwbuSBo bwvhTcuAdtLTEU7HriFqKJHpHXwxhcghFvyXXXUi8K8x3Y1dGkB29IlW6fUjtmqGS3ae RWiDlxUpbvL47p2E7lR3alBkMylcqxucCcMO2O5fnPVksLngdY3ELEtdmEe/imHaezAq OiKqSz1f5317CUbyjjwsDHVBtTfPcu9DfD923/OuNqJ1U8epzpwCRFMWZn5sSK417fcM HdsQ== 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=T8EXztoeGv47jkAxRPdL2VK5hIYrtELt8sT4ubE698w=; b=qreV1ujazkGFApFKfaXnPVa4qAR60ByttEA+64f8L3WuH36B2gjR4yXCN79tsbFo9n qPcPmECoQapkWyhOYhhjK6hQSABtcui2g110cO4JNZGydOr4oOwtnwZcyinqyjQ6i3rp 5t3K/buJrSjlKGo8Q5JZUe/7Fib9S72ktf5ukTf2DiadMOPCfl50SJle69nJAUJ16HHB OLWE9m7BrhE2sscmSN6DRY0KCSA2oT6Pyn7Jli4v5fagpIyTsYlQ8zdmzN+3uz1TPWz8 r1doB0pPI8Dcky/cDFK8uP+cN7b6bdOi7TA9I6cgPOMEn06xcWhZ3mKhVVL43fY8QuYJ zZbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BoDcRaDp; 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 w1si7765231ejn.628.2021.01.18.20.28.57; Mon, 18 Jan 2021 20:29:22 -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=BoDcRaDp; 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 S2404636AbhAROTy (ORCPT + 99 others); Mon, 18 Jan 2021 09:19:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:39146 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390624AbhARLot (ORCPT ); Mon, 18 Jan 2021 06:44:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1B10B22E01; Mon, 18 Jan 2021 11:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610970250; bh=m9RstEPCumU8Lo/fqYJ4cs9tZXJkpHMODr5qVXvkzls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BoDcRaDpSwcadtpsNSJu4oL7A7gbdjETUQSgWITr+eQzEZsxE7P3p5VF/gzjc+dP1 mz6usNddcAwU0PziQziqrBxh0NxtyrgwCb7r7nR4OM5ARA1Iku/gp70FhXwlRmrVz+ 6sguB/kbAVakIwHxzNKMC5I8OuZJENtfUl3CnCXY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Song Liu , Daniel Borkmann , Yonghong Song , Sasha Levin Subject: [PATCH 5.10 099/152] bpf: Simplify task_file_seq_get_next() Date: Mon, 18 Jan 2021 12:34:34 +0100 Message-Id: <20210118113357.490328939@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210118113352.764293297@linuxfoundation.org> References: <20210118113352.764293297@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: Song Liu [ Upstream commit 91b2db27d3ff9ad29e8b3108dfbf1e2f49fe9bd3 ] Simplify task_file_seq_get_next() by removing two in/out arguments: task and fstruct. Use info->task and info->files instead. Signed-off-by: Song Liu Signed-off-by: Daniel Borkmann Acked-by: Yonghong Song Link: https://lore.kernel.org/bpf/20201120002833.2481110-1-songliubraving@fb.com Signed-off-by: Sasha Levin --- kernel/bpf/task_iter.c | 54 +++++++++++++----------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index 5b6af30bfbcd8..767c93d38bf55 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -136,8 +136,7 @@ struct bpf_iter_seq_task_file_info { }; static struct file * -task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, - struct task_struct **task, struct files_struct **fstruct) +task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info) { struct pid_namespace *ns = info->common.ns; u32 curr_tid = info->tid, max_fds; @@ -150,14 +149,17 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, * Otherwise, it does not hold any reference. */ again: - if (*task) { - curr_task = *task; - curr_files = *fstruct; + if (info->task) { + curr_task = info->task; + curr_files = info->files; curr_fd = info->fd; } else { curr_task = task_seq_get_next(ns, &curr_tid, true); - if (!curr_task) + if (!curr_task) { + info->task = NULL; + info->files = NULL; return NULL; + } curr_files = get_files_struct(curr_task); if (!curr_files) { @@ -167,9 +169,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, goto again; } - /* set *fstruct, *task and info->tid */ - *fstruct = curr_files; - *task = curr_task; + info->files = curr_files; + info->task = curr_task; if (curr_tid == info->tid) { curr_fd = info->fd; } else { @@ -199,8 +200,8 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, rcu_read_unlock(); put_files_struct(curr_files); put_task_struct(curr_task); - *task = NULL; - *fstruct = NULL; + info->task = NULL; + info->files = NULL; info->fd = 0; curr_tid = ++(info->tid); goto again; @@ -209,21 +210,13 @@ task_file_seq_get_next(struct bpf_iter_seq_task_file_info *info, static void *task_file_seq_start(struct seq_file *seq, loff_t *pos) { struct bpf_iter_seq_task_file_info *info = seq->private; - struct files_struct *files = NULL; - struct task_struct *task = NULL; struct file *file; - file = task_file_seq_get_next(info, &task, &files); - if (!file) { - info->files = NULL; - info->task = NULL; - return NULL; - } - - if (*pos == 0) + info->task = NULL; + info->files = NULL; + file = task_file_seq_get_next(info); + if (file && *pos == 0) ++*pos; - info->task = task; - info->files = files; return file; } @@ -231,24 +224,11 @@ static void *task_file_seq_start(struct seq_file *seq, loff_t *pos) static void *task_file_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct bpf_iter_seq_task_file_info *info = seq->private; - struct files_struct *files = info->files; - struct task_struct *task = info->task; - struct file *file; ++*pos; ++info->fd; fput((struct file *)v); - file = task_file_seq_get_next(info, &task, &files); - if (!file) { - info->files = NULL; - info->task = NULL; - return NULL; - } - - info->task = task; - info->files = files; - - return file; + return task_file_seq_get_next(info); } struct bpf_iter__task_file { -- 2.27.0