Patch "eventfs: Save directory inodes in the eventfs_inode structure" has been added to the 6.7-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    eventfs: Save directory inodes in the eventfs_inode structure

to the 6.7-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     eventfs-save-directory-inodes-in-the-eventfs_inode-structure.patch
and it can be found in the queue-6.7 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.


>From SRS0=eEWY=JP=rostedt.homelinux.com=rostedt@xxxxxxxxxx Tue Feb  6 12:33:32 2024
From: Steven Rostedt <rostedt@xxxxxxxxxxx>
Date: Tue, 06 Feb 2024 06:32:09 -0500
Subject: eventfs: Save directory inodes in the eventfs_inode structure
To: linux-kernel@xxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Sasha Levin <sashal@xxxxxxxxxx>, Masami Hiramatsu <mhiramat@xxxxxxxxxx>, Mark Rutland <mark.rutland@xxxxxxx>, Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Geert Uytterhoeven <geert+renesas@xxxxxxxxx>, Kees Cook <keescook@xxxxxxxxxxxx>
Message-ID: <20240206113359.872124971@xxxxxxxxxxxxxxxxxxxxx>

From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

commit 834bf76add3e6168038150f162cbccf1fd492a67 upstream.

The eventfs inodes and directories are allocated when referenced. But this
leaves the issue of keeping consistent inode numbers and the number is
only saved in the inode structure itself. When the inode is no longer
referenced, it can be freed. When the file that the inode was representing
is referenced again, the inode is once again created, but the inode number
needs to be the same as it was before.

Just making the inode numbers the same for all files is fine, but that
does not work with directories. The find command will check for loops via
the inode number and having the same inode number for directories triggers:

  # find /sys/kernel/tracing
find: File system loop detected;
'/sys/kernel/debug/tracing/events/initcall/initcall_finish' is part of the same file system loop as
'/sys/kernel/debug/tracing/events/initcall'.
[..]

Linus pointed out that the eventfs_inode structure ends with a single
32bit int, and on 64 bit machines, there's likely a 4 byte hole due to
alignment. We can use this hole to store the inode number for the
eventfs_inode. All directories in eventfs are represented by an
eventfs_inode and that data structure can hold its inode number.

That last int was also purposely placed at the end of the structure to
prevent holes from within. Now that there's a 4 byte number to hold the
inode, both the inode number and the last integer can be moved up in the
structure for better cache locality, where the llist and rcu fields can be
moved to the end as they are only used when the eventfs_inode is being
deleted.

Link: https://lore.kernel.org/all/CAMuHMdXKiorg-jiuKoZpfZyDJ3Ynrfb8=X+c7x0Eewxn-YRdCA@xxxxxxxxxxxxxx/
Link: https://lore.kernel.org/linux-trace-kernel/20240122152748.46897388@xxxxxxxxxxxxxxxxxx

Cc: Masami Hiramatsu <mhiramat@xxxxxxxxxx>
Cc: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Reported-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>
Tested-by: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
Fixes: 53c41052ba31 ("eventfs: Have the inodes all for files and directories all be the same")
Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 fs/tracefs/event_inode.c |   14 +++++++++++---
 fs/tracefs/internal.h    |    7 ++++---
 2 files changed, 15 insertions(+), 6 deletions(-)

--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -34,7 +34,15 @@ static DEFINE_MUTEX(eventfs_mutex);
 
 /* Choose something "unique" ;-) */
 #define EVENTFS_FILE_INODE_INO		0x12c4e37
-#define EVENTFS_DIR_INODE_INO		0x134b2f5
+
+/* Just try to make something consistent and unique */
+static int eventfs_dir_ino(struct eventfs_inode *ei)
+{
+	if (!ei->ino)
+		ei->ino = get_next_ino();
+
+	return ei->ino;
+}
 
 /*
  * The eventfs_inode (ei) itself is protected by SRCU. It is released from
@@ -358,7 +366,7 @@ static struct dentry *create_dir(struct
 	inode->i_fop = &eventfs_file_operations;
 
 	/* All directories will have the same inode number */
-	inode->i_ino = EVENTFS_DIR_INODE_INO;
+	inode->i_ino = eventfs_dir_ino(ei);
 
 	ti = get_tracefs(inode);
 	ti->flags |= TRACEFS_EVENT_INODE;
@@ -764,7 +772,7 @@ static int eventfs_iterate(struct file *
 
 		name = ei_child->name;
 
-		ino = EVENTFS_DIR_INODE_INO;
+		ino = eventfs_dir_ino(ei_child);
 
 		if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR))
 			goto out_dec;
--- a/fs/tracefs/internal.h
+++ b/fs/tracefs/internal.h
@@ -55,6 +55,10 @@ struct eventfs_inode {
 	struct eventfs_attr		*entry_attrs;
 	struct eventfs_attr		attr;
 	void				*data;
+	unsigned int			is_freed:1;
+	unsigned int			is_events:1;
+	unsigned int			nr_entries:30;
+	unsigned int			ino;
 	/*
 	 * Union - used for deletion
 	 * @llist:	for calling dput() if needed after RCU
@@ -64,9 +68,6 @@ struct eventfs_inode {
 		struct llist_node	llist;
 		struct rcu_head		rcu;
 	};
-	unsigned int			is_freed:1;
-	unsigned int			is_events:1;
-	unsigned int			nr_entries:30;
 };
 
 static inline struct tracefs_inode *get_tracefs(const struct inode *inode)


Patches currently in stable-queue which might be from rostedt@xxxxxxxxxx are

queue-6.7/eventfs-keep-all-directory-links-at-1.patch
queue-6.7/eventfs-save-directory-inodes-in-the-eventfs_inode-structure.patch
queue-6.7/tracefs-zero-out-the-tracefs_inode-when-allocating-it.patch
queue-6.7/eventfs-read-ei-entries-before-ei-children-in-eventfs_iterate.patch
queue-6.7/eventfs-remove-lookup-parameter-from-create_dir-file_dentry.patch
queue-6.7/eventfs-remove-fsnotify-functions-from-lookup.patch
queue-6.7/eventfs-stop-using-dcache_readdir-for-getdents.patch
queue-6.7/tracefs-avoid-using-the-ei-dentry-pointer-unnecessarily.patch
queue-6.7/eventfs-initialize-the-tracefs-inode-properly.patch
queue-6.7/eventfs-do-ctx-pos-update-for-all-iterations-in-eventfs_iterate.patch
queue-6.7/tracefs-dentry-lookup-crapectomy.patch
queue-6.7/eventfs-have-the-inodes-all-for-files-and-directories-all-be-the-same.patch
queue-6.7/eventfs-use-kcalloc-instead-of-kzalloc.patch
queue-6.7/eventfs-shortcut-eventfs_iterate-by-skipping-entries-already-read.patch
queue-6.7/eventfs-do-not-create-dentries-nor-inodes-in-iterate_shared.patch
queue-6.7/eventfs-have-eventfs_iterate-stop-immediately-if-ei-is_freed-is-set.patch
queue-6.7/eventfs-restructure-eventfs_inode-structure-to-be-more-condensed.patch
queue-6.7/eventfs-warn-if-an-eventfs_inode-is-freed-without-is_freed-being-set.patch
queue-6.7/eventfs-get-rid-of-dentry-pointers-without-refcounts.patch
queue-6.7/eventfs-remove-unused-d_parent-pointer-field.patch
queue-6.7/eventfs-clean-up-dentry-ops-and-add-revalidate-function.patch




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux