From nobody Fri Dec 26 13:26:20 2025 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 5FE8834CEA for ; Fri, 5 Jan 2024 18:00:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA708C433CD; Fri, 5 Jan 2024 18:00:10 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rLoVT-000000012Vt-1Y3M; Fri, 05 Jan 2024 13:01:19 -0500 Message-ID: <20240105180119.231810370@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 05 Jan 2024 13:00:54 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Al Viro , Christian Brauner , Greg Kroah-Hartman Subject: [for-next][PATCH 3/4] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240105180051.741934288@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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-=3DwiKwDUDv3+jCsv-uacDcHDVTYsXtBR9= =3D6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.333115095@g= oodmis.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) --- 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 di= r_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 =3D 0; i < ei->nr_entries; i++) { + void *cdata =3D ei->data; =20 if (c > 0) { c--; @@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct = dir_context *ctx) =20 ctx->pos++; =20 - if (ei_child->is_freed) - continue; + entry =3D &ei->entries[i]; + name =3D entry->name; =20 - name =3D 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 =3D entry->callback(name, &mode, &cdata, &fops); + mutex_unlock(&eventfs_mutex); + if (r <=3D 0) + continue; =20 - dentry =3D create_dir_dentry(ei, ei_child, ei_dentry); + dentry =3D create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) goto out_dec; ino =3D dentry->d_inode->i_ino; dput(dentry); =20 - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out_dec; } =20 - for (i =3D 0; i < ei->nr_entries; i++) { - void *cdata =3D ei->data; + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { =20 if (c > 0) { c--; @@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct = dir_context *ctx) =20 ctx->pos++; =20 - entry =3D &ei->entries[i]; - name =3D 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 =3D entry->callback(name, &mode, &cdata, &fops); - mutex_unlock(&eventfs_mutex); - if (r <=3D 0) + if (ei_child->is_freed) continue; =20 - dentry =3D create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + name =3D ei_child->name; + + dentry =3D create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) goto out_dec; ino =3D dentry->d_inode->i_ino; dput(dentry); =20 - if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; } ret =3D 1; --=20 2.42.0