[RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs

Steven Rostedt posted 1 patch 3 months, 3 weeks ago
There is a newer version of this series
.../ABI/obsolete/automount-tracefs-debugfs    | 20 +++++++++++++++++++
kernel/trace/Kconfig                          | 13 ++++++++++++
kernel/trace/trace.c                          | 13 ++++++++----
3 files changed, 42 insertions(+), 4 deletions(-)
create mode 100644 Documentation/ABI/obsolete/automount-tracefs-debugfs
[RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Steven Rostedt 3 months, 3 weeks ago
From: Steven Rostedt <rostedt@goodmis.org>

In January 2015, tracefs was created to allow access to the tracing
infrastructure without needing to compile in debugfs. When tracefs is
configured, the directory /sys/kernel/tracing will exist and tooling is
expected to use that path to access the tracing infrastructure.

To allow backward compatibility, when debugfs is mounted, it would
automount tracefs in its "tracing" directory so that tooling that had hard
coded /sys/kernel/debug/tracing would still work.

It has been over 10 years since the new interface was introduced, and all
tooling should now be using it. Start the process of deprecating the old
path so that it doesn't need to be maintained anymore.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 .../ABI/obsolete/automount-tracefs-debugfs    | 20 +++++++++++++++++++
 kernel/trace/Kconfig                          | 13 ++++++++++++
 kernel/trace/trace.c                          | 13 ++++++++----
 3 files changed, 42 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/ABI/obsolete/automount-tracefs-debugfs

diff --git a/Documentation/ABI/obsolete/automount-tracefs-debugfs b/Documentation/ABI/obsolete/automount-tracefs-debugfs
new file mode 100644
index 000000000000..8d03cf9e579f
--- /dev/null
+++ b/Documentation/ABI/obsolete/automount-tracefs-debugfs
@@ -0,0 +1,20 @@
+What:		/sys/kernel/debug/tracing
+Date:		May 2008
+KernelVersion:	2.6.27
+Contact:	linux-trace-kernel@vger.kernel.org
+Description:
+
+	The ftrace was first added to the kernel, its interface was placed
+	into the debugfs file system under the "tracing" directory. Access
+	to the files were in /sys/kernel/debug/tracing. As systems wanted
+	access to the tracing interface without having to enable debugfs, a
+	new interface was created called "tracefs". This was a stand alone
+	file system and was usually mounted in /sys/kernel/tracing.
+
+	To allow older tooling to continue to operate, when mounting
+	debugfs, the tracefs file system would automatically get mounted in
+	the "tracing" directory of debugfs. The tracefs interface was added
+	in January 2015 in the v4.1 kernel.
+
+	All tooling should now be using tracefs directly and the "tracing"
+	directory in debugfs should be removed by January 2027.
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index a3f35c7d83b6..93e8e7fc11c0 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -199,6 +199,19 @@ menuconfig FTRACE
 
 if FTRACE
 
+config TRACEFS_AUTOMOUNT_DEPRECATED
+	bool "Automount tracefs on debugfs [DEPRECATED]"
+	depends on TRACING
+	default y
+	help
+	  The tracing interface was moved from /sys/kernel/debug/tracing
+	  to /sys/kernel/tracing in 2015, but the tracing file system
+	  was still automounted in /sys/kernel/debug for backward
+	  compatibility with tooling.
+
+	  The new interface has been around for more than 10 years and
+	  the old debug mount will soon be removed.
+
 config BOOTTIME_TRACING
 	bool "Boot-time Tracing support"
 	depends on TRACING
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 95ae7c4e5835..71bd1f001e79 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6303,7 +6303,7 @@ static bool tracer_options_updated;
 static void add_tracer_options(struct trace_array *tr, struct tracer *t)
 {
 	/* Only enable if the directory has been created already. */
-	if (!tr->dir)
+	if (!tr->dir && !(tr->flags & TRACE_ARRAY_FL_GLOBAL))
 		return;
 
 	/* Only create trace option files after update_tracer_options finish */
@@ -8984,13 +8984,13 @@ static inline __init int register_snapshot_cmd(void) { return 0; }
 
 static struct dentry *tracing_get_dentry(struct trace_array *tr)
 {
-	if (WARN_ON(!tr->dir))
-		return ERR_PTR(-ENODEV);
-
 	/* Top directory uses NULL as the parent */
 	if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
 		return NULL;
 
+	if (WARN_ON(!tr->dir))
+		return ERR_PTR(-ENODEV);
+
 	/* All sub buffers have a descriptor */
 	return tr->dir;
 }
@@ -10256,6 +10256,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 	ftrace_init_tracefs(tr, d_tracer);
 }
 
+#ifdef CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED
 static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)
 {
 	struct vfsmount *mnt;
@@ -10287,6 +10288,7 @@ static struct vfsmount *trace_automount(struct dentry *mntpt, void *ingore)
 	put_fs_context(fc);
 	return mnt;
 }
+#endif
 
 /**
  * tracing_init_dentry - initialize top level trace array
@@ -10311,6 +10313,8 @@ int tracing_init_dentry(void)
 	if (WARN_ON(!tracefs_initialized()))
 		return -ENODEV;
 
+#ifdef CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED
+	pr_warning("NOTICE: Automounting of tracing to debugfs is deprecated and will be removed in 2027\n");
 	/*
 	 * As there may still be users that expect the tracing
 	 * files to exist in debugfs/tracing, we must automount
@@ -10319,6 +10323,7 @@ int tracing_init_dentry(void)
 	 */
 	tr->dir = debugfs_create_automount("tracing", NULL,
 					   trace_automount, NULL);
+#endif
 
 	return 0;
 }
-- 
2.47.2
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Christian Brauner 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 01:36:14PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
> 
> In January 2015, tracefs was created to allow access to the tracing
> infrastructure without needing to compile in debugfs. When tracefs is
> configured, the directory /sys/kernel/tracing will exist and tooling is
> expected to use that path to access the tracing infrastructure.
> 
> To allow backward compatibility, when debugfs is mounted, it would
> automount tracefs in its "tracing" directory so that tooling that had hard
> coded /sys/kernel/debug/tracing would still work.
> 
> It has been over 10 years since the new interface was introduced, and all
> tooling should now be using it. Start the process of deprecating the old
> path so that it doesn't need to be maintained anymore.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---

Sounds reasonable.
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Steven Rostedt 3 months, 3 weeks ago
On Tue, 17 Jun 2025 13:36:14 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> @@ -10311,6 +10313,8 @@ int tracing_init_dentry(void)
>  	if (WARN_ON(!tracefs_initialized()))
>  		return -ENODEV;
>  
> +#ifdef CONFIG_TRACEFS_AUTOMOUNT_DEPRECATED
> +	pr_warning("NOTICE: Automounting of tracing to debugfs is deprecated and will be removed in 2027\n");

I tested this with the config off but not on.

The above errors with pr_warning() undefined, "do you mean pr_warn?" :-p

-- Steve

>  	/*
>  	 * As there may still be users that expect the tracing
>  	 * files to exist in debugfs/tracing, we must automount
> @@ -10319,6 +10323,7 @@ int tracing_init_dentry(void)
>  	 */
>  	tr->dir = debugfs_create_automount("tracing", NULL,
>  					   trace_automount, NULL);
> +#endif
>  
>  	return 0;
>  }
> --
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Peter Zijlstra 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 01:36:14PM -0400, Steven Rostedt wrote:
> From: Steven Rostedt <rostedt@goodmis.org>
> 
> In January 2015, tracefs was created to allow access to the tracing
> infrastructure without needing to compile in debugfs. When tracefs is
> configured, the directory /sys/kernel/tracing will exist and tooling is
> expected to use that path to access the tracing infrastructure.
> 
> To allow backward compatibility, when debugfs is mounted, it would
> automount tracefs in its "tracing" directory so that tooling that had hard
> coded /sys/kernel/debug/tracing would still work.
> 
> It has been over 10 years since the new interface was introduced, and all
> tooling should now be using it. Start the process of deprecating the old
> path so that it doesn't need to be maintained anymore.

I've always used /debug/tracing/ (because /debug is the right place to
mount debugfs). You're saying this is going away and will break all my
scripts?!
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Steven Rostedt 3 months, 3 weeks ago

On June 17, 2025 1:41:07 PM EDT, Peter Zijlstra <peterz@infradead.org> wrote:
>On Tue, Jun 17, 2025 at 01:36:14PM -0400, Steven Rostedt wrote:
>> From: Steven Rostedt <rostedt@goodmis.org>
>> 
>> In January 2015, tracefs was created to allow access to the tracing
>> infrastructure without needing to compile in debugfs. When tracefs is
>> configured, the directory /sys/kernel/tracing will exist and tooling is
>> expected to use that path to access the tracing infrastructure.
>> 
>> To allow backward compatibility, when debugfs is mounted, it would
>> automount tracefs in its "tracing" directory so that tooling that had hard
>> coded /sys/kernel/debug/tracing would still work.
>> 
>> It has been over 10 years since the new interface was introduced, and all
>> tooling should now be using it. Start the process of deprecating the old
>> path so that it doesn't need to be maintained anymore.
>
>I've always used /debug/tracing/ (because /debug is the right place to
>mount debugfs). You're saying this is going away and will break all my
>scripts?!

You could mount tracefs in /tracing too:

  # mount -t tracefs nodev /tracing 

And update you scripts with a simple sed script.

-- Steve 
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Peter Zijlstra 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 01:54:46PM -0400, Steven Rostedt wrote:
> 
> 
> On June 17, 2025 1:41:07 PM EDT, Peter Zijlstra <peterz@infradead.org> wrote:
> >On Tue, Jun 17, 2025 at 01:36:14PM -0400, Steven Rostedt wrote:
> >> From: Steven Rostedt <rostedt@goodmis.org>
> >> 
> >> In January 2015, tracefs was created to allow access to the tracing
> >> infrastructure without needing to compile in debugfs. When tracefs is
> >> configured, the directory /sys/kernel/tracing will exist and tooling is
> >> expected to use that path to access the tracing infrastructure.
> >> 
> >> To allow backward compatibility, when debugfs is mounted, it would
> >> automount tracefs in its "tracing" directory so that tooling that had hard
> >> coded /sys/kernel/debug/tracing would still work.
> >> 
> >> It has been over 10 years since the new interface was introduced, and all
> >> tooling should now be using it. Start the process of deprecating the old
> >> path so that it doesn't need to be maintained anymore.
> >
> >I've always used /debug/tracing/ (because /debug is the right place to
> >mount debugfs). You're saying this is going away and will break all my
> >scripts?!
> 
> You could mount tracefs in /tracing too:
> 
>   # mount -t tracefs nodev /tracing 
> 
> And update you scripts with a simple sed script.

If I have to edit the mount table, I'll just keep it at /debug/tracing/.
Tracing is very much debug stuff anyway. While I knew there was tracefs,
I never knew there was another mount point.

Just annoying I now have to add two entries to every new machine.. Oh
well.
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Sebastian Andrzej Siewior 3 months, 3 weeks ago
On 2025-06-17 20:00:23 [+0200], Peter Zijlstra wrote:
> If I have to edit the mount table, I'll just keep it at /debug/tracing/.
> Tracing is very much debug stuff anyway. While I knew there was tracefs,
> I never knew there was another mount point.
> 
> Just annoying I now have to add two entries to every new machine.. Oh
> well.

I don't know what you run but since Debian 11/ Bullseye (v5.10) this happens
more or less on its own. systemd has the proper mount units:
| # mount | grep trace
| tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
| # ls -lh /sys/kernel/debug/tracing/ > /dev/null
| # mount | grep trace
| tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
| tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)

This of course doesn't work if you manually mount it to /debug. While a
symlink would work, you still have to touch the boxes.

Sebastian
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Peter Zijlstra 3 months, 3 weeks ago
On Wed, Jun 18, 2025 at 09:21:02AM +0200, Sebastian Andrzej Siewior wrote:
> On 2025-06-17 20:00:23 [+0200], Peter Zijlstra wrote:
> > If I have to edit the mount table, I'll just keep it at /debug/tracing/.
> > Tracing is very much debug stuff anyway. While I knew there was tracefs,
> > I never knew there was another mount point.
> > 
> > Just annoying I now have to add two entries to every new machine.. Oh
> > well.
> 
> I don't know what you run but since Debian 11/ Bullseye (v5.10) this happens
> more or less on its own. systemd has the proper mount units:
> | # mount | grep trace
> | tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
> | # ls -lh /sys/kernel/debug/tracing/ > /dev/null
> | # mount | grep trace
> | tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
> | tracefs on /sys/kernel/debug/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
> 
> This of course doesn't work if you manually mount it to /debug. While a
> symlink would work, you still have to touch the boxes.

Mostly debian/testing. I prefer a mount from /etc/fstab, I tried a
symlink once but that is weird with tab completion for some reason.
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Ian Rogers 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 11:00 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Tue, Jun 17, 2025 at 01:54:46PM -0400, Steven Rostedt wrote:
> >
> >
> > On June 17, 2025 1:41:07 PM EDT, Peter Zijlstra <peterz@infradead.org> wrote:
> > >On Tue, Jun 17, 2025 at 01:36:14PM -0400, Steven Rostedt wrote:
> > >> From: Steven Rostedt <rostedt@goodmis.org>
> > >>
> > >> In January 2015, tracefs was created to allow access to the tracing
> > >> infrastructure without needing to compile in debugfs. When tracefs is
> > >> configured, the directory /sys/kernel/tracing will exist and tooling is
> > >> expected to use that path to access the tracing infrastructure.
> > >>
> > >> To allow backward compatibility, when debugfs is mounted, it would
> > >> automount tracefs in its "tracing" directory so that tooling that had hard
> > >> coded /sys/kernel/debug/tracing would still work.
> > >>
> > >> It has been over 10 years since the new interface was introduced, and all
> > >> tooling should now be using it. Start the process of deprecating the old
> > >> path so that it doesn't need to be maintained anymore.
> > >
> > >I've always used /debug/tracing/ (because /debug is the right place to
> > >mount debugfs). You're saying this is going away and will break all my
> > >scripts?!
> >
> > You could mount tracefs in /tracing too:
> >
> >   # mount -t tracefs nodev /tracing
> >
> > And update you scripts with a simple sed script.
>
> If I have to edit the mount table, I'll just keep it at /debug/tracing/.
> Tracing is very much debug stuff anyway. While I knew there was tracefs,
> I never knew there was another mount point.
>
> Just annoying I now have to add two entries to every new machine.. Oh
> well.

It seems cleaning this up is a good thing wrt permission issues. On my
local debian derived machine:
```
$ ls  /sys/kernel/debug/tracing/events
ls: cannot access '/sys/kernel/debug/tracing/events': Permission denied
$ ls  /sys/kernel/tracing/events
alarmtimer        fib             irq            nmi             sunrpc
...
```
I see a number of references to debug/tracing in places like perf testing:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/common/init.sh?h=perf-tools-next#n122
are you planning patches for these?

Thanks,
Ian
Re: [RFC][PATCH] tracing: Deprecate auto-mounting tracefs in debugfs
Posted by Steven Rostedt 3 months, 3 weeks ago
On Tue, 17 Jun 2025 11:48:53 -0700
Ian Rogers <irogers@google.com> wrote:

> I see a number of references to debug/tracing in places like perf testing:
> https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/common/init.sh?h=perf-tools-next#n122
> are you planning patches for these?

Thanks for pointing that out.

Yes, I plan on sending patches to remove all references to debug/tracing.

One reason I put the removal date to Jan 2027. To give a year and a half.

-- Steve