Skip to content

Commit 88903da

Browse files
committed
eventfs: Remove expectation that ei->is_freed means ei->dentry == NULL
The logic to free the eventfs_inode (ei) use to set is_freed and clear the "dentry" field under the eventfs_mutex. But that changed when a race was found where the ei->dentry needed to be cleared when the last dput() was called on it. But there was still logic that checked if ei->dentry was not NULL and is_freed is set, and would warn if it was. But since that situation was changed and the ei->dentry isn't cleared until the last dput() is called on it while the ei->is_freed is set, do not test for that condition anymore, and change the comments to reflect that. Link: https://lkml.kernel.org/r/20231120235154.265826243@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Fixes: 020010f ("eventfs: Delete eventfs_inode when the last dentry is freed") Reported-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 98b1cc8 commit 88903da

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

fs/tracefs/event_inode.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
/*
2828
* eventfs_mutex protects the eventfs_inode (ei) dentry. Any access
2929
* to the ei->dentry must be done under this mutex and after checking
30-
* if ei->is_freed is not set. The ei->dentry is released under the
31-
* mutex at the same time ei->is_freed is set. If ei->is_freed is set
32-
* then the ei->dentry is invalid.
30+
* if ei->is_freed is not set. When ei->is_freed is set, the dentry
31+
* is on its way to being freed after the last dput() is made on it.
3332
*/
3433
static DEFINE_MUTEX(eventfs_mutex);
3534

3635
/*
3736
* The eventfs_inode (ei) itself is protected by SRCU. It is released from
3837
* its parent's list and will have is_freed set (under eventfs_mutex).
39-
* After the SRCU grace period is over, the ei may be freed.
38+
* After the SRCU grace period is over and the last dput() is called
39+
* the ei is freed.
4040
*/
4141
DEFINE_STATIC_SRCU(eventfs_srcu);
4242

@@ -365,12 +365,14 @@ create_file_dentry(struct eventfs_inode *ei, int idx,
365365
* created the dentry for this e_dentry. In which case
366366
* use that one.
367367
*
368-
* Note, with the mutex held, the e_dentry cannot have content
369-
* and the ei->is_freed be true at the same time.
368+
* If ei->is_freed is set, the e_dentry is currently on its
369+
* way to being freed, don't return it. If e_dentry is NULL
370+
* it means it was already freed.
370371
*/
371-
dentry = *e_dentry;
372-
if (WARN_ON_ONCE(dentry && ei->is_freed))
372+
if (ei->is_freed)
373373
dentry = NULL;
374+
else
375+
dentry = *e_dentry;
374376
/* The lookup does not need to up the dentry refcount */
375377
if (dentry && !lookup)
376378
dget(dentry);
@@ -473,8 +475,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei,
473475
* created the dentry for this e_dentry. In which case
474476
* use that one.
475477
*
476-
* Note, with the mutex held, the e_dentry cannot have content
477-
* and the ei->is_freed be true at the same time.
478+
* If ei->is_freed is set, the e_dentry is currently on its
479+
* way to being freed.
478480
*/
479481
dentry = ei->dentry;
480482
if (dentry && !lookup)

0 commit comments

Comments
 (0)