linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 5/6] eventfs: get rid of dentry pointers without refcounts
Date: Wed, 31 Jan 2024 00:09:56 -0500	[thread overview]
Message-ID: <20240131000956.3dbc0fc0@gandalf.local.home> (raw)
In-Reply-To: <20240130190355.11486-5-torvalds@linux-foundation.org>

On Tue, 30 Jan 2024 11:03:54 -0800
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> +/*
> + * eventfs_inode reference count management.
> + *
> + * NOTE! We count only references from dentries, in the
> + * form 'dentry->d_fsdata'. There are also references from
> + * directory inodes ('ti->private'), but the dentry reference
> + * count is always a superset of the inode reference count.
> + */
> +static void release_ei(struct kref *ref)
> +{
> +	struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref);
> +	kfree(ei->entry_attrs);

I did modify this to add back the kfree_const(ei->name);

I would also like to add a:

	WARN_ON_ONCE(!ei->is_freed);

The kref_put() logic should add the protection that this is guaranteed to
be true as the logic in the removal does:

	ei->is_freed = 1;
  [..]
	kref_put(ei);

I would think that the last "put" would always have the "is_freed" set. The
WARN_ON is to catch things doing too many put_ei().


> +	kfree(ei);
> +}
> +


> @@ -951,5 +857,6 @@ void eventfs_remove_events_dir(struct eventfs_inode *ei)
>  	 * sticks around while the other ei->dentry are created
>  	 * and destroyed dynamically.
>  	 */
> +	simple_recursive_removal(dentry, NULL);

Actually, this doesn't work. It expects all the dentries in the list to
have positive ref counts, as it does dput() on them. If there's any cached,
it will bug with a dput() on a dentry of zero.

The only dentries that should have non zero ref counts are ones that are
currently being accessed and wont go away until finished. I think all we
need to do is invalidate the top dentry. Is that true?

Does this work:

	d_invalidate(dentry);

to make the directory no longer accessible. And all dentries within it
should be zero, and hopefully go away on memory reclaim. The last patch
removes it, but if you want to test the deletion, you can do this:

 # cd /sys/kernel/tracing
 # mkdir instances/foo
 # ls instances/foo/events
 # rmdir instances/foo


But also note that this patch fails with the "ghost" files with the kprobe
test again. When I apply patch 6, that goes away. I'm guessing that's
because this needs the d_revalidate() call. To not break bisection, I think
we need to merge this and patch 6 together.

Also patch 6 removes the simple_recursive_removal() which without at least
the d_invalidate() causes a dput splat. That's because the rmdir calls
tracefs_remove() which calls simple_recursive_removal() that will walk to
the events directory and I'm assuming if it hasn't been invalidated, it
walks into it causing the same issue as a simple_recursive_removal() would
have here.

Try the above mkdir and rmdir to see.

-- Steve


>  	dput(dentry);
>  }

  parent reply	other threads:[~2024-01-31  5:09 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30 19:03 [PATCH 1/6] tracefs: avoid using the ei->dentry pointer unnecessarily Linus Torvalds
2024-01-30 19:03 ` [PATCH 2/6] eventfsfs: initialize the tracefs inode properly Linus Torvalds
2024-01-30 19:48   ` Steven Rostedt
2024-01-30 19:56     ` Steven Rostedt
2024-01-30 19:49   ` Steven Rostedt
2024-01-30 19:03 ` [PATCH 3/6] tracefs: dentry lookup crapectomy Linus Torvalds
2024-01-30 23:26   ` Al Viro
2024-01-30 23:55     ` Steven Rostedt
2024-01-31  0:07       ` Al Viro
2024-01-31  0:23   ` Al Viro
2024-01-31  0:39     ` Linus Torvalds
2024-01-30 19:03 ` [PATCH 4/6] eventfs: remove unused 'd_parent' pointer field Linus Torvalds
2024-01-30 19:03 ` [PATCH 5/6] eventfs: get rid of dentry pointers without refcounts Linus Torvalds
2024-01-30 20:55   ` Steven Rostedt
2024-01-30 21:52     ` Linus Torvalds
2024-01-30 22:56       ` Steven Rostedt
2024-01-30 22:58         ` Linus Torvalds
2024-01-30 23:04           ` Steven Rostedt
2024-01-30 22:56       ` Linus Torvalds
2024-01-30 23:06         ` Linus Torvalds
2024-01-30 23:10           ` Steven Rostedt
2024-01-30 23:25             ` Linus Torvalds
2024-01-31  0:48   ` Al Viro
2024-01-31  5:09   ` Steven Rostedt [this message]
2024-01-31  5:25     ` Linus Torvalds
2024-01-31  5:33       ` Steven Rostedt
2024-01-31  5:57         ` Linus Torvalds
2024-01-31  6:20           ` Linus Torvalds
2024-01-31 12:57             ` Steven Rostedt
2024-01-31 13:14               ` Steven Rostedt
2024-01-31 18:08                 ` Linus Torvalds
2024-01-31 18:39                   ` Steven Rostedt
2024-01-30 19:03 ` [PATCH 6/6] eventfs: clean up dentry ops and add revalidate function Linus Torvalds
2024-01-30 21:25   ` Steven Rostedt
2024-01-30 21:36     ` Linus Torvalds
2024-01-31  1:12   ` Al Viro
2024-01-31  2:37     ` Linus Torvalds
2024-01-31  2:46       ` Al Viro
2024-01-31  3:39         ` Linus Torvalds
2024-01-31  4:28           ` Al Viro
2024-01-31 18:00   ` Steven Rostedt
2024-01-31 23:07     ` Masami Hiramatsu
2024-01-31 23:23       ` Steven Rostedt

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=20240131000956.3dbc0fc0@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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;
as well as URLs for NNTP newsgroup(s).