linux-trace-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: Al Viro <viro@zeniv.linux.org.uk>,
	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 08:14:49 -0500	[thread overview]
Message-ID: <20240131081449.6e917b71@rorschach.local.home> (raw)
In-Reply-To: <20240131075740.660e7634@rorschach.local.home>

On Wed, 31 Jan 2024 07:57:40 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> static int instance_rmdir(const char *name)
> {
>         struct trace_array *tr;
>         int ret;
> 
>         mutex_lock(&event_mutex);

Note, event_mutex prevents dynamic events from being created. No kprobe
can be added while the event_mutex is held (not to be confused with
eventfs_mutex).

>         mutex_lock(&trace_types_lock);
> 
>         ret = -ENODEV;
>         tr = trace_array_find(name);
>         if (tr)
>                 ret = __remove_instance(tr);
> 
>         mutex_unlock(&trace_types_lock);
>         mutex_unlock(&event_mutex);
> 
>         return ret;
> }

And

static int instance_mkdir(const char *name)
{
        struct trace_array *tr;
        int ret;

        mutex_lock(&event_mutex);
        mutex_lock(&trace_types_lock);

        ret = -EEXIST;
        if (trace_array_find(name))
                goto out_unlock;

        tr = trace_array_create(name);

        ret = PTR_ERR_OR_ZERO(tr);

out_unlock:
        mutex_unlock(&trace_types_lock);
        mutex_unlock(&event_mutex);
        return ret;
}


The above functions would have been basically what would have been
called if I had created:

  echo foo >> make_instance
  echo '!foo' >> remove_instance

In fact, IIRC, I did do the above first, and then moved that code into
mkdir/rmdir. Such that the tracefs mkdir and rmdir were just helpers
and not real "mkdir" and "rmdir" routines. This isn't in git history
because it was done only on my local repository.

If you also notice, tracefs only allows mkdir/rmdir to be assigned to
one directory. Once it is assigned, no other directories can have mkdir
rmdir functionality.

 /sys/kernel/tracing/instances

is the *only* directory that can have mkdir rmdir on it.

__init struct dentry *tracefs_create_instance_dir(const char *name,
                                          struct dentry *parent,
                                          int (*mkdir)(const char *name),
                                          int (*rmdir)(const char *name))
{
        struct dentry *dentry;

        /* Only allow one instance of the instances directory. */
        if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir))
                return NULL;

And IIRC, Al told me that if I released the locks, it's up to the above
functions to prevent the races from occurring. That is, no file can be
created or remove when the mkdir and rmdir are running. Which the
event_mutex prevents.

Basically, I freeze external file creation and deletion within
tracefs/eventfs when the above mkdir/rmdir is being executed, and
prevent rmdir if any file within it is open.

-- Steve

  reply	other threads:[~2024-01-31 13:14 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
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 [this message]
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=20240131081449.6e917b71@rorschach.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 \
    --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;
as well as URLs for NNTP newsgroup(s).