Skip to contentSkip to conversation

Some tracing fixes.

PATCH In review Jiaxing Wang 4 participants 17 messages Oct 18, 2015 – Nov 6, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Some tracing fixes.

In short:
The first patch update instance_rmdir() to use tracefs_remove_recursive. The second one make tracing work when debugfs is not initialized, currently
we get an empty directory after mounting tracefs manually.
The third one makes it possible to specify tracer specific options from
kernel parameter, like the following:

ftrace=function ftrace_filter=kfree trace_options=func_stack_trace

Jiaxing Wang (3):
tracing: Update instance_rmdir() to use tracefs_remove_recursive.
tracing: Make tracing work when debugfs is not compiled or
initialized.
tracing: Apply tracer specific options from kernel command line.

 kernel/trace/Kconfig |  1 -
 kernel/trace/trace.c | 72 +++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 52 insertions(+), 21 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/3 tracing: Update instance_rmdir() to use tracefs_remove_recursive.

Update instancd_rmdir to use tracefs_remove_recursive instead of debugfs_remove_recursive.This was left in the transition from debugfs to tracefs.

---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
index 6e79408..69f9754 100644
@@ -6602,7 +6602,7 @@ static int instance_rmdir(const char *name)
 	tracing_set_nop(tr);
 	event_trace_del_tracer(tr);
 	ftrace_destroy_function_files(tr);
-	debugfs_remove_recursive(tr->dir);
+	tracefs_remove_recursive(tr->dir);
 	free_trace_buffers(tr);
 
 	kfree(tr->name);
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/3 tracing: Make tracing work when debugfs is not compiled or initialized.

In reply to Jiaxing Wang

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

---
 kernel/trace/Kconfig |  1 -
 kernel/trace/trace.c | 29 +++++++++++++++++------------
 2 files changed, 17 insertions(+), 13 deletions(-)
kernel/trace/Kconfig +0 -1
index 1153c43..59f6377f 100644
@@ -95,7 +95,6 @@ config RING_BUFFER_ALLOW_SWAP
 
 config TRACING
 	bool
-	select DEBUG_FS
 	select RING_BUFFER
 	select STACKTRACE if STACKTRACE_SUPPORT
 	select TRACEPOINTS
kernel/trace/trace.c +17 -12
index 69f9754..2d3042f 100644
@@ -6706,6 +6706,8 @@ static struct vfsmount *trace_automount(void *ingore)
 	return mnt;
 }
 
+#define TRACE_TOP_DIR_ENTRY	((struct dentry *)1)
+
 /**
  * tracing_init_dentry - initialize top level trace array
  *
@@ -6716,27 +6718,30 @@ static struct vfsmount *trace_automount(void *ingore)
 struct dentry *tracing_init_dentry(void)
 {
 	struct trace_array *tr = &global_trace;
+	struct dentry *traced;
 
 	/* The top level trace array uses  NULL as parent */
 	if (tr->dir)
 		return NULL;
 
-	if (WARN_ON(!debugfs_initialized()))
+	if (WARN_ON(!tracefs_initialized()))
 		return ERR_PTR(-ENODEV);
 
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+
 	return NULL;
 }
 
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH 2/3] tracing: Make tracing work when debugfs is not compiled or initialized.

reproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…

Hi Jiaxing,

[auto build test ERROR on tip/perf/core -- if it's inappropriate base, please suggest rules for selecting the more suitable base]

url:    https://github.com/0day-ci/linux/commits/Jiaxing-Wang/Some-tracing-fixes/20151018-200252
config: arm-omap2plus_defconfig (attached as .config)

reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All error/warnings (new ones prefixed by >>):

kernel/trace/trace.c: In function 'tracing_init_dentry':

>> kernel/trace/trace.c:6737:3: error: implicit declaration of function 'debugfs_create_automount' [-Werror=implicit-function-declaration]
      traced = debugfs_create_automount("tracing", NULL,
      ^
>> kernel/trace/trace.c:6737:10: warning: assignment makes pointer from integer without a cast

traced = debugfs_create_automount("tracing", NULL,
^
cc1: some warnings being treated as errors

vim +/debugfs_create_automount +6737 kernel/trace/trace.c

6731 /*
6732 * As there may still be users that expect the tracing
6733 * files to exist in debugfs/tracing, we must automount
6734 * the tracefs file system there, so older tools still
6735 * work with the newer kerenl.
6736 */

> 6737			traced = debugfs_create_automount("tracing", NULL,

6738 trace_automount, NULL);
6739 if (!traced)
6740 pr_warn_once("Could not create debugfs directory 'tracing'\n");

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

Re: [PATCH 2/3] tracing: Make tracing work when debugfs is not compiled or initialized.

In reply to Jiaxing Wang

Sorry for the last patch, please use this to add stub for debugfs_create_automount().

Quoted 1 line

From b3b877d8d9fd9795ea1055042039a272e47f4dc5 Mon Sep 17 00:00:00 2001

From: Jiaxing Wang <[email protected]>
Date: Mon, 19 Oct 2015 09:46:12 +0800
Subject: [PATCH] debugfs: Add stub function for debugfs_create_automount().

Add stub for debugfs_create_automount() for when debugfs is not configured in.

---
 include/linux/debugfs.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/debugfs.h +8 -0
index 9beb636..b42ef88 100644
@@ -160,6 +160,14 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_automount(const char *name,
+					struct dentry *parent,
+					struct vfsmount *(*f)(void *),
+					void *data)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline void debugfs_remove(struct dentry *dentry)
 { }
 
Signature · 1 line
2.1.4
maintainer
#5 lore raw

Re: [PATCH 2/3] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 2 lines · On Mon, 19 Oct 2015 09:54:16 +0800 Jiaxing Wang <[email protected]> wrote:

Sorry for the last patch, please use this to add stub for debugfs_create_automount().

Can you fold this into patch number two and resubmit that patch.

Thanks,

-- Steve

Quoted 33 lines
Quoted 2 lines

From b3b877d8d9fd9795ea1055042039a272e47f4dc5 Mon Sep 17 00:00:00 2001

From: Jiaxing Wang <[email protected]>
Date: Mon, 19 Oct 2015 09:46:12 +0800
Subject: [PATCH] debugfs: Add stub function for debugfs_create_automount().

Add stub for debugfs_create_automount() for when debugfs is not configured in.

---
 include/linux/debugfs.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/linux/debugfs.h +8 -0
index 9beb636..b42ef88 100644
@@ -160,6 +160,14 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_automount(const char *name,
+					struct dentry *parent,
+					struct vfsmount *(*f)(void *),
+					void *data)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline void debugfs_remove(struct dentry *dentry)
 { }
 
#6 lore raw

PATCH RESEND 1/1 tracing: Make tracing work when debugfs is not compiled or initialized.

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

Also added stub debugfs_create_automount() for when debugfs is not configured in.

---
 include/linux/debugfs.h |  8 ++++++++
 kernel/trace/Kconfig    |  1 -
 kernel/trace/trace.c    | 29 +++++++++++++++++------------
 3 files changed, 25 insertions(+), 13 deletions(-)
include/linux/debugfs.h +8 -0
index 9beb636..b42ef88 100644
@@ -160,6 +160,14 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_automount(const char *name,
+					struct dentry *parent,
+					struct vfsmount *(*f)(void *),
+					void *data)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline void debugfs_remove(struct dentry *dentry)
 { }
 
kernel/trace/Kconfig +0 -1
index 1153c43..59f6377f 100644
@@ -95,7 +95,6 @@ config RING_BUFFER_ALLOW_SWAP
 
 config TRACING
 	bool
-	select DEBUG_FS
 	select RING_BUFFER
 	select STACKTRACE if STACKTRACE_SUPPORT
 	select TRACEPOINTS
kernel/trace/trace.c +17 -12
index 6e79408..6dd064e 100644
@@ -6706,6 +6706,8 @@ static struct vfsmount *trace_automount(void *ingore)
 	return mnt;
 }
 
+#define TRACE_TOP_DIR_ENTRY	((struct dentry *)1)
+
 /**
  * tracing_init_dentry - initialize top level trace array
  *
@@ -6716,27 +6718,30 @@ static struct vfsmount *trace_automount(void *ingore)
 struct dentry *tracing_init_dentry(void)
 {
 	struct trace_array *tr = &global_trace;
+	struct dentry *traced;
 
 	/* The top level trace array uses  NULL as parent */
 	if (tr->dir)
 		return NULL;
 
-	if (WARN_ON(!debugfs_initialized()))
+	if (WARN_ON(!tracefs_initialized()))
 		return ERR_PTR(-ENODEV);
 
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+
 	return NULL;
 }
 
Signature · 1 line
2.1.4
maintainer
#7 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 26 lines · On Wed, 4 Nov 2015 09:11:18 +0800 Jiaxing Wang <[email protected]> wrote:

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

Also added stub debugfs_create_automount() for when debugfs is not configured in.

---
 include/linux/debugfs.h |  8 ++++++++
 kernel/trace/Kconfig    |  1 -
 kernel/trace/trace.c    | 29 +++++++++++++++++------------
 3 files changed, 25 insertions(+), 13 deletions(-)
include/linux/debugfs.h +0 -0
index 9beb636..b42ef88 100644

include/linux/debugfs.h static inline struct dentry *debugfs_create_symlink(const char *name, · line 169

Quoted 10 lines
include/linux/debugfs.h +7 -0
@@ -160,6 +160,14 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_automount(const char *name,
+					struct dentry *parent,
+					struct vfsmount *(*f)(void *),
+					void *data)
+{
+	return ERR_PTR(-ENODEV);
+}

This part needs an Acked-by from Greg KH.

Quoted 55 lines
include/linux/debugfs.h +1 -0
+
 static inline void debugfs_remove(struct dentry *dentry)
 { }
 
kernel/trace/Kconfig +0 -1
index 1153c43..59f6377f 100644
@@ -95,7 +95,6 @@ config RING_BUFFER_ALLOW_SWAP
 
 config TRACING
 	bool
-	select DEBUG_FS
 	select RING_BUFFER
 	select STACKTRACE if STACKTRACE_SUPPORT
 	select TRACEPOINTS
kernel/trace/trace.c +5 -12
index 6e79408..6dd064e 100644
@@ -6706,6 +6706,8 @@ static struct vfsmount *trace_automount(void *ingore)
 	return mnt;
 }
 
+#define TRACE_TOP_DIR_ENTRY	((struct dentry *)1)
+
 /**
  * tracing_init_dentry - initialize top level trace array
  *
@@ -6716,27 +6718,30 @@ static struct vfsmount *trace_automount(void *ingore)
 struct dentry *tracing_init_dentry(void)
 {
 	struct trace_array *tr = &global_trace;
+	struct dentry *traced;
 
 	/* The top level trace array uses  NULL as parent */
 	if (tr->dir)
 		return NULL;
 
-	if (WARN_ON(!debugfs_initialized()))
+	if (WARN_ON(!tracefs_initialized()))
 		return ERR_PTR(-ENODEV);
 
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6740

Quoted 10 lines
kernel/trace/trace.c +10 -0
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");

This should return a warning, and please keep the tr->dir instead of this new traced variable.

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6744

Quoted 4 lines
kernel/trace/trace.c +2 -0
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+

Also, no need to add this, because if debugfs is not initialize, then tr->dir would be ERR_PTR(-ENODEV), which still works as tr->dir is not NULL.

-- Steve

Quoted 3 lines
kernel/trace/trace.c +0 -0
 	return NULL;
 }
 
#8 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 8 lines · Steven Rostedt
Quoted 5 lines · On Wed, 4 Nov 2015 09:11:18 +0800 Jiaxing Wang <[email protected]> wrote:

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

Quoted 8 lines
Quoted 8 lines

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

Also added stub debugfs_create_automount() for when debugfs is not configured in.

The debugfs change should be split out into a separate patch, which I'll be glad to take through my tree, it isn't dependant on the tracing code at all.

thanks,

greg k-h

maintainer
#9 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 15 lines · On Wed, 4 Nov 2015 10:54:42 -0800 Greg Kroah-Hartman…
Quoted 14 lines · Steven Rostedt
Quoted 11 lines · On Wed, 4 Nov 2015 09:11:18 +0800 Jiaxing Wang <[email protected]> wrote:

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Also added stub debugfs_create_automount() for when debugfs is not configured in.

The debugfs change should be split out into a separate patch, which I'll be glad to take through my tree, it isn't dependant on the tracing code at all.

I guess the tracing code is dependent on that change. As the tracing code will then be compiled without the select DEBUGFS, and will fail to compile if that change is not there.

That said. I think it's best to split it up, and have the debugfs change go through your tree, and the other part go through mine without the remove of the "select DEBUGFS". After both are in mainline, then we can remove the select statement.

-- Steve

#10 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

In reply to Steven Rostedt
Quoted 102 lines · Steven Rostedt
Quoted 26 lines · On Wed, 4 Nov 2015 09:11:18 +0800 Jiaxing Wang <[email protected]> wrote:

Currently tracing_init_dentry() returns -ENODEV when debugfs is not initialized, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL as long as tracefs is initialized and get a populated tracefs.

We also need to make global_trace.dir not NULL in order to pass the checks in tracing_get_dentry() and add_tracer_options().

Also added stub debugfs_create_automount() for when debugfs is not configured in.

---
 include/linux/debugfs.h |  8 ++++++++
 kernel/trace/Kconfig    |  1 -
 kernel/trace/trace.c    | 29 +++++++++++++++++------------
 3 files changed, 25 insertions(+), 13 deletions(-)
include/linux/debugfs.h +0 -0
index 9beb636..b42ef88 100644

include/linux/debugfs.h static inline struct dentry *debugfs_create_symlink(const char *name, · line 169

Quoted 10 lines
include/linux/debugfs.h +7 -0
@@ -160,6 +160,14 @@ static inline struct dentry *debugfs_create_symlink(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_automount(const char *name,
+					struct dentry *parent,
+					struct vfsmount *(*f)(void *),
+					void *data)
+{
+	return ERR_PTR(-ENODEV);
+}

This part needs an Acked-by from Greg KH.

Quoted 60 lines
include/linux/debugfs.h +1 -0
+
 static inline void debugfs_remove(struct dentry *dentry)
 { }
 
kernel/trace/Kconfig +0 -1
index 1153c43..59f6377f 100644
@@ -95,7 +95,6 @@ config RING_BUFFER_ALLOW_SWAP
 
 config TRACING
 	bool
-	select DEBUG_FS
 	select RING_BUFFER
 	select STACKTRACE if STACKTRACE_SUPPORT
 	select TRACEPOINTS
kernel/trace/trace.c +10 -12
index 6e79408..6dd064e 100644
@@ -6706,6 +6706,8 @@ static struct vfsmount *trace_automount(void *ingore)
 	return mnt;
 }
 
+#define TRACE_TOP_DIR_ENTRY	((struct dentry *)1)
+
 /**
  * tracing_init_dentry - initialize top level trace array
  *
@@ -6716,27 +6718,30 @@ static struct vfsmount *trace_automount(void *ingore)
 struct dentry *tracing_init_dentry(void)
 {
 	struct trace_array *tr = &global_trace;
+	struct dentry *traced;
 
 	/* The top level trace array uses  NULL as parent */
 	if (tr->dir)
 		return NULL;
 
-	if (WARN_ON(!debugfs_initialized()))
+	if (WARN_ON(!tracefs_initialized()))
 		return ERR_PTR(-ENODEV);
 
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
Quoted 8 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6740

Quoted 5 lines
kernel/trace/trace.c +5 -0
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");

This should return a warning, and please keep the tr->dir instead of this new traced variable.

Do you mean return ERR_PTR(-ENOMEM); when debugfs_create_automount() return NULL?
As long as tracefs is initialized, we can make tracing_init_dentry() return NULL even if the debugfs automount point is not created(), and tracefs can still be populated. If tracing_init_dentry() returns error in this case, the caller of tracing_init_dentry() will not populate tracefs.

Quoted 9 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6744

Quoted 5 lines
kernel/trace/trace.c +2 -0
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+

Also, no need to add this, because if debugfs is not initialize, then tr->dir would be ERR_PTR(-ENODEV), which still works as tr->dir is not NULL.

If we accept debugfs_create_automount() return NULL, tr->dir can still be NULL if we do tr->dir = debugfs_create_automount().

Quoted 7 lines

-- Steve

Quoted 3 lines
kernel/trace/trace.c +0 -0
 	return NULL;
 }
 
maintainer
#11 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 25 lines · On Thu, 5 Nov 2015 13:23:01 +0800 Jiaxing Wang <[email protected]> wrote:
Quoted 17 lines
Quoted 17 lines
kernel/trace/trace.c +6 -11
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
Quoted 8 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6740

Quoted 5 lines
kernel/trace/trace.c +5 -0
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");

This should return a warning, and please keep the tr->dir instead of this new traced variable.

Quoted 2 lines

Do you mean return ERR_PTR(-ENOMEM); when debugfs_create_automount() return NULL?

Right.

Quoted 4 lines

As long as tracefs is initialized, we can make tracing_init_dentry() return NULL even if the debugfs automount point is not created(), and tracefs can still be populated. If tracing_init_dentry() returns error in this case, the caller of tracing_init_dentry() will not populate tracefs.

But this is still a failure. tracing_init_dentry() now only mounts tracefs on the debugfs/tracing directory. If it fails to do that when debugfs is available, then it should fail, as it would break backward compatibility with other tools.

If debugfs is not configured in, then it should set tr->dir to whatever (ENOMEM is fine), and return NULL.

Quoted 11 lines
Quoted 9 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6744

Quoted 5 lines
kernel/trace/trace.c +2 -0
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+

Also, no need to add this, because if debugfs is not initialize, then tr->dir would be ERR_PTR(-ENODEV), which still works as tr->dir is not NULL.

If we accept debugfs_create_automount() return NULL, tr->dir can still be NULL if we do tr->dir = debugfs_create_automount().

What's wrong with that? This function is only to automount debugfs now.

Also, I think the first check should be:

	if (WARN_ON(!tracefs_initialized()) ||
	    (IS_ENABLED(CONFIG_DEBUGFS) &&
	     WARN_ON(!debugfs_initialized()))
		return ERR_PTR(-ENODEV);

Then we don't need the if (debugfs_initialized()) conditional.

-- Steve

Quoted 7 lines
Quoted 7 lines

-- Steve

Quoted 3 lines

return NULL;
}

#12 lore raw

Re: [PATCH RESEND] tracing: Make tracing work when debugfs is not compiled or initialized.

Quoted 61 lines · Steven Rostedt
Quoted 25 lines · On Thu, 5 Nov 2015 13:23:01 +0800 Jiaxing Wang <[email protected]> wrote:
Quoted 17 lines
Quoted 17 lines
kernel/trace/trace.c +6 -11
-	/*
-	 * As there may still be users that expect the tracing
-	 * files to exist in debugfs/tracing, we must automount
-	 * the tracefs file system there, so older tools still
-	 * work with the newer kerenl.
-	 */
-	tr->dir = debugfs_create_automount("tracing", NULL,
-					   trace_automount, NULL);
-	if (!tr->dir) {
-		pr_warn_once("Could not create debugfs directory 'tracing'\n");
-		return ERR_PTR(-ENOMEM);
+	if (debugfs_initialized()) {
+		/*
+		 * As there may still be users that expect the tracing
+		 * files to exist in debugfs/tracing, we must automount
+		 * the tracefs file system there, so older tools still
+		 * work with the newer kerenl.
Quoted 8 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6740

Quoted 5 lines
kernel/trace/trace.c +5 -0
+		 */
+		traced = debugfs_create_automount("tracing", NULL,
+						   trace_automount, NULL);
+		if (!traced)
+			pr_warn_once("Could not create debugfs directory 'tracing'\n");

This should return a warning, and please keep the tr->dir instead of this new traced variable.

Quoted 2 lines

Do you mean return ERR_PTR(-ENOMEM); when debugfs_create_automount() return NULL?

Right.

Quoted 4 lines

As long as tracefs is initialized, we can make tracing_init_dentry() return NULL even if the debugfs automount point is not created(), and tracefs can still be populated. If tracing_init_dentry() returns error in this case, the caller of tracing_init_dentry() will not populate tracefs.

But this is still a failure. tracing_init_dentry() now only mounts tracefs on the debugfs/tracing directory. If it fails to do that when debugfs is available, then it should fail, as it would break backward compatibility with other tools.

If debugfs is not configured in, then it should set tr->dir to whatever (ENOMEM is fine), and return NULL.

Quoted 11 lines
Quoted 9 lines

kernel/trace/trace.c static struct vfsmount *trace_automount(void *ingore) · line 6744

Quoted 5 lines
kernel/trace/trace.c +2 -0
 	}
 
+	tr->dir = TRACE_TOP_DIR_ENTRY;
+

Also, no need to add this, because if debugfs is not initialize, then tr->dir would be ERR_PTR(-ENODEV), which still works as tr->dir is not NULL.

If we accept debugfs_create_automount() return NULL, tr->dir can still be NULL if we do tr->dir = debugfs_create_automount().

What's wrong with that? This function is only to automount debugfs now.

Quoted 8 lines

Also, I think the first check should be:

	if (WARN_ON(!tracefs_initialized()) ||
	    (IS_ENABLED(CONFIG_DEBUGFS) &&
	     WARN_ON(!debugfs_initialized()))
		return ERR_PTR(-ENODEV);

Then we don't need the if (debugfs_initialized()) conditional.

I will send you a new patch according to your suggestion, and if that is OK, I will send a seperate patch to Greg KH to add stub for debugfs_create_automount().

Thanks.

Quoted 17 lines

-- Steve

Quoted 7 lines
Quoted 7 lines

-- Steve

Quoted 3 lines

return NULL;
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#13 lore raw

PATCH 1/1 tracing: Make tracing work when debugfs is not configured in

In reply to Steven Rostedt

Currently tracing_init_dentry() returns -ENODEV when debugfs is not configured in, which causes tracefs not populated with tracing files and directories, so we will get an empty directory even after we manually mount tracefs.

We can make tracing_init_dentry() return NULL if debugfs is not configured in and can manually mount tracefs. But return -ENODEV if debugfs is configured in but not initialized or failed to create automount point as that would break backward compatibility with older tools.

---
 kernel/trace/trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace.c +3 -1
index 6e79408..c89296f 100644
@@ -6721,7 +6721,9 @@ struct dentry *tracing_init_dentry(void)
 	if (tr->dir)
 		return NULL;
 
-	if (WARN_ON(!debugfs_initialized()))
+	if (WARN_ON(!tracefs_initialized()) ||
+		(IS_ENABLED(CONFIG_DEBUG_FS) &&
+		 WARN_ON(!debugfs_initialized())))
 		return ERR_PTR(-ENODEV);
 
 	/*
Signature · 1 line
2.1.4
#14 lore raw

PATCH 3/3 tracing: Apply tracer specific options from kernel command line.

In reply to Jiaxing Wang

Currently, the trace_options parameter is only applied in tracer_alloc_buffers() when global_trace.current_trace is nop_trace, so a tracer specific option will not be applied even when the specific tracer is also enabled from kernel command line. For example, the 'func_stack_trace' option can't be enabled with the following kernel parameter:

ftrace=function ftrace_filter=kfree trace_options=func_stack_trace

We can enable tracer specific options by simply apply the options again if the specific tracer is also supplied from command line and started in register_tracer().

To keep trace_boot_options_buf from overwritten by strsep() and strstrip() and can be parsed again, a copy is made for them to work on.

Also make register_tracer() be __init to access the __init data, and in fact register_tracer is only called from __init code.

---
 kernel/trace/trace.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)
kernel/trace/trace.c +34 -7
index 2d3042f..d42af59 100644
@@ -1204,13 +1204,15 @@ static inline int run_tracer_selftest(struct tracer *type)
 }
 #endif /* CONFIG_FTRACE_STARTUP_TEST */
 
+static int __init apply_trace_boot_options(void);
+
 /**
  * register_tracer - register a tracer with the ftrace system.
  * @type - the plugin for the tracer
  *
  * Register a new plugin tracer.
  */
-int register_tracer(struct tracer *type)
+int __init register_tracer(struct tracer *type)
 {
 	struct tracer *t;
 	int ret = 0;
@@ -1268,6 +1270,9 @@ int register_tracer(struct tracer *type)
 	/* Do we want this tracer to start on bootup? */
 	tracing_set_tracer(&global_trace, type->name);
 	default_bootup_tracer = NULL;
+
+	apply_trace_boot_options();
+
 	/* disable other selftests, since this will break it. */
 	tracing_selftest_disabled = true;
 #ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -3603,6 +3608,33 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	return ret;
 }
 
+static int __init apply_trace_boot_options(void)
+{
+	char *option;
+	char *buf;
+	char *str;
+	size_t len;
+
+	if (trace_boot_options) {
+		len = strlen(trace_boot_options);
+
+		buf = str = kmalloc(len + 1, GFP_KERNEL);
+		if (!buf)
+			return -ENOMEM;
+
+		memcpy(buf, trace_boot_options, len + 1);
+
+		while (str) {
+			option = strsep(&str, ",");
+			trace_set_options(&global_trace, option);
+		}
+
+		kfree(buf);
+	}
+
+	return 0;
+}
+
 static ssize_t
 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
@@ -7153,12 +7185,7 @@ __init static int tracer_alloc_buffers(void)
 	INIT_LIST_HEAD(&global_trace.events);
 	list_add(&global_trace.list, &ftrace_trace_arrays);
 
-	while (trace_boot_options) {
-		char *option;
-
-		option = strsep(&trace_boot_options, ",");
-		trace_set_options(&global_trace, option);
-	}
+	apply_trace_boot_options();
 
 	register_snapshot_cmd();
 
Signature · 1 line
2.1.4
maintainer
#15 lore raw

Re: [PATCH 3/3] tracing: Apply tracer specific options from kernel command line.

Quoted 12 lines · On Sun, 18 Oct 2015 19:58:10 +0800 Jiaxing Wang <[email protected]> wrote:
kernel/trace/trace.c +12 -0
+static int __init apply_trace_boot_options(void)
+{
+	char *option;
+	char *buf;
+	char *str;
+	size_t len;
+
+	if (trace_boot_options) {
+		len = strlen(trace_boot_options);
+
+		buf = str = kmalloc(len + 1, GFP_KERNEL);
+		if (!buf)

kernel/trace/trace.c static int trace_set_options(struct trace_array *tr, char *option) · line 3632

Quoted 10 lines
kernel/trace/trace.c +10 -0
+			return -ENOMEM;
+
+		memcpy(buf, trace_boot_options, len + 1);
+
+		while (str) {
+			option = strsep(&str, ",");
+			trace_set_options(&global_trace, option);
+		}
+
+		kfree(buf);

Instead of allocating a buffer, do what I do in early_enable_events() (see trace_events.c), where I put back the ',' after processing.

-- Steve

Quoted 22 lines
kernel/trace/trace.c +6 -6
+	}
+
+	return 0;
+}
+
 static ssize_t
 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
@@ -7153,12 +7185,7 @@ __init static int tracer_alloc_buffers(void)
 	INIT_LIST_HEAD(&global_trace.events);
 	list_add(&global_trace.list, &ftrace_trace_arrays);
 
-	while (trace_boot_options) {
-		char *option;
-
-		option = strsep(&trace_boot_options, ",");
-		trace_set_options(&global_trace, option);
-	}
+	apply_trace_boot_options();
 
 	register_snapshot_cmd();
 
#16 lore raw

PATCH v2 1/1 tracing: Apply tracer specific options from kernel command line.

Currently, the trace_options parameter is only applied in tracer_alloc_buffers() when global_trace.current_trace is nop_trace, so a tracer specific option will not be applied even when the specific tracer is also enabled from kernel command line. For example, the 'func_stack_trace' option can't be enabled with the following kernel parameter:

ftrace=function ftrace_filter=kfree trace_options=func_stack_trace

We can enable tracer specific options by simply apply the options again if the specific tracer is also supplied from command line and started in register_tracer().

To make trace_boot_options_buf can be parsed again, a comma and a space is put back if they were replaced by strsep and strstrip respectively.

Also make register_tracer() be __init to access the __init data, and in fact register_tracer is only called from __init code.

---
 kernel/trace/trace.c | 45 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 9 deletions(-)
kernel/trace/trace.c +36 -9
index 6dd064e..689886c 100644
@@ -214,12 +214,10 @@ __setup("alloc_snapshot", boot_alloc_snapshot);
 
 
 static char trace_boot_options_buf[MAX_TRACER_SIZE] __initdata;
-static char *trace_boot_options __initdata;
 
 static int __init set_trace_boot_options(char *str)
 {
 	strlcpy(trace_boot_options_buf, str, MAX_TRACER_SIZE);
-	trace_boot_options = trace_boot_options_buf;
 	return 0;
 }
 __setup("trace_options=", set_trace_boot_options);
@@ -1204,13 +1202,15 @@ static inline int run_tracer_selftest(struct tracer *type)
 }
 #endif /* CONFIG_FTRACE_STARTUP_TEST */
 
+static void __init apply_trace_boot_options(void);
+
 /**
  * register_tracer - register a tracer with the ftrace system.
  * @type - the plugin for the tracer
  *
  * Register a new plugin tracer.
  */
-int register_tracer(struct tracer *type)
+int __init register_tracer(struct tracer *type)
 {
 	struct tracer *t;
 	int ret = 0;
@@ -1268,6 +1268,9 @@ int register_tracer(struct tracer *type)
 	/* Do we want this tracer to start on bootup? */
 	tracing_set_tracer(&global_trace, type->name);
 	default_bootup_tracer = NULL;
+
+	apply_trace_boot_options();
+
 	/* disable other selftests, since this will break it. */
 	tracing_selftest_disabled = true;
 #ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -3577,6 +3580,7 @@ static int trace_set_options(struct trace_array *tr, char *option)
 	int neg = 0;
 	int ret = -ENODEV;
 	int i;
+	size_t orig_len = strlen(option);
 
 	cmp = strstrip(option);
 
@@ -3600,9 +3604,37 @@ static int trace_set_options(struct trace_array *tr, char *option)
 
 	mutex_unlock(&trace_types_lock);
 
+	/*
+	 * If the first trailing whitespace is replaced with '\0' by strstrip,
+	 * turn it back into a space.
+	 */
+	if (orig_len > strlen(option))
+		option[strlen(option)] = ' ';
+
 	return ret;
 }
 
+static void __init apply_trace_boot_options(void)
+{
+	char *buf = trace_boot_options_buf;
+	char *option;
+
+	while (true) {
+		option = strsep(&buf, ",");
+
+		if (!option)
+			break;
+		if (!*option)
+			continue;
+
+		trace_set_options(&global_trace, option);
+
+		/* Put back the comma to allow this to be called again */
+		if (buf)
+			*(buf - 1) = ',';
+	}
+}
+
 static ssize_t
 tracing_trace_options_write(struct file *filp, const char __user *ubuf,
 			size_t cnt, loff_t *ppos)
@@ -7153,12 +7185,7 @@ __init static int tracer_alloc_buffers(void)
 	INIT_LIST_HEAD(&global_trace.events);
 	list_add(&global_trace.list, &ftrace_trace_arrays);
 
-	while (trace_boot_options) {
-		char *option;
-
-		option = strsep(&trace_boot_options, ",");
-		trace_set_options(&global_trace, option);
-	}
+	apply_trace_boot_options();
 
 	register_snapshot_cmd();
 
Signature · 1 line
2.1.4