* [PATCH 0/4] eventfs: Some more minor fixes
@ 2023-11-21 23:10 Steven Rostedt
2023-11-21 23:10 ` [PATCH 1/4] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held Steven Rostedt
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-21 23:10 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, linux-fsdevel
Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton
Mark Rutland reported some crashes from the latest eventfs updates.
This fixes most of them.
He still has one splat that he can trigger but I can not. Still looking
into that.
Steven Rostedt (Google) (4):
eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held
eventfs: Move taking of inode_lock into dcache_dir_open_wrapper()
eventfs: Do not allow NULL parent to eventfs_start_creating()
eventfs: Make sure that parent->d_inode is locked in creating files/dirs
----
fs/tracefs/event_inode.c | 24 ++++++++----------------
fs/tracefs/inode.c | 13 ++++---------
2 files changed, 12 insertions(+), 25 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
@ 2023-11-21 23:10 ` Steven Rostedt
2023-11-21 23:10 ` [PATCH 2/4] eventfs: Move taking of inode_lock into dcache_dir_open_wrapper() Steven Rostedt
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-21 23:10 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, linux-fsdevel
Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
If memory reclaim happens, it can reclaim file system pages. The file
system pages from eventfs may take the eventfs_mutex on reclaim. This
means that allocation while holding the eventfs_mutex must not call into
filesystem reclaim. A lockdep splat uncovered this.
Fixes: 28e12c09f5aa0 ("eventfs: Save ownership and mode")
Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode")
Reported-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
fs/tracefs/event_inode.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 3eb6c622a74d..56d192f0ead8 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -95,7 +95,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry,
if (!(dentry->d_inode->i_mode & S_IFDIR)) {
if (!ei->entry_attrs) {
ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries,
- GFP_KERNEL);
+ GFP_NOFS);
if (!ei->entry_attrs) {
ret = -ENOMEM;
goto out;
@@ -627,7 +627,7 @@ static int add_dentries(struct dentry ***dentries, struct dentry *d, int cnt)
{
struct dentry **tmp;
- tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_KERNEL);
+ tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_NOFS);
if (!tmp)
return -1;
tmp[cnt] = d;
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] eventfs: Move taking of inode_lock into dcache_dir_open_wrapper()
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
2023-11-21 23:10 ` [PATCH 1/4] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held Steven Rostedt
@ 2023-11-21 23:10 ` Steven Rostedt
2023-11-21 23:10 ` [PATCH 3/4] eventfs: Do not allow NULL parent to eventfs_start_creating() Steven Rostedt
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-21 23:10 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, linux-fsdevel
Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The both create_file_dentry() and create_dir_dentry() takes a boolean
parameter "lookup", as on lookup the inode_lock should already be taken,
but for dcache_dir_open_wrapper() it is not taken.
There's no reason that the dcache_dir_open_wrapper() can't take the
inode_lock before calling these functions. In fact, it's better if it
does, as the lock can be held throughout both directory and file
creations.
This also simplifies the code, and possibly prevents unexpected race
conditions when the lock is released.
Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
fs/tracefs/event_inode.c | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 56d192f0ead8..590e8176449b 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -347,15 +347,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
mutex_unlock(&eventfs_mutex);
- /* The lookup already has the parent->d_inode locked */
- if (!lookup)
- inode_lock(parent->d_inode);
-
dentry = create_file(name, mode, attr, parent, data, fops);
- if (!lookup)
- inode_unlock(parent->d_inode);
-
mutex_lock(&eventfs_mutex);
if (IS_ERR_OR_NULL(dentry)) {
@@ -453,15 +446,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
}
mutex_unlock(&eventfs_mutex);
- /* The lookup already has the parent->d_inode locked */
- if (!lookup)
- inode_lock(parent->d_inode);
-
dentry = create_dir(ei, parent);
- if (!lookup)
- inode_unlock(parent->d_inode);
-
mutex_lock(&eventfs_mutex);
if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) {
@@ -693,6 +679,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
return -ENOMEM;
}
+ inode_lock(parent->d_inode);
list_for_each_entry_srcu(ei_child, &ei->children, list,
srcu_read_lock_held(&eventfs_srcu)) {
d = create_dir_dentry(ei, ei_child, parent, false);
@@ -725,6 +712,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file)
cnt++;
}
}
+ inode_unlock(parent->d_inode);
srcu_read_unlock(&eventfs_srcu, idx);
ret = dcache_dir_open(inode, file);
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] eventfs: Do not allow NULL parent to eventfs_start_creating()
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
2023-11-21 23:10 ` [PATCH 1/4] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held Steven Rostedt
2023-11-21 23:10 ` [PATCH 2/4] eventfs: Move taking of inode_lock into dcache_dir_open_wrapper() Steven Rostedt
@ 2023-11-21 23:10 ` Steven Rostedt
2023-11-21 23:10 ` [PATCH 4/4] eventfs: Make sure that parent->d_inode is locked in creating files/dirs Steven Rostedt
2023-11-22 14:19 ` [PATCH 0/4] eventfs: Some more minor fixes Josef Bacik
4 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-21 23:10 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, linux-fsdevel
Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The eventfs directory is dynamically created via the meta data supplied by
the existing trace events. All files and directories in eventfs has a
parent. Do not allow NULL to be passed into eventfs_start_creating() as
the parent because that should never happen. Warn if it does.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
fs/tracefs/inode.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c
index 5b54948514fe..ae648deed019 100644
--- a/fs/tracefs/inode.c
+++ b/fs/tracefs/inode.c
@@ -509,20 +509,15 @@ struct dentry *eventfs_start_creating(const char *name, struct dentry *parent)
struct dentry *dentry;
int error;
+ /* Must always have a parent. */
+ if (WARN_ON_ONCE(!parent))
+ return ERR_PTR(-EINVAL);
+
error = simple_pin_fs(&trace_fs_type, &tracefs_mount,
&tracefs_mount_count);
if (error)
return ERR_PTR(error);
- /*
- * If the parent is not specified, we create it in the root.
- * We need the root dentry to do this, which is in the super
- * block. A pointer to that is in the struct vfsmount that we
- * have around.
- */
- if (!parent)
- parent = tracefs_mount->mnt_root;
-
if (unlikely(IS_DEADDIR(parent->d_inode)))
dentry = ERR_PTR(-ENOENT);
else
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] eventfs: Make sure that parent->d_inode is locked in creating files/dirs
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
` (2 preceding siblings ...)
2023-11-21 23:10 ` [PATCH 3/4] eventfs: Do not allow NULL parent to eventfs_start_creating() Steven Rostedt
@ 2023-11-21 23:10 ` Steven Rostedt
2023-11-22 14:19 ` [PATCH 0/4] eventfs: Some more minor fixes Josef Bacik
4 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-21 23:10 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, linux-fsdevel
Cc: Masami Hiramatsu, Mark Rutland, Andrew Morton
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Since the locking of the parent->d_inode has been moved outside the
creation of the files and directories (as it use to be locked via a
conditional), add a WARN_ON_ONCE() to the case that it's not locked.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
fs/tracefs/event_inode.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c
index 590e8176449b..0b90869fd805 100644
--- a/fs/tracefs/event_inode.c
+++ b/fs/tracefs/event_inode.c
@@ -327,6 +327,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
struct dentry **e_dentry = &ei->d_children[idx];
struct dentry *dentry;
+ WARN_ON_ONCE(!inode_is_locked(parent->d_inode));
+
mutex_lock(&eventfs_mutex);
if (ei->is_freed) {
mutex_unlock(&eventfs_mutex);
@@ -430,6 +432,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
{
struct dentry *dentry = NULL;
+ WARN_ON_ONCE(!inode_is_locked(parent->d_inode));
+
mutex_lock(&eventfs_mutex);
if (pei->is_freed || ei->is_freed) {
mutex_unlock(&eventfs_mutex);
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] eventfs: Some more minor fixes
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
` (3 preceding siblings ...)
2023-11-21 23:10 ` [PATCH 4/4] eventfs: Make sure that parent->d_inode is locked in creating files/dirs Steven Rostedt
@ 2023-11-22 14:19 ` Josef Bacik
2023-11-22 23:40 ` Steven Rostedt
4 siblings, 1 reply; 7+ messages in thread
From: Josef Bacik @ 2023-11-22 14:19 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-kernel, linux-trace-kernel, linux-fsdevel, Masami Hiramatsu,
Mark Rutland, Andrew Morton
On Tue, Nov 21, 2023 at 06:10:03PM -0500, Steven Rostedt wrote:
> Mark Rutland reported some crashes from the latest eventfs updates.
> This fixes most of them.
>
> He still has one splat that he can trigger but I can not. Still looking
> into that.
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks,
Josef
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] eventfs: Some more minor fixes
2023-11-22 14:19 ` [PATCH 0/4] eventfs: Some more minor fixes Josef Bacik
@ 2023-11-22 23:40 ` Steven Rostedt
0 siblings, 0 replies; 7+ messages in thread
From: Steven Rostedt @ 2023-11-22 23:40 UTC (permalink / raw)
To: Josef Bacik
Cc: linux-kernel, linux-trace-kernel, linux-fsdevel, Masami Hiramatsu,
Mark Rutland, Andrew Morton
On Wed, 22 Nov 2023 09:19:25 -0500
Josef Bacik <josef@toxicpanda.com> wrote:
> On Tue, Nov 21, 2023 at 06:10:03PM -0500, Steven Rostedt wrote:
> > Mark Rutland reported some crashes from the latest eventfs updates.
> > This fixes most of them.
> >
> > He still has one splat that he can trigger but I can not. Still looking
> > into that.
>
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Thanks Josef!
-- Steve
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-11-22 23:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-21 23:10 [PATCH 0/4] eventfs: Some more minor fixes Steven Rostedt
2023-11-21 23:10 ` [PATCH 1/4] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held Steven Rostedt
2023-11-21 23:10 ` [PATCH 2/4] eventfs: Move taking of inode_lock into dcache_dir_open_wrapper() Steven Rostedt
2023-11-21 23:10 ` [PATCH 3/4] eventfs: Do not allow NULL parent to eventfs_start_creating() Steven Rostedt
2023-11-21 23:10 ` [PATCH 4/4] eventfs: Make sure that parent->d_inode is locked in creating files/dirs Steven Rostedt
2023-11-22 14:19 ` [PATCH 0/4] eventfs: Some more minor fixes Josef Bacik
2023-11-22 23:40 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).