Skip to contentSkip to conversation

tracing: Updates for 5.19

PATCH New Steven Rostedt 1 participant 22 messages Apr 27, 2022

Subsystems (6)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Updates for 5.19

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next-core

Head SHA1: 6621a7004684bfcff5af4c8e4d37989941f42a6b

Ammar Faizi (2):
tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse()
tracing: Change if (strlen(glob)) to if (glob[0])

Christophe Leroy (1):
MAINTAINERS: Enlarge coverage of TRACING inside architectures

Guo Zhengkui (1):
tracing: Use WARN instead of printk and WARN_ON

Jeff Xie (1):
tracing: Make tp_printk work on syscall tracepoints

Jiapeng Chong (1):
tracing: Fix kernel-doc

Jun Miao (1):
tracing: Fix sleeping function called from invalid context on RT kernel

Mark-PK Tsai (2):
tracing: Avoid adding tracer option before update_tracer_options
tracing: make tracer_init_tracefs initcall asynchronous

Masami Hiramatsu (4):
bootconfig: Make the bootconfig.o as a normal object file
bootconfig: Check the checksum before removing the bootconfig from initrd
bootconfig: Support embedding a bootconfig file in kernel
docs: bootconfig: Add how to embed the bootconfig into kernel

Oscar Shiang (1):
tracing: Fix inconsistent style of mini-HOWTO

Tom Rix (1):
tracing: Cleanup double word in comment

Tom Zanussi (4):
tracing: Remove logic for registering multiple event triggers at a time
tracing: Remove redundant trigger_ops params
tracing: Have existing event_command.parse() implementations use helpers
tracing: Separate hist state updates from hist registration

Wan Jiabing (1):
ring-buffer: Simplify if-if to if-else

Yang Li (1):
tracing: Fix tracing_map_sort_entries() kernel-doc comment

----

 Documentation/admin-guide/bootconfig.rst |  31 +++-
 MAINTAINERS                              |   5 +-
 include/linux/bootconfig.h               |  10 ++
 init/Kconfig                             |  21 ++-
 init/main.c                              |  38 ++--
 kernel/trace/pid_list.c                  |   4 +-
 kernel/trace/ring_buffer.c               |   4 +-
 kernel/trace/trace.c                     |  51 ++++--
 kernel/trace/trace.h                     |  26 ++-
 kernel/trace/trace_eprobe.c              |  10 +-
 kernel/trace/trace_events_hist.c         | 171 +++++++++---------
 kernel/trace/trace_events_trigger.c      | 292 ++++++++++---------------------
 kernel/trace/trace_output.c              |  12 +-
 kernel/trace/trace_syscalls.c            |  35 ++--
 kernel/trace/tracing_map.c               |   3 +-
 lib/.gitignore                           |   1 +
 lib/Makefile                             |  10 +-
 lib/bootconfig-data.S                    |  10 ++
 lib/bootconfig.c                         |  13 ++
 19 files changed, 364 insertions(+), 383 deletions(-)
 create mode 100644 lib/bootconfig-data.S
author maintainer
#1 lore raw

PATCH 1/21 tracing: Cleanup double word in comment

From: Tom Rix <[email protected]>

Remove the second 'is' and 'to'.

---
 kernel/trace/pid_list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/pid_list.c +2 -2
index a2ef1d18126a..95106d02b32d 100644
@@ -118,9 +118,9 @@ static inline unsigned int pid_join(unsigned int upper1,
 /**
  * trace_pid_list_is_set - test if the pid is set in the list
  * @pid_list: The pid list to test
- * @pid: The pid to to see if set in the list.
+ * @pid: The pid to see if set in the list.
  *
- * Tests if @pid is is set in the @pid_list. This is usually called
+ * Tests if @pid is set in the @pid_list. This is usually called
  * from the scheduler when a task is scheduled. Its pid is checked
  * if it should be traced or not.
  *
Signature · 1 line
2.35.1
author maintainer
#2 lore raw

PATCH 2/21 tracing: Remove logic for registering multiple event triggers at a time

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

Code for registering triggers assumes it's possible to register more than one trigger at a time. In fact, it's unimplemented and there doesn't seem to be a reason to do that.

Remove the n_registered param from event_trigger_register() and fix up callers.

Doing so simplifies the logic in event_trigger_register to the point that it just becomes a wrapper calling event_command.reg().

It also removes the problematic call to event_command.unreg() in case of failure. A new function, event_trigger_unregister() is also added for callers to call themselves.

The changes to trace_events_hist.c simply allow compilation; a separate patch follows which updates the hist triggers to work correctly with the new changes.

---
 kernel/trace/trace.h                |  9 +--
 kernel/trace/trace_events_hist.c    | 17 ++---
 kernel/trace/trace_events_trigger.c | 96 ++++++++++-------------------
 3 files changed, 45 insertions(+), 77 deletions(-)
kernel/trace/trace.h +5 -4
index 07d990270e2a..2bc8036b0659 100644
@@ -1629,10 +1629,11 @@ extern void event_trigger_reset_filter(struct event_command *cmd_ops,
 extern int event_trigger_register(struct event_command *cmd_ops,
 				  struct trace_event_file *file,
 				  char *glob,
-				  char *cmd,
-				  char *trigger,
-				  struct event_trigger_data *trigger_data,
-				  int *n_registered);
+				  struct event_trigger_data *trigger_data);
+extern void event_trigger_unregister(struct event_command *cmd_ops,
+				     struct trace_event_file *file,
+				     char *glob,
+				     struct event_trigger_data *trigger_data);
 
 /**
  * struct event_trigger_ops - callbacks for trace event triggers
kernel/trace/trace_events_hist.c +6 -11
index 44db5ba9cabb..b18d00905eae 100644
@@ -6287,7 +6287,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 			goto out_free;
 		}
 
-		cmd_ops->unreg(glob+1, trigger_data, file);
+		event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
 		se_name = trace_event_name(file->event_call);
 		se = find_synth_event(se_name);
 		if (se)
@@ -6296,13 +6296,10 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 		goto out_free;
 	}
 
-	ret = cmd_ops->reg(glob, trigger_data, file);
-	/*
-	 * The above returns on success the # of triggers registered,
-	 * but if it didn't register any it returns zero.  Consider no
-	 * triggers registered a failure too.
-	 */
-	if (!ret) {
+	ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
+	if (ret)
+		goto out_free;
+	if (ret == 0) {
 		if (!(attrs->pause || attrs->cont || attrs->clear))
 			ret = -ENOENT;
 		goto out_free;
@@ -6331,15 +6328,13 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 	se = find_synth_event(se_name);
 	if (se)
 		se->ref++;
-	/* Just return zero, not the number of registered triggers */
-	ret = 0;
  out:
 	if (ret == 0)
 		hist_err_clear();
 
 	return ret;
  out_unreg:
-	cmd_ops->unreg(glob+1, trigger_data, file);
+	event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
  out_free:
 	if (cmd_ops->set_filter)
 		cmd_ops->set_filter(NULL, trigger_data, NULL);
kernel/trace/trace_events_trigger.c +34 -62

158 lines not on this page · raw message

Signature · 1 line
2.35.1
author maintainer
#3 lore raw

PATCH 3/21 tracing: Remove redundant trigger_ops params

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

Since event_trigger_data contains the .ops trigger_ops field, there's no reason to pass the trigger_ops separately. Remove it as a param from functions whenever event_trigger_data is passed.

---
 kernel/trace/trace.h                | 14 +++------
 kernel/trace/trace_eprobe.c         |  7 ++---
 kernel/trace/trace_events_hist.c    | 29 ++++++++----------
 kernel/trace/trace_events_trigger.c | 46 +++++++++++------------------
 4 files changed, 36 insertions(+), 60 deletions(-)
kernel/trace/trace.h +4 -10
index 2bc8036b0659..f3e4cd1bb60e 100644
@@ -1573,10 +1573,8 @@ struct enable_trigger_data {
 };
 
 extern int event_enable_trigger_print(struct seq_file *m,
-				      struct event_trigger_ops *ops,
-				      struct event_trigger_data *data);
-extern void event_enable_trigger_free(struct event_trigger_ops *ops,
 				      struct event_trigger_data *data);
+extern void event_enable_trigger_free(struct event_trigger_data *data);
 extern int event_enable_trigger_parse(struct event_command *cmd_ops,
 				      struct trace_event_file *file,
 				      char *glob, char *cmd, char *param);
@@ -1587,8 +1585,7 @@ extern void event_enable_unregister_trigger(char *glob,
 					    struct event_trigger_data *test,
 					    struct trace_event_file *file);
 extern void trigger_data_free(struct event_trigger_data *data);
-extern int event_trigger_init(struct event_trigger_ops *ops,
-			      struct event_trigger_data *data);
+extern int event_trigger_init(struct event_trigger_data *data);
 extern int trace_event_trigger_enable_disable(struct trace_event_file *file,
 					      int trigger_enable);
 extern void update_cond_flag(struct trace_event_file *file);
@@ -1687,12 +1684,9 @@ struct event_trigger_ops {
 					   struct trace_buffer *buffer,
 					   void *rec,
 					   struct ring_buffer_event *rbe);
-	int			(*init)(struct event_trigger_ops *ops,
-					struct event_trigger_data *data);
-	void			(*free)(struct event_trigger_ops *ops,
-					struct event_trigger_data *data);
+	int			(*init)(struct event_trigger_data *data);
+	void			(*free)(struct event_trigger_data *data);
 	int			(*print)(struct seq_file *m,
-					 struct event_trigger_ops *ops,
 					 struct event_trigger_data *data);
 };
 
kernel/trace/trace_eprobe.c +2 -5
index 541aa13581b9..9b3dfc9da067 100644
@@ -511,20 +511,17 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec)
  * functions are just stubs to fulfill what is needed to use the trigger
  * infrastructure.
  */
-static int eprobe_trigger_init(struct event_trigger_ops *ops,
-			       struct event_trigger_data *data)
+static int eprobe_trigger_init(struct event_trigger_data *data)
 {
 	return 0;
 }
 
-static void eprobe_trigger_free(struct event_trigger_ops *ops,
-				struct event_trigger_data *data)
+static void eprobe_trigger_free(struct event_trigger_data *data)
 {
 
 }
 
 static int eprobe_trigger_print(struct seq_file *m,
-				struct event_trigger_ops *ops,
 				struct event_trigger_data *data)
 {
 	/* Do not print eprobe event triggers */
kernel/trace/trace_events_hist.c +12 -17
index b18d00905eae..40a7e5582dfb 100644
@@ -5252,7 +5252,7 @@ static void hist_trigger_show(struct seq_file *m,
 		seq_puts(m, "\n\n");
 
 	seq_puts(m, "# event histogram\n#\n# trigger info: ");
-	data->ops->print(m, data->ops, data);
+	data->ops->print(m, data);
 	seq_puts(m, "#\n\n");
 
 	hist_data = data->private_data;
@@ -5484,7 +5484,7 @@ static void hist_trigger_debug_show(struct seq_file *m,
 		seq_puts(m, "\n\n");
 
 	seq_puts(m, "# event histogram\n#\n# trigger info: ");
-	data->ops->print(m, data->ops, data);
+	data->ops->print(m, data);
 	seq_puts(m, "#\n\n");
 
 	hist_data = data->private_data;
@@ -5621,7 +5621,6 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
 }
 
 static int event_hist_trigger_print(struct seq_file *m,
-				    struct event_trigger_ops *ops,
 				    struct event_trigger_data *data)
 {
 	struct hist_trigger_data *hist_data = data->private_data;
@@ -5729,8 +5728,7 @@ static int event_hist_trigger_print(struct seq_file *m,
 	return 0;
 }
 
-static int event_hist_trigger_init(struct event_trigger_ops *ops,
-				   struct event_trigger_data *data)
+static int event_hist_trigger_init(struct event_trigger_data *data)
 {
 	struct hist_trigger_data *hist_data = data->private_data;
 
@@ -5758,8 +5756,7 @@ static void unregister_field_var_hists(struct hist_trigger_data *hist_data)
 	}
 }
 
-static void event_hist_trigger_free(struct event_trigger_ops *ops,
-				    struct event_trigger_data *data)
+static void event_hist_trigger_free(struct event_trigger_data *data)
 {
 	struct hist_trigger_data *hist_data = data->private_data;
 
@@ -5788,25 +5785,23 @@ static struct event_trigger_ops event_hist_trigger_ops = {
 	.free			= event_hist_trigger_free,
 };
 
-static int event_hist_trigger_named_init(struct event_trigger_ops *ops,
-					 struct event_trigger_data *data)
+static int event_hist_trigger_named_init(struct event_trigger_data *data)
 {
 	data->ref++;
 
 	save_named_trigger(data->named_data->name, data);
 
-	event_hist_trigger_init(ops, data->named_data);
+	event_hist_trigger_init(data->named_data);
 
 	return 0;
 }
 
-static void event_hist_trigger_named_free(struct event_trigger_ops *ops,
-					  struct event_trigger_data *data)
+static void event_hist_trigger_named_free(struct event_trigger_data *data)
 {
 	if (WARN_ON_ONCE(data->ref <= 0))
 		return;
 
-	event_hist_trigger_free(ops, data->named_data);
+	event_hist_trigger_free(data->named_data);
 
 	data->ref--;
 	if (!data->ref) {
@@ -5993,7 +5988,7 @@ static int hist_register_trigger(char *glob,
 	}
 
 	if (data->ops->init) {
-		ret = data->ops->init(data->ops, data);
+		ret = data->ops->init(data);
 		if (ret < 0)
 			goto out;
 	}
@@ -6111,7 +6106,7 @@ static void hist_unregister_trigger(char *glob,
 	}
 
 	if (unregistered && test->ops->free)
-		test->ops->free(test->ops, test);
+		test->ops->free(test);
 
 	if (hist_data->enable_timestamps) {
 		if (!hist_data->remove || unregistered)
@@ -6164,7 +6159,7 @@ static void hist_unreg_all(struct trace_event_file *file)
 			if (hist_data->enable_timestamps)
 				tracing_set_filter_buffering(file->tr, false);
 			if (test->ops->free)
-				test->ops->free(test->ops, test);
+				test->ops->free(test);
 		}
 	}
 }
@@ -6458,7 +6453,7 @@ static void hist_enable_unreg_all(struct trace_event_file *file)
 			update_cond_flag(file);
 			trace_event_trigger_enable_disable(file, 0);
 			if (test->ops->free)
-				test->ops->free(test->ops, test);
+				test->ops->free(test);
 		}
 	}
 }
kernel/trace/trace_events_trigger.c +18 -28

172 lines not on this page · raw message

Signature · 1 line
2.35.1
author maintainer
#4 lore raw

PATCH 4/21 tracing: Have existing event_command.parse() implementations use helpers

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

Simplify the existing event_command.parse() implementations by having them make use of the helper functions previously introduced.

---
 kernel/trace/trace.h                |   3 +-
 kernel/trace/trace_eprobe.c         |   3 +-
 kernel/trace/trace_events_hist.c    |  64 +++++-------
 kernel/trace/trace_events_trigger.c | 150 ++++++++--------------------
 4 files changed, 69 insertions(+), 151 deletions(-)
kernel/trace/trace.h +2 -1
index f3e4cd1bb60e..ff816fb41e48 100644
@@ -1577,7 +1577,8 @@ extern int event_enable_trigger_print(struct seq_file *m,
 extern void event_enable_trigger_free(struct event_trigger_data *data);
 extern int event_enable_trigger_parse(struct event_command *cmd_ops,
 				      struct trace_event_file *file,
-				      char *glob, char *cmd, char *param);
+				      char *glob, char *cmd,
+				      char *param_and_filter);
 extern int event_enable_register_trigger(char *glob,
 					 struct event_trigger_data *data,
 					 struct trace_event_file *file);
kernel/trace/trace_eprobe.c +2 -1
index 9b3dfc9da067..b045fa9f276c 100644
@@ -546,7 +546,8 @@ static struct event_trigger_ops eprobe_trigger_ops = {
 
 static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops,
 				    struct trace_event_file *file,
-				    char *glob, char *cmd, char *param)
+				    char *glob, char *cmd,
+				    char *param_and_filter)
 {
 	return -1;
 }
kernel/trace/trace_events_hist.c +24 -40

148 lines not on this page · raw message

kernel/trace/trace_events_trigger.c +41 -109

247 lines not on this page · raw message

Signature · 1 line
2.35.1
author maintainer
#5 lore raw

PATCH 5/21 tracing: Separate hist state updates from hist registration

In reply to Steven Rostedt

From: Tom Zanussi <[email protected]>

hist_register_trigger() handles both new hist registration as well as existing hist registration through event_command.reg().

Adding a new function, existing_hist_update_only(), that checks and updates existing histograms and exits after doing so allows the confusing logic in event_hist_trigger_parse() to be simplified.

---
 kernel/trace/trace_events_hist.c | 66 +++++++++++++++++++++++---------
 1 file changed, 48 insertions(+), 18 deletions(-)
kernel/trace/trace_events_hist.c +48 -18
index 1b71bdb0bcb1..998dfe2162fc 100644
@@ -5929,6 +5929,48 @@ static bool hist_trigger_match(struct event_trigger_data *data,
 	return true;
 }
 
+static bool existing_hist_update_only(char *glob,
+				      struct event_trigger_data *data,
+				      struct trace_event_file *file)
+{
+	struct hist_trigger_data *hist_data = data->private_data;
+	struct event_trigger_data *test, *named_data = NULL;
+	bool updated = false;
+
+	if (!hist_data->attrs->pause && !hist_data->attrs->cont &&
+	    !hist_data->attrs->clear)
+		goto out;
+
+	if (hist_data->attrs->name) {
+		named_data = find_named_trigger(hist_data->attrs->name);
+		if (named_data) {
+			if (!hist_trigger_match(data, named_data, named_data,
+						true))
+				goto out;
+		}
+	}
+
+	if (hist_data->attrs->name && !named_data)
+		goto out;
+
+	list_for_each_entry(test, &file->triggers, list) {
+		if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
+			if (!hist_trigger_match(data, test, named_data, false))
+				continue;
+			if (hist_data->attrs->pause)
+				test->paused = true;
+			else if (hist_data->attrs->cont)
+				test->paused = false;
+			else if (hist_data->attrs->clear)
+				hist_clear(test);
+			updated = true;
+			goto out;
+		}
+	}
+ out:
+	return updated;
+}
+
 static int hist_register_trigger(char *glob,
 				 struct event_trigger_data *data,
 				 struct trace_event_file *file)
@@ -5957,19 +5999,11 @@ static int hist_register_trigger(char *glob,
 
 	list_for_each_entry(test, &file->triggers, list) {
 		if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
-			if (!hist_trigger_match(data, test, named_data, false))
-				continue;
-			if (hist_data->attrs->pause)
-				test->paused = true;
-			else if (hist_data->attrs->cont)
-				test->paused = false;
-			else if (hist_data->attrs->clear)
-				hist_clear(test);
-			else {
+			if (hist_trigger_match(data, test, named_data, false)) {
 				hist_err(tr, HIST_ERR_TRIGGER_EEXIST, 0);
 				ret = -EEXIST;
+				goto out;
 			}
-			goto out;
 		}
 	}
  new:
@@ -6008,8 +6042,6 @@ static int hist_register_trigger(char *glob,
 
 	if (named_data)
 		destroy_hist_data(hist_data);
-
-	ret++;
  out:
 	return ret;
 }
@@ -6277,14 +6309,12 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 		goto out_free;
 	}
 
-	ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
-	if (ret)
+	if (existing_hist_update_only(glob, trigger_data, file))
 		goto out_free;
-	if (ret == 0) {
-		if (!(attrs->pause || attrs->cont || attrs->clear))
-			ret = -ENOENT;
+
+	ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
+	if (ret < 0)
 		goto out_free;
-	}
 
 	if (get_named_trigger_data(trigger_data))
 		goto enable;
Signature · 1 line
2.35.1
author maintainer
#6 lore raw

PATCH 6/21 tracing: Fix inconsistent style of mini-HOWTO

In reply to Steven Rostedt

From: Oscar Shiang <[email protected]>

Each description should start with a hyphen and a space. Insert spaces to fix it.

---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index f4de111fa18f..4f9c499368c4 100644
@@ -5475,7 +5475,7 @@ static const char readme_msg[] =
 	"  error_log\t- error log for failed commands (that support it)\n"
 	"  buffer_size_kb\t- view and modify size of per cpu buffer\n"
 	"  buffer_total_size_kb  - view total size of all cpu buffers\n\n"
-	"  trace_clock\t\t-change the clock used to order events\n"
+	"  trace_clock\t\t- change the clock used to order events\n"
 	"       local:   Per cpu clock but may not be synced across CPUs\n"
 	"      global:   Synced across CPUs but slows tracing down.\n"
 	"     counter:   Not a clock, but just an increment\n"
@@ -5484,7 +5484,7 @@ static const char readme_msg[] =
 #ifdef CONFIG_X86_64
 	"     x86-tsc:   TSC cycle counter\n"
 #endif
-	"\n  timestamp_mode\t-view the mode used to timestamp events\n"
+	"\n  timestamp_mode\t- view the mode used to timestamp events\n"
 	"       delta:   Delta difference against a buffer-wide timestamp\n"
 	"    absolute:   Absolute (standalone) timestamp\n"
 	"\n  trace_marker\t\t- Writes into this file writes into the kernel buffer\n"
Signature · 1 line
2.35.1
author maintainer
#7 lore raw

PATCH 7/21 tracing: Fix kernel-doc

In reply to Steven Rostedt

From: Jiapeng Chong <[email protected]>

Fix the following W=1 kernel warnings:

kernel/trace/trace.c:1181: warning: expecting prototype for tracing_snapshot_cond_data(). Prototype was for tracing_cond_snapshot_data() instead.

---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
index 4f9c499368c4..aceeeea21c11 100644
@@ -1174,7 +1174,7 @@ void tracing_snapshot_cond(struct trace_array *tr, void *cond_data)
 EXPORT_SYMBOL_GPL(tracing_snapshot_cond);
 
 /**
- * tracing_snapshot_cond_data - get the user data associated with a snapshot
+ * tracing_cond_snapshot_data - get the user data associated with a snapshot
  * @tr:		The tracing instance
  *
  * When the user enables a conditional snapshot using
Signature · 1 line
2.35.1
author maintainer
#8 lore raw

PATCH 8/21 MAINTAINERS: Enlarge coverage of TRACING inside architectures

In reply to Steven Rostedt

From: Christophe Leroy <[email protected]>

Most architectures have ftrace related stuff in arch/*/kernel/ftrace.c but powerpc has it spread in multiple files located in arch/powerpc/kernel/trace/
In several architectures, there are also additional files containing 'ftrace' as part of the name but with some prefix or suffix.

Use wildcards to enlarge coverage.

With arch/*/*/*/*ftrace*:

	arch/alpha/include/asm/ftrace.h
	arch/arm64/include/asm/ftrace.h
	arch/arm/include/asm/ftrace.h
	arch/csky/include/asm/ftrace.h
	arch/csky/kernel/probes/ftrace.c
	arch/ia64/include/asm/ftrace.h
	arch/m68k/include/asm/ftrace.h
	arch/microblaze/include/asm/ftrace.h
	arch/mips/include/asm/ftrace.h
	arch/nds32/include/asm/ftrace.h
	arch/parisc/include/asm/ftrace.h
	arch/powerpc/include/asm/ftrace.h
	arch/powerpc/kernel/trace/ftrace_64_pg.S
	arch/powerpc/kernel/trace/ftrace.c
	arch/powerpc/kernel/trace/ftrace_low.S
	arch/powerpc/kernel/trace/ftrace_mprofile.S
	arch/riscv/include/asm/ftrace.h
	arch/riscv/kernel/probes/ftrace.c
	arch/s390/include/asm/ftrace.h
	arch/s390/include/asm/ftrace.lds.h
	arch/sh/include/asm/ftrace.h
	arch/sparc/include/asm/ftrace.h
	arch/x86/include/asm/ftrace.h
	arch/x86/kernel/kprobes/ftrace.c
	arch/xtensa/include/asm/ftrace.h

With arch/*/*/*ftrace*:

	arch/arm64/kernel/entry-ftrace.S
	arch/arm64/kernel/ftrace.c
	arch/arm/kernel/entry-ftrace.S
	arch/arm/kernel/ftrace.c
	arch/csky/kernel/ftrace.c
	arch/ia64/kernel/ftrace.c
	arch/microblaze/kernel/ftrace.c
	arch/mips/kernel/ftrace.c
	arch/nds32/kernel/ftrace.c
	arch/parisc/kernel/ftrace.c
	arch/powerpc/kernel/kprobes-ftrace.c
	arch/riscv/kernel/ftrace.c
	arch/s390/kernel/ftrace.c
	arch/s390/kernel/ftrace.h
	arch/sh/kernel/ftrace.c
	arch/sparc/kernel/ftrace.c
	arch/x86/kernel/ftrace_32.S
	arch/x86/kernel/ftrace_64.S
	arch/x86/kernel/ftrace.c
---
 MAINTAINERS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
MAINTAINERS +2 -2
index 61d9f114c37f..b90535d923a0 100644
@@ -19951,8 +19951,8 @@ M:	Ingo Molnar <[email protected]>
 S:	Maintained
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
 F:	Documentation/trace/ftrace.rst
-F:	arch/*/*/*/ftrace.h
-F:	arch/*/kernel/ftrace.c
+F:	arch/*/*/*/*ftrace*
+F:	arch/*/*/*ftrace*
 F:	fs/tracefs/
 F:	include/*/ftrace.h
 F:	include/linux/trace*.h
Signature · 1 line
2.35.1
author maintainer
#9 lore raw

PATCH 9/21 tracing: Fix tracing_map_sort_entries() kernel-doc comment

In reply to Steven Rostedt

From: Yang Li <[email protected]>

Add the description of @n_sort_keys and make @sort_key -> @sort_keys in tracing_map_sort_entries() kernel-doc comment to remove warnings found by running scripts/kernel-doc, which is caused by using 'make W=1'.

kernel/trace/tracing_map.c:1073: warning: Function parameter or member 'sort_keys' not described in 'tracing_map_sort_entries' kernel/trace/tracing_map.c:1073: warning: Function parameter or member 'n_sort_keys' not described in 'tracing_map_sort_entries' kernel/trace/tracing_map.c:1073: warning: Excess function parameter 'sort_key' description in 'tracing_map_sort_entries'

---
 kernel/trace/tracing_map.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/tracing_map.c +2 -1
index 9628b5571846..9901708ce6b8 100644
@@ -1045,7 +1045,8 @@ static void sort_secondary(struct tracing_map *map,
 /**
  * tracing_map_sort_entries - Sort the current set of tracing_map_elts in a map
  * @map: The tracing_map
- * @sort_key: The sort key to use for sorting
+ * @sort_keys: The sort key to use for sorting
+ * @n_sort_keys: hitcount, always have at least one
  * @sort_entries: outval: pointer to allocated and sorted array of entries
  *
  * tracing_map_sort_entries() sorts the current set of entries in the
Signature · 1 line
2.35.1
author maintainer
#10 lore raw

PATCH 10/21 bootconfig: Make the bootconfig.o as a normal object file

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Since the APIs defined in the bootconfig.o are not individually used, it is meaningless to build it as library by lib-y. Use obj-y for that.

Cc Padmanabha Srinivasaiah <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Linux Kbuild mailing list <[email protected]>
---
 lib/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/Makefile +1 -1
index 6b9ffc1bd1ee..08053df16c7c 100644
@@ -279,7 +279,7 @@ $(foreach file, $(libfdt_files), \
 	$(eval CFLAGS_$(file) = -I $(srctree)/scripts/dtc/libfdt))
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
 
-lib-$(CONFIG_BOOT_CONFIG) += bootconfig.o
+obj-$(CONFIG_BOOT_CONFIG) += bootconfig.o
 
 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
Signature · 1 line
2.35.1
author maintainer
#11 lore raw

PATCH 11/21 bootconfig: Check the checksum before removing the bootconfig from initrd

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Check the bootconfig's checksum before removing the bootconfig data from initrd to avoid modifying initrd by mistake.
This will also simplifies the get_boot_config_from_initrd() interface.

Cc Padmanabha Srinivasaiah <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Linux Kbuild mailing list <[email protected]>
---
 init/main.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
init/main.c +10 -12
index 98182c3c2c4b..266d61bc67b0 100644
@@ -266,7 +266,7 @@ static int __init loglevel(char *str)
 early_param("loglevel", loglevel);
 
 #ifdef CONFIG_BLK_DEV_INITRD
-static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
+static void * __init get_boot_config_from_initrd(u32 *_size)
 {
 	u32 size, csum;
 	char *data;
@@ -300,17 +300,20 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
 		return NULL;
 	}
 
+	if (xbc_calc_checksum(data, size) != csum) {
+		pr_err("bootconfig checksum failed\n");
+		return NULL;
+	}
+
 	/* Remove bootconfig from initramfs/initrd */
 	initrd_end = (unsigned long)data;
 	if (_size)
 		*_size = size;
-	if (_csum)
-		*_csum = csum;
 
 	return data;
 }
 #else
-static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
+static void * __init get_boot_config_from_initrd(u32 *_size)
 {
 	return NULL;
 }
@@ -409,12 +412,12 @@ static void __init setup_boot_config(void)
 	static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
 	const char *msg;
 	int pos;
-	u32 size, csum;
+	u32 size;
 	char *data, *err;
 	int ret;
 
 	/* Cut out the bootconfig data even if we have no bootconfig option */
-	data = get_boot_config_from_initrd(&size, &csum);
+	data = get_boot_config_from_initrd(&size);
 
 	strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
 	err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
@@ -438,11 +441,6 @@ static void __init setup_boot_config(void)
 		return;
 	}
 
-	if (xbc_calc_checksum(data, size) != csum) {
-		pr_err("bootconfig checksum failed\n");
-		return;
-	}
-
 	ret = xbc_init(data, size, &msg, &pos);
 	if (ret < 0) {
 		if (pos < 0)
@@ -471,7 +469,7 @@ static void __init exit_boot_config(void)
 static void __init setup_boot_config(void)
 {
 	/* Remove bootconfig data from initrd */
-	get_boot_config_from_initrd(NULL, NULL);
+	get_boot_config_from_initrd(NULL);
 }
 
 static int __init warn_bootconfig(char *str)
Signature · 1 line
2.35.1
author maintainer
#12 lore raw

PATCH 12/21 bootconfig: Support embedding a bootconfig file in kernel

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

This allows kernel developer to embed a default bootconfig file in the kernel instead of embedding it in the initrd. This will be good for who are using the kernel without initrd, or who needs a default bootconfigs.
This needs to set two kconfigs: CONFIG_BOOT_CONFIG_EMBED=y and set the file path to CONFIG_BOOT_CONFIG_EMBED_FILE.

Note that you still need 'bootconfig' command line option to load the embedded bootconfig. Also if you boot using an initrd with a different bootconfig, the kernel will use the bootconfig in the initrd, instead of the default bootconfig.

Cc Padmanabha Srinivasaiah <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Linux Kbuild mailing list <[email protected]>
---
 MAINTAINERS                |  1 +
 include/linux/bootconfig.h | 10 ++++++++++
 init/Kconfig               | 21 ++++++++++++++++++++-
 init/main.c                | 22 ++++++++++++----------
 lib/.gitignore             |  1 +
 lib/Makefile               |  8 ++++++++
 lib/bootconfig-data.S      | 10 ++++++++++
 lib/bootconfig.c           | 13 +++++++++++++
 8 files changed, 75 insertions(+), 11 deletions(-)
 create mode 100644 lib/bootconfig-data.S
MAINTAINERS +1 -0
index b90535d923a0..abc8e6fee21e 100644
@@ -7457,6 +7457,7 @@ S:	Maintained
 F:	Documentation/admin-guide/bootconfig.rst
 F:	fs/proc/bootconfig.c
 F:	include/linux/bootconfig.h
+F:	lib/bootconfig-data.S
 F:	lib/bootconfig.c
 F:	tools/bootconfig/*
 F:	tools/bootconfig/scripts/*
include/linux/bootconfig.h +10 -0
index a4665c7ab07c..1611f9db878e 100644
@@ -289,4 +289,14 @@ int __init xbc_get_info(int *node_size, size_t *data_size);
 /* XBC cleanup data structures */
 void __init xbc_exit(void);
 
+/* XBC embedded bootconfig data in kernel */
+#ifdef CONFIG_BOOT_CONFIG_EMBED
+const char * __init xbc_get_embedded_bootconfig(size_t *size);
+#else
+static inline const char *xbc_get_embedded_bootconfig(size_t *size)
+{
+	return NULL;
+}
+#endif
+
 #endif
init/Kconfig +20 -1
index ddcbefe535e9..2462d4ae2dc8 100644
@@ -1351,7 +1351,7 @@ endif
 
 config BOOT_CONFIG
 	bool "Boot config support"
-	select BLK_DEV_INITRD
+	select BLK_DEV_INITRD if !BOOT_CONFIG_EMBED
 	help
 	  Extra boot config allows system admin to pass a config file as
 	  complemental extension of kernel cmdline when booting.
@@ -1361,6 +1361,25 @@ config BOOT_CONFIG
 
 	  If unsure, say Y.
 
+config BOOT_CONFIG_EMBED
+	bool "Embed bootconfig file in the kernel"
+	depends on BOOT_CONFIG
+	help
+	  Embed a bootconfig file given by BOOT_CONFIG_EMBED_FILE in the
+	  kernel. Usually, the bootconfig file is loaded with the initrd
+	  image. But if the system doesn't support initrd, this option will
+	  help you by embedding a bootconfig file while building the kernel.
+
+	  If unsure, say N.
+
+config BOOT_CONFIG_EMBED_FILE
+	string "Embedded bootconfig file path"
+	depends on BOOT_CONFIG_EMBED
+	help
+	  Specify a bootconfig file which will be embedded to the kernel.
+	  This bootconfig will be used if there is no initrd or no other
+	  bootconfig in the initrd.
+
 choice
 	prompt "Compiler optimization level"
 	default CC_OPTIMIZE_FOR_PERFORMANCE
init/main.c +12 -10
index 266d61bc67b0..f7fe7cbb1df8 100644
@@ -266,7 +266,7 @@ static int __init loglevel(char *str)
 early_param("loglevel", loglevel);
 
 #ifdef CONFIG_BLK_DEV_INITRD
-static void * __init get_boot_config_from_initrd(u32 *_size)
+static void * __init get_boot_config_from_initrd(size_t *_size)
 {
 	u32 size, csum;
 	char *data;
@@ -313,7 +313,7 @@ static void * __init get_boot_config_from_initrd(u32 *_size)
 	return data;
 }
 #else
-static void * __init get_boot_config_from_initrd(u32 *_size)
+static void * __init get_boot_config_from_initrd(size_t *_size)
 {
 	return NULL;
 }
@@ -410,14 +410,16 @@ static int __init warn_bootconfig(char *str)
 static void __init setup_boot_config(void)
 {
 	static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
-	const char *msg;
-	int pos;
-	u32 size;
-	char *data, *err;
-	int ret;
+	const char *msg, *data;
+	int pos, ret;
+	size_t size;
+	char *err;
 
 	/* Cut out the bootconfig data even if we have no bootconfig option */
 	data = get_boot_config_from_initrd(&size);
+	/* If there is no bootconfig in initrd, try embedded one. */
+	if (!data)
+		data = xbc_get_embedded_bootconfig(&size);
 
 	strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
 	err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
@@ -436,8 +438,8 @@ static void __init setup_boot_config(void)
 	}
 
 	if (size >= XBC_DATA_MAX) {
-		pr_err("bootconfig size %d greater than max size %d\n",
-			size, XBC_DATA_MAX);
+		pr_err("bootconfig size %ld greater than max size %d\n",
+			(long)size, XBC_DATA_MAX);
 		return;
 	}
 
@@ -450,7 +452,7 @@ static void __init setup_boot_config(void)
 				msg, pos);
 	} else {
 		xbc_get_info(&ret, NULL);
-		pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret);
+		pr_info("Load bootconfig: %ld bytes %d nodes\n", (long)size, ret);
 		/* keys starting with "kernel." are passed via cmdline */
 		extra_command_line = xbc_make_cmdline("kernel");
 		/* Also, "init." keys are init arguments */
lib/.gitignore +1 -0
index e5e217b8307b..54596b634ecb 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 /crc32table.h
 /crc64table.h
+/default.bconf
 /gen_crc32table
 /gen_crc64table
 /oid_registry_data.c
lib/Makefile +8 -0
index 08053df16c7c..95268d6c75b7 100644
@@ -280,6 +280,14 @@ $(foreach file, $(libfdt_files), \
 lib-$(CONFIG_LIBFDT) += $(libfdt_files)
 
 obj-$(CONFIG_BOOT_CONFIG) += bootconfig.o
+obj-$(CONFIG_BOOT_CONFIG_EMBED) += bootconfig-data.o
+
+$(obj)/bootconfig-data.o: $(obj)/default.bconf
+
+targets += default.bconf
+filechk_defbconf = cat $(or $(real-prereqs), /dev/null)
+$(obj)/default.bconf: $(CONFIG_BOOT_CONFIG_EMBED_FILE) FORCE
+	$(call filechk,defbconf)
 
 obj-$(CONFIG_RBTREE_TEST) += rbtree_test.o
 obj-$(CONFIG_INTERVAL_TREE_TEST) += interval_tree_test.o
lib/bootconfig-data.S new file +10 -0
new file mode 100644
index 000000000000..ef85ba1a82f4
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Embed default bootconfig in the kernel.
+ */
+	.section .init.rodata, "aw"
+	.global embedded_bootconfig_data
+embedded_bootconfig_data:
+	.incbin "lib/default.bconf"
+	.global embedded_bootconfig_data_end
+embedded_bootconfig_data_end:
lib/bootconfig.c +13 -0
index 74f3201ab8e5..c59d26068a64 100644
@@ -12,6 +12,19 @@
 #include <linux/kernel.h>
 #include <linux/memblock.h>
 #include <linux/string.h>
+
+#ifdef CONFIG_BOOT_CONFIG_EMBED
+/* embedded_bootconfig_data is defined in bootconfig-data.S */
+extern __visible const char embedded_bootconfig_data[];
+extern __visible const char embedded_bootconfig_data_end[];
+
+const char * __init xbc_get_embedded_bootconfig(size_t *size)
+{
+	*size = embedded_bootconfig_data_end - embedded_bootconfig_data;
+	return (*size) ? embedded_bootconfig_data : NULL;
+}
+#endif
+
 #else /* !__KERNEL__ */
 /*
  * NOTE: This is only for tools/bootconfig, because tools/bootconfig will
Signature · 1 line
2.35.1
author maintainer
#13 lore raw

PATCH 13/21 docs: bootconfig: Add how to embed the bootconfig into kernel

In reply to Steven Rostedt

From: Masami Hiramatsu <[email protected]>

Add a description how to embed the bootconfig file into kernel.

Cc Padmanabha Srinivasaiah <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Randy Dunlap <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Sami Tolvanen <[email protected]>
Cc Nathan Chancellor <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Linux Kbuild mailing list <[email protected]>
---
 Documentation/admin-guide/bootconfig.rst | 31 +++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
Documentation/admin-guide/bootconfig.rst +28 -3
index a1860fc0ca88..d99994345d41 100644
@@ -158,9 +158,15 @@ Each key-value pair is shown in each line with following style::
 Boot Kernel With a Boot Config
 ==============================
 
-Since the boot configuration file is loaded with initrd, it will be added
-to the end of the initrd (initramfs) image file with padding, size,
-checksum and 12-byte magic word as below.
+There are two options to boot the kernel with bootconfig: attaching the
+bootconfig to the initrd image or embedding it in the kernel itself.
+
+Attaching a Boot Config to Initrd
+---------------------------------
+
+Since the boot configuration file is loaded with initrd by default,
+it will be added to the end of the initrd (initramfs) image file with
+padding, size, checksum and 12-byte magic word as below.
 
 [initrd][bootconfig][padding][size(le32)][checksum(le32)][#BOOTCONFIG\n]
 
@@ -196,6 +202,25 @@ To remove the config from the image, you can use -d option as below::
 Then add "bootconfig" on the normal kernel command line to tell the
 kernel to look for the bootconfig at the end of the initrd file.
 
+Embedding a Boot Config into Kernel
+-----------------------------------
+
+If you can not use initrd, you can also embed the bootconfig file in the
+kernel by Kconfig options. In this case, you need to recompile the kernel
+with the following configs::
+
+ CONFIG_BOOT_CONFIG_EMBED=y
+ CONFIG_BOOT_CONFIG_EMBED_FILE="/PATH/TO/BOOTCONFIG/FILE"
+
+``CONFIG_BOOT_CONFIG_EMBED_FILE`` requires an absolute path or a relative
+path to the bootconfig file from source tree or object tree.
+The kernel will embed it as the default bootconfig.
+
+Just as when attaching the bootconfig to the initrd, you need ``bootconfig``
+option on the kernel command line to enable the embedded bootconfig.
+
+Note that even if you set this option, you can override the embedded
+bootconfig by another bootconfig which attached to the initrd.
 
 Kernel parameters via Boot Config
 =================================
Signature · 1 line
2.35.1
author maintainer
#14 lore raw

PATCH 14/21 tracing: Make tp_printk work on syscall tracepoints

In reply to Steven Rostedt

From: Jeff Xie <[email protected]>

Currently the tp_printk option has no effect on syscall tracepoint. When adding the kernel option parameter tp_printk, then:

echo 1 > /sys/kernel/debug/tracing/events/syscalls/enable

When running any application, no trace information is printed on the terminal.

Now added printk for syscall tracepoints.

---
 kernel/trace/trace_syscalls.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)
kernel/trace/trace_syscalls.c +11 -24
index f755bde42fd0..b69e207012c9 100644
@@ -154,7 +154,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags,
 			goto end;
 
 		/* parameter types */
-		if (tr->trace_flags & TRACE_ITER_VERBOSE)
+		if (tr && tr->trace_flags & TRACE_ITER_VERBOSE)
 			trace_seq_printf(s, "%s ", entry->types[i]);
 
 		/* parameter values */
@@ -296,9 +296,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
 	struct trace_event_file *trace_file;
 	struct syscall_trace_enter *entry;
 	struct syscall_metadata *sys_data;
-	struct ring_buffer_event *event;
-	struct trace_buffer *buffer;
-	unsigned int trace_ctx;
+	struct trace_event_buffer fbuffer;
 	unsigned long args[6];
 	int syscall_nr;
 	int size;
@@ -321,20 +319,16 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
 
 	size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;
 
-	trace_ctx = tracing_gen_ctx();
-
-	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-			sys_data->enter_event->event.type, size, trace_ctx);
-	if (!event)
+	entry = trace_event_buffer_reserve(&fbuffer, trace_file, size);
+	if (!entry)
 		return;
 
-	entry = ring_buffer_event_data(event);
+	entry = ring_buffer_event_data(fbuffer.event);
 	entry->nr = syscall_nr;
 	syscall_get_arguments(current, regs, args);
 	memcpy(entry->args, args, sizeof(unsigned long) * sys_data->nb_args);
 
-	event_trigger_unlock_commit(trace_file, buffer, event, entry,
-				    trace_ctx);
+	trace_event_buffer_commit(&fbuffer);
 }
 
 static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
@@ -343,9 +337,7 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
 	struct trace_event_file *trace_file;
 	struct syscall_trace_exit *entry;
 	struct syscall_metadata *sys_data;
-	struct ring_buffer_event *event;
-	struct trace_buffer *buffer;
-	unsigned int trace_ctx;
+	struct trace_event_buffer fbuffer;
 	int syscall_nr;
 
 	syscall_nr = trace_get_syscall_nr(current, regs);
@@ -364,20 +356,15 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
 	if (!sys_data)
 		return;
 
-	trace_ctx = tracing_gen_ctx();
-
-	event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-			sys_data->exit_event->event.type, sizeof(*entry),
-			trace_ctx);
-	if (!event)
+	entry = trace_event_buffer_reserve(&fbuffer, trace_file, sizeof(*entry));
+	if (!entry)
 		return;
 
-	entry = ring_buffer_event_data(event);
+	entry = ring_buffer_event_data(fbuffer.event);
 	entry->nr = syscall_nr;
 	entry->ret = syscall_get_return_value(current, regs);
 
-	event_trigger_unlock_commit(trace_file, buffer, event, entry,
-				    trace_ctx);
+	trace_event_buffer_commit(&fbuffer);
 }
 
 static int reg_event_syscall_enter(struct trace_event_file *file,
Signature · 1 line
2.35.1
author maintainer
#15 lore raw

PATCH 15/21 tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse()

In reply to Steven Rostedt

From: Ammar Faizi <[email protected]>

If WARN_ON(!glob) is ever triggered, we will still continue executing the next lines. This will trigger the more serious problem, a NULL pointer dereference bug.

Just return -EINVAL if @glob is NULL.

---
 kernel/trace/trace_events_hist.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +2 -1
index 998dfe2162fc..80c25be23c45 100644
@@ -6214,7 +6214,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 
 	lockdep_assert_held(&event_mutex);
 
-	WARN_ON(!glob);
+	if (WARN_ON(!glob))
+		return -EINVAL;
 
 	if (strlen(glob)) {
 		hist_err_clear();
Signature · 1 line
2.35.1
author maintainer
#16 lore raw

PATCH 16/21 tracing: Change `if (strlen(glob))` to `if (glob[0])`

In reply to Steven Rostedt

From: Ammar Faizi <[email protected]>

No need to traverse to the end of string. If the first byte is not a NUL char, it's guaranteed if (strlen(glob)) is true.

---
 kernel/trace/trace_events_hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
index 80c25be23c45..fe10179893c1 100644
@@ -6217,7 +6217,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 	if (WARN_ON(!glob))
 		return -EINVAL;
 
-	if (strlen(glob)) {
+	if (glob[0]) {
 		hist_err_clear();
 		last_cmd_set(file, param_and_filter);
 	}
Signature · 1 line
2.35.1
author maintainer
#17 lore raw

PATCH 17/21 tracing: Fix sleeping function called from invalid context on RT kernel

In reply to Steven Rostedt

From: Jun Miao <[email protected]>

When setting bootparams="trace_event=initcall:initcall_start tp_printk=1" in the cmdline, the output_printk() was called, and the spin_lock_irqsave() was called in the atomic and irq disable interrupt context suitation. On the PREEMPT_RT kernel, these locks are replaced with sleepable rt-spinlock, so the stack calltrace will be triggered.
Fix it by raw_spin_lock_irqsave when PREEMPT_RT and "trace_event=initcall:initcall_start tp_printk=1" enabled.

 BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:46
 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 1, name: swapper/0
 preempt_count: 2, expected: 0
 RCU nest depth: 0, expected: 0
 Preemption disabled at:
 [<ffffffff8992303e>] try_to_wake_up+0x7e/0xba0
 CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.17.1-rt17+ #19 34c5812404187a875f32bee7977f7367f9679ea7
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
 Call Trace:
  <TASK>
  dump_stack_lvl+0x60/0x8c
  dump_stack+0x10/0x12
  __might_resched.cold+0x11d/0x155
  rt_spin_lock+0x40/0x70
  trace_event_buffer_commit+0x2fa/0x4c0
  ? map_vsyscall+0x93/0x93
  trace_event_raw_event_initcall_start+0xbe/0x110
  ? perf_trace_initcall_finish+0x210/0x210
  ? probe_sched_wakeup+0x34/0x40
  ? ttwu_do_wakeup+0xda/0x310
  ? trace_hardirqs_on+0x35/0x170
  ? map_vsyscall+0x93/0x93
  do_one_initcall+0x217/0x3c0
  ? trace_event_raw_event_initcall_level+0x170/0x170
  ? push_cpu_stop+0x400/0x400
  ? cblist_init_generic+0x241/0x290
  kernel_init_freeable+0x1ac/0x347
  ? _raw_spin_unlock_irq+0x65/0x80
  ? rest_init+0xf0/0xf0
  kernel_init+0x1e/0x150
  ret_from_fork+0x22/0x30
  </TASK>
---
 kernel/trace/trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace.c +3 -3
index aceeeea21c11..27bb486c3f97 100644
@@ -2835,7 +2835,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
 }
 EXPORT_SYMBOL_GPL(trace_event_buffer_lock_reserve);
 
-static DEFINE_SPINLOCK(tracepoint_iter_lock);
+static DEFINE_RAW_SPINLOCK(tracepoint_iter_lock);
 static DEFINE_MUTEX(tracepoint_printk_mutex);
 
 static void output_printk(struct trace_event_buffer *fbuffer)
@@ -2863,14 +2863,14 @@ static void output_printk(struct trace_event_buffer *fbuffer)
 
 	event = &fbuffer->trace_file->event_call->event;
 
-	spin_lock_irqsave(&tracepoint_iter_lock, flags);
+	raw_spin_lock_irqsave(&tracepoint_iter_lock, flags);
 	trace_seq_init(&iter->seq);
 	iter->ent = fbuffer->entry;
 	event_call->event.funcs->trace(iter, 0, event);
 	trace_seq_putc(&iter->seq, 0);
 	printk("%s", iter->seq.buffer);
 
-	spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
+	raw_spin_unlock_irqrestore(&tracepoint_iter_lock, flags);
 }
 
 int tracepoint_printk_sysctl(struct ctl_table *table, int write,
Signature · 1 line
2.35.1
author maintainer
#18 lore raw

PATCH 18/21 tracing: Use WARN instead of printk and WARN_ON

In reply to Steven Rostedt

From: Guo Zhengkui <[email protected]>

Use WARN(cond, ...) instead of if (cond) + printk(...) + WARN_ON(1).

---
 kernel/trace/trace_output.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
kernel/trace/trace_output.c +3 -9
index 8aa493d25c73..d89e3f7e26eb 100644
@@ -778,9 +778,8 @@ int register_trace_event(struct trace_event *event)
 
 		list_add_tail(&event->list, list);
 
-	} else if (event->type > __TRACE_LAST_TYPE) {
-		printk(KERN_WARNING "Need to add type to trace.h\n");
-		WARN_ON(1);
+	} else if (WARN(event->type > __TRACE_LAST_TYPE,
+			"Need to add type to trace.h")) {
 		goto out;
 	} else {
 		/* Is this event already used */
@@ -1571,13 +1570,8 @@ __init static int init_events(void)
 
 	for (i = 0; events[i]; i++) {
 		event = events[i];
-
 		ret = register_trace_event(event);
-		if (!ret) {
-			printk(KERN_WARNING "event %d failed to register\n",
-			       event->type);
-			WARN_ON_ONCE(1);
-		}
+		WARN_ONCE(!ret, "event %d failed to register", event->type);
 	}
 
 	return 0;
Signature · 1 line
2.35.1
author maintainer
#19 lore raw

PATCH 19/21 ring-buffer: Simplify if-if to if-else

In reply to Steven Rostedt

From: Wan Jiabing <[email protected]>

Use if and else instead of if(A) and if (!A).

---
 kernel/trace/ring_buffer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/ring_buffer.c +2 -2
index 05dfc7a12d3d..655d6db3e3c3 100644
@@ -6011,10 +6011,10 @@ static __init int test_ringbuffer(void)
 		pr_info("        total events:   %ld\n", total_lost + total_read);
 		pr_info("  recorded len bytes:   %ld\n", total_len);
 		pr_info(" recorded size bytes:   %ld\n", total_size);
-		if (total_lost)
+		if (total_lost) {
 			pr_info(" With dropped events, record len and size may not match\n"
 				" alloced and written from above\n");
-		if (!total_lost) {
+		} else {
 			if (RB_WARN_ON(buffer, total_len != total_alloc ||
 				       total_size != total_written))
 				break;
Signature · 1 line
2.35.1
author maintainer
#20 lore raw

PATCH 20/21 tracing: Avoid adding tracer option before update_tracer_options

In reply to Steven Rostedt

From: Mark-PK Tsai <[email protected]>

To prepare for support asynchronous tracer_init_tracefs initcall, avoid calling create_trace_option_files before __update_tracer_options. Otherwise, create_trace_option_files will show warning because some tracers in trace_types list are already in tr->topts.

For example, hwlat_tracer call register_tracer in late_initcall, and global_trace.dir is already created in tracing_init_dentry, hwlat_tracer will be put into tr->topts.
Then if the __update_tracer_options is executed after hwlat_tracer registered, create_trace_option_files find that hwlat_tracer is already in tr->topts.

---
 kernel/trace/trace.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/trace/trace.c +7 -0
index 27bb486c3f97..7275173c55d0 100644
@@ -6332,12 +6332,18 @@ static void tracing_set_nop(struct trace_array *tr)
 	tr->current_trace = &nop_trace;
 }
 
+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)
 		return;
 
+	/* Only create trace option files after update_tracer_options finish */
+	if (!tracer_options_updated)
+		return;
+
 	create_trace_option_files(tr, t);
 }
 
@@ -9176,6 +9182,7 @@ static void __update_tracer_options(struct trace_array *tr)
 static void update_tracer_options(struct trace_array *tr)
 {
 	mutex_lock(&trace_types_lock);
+	tracer_options_updated = true;
 	__update_tracer_options(tr);
 	mutex_unlock(&trace_types_lock);
 }
Signature · 1 line
2.35.1
author maintainer
#21 lore raw

PATCH 21/21 tracing: make tracer_init_tracefs initcall asynchronous

In reply to Steven Rostedt

From: Mark-PK Tsai <[email protected]>

Move trace_eval_init() to subsys_initcall to make it start earlier.
And to avoid tracer_init_tracefs being blocked by trace_event_sem which trace_eval_init() hold [1], queue tracer_init_tracefs() to eval_map_wq to let the two works being executed sequentially.

It can speed up the initialization of kernel as result of making tracer_init_tracefs asynchronous.

On my arm64 platform, it reduce ~20ms of 125ms which total time do_initcalls spend.

[1]: https://lore.kernel.org/r/[email protected]

---
 kernel/trace/trace.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
kernel/trace/trace.c +22 -10
index 7275173c55d0..400d3e9fe9ff 100644
@@ -9615,6 +9615,7 @@ extern struct trace_eval_map *__stop_ftrace_eval_maps[];
 
 static struct workqueue_struct *eval_map_wq __initdata;
 static struct work_struct eval_map_work __initdata;
+static struct work_struct tracerfs_init_work __initdata;
 
 static void __init eval_map_work_func(struct work_struct *work)
 {
@@ -9640,6 +9641,8 @@ static int __init trace_eval_init(void)
 	return 0;
 }
 
+subsys_initcall(trace_eval_init);
+
 static int __init trace_eval_sync(void)
 {
 	/* Make sure the eval map updates are finished */
@@ -9722,15 +9725,8 @@ static struct notifier_block trace_module_nb = {
 };
 #endif /* CONFIG_MODULES */
 
-static __init int tracer_init_tracefs(void)
+static __init void tracer_init_tracefs_work_func(struct work_struct *work)
 {
-	int ret;
-
-	trace_access_lock_init();
-
-	ret = tracing_init_dentry();
-	if (ret)
-		return 0;
 
 	event_trace_init();
 
@@ -9752,8 +9748,6 @@ static __init int tracer_init_tracefs(void)
 	trace_create_file("saved_tgids", TRACE_MODE_READ, NULL,
 			NULL, &tracing_saved_tgids_fops);
 
-	trace_eval_init();
-
 	trace_create_eval_file(NULL);
 
 #ifdef CONFIG_MODULES
@@ -9768,6 +9762,24 @@ static __init int tracer_init_tracefs(void)
 	create_trace_instances(NULL);
 
 	update_tracer_options(&global_trace);
+}
+
+static __init int tracer_init_tracefs(void)
+{
+	int ret;
+
+	trace_access_lock_init();
+
+	ret = tracing_init_dentry();
+	if (ret)
+		return 0;
+
+	if (eval_map_wq) {
+		INIT_WORK(&tracerfs_init_work, tracer_init_tracefs_work_func);
+		queue_work(eval_map_wq, &tracerfs_init_work);
+	} else {
+		tracer_init_tracefs_work_func(NULL);
+	}
 
 	return 0;
 }
Signature · 1 line
2.35.1