From patchwork Tue Feb 6 12:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500687dyb; Tue, 6 Feb 2024 04:26:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2hhZ+db1ZXQoS660d6J4unNGSRHIct7Ssyq2IegRd9P4MwrN2UBgmsN1ZO89eF8stsYpj X-Received: by 2002:a17:906:f9c5:b0:a38:350:bbdd with SMTP id lj5-20020a170906f9c500b00a380350bbddmr1427632ejb.48.1707222367197; Tue, 06 Feb 2024 04:26:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222367; cv=pass; d=google.com; s=arc-20160816; b=hXYoaumiDN4AgnqPdWNOhT/ZY5BzZJbjMxOsTkaDrBnE8svdz0+XoKolumTSEX0rdp csWOBSrxE9gUZN9ELXzbf+Cq5UC75bO2ICTWXdCfK5vKRvz62qfhQaACVW2Y2POsi6iO 70POdSOsO6HdAZFXgNl/9RTPQa6YuQhjg/08jmu4H850Kfqh6GN+lFCOOQIWcMvNXkt1 Z+Cz3qfocz4rZs4kVCH7H8IEn7CWQjVlyLrwMwtzdr0T4hoL0sz+40du/+l8ZNhu1N9b DEMbJLdtGMBz3KK5T+KYhJd+btT/dI9CeBIlnOOFLAiUaROuN6vM1EvfoJdSVsQREogY 8yhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=SXG6kX6vpOBEiMVmlEzwWPSMsib1/4LFk5czFSKSK4M=; fh=6h+FSn/J9FL7nQutFq9nHq8Aefcj+c+gywjP/7GjtQM=; b=kuBtJAmtd2SNK9YZsgUjC4d+J/F+GVdPax2Mne+7wcjjnvFEpdY4CwmlzbTIzC7qXm UjddQv9dVnbzXRXQ6zU65bBtC0JjI/rnYxh8ZMHVGKMS1Wn3ceAboqnMW+F0PYmI3AlC N7EtZv68gFv8s4TYMNTCxBEmuvnPqbvWLEu8/2VJbCdpQdVtn+da3KaWH1VMvDQE2aE0 3MqjlUqvpNfc7FasU8JlBw4G3fL9fj+aqXiKsCiJ5+RdHG49IrjQ6yRUdeKCqB+Rahi/ o9CsNg4to9NfMcHwUHPVm3NBQq5XsrdlKdVu18Zg8bbBRyesiEX00BtHzW4Q4k7tVScZ pXMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXM7ZbVSEjiu8WY+hwta7VlpRBg4Pb7SSnFBrOZynvIr04T7uoRdk6tddfAcPGGRtH1Hw7450Nv5JBLiJllJrJZgm2cxw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g13-20020a1709067c4d00b00a367f22a26csi1077008ejp.355.2024.02.06.04.26.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CB27B1F23B57 for ; Tue, 6 Feb 2024 12:26:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCCC214F9F6; Tue, 6 Feb 2024 12:09:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADFD413A889; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; cv=none; b=qWiyBSrWNMSmo/Dr8A3rvXJr+w0k+pq8ElAjDjP3oDbb9bnlcUcDB795IcL0Ni5HcYI0Z3/E89UosXi466tanPKIRL/2nU6y+G//uKbNF7v3RKgMkcXUAOIvAioHKRqQbFkMRaV7dUFHvNzteTKlXjAYaxjmEFiLMr9d9FctlRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=msUlAhKaN43vF7JsX1xwBfcdPGlDn+EyYYaBimHJa/8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Z9cFyddLBBpVdIG8cB6CntUiAUEehdPiJjPf4fikVF6aYJR4TUY7MQqtz+of0VpX4uIlz279I/2oP5VpH888jtL+Y93SRjK6SegJYRFYNK1Ke8/xXH7nDq+9avBZPEm/i+KIUbJUabpE5TuUOe85NjFoF4gAfHBksw0ZFoxUgrw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 916EDC4167D; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bLL-07BP; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120952.892527913@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:45 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.6][PATCH 40/57] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152400905688593 X-GMAIL-MSGID: 1790152400905688593 From: "Steven Rostedt (Google)" In order to apply a shortcut to skip over the current ctx->pos immediately, by using the ei->entries array, the reading of that array should be first. Moving the array reading before the linked list reading will make the shortcut change diff nicer to read. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.333115095@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 704f960dbee2f1634f4b4e16f208cb16eaf41c1e) --- fs/tracefs/event_inode.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c73fb1f7ddbc..a1934e0eea3b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -752,8 +752,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) * Need to create the dentries and inodes to have a consistent * inode number. */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + for (i = 0; i < ei->nr_entries; i++) { + void *cdata = ei->data; if (c > 0) { c--; @@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - if (ei_child->is_freed) - continue; + entry = &ei->entries[i]; + name = entry->name; - name = ei_child->name; + mutex_lock(&eventfs_mutex); + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out_dec; + } + r = entry->callback(name, &mode, &cdata, &fops); + mutex_unlock(&eventfs_mutex); + if (r <= 0) + continue; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out_dec; } - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { if (c > 0) { c--; @@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - entry = &ei->entries[i]; - name = entry->name; - - mutex_lock(&eventfs_mutex); - /* If ei->is_freed then just bail here, nothing more to do */ - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - goto out_dec; - } - r = entry->callback(name, &mode, &cdata, &fops); - mutex_unlock(&eventfs_mutex); - if (r <= 0) + if (ei_child->is_freed) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; } ret = 1;