Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sasha Levin <sashal@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Christian Brauner <brauner@kernel.org>,
	Al Viro <viro@ZenIV.linux.org.uk>,
	Ajay Kaher <ajay.kaher@broadcom.com>
Subject: [v6.7][PATCH v2 18/23] eventfs: Clean up dentry ops and add revalidate function
Date: Tue, 06 Feb 2024 06:32:16 -0500	[thread overview]
Message-ID: <20240206113401.010494265@rostedt.homelinux.com> (raw)
In-Reply-To: 20240206113158.822006147@rostedt.homelinux.com

From: Linus Torvalds <torvalds@linux-foundation.org>

In order for the dentries to stay up-to-date with the eventfs changes,
just add a 'd_revalidate' function that checks the 'is_freed' bit.

Also, clean up the dentry release to actually use d_release() rather
than the slightly odd d_iput() function.  We don't care about the inode,
all we want to do is to get rid of the refcount to the eventfs data
added by dentry->d_fsdata.

It would probably be cleaner to make eventfs its own filesystem, or at
least set its own dentry ops when looking up eventfs files.  But as it
is, only eventfs dentries use d_fsdata, so we don't really need to split
these things up by use.

Another thing that might be worth doing is to make all eventfs lookups
mark their dentries as not worth caching.  We could do that with
d_delete(), but the DCACHE_DONTCACHE flag would likely be even better.

As it is, the dentries are all freeable, but they only tend to get freed
at memory pressure rather than more proactively.  But that's a separate
issue.

Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/
Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.124644253@goodmis.org

Cc: stable@vger.kernel.org
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Ajay Kaher <ajay.kaher@broadcom.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions")
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
(cherry picked from commit 8dce06e98c70a7fcbb4bca7d90faf40522e65c58)
---
 fs/tracefs/event_inode.c |  5 ++---
 fs/tracefs/inode.c       | 27 ++++++++++++++++++---------
 fs/tracefs/internal.h    |  3 ++-
 3 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 16ca8d9759b1..b2285d5f3fed 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei)
 }
 
 /**
- * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode
- * @ti: the tracefs_inode of the dentry
+ * eventfs_d_release - dentry is going away
  * @dentry: dentry which has the reference to remove.
  *
  * Remove the association between a dentry from an eventfs_inode.
  */
-void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry)
+void eventfs_d_release(struct dentry *dentry)
 {
 	struct eventfs_inode *ei;
 	int i;
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 5c84460feeeb..d65ffad4c327 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = {
 	.show_options	= tracefs_show_options,
 };
 
-static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode)
+/*
+ * It would be cleaner if eventfs had its own dentry ops.
+ *
+ * Note that d_revalidate is called potentially under RCU,
+ * so it can't take the eventfs mutex etc. It's fine - if
+ * we open a file just as it's marked dead, things will
+ * still work just fine, and just see the old stale case.
+ */
+static void tracefs_d_release(struct dentry *dentry)
 {
-	struct tracefs_inode *ti;
+	if (dentry->d_fsdata)
+		eventfs_d_release(dentry);
+}
 
-	if (!dentry || !inode)
-		return;
+static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags)
+{
+	struct eventfs_inode *ei = dentry->d_fsdata;
 
-	ti = get_tracefs(inode);
-	if (ti && ti->flags & TRACEFS_EVENT_INODE)
-		eventfs_set_ei_status_free(ti, dentry);
-	iput(inode);
+	return !(ei && ei->is_freed);
 }
 
 static const struct dentry_operations tracefs_dentry_operations = {
-	.d_iput = tracefs_dentry_iput,
+	.d_revalidate = tracefs_d_revalidate,
+	.d_release = tracefs_d_release,
 };
 
 static int trace_fill_super(struct super_block *sb, void *data, int silent)
diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h
index 932733a2696a..4b50a0668055 100644
--- a/fs/tracefs/internal.h
+++ b/fs/tracefs/internal.h
@@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent);
 struct dentry *tracefs_end_creating(struct dentry *dentry);
 struct dentry *tracefs_failed_creating(struct dentry *dentry);
 struct inode *tracefs_get_inode(struct super_block *sb);
-void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry);
+
+void eventfs_d_release(struct dentry *dentry);
 
 #endif /* _TRACEFS_INTERNAL_H */
-- 
2.43.0



  parent reply	other threads:[~2024-02-06 11:33 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 11:31 [v6.7][PATCH v2 00/23] eventfs: Linus's updates for 6.7 Steven Rostedt
2024-02-06 11:31 ` [v6.7][PATCH v2 01/23] eventfs: Remove "lookup" parameter from create_dir/file_dentry() Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 02/23] eventfs: Stop using dcache_readdir() for getdents() Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 03/23] tracefs/eventfs: Use root and instance inodes as default ownership Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 04/23] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set Steven Rostedt
2024-02-06 11:43   ` kernel test robot
2024-02-06 11:32 ` [v6.7][PATCH v2 05/23] eventfs: Do ctx->pos update for all iterations in eventfs_iterate() Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 06/23] eventfs: Read ei->entries before ei->children " Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 07/23] eventfs: Shortcut eventfs_iterate() by skipping entries already read Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 08/23] eventfs: Have the inodes all for files and directories all be the same Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 09/23] eventfs: Do not create dentries nor inodes in iterate_shared Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 10/23] eventfs: Use kcalloc() instead of kzalloc() Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 11/23] eventfs: Save directory inodes in the eventfs_inode structure Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 12/23] tracefs: remove stale update_gid code Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 13/23] tracefs: Zero out the tracefs_inode when allocating it Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 14/23] eventfs: Initialize the tracefs inode properly Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 15/23] tracefs: Avoid using the ei->dentry pointer unnecessarily Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 16/23] tracefs: dentry lookup crapectomy Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 17/23] eventfs: Remove unused d_parent pointer field Steven Rostedt
2024-02-06 11:32 ` Steven Rostedt [this message]
2024-02-06 11:32 ` [v6.7][PATCH v2 19/23] eventfs: Get rid of dentry pointers without refcounts Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 20/23] eventfs: Warn if an eventfs_inode is freed without is_freed being set Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 21/23] eventfs: Restructure eventfs_inode structure to be more condensed Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 22/23] eventfs: Remove fsnotify*() functions from lookup() Steven Rostedt
2024-02-06 11:32 ` [v6.7][PATCH v2 23/23] eventfs: Keep all directory links at 1 Steven Rostedt
2024-02-19 18:10 ` [v6.7][PATCH v2 00/23] eventfs: Linus's updates for 6.7 Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240206113401.010494265@rostedt.homelinux.com \
    --to=rostedt@goodmis.org \
    --cc=ajay.kaher@broadcom.com \
    --cc=brauner@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox