Skip to contentSkip to conversation

tracing: Fixes for 6.1

PATCH New Steven Rostedt 1 participant 6 messages Nov 24, 2022

Subsystems (3)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

cover tracing: Fixes for 6.1

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/urgent

Head SHA1: 4313e5a613049dfc1819a6dfb5f94cf2caff9452

Colin Ian King (1):
tracing/hist: add in missing * in comment blocks

Daniel Bristot de Oliveira (1):
tracing/osnoise: Fix duration type

Steven Rostedt (Google) (3):
tracing: Fix race where histograms can be called before the event
tracing: Add tracing_reset_all_online_cpus_unlocked() function
tracing: Free buffers when a used dynamic event is removed

Xiu Jianfeng (1):
tracing/user_events: Fix memory leak in user_event_create()

----

 kernel/trace/trace.c              | 11 ++++++++++-
 kernel/trace/trace.h              |  1 +
 kernel/trace/trace_dynevent.c     |  2 ++
 kernel/trace/trace_events.c       | 13 +++++++++++--
 kernel/trace/trace_events_hist.c  |  7 +++++--
 kernel/trace/trace_events_synth.c |  2 --
 kernel/trace/trace_events_user.c  |  4 +++-
 kernel/trace/trace_osnoise.c      |  6 +++---
 8 files changed, 35 insertions(+), 11 deletions(-)
author maintainer
#1 lore raw

PATCH 1/6 tracing/hist: add in missing * in comment blocks

From: Colin Ian King <[email protected]>

There are a couple of missing * in comment blocks. Fix these. Cleans up two clang warnings:

kernel/trace/trace_events_hist.c:986: warning: bad line:
kernel/trace/trace_events_hist.c:3229: warning: bad line:

---
 kernel/trace/trace_events_hist.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace_events_hist.c +2 -2
index 48465f7e97b4..087c19548049 100644
@@ -983,7 +983,7 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
  * A trigger can define one or more variables.  If any one of them is
  * currently referenced by any other trigger, this function will
  * determine that.
-
+ *
  * Typically used to determine whether or not a trigger can be removed
  * - if there are any references to a trigger's variables, it cannot.
  *
@@ -3226,7 +3226,7 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
  * events.  However, for convenience, users are allowed to directly
  * specify an event field in an action, which will be automatically
  * converted into a variable on their behalf.
-
+ *
  * This function creates a field variable with the name var_name on
  * the hist trigger currently being defined on the target event.  If
  * subsys_name and event_name are specified, this function simply
Signature · 1 line
2.35.1
author maintainer
#2 lore raw

PATCH 2/6 tracing/user_events: Fix memory leak in user_event_create()

In reply to Steven Rostedt

From: Xiu Jianfeng <[email protected]>

Before current_user_event_group(), it has allocated memory and save it in @name, this should freed before return error.

Fixes e5d271812e7a ("tracing/user_events: Move pages/locks into groups to prepare for namespaces")
---
 kernel/trace/trace_events_user.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_events_user.c +3 -1
index ae78c2d53c8a..539b08ae7020 100644
@@ -1100,8 +1100,10 @@ static int user_event_create(const char *raw_command)
 
 	group = current_user_event_group();
 
-	if (!group)
+	if (!group) {
+		kfree(name);
 		return -ENOENT;
+	}
 
 	mutex_lock(&group->reg_mutex);
 
Signature · 1 line
2.35.1
author maintainer
#3 lore raw

PATCH 3/6 tracing/osnoise: Fix duration type

In reply to Steven Rostedt

From: Daniel Bristot de Oliveira <[email protected]>

The duration type is a 64 long value, not an int. This was causing some long noise to report wrong values.

Change the duration to a 64 bits value.

Cc Daniel Bristot de Oliveira <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Jonathan Corbet <[email protected]>
Fixes bce29ac9ce0b ("trace: Add osnoise tracer")
---
 kernel/trace/trace_osnoise.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_osnoise.c +3 -3
index 78d536d3ff3d..4300c5dc4e5d 100644
@@ -917,7 +917,7 @@ void osnoise_trace_irq_entry(int id)
 void osnoise_trace_irq_exit(int id, const char *desc)
 {
 	struct osnoise_variables *osn_var = this_cpu_osn_var();
-	int duration;
+	s64 duration;
 
 	if (!osn_var->sampling)
 		return;
@@ -1048,7 +1048,7 @@ static void trace_softirq_entry_callback(void *data, unsigned int vec_nr)
 static void trace_softirq_exit_callback(void *data, unsigned int vec_nr)
 {
 	struct osnoise_variables *osn_var = this_cpu_osn_var();
-	int duration;
+	s64 duration;
 
 	if (!osn_var->sampling)
 		return;
@@ -1144,7 +1144,7 @@ thread_entry(struct osnoise_variables *osn_var, struct task_struct *t)
 static void
 thread_exit(struct osnoise_variables *osn_var, struct task_struct *t)
 {
-	int duration;
+	s64 duration;
 
 	if (!osn_var->sampling)
 		return;
Signature · 1 line
2.35.1
author maintainer
#4 lore raw

PATCH 4/6 tracing: Fix race where histograms can be called before the event

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

commit 94eedf3dded5 ("tracing: Fix race where eprobes can be called before the event") fixed an issue where if an event is soft disabled, and the trigger is being added, there's a small window where the event sees that there's a trigger but does not see that it requires reading the event yet, and then calls the trigger with the record == NULL.

This could be solved with adding memory barriers in the hot path, or to make sure that all the triggers requiring a record check for NULL. The latter was chosen.

Commit 94eedf3dded5 set the eprobe trigger handle to check for NULL, but the same needs to be done with histograms.

Cc Tom Zanussi <[email protected]>
Fixes 7491e2c442781 ("tracing: Add a probe that attaches to trace events")
---
 kernel/trace/trace_events_hist.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_events_hist.c +3 -0
index 087c19548049..1c82478e8dff 100644
@@ -5143,6 +5143,9 @@ static void event_hist_trigger(struct event_trigger_data *data,
 	void *key = NULL;
 	unsigned int i;
 
+	if (unlikely(!rbe))
+		return;
+
 	memset(compound_key, 0, hist_data->key_size);
 
 	for_each_hist_key_field(i, hist_data) {
Signature · 1 line
2.35.1
author maintainer
#5 lore raw

PATCH 5/6 tracing: Add tracing_reset_all_online_cpus_unlocked() function

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

Currently the tracing_reset_all_online_cpus() requires the trace_types_lock held. But only one caller of this function actually has that lock held before calling it, and the other just takes the lock so that it can call it. More users of this function is needed where the lock is not held.

Add a tracing_reset_all_online_cpus_unlocked() function for the one use case that calls it without being held, and also add a lockdep_assert to make sure it is held when called.

Then have tracing_reset_all_online_cpus() take the lock internally, such that callers do not need to worry about taking it.

Cc Masami Hiramatsu <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Zheng Yejian <[email protected]>
---
 kernel/trace/trace.c              | 11 ++++++++++-
 kernel/trace/trace.h              |  1 +
 kernel/trace/trace_events.c       |  2 +-
 kernel/trace/trace_events_synth.c |  2 --
 4 files changed, 12 insertions(+), 4 deletions(-)
kernel/trace/trace.c +10 -1
index a7fe0e115272..5cfc95a52bc3 100644
@@ -2180,10 +2180,12 @@ void tracing_reset_online_cpus(struct array_buffer *buf)
 }
 
 /* Must have trace_types_lock held */
-void tracing_reset_all_online_cpus(void)
+void tracing_reset_all_online_cpus_unlocked(void)
 {
 	struct trace_array *tr;
 
+	lockdep_assert_held(&trace_types_lock);
+
 	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
 		if (!tr->clear_trace)
 			continue;
@@ -2195,6 +2197,13 @@ void tracing_reset_all_online_cpus(void)
 	}
 }
 
+void tracing_reset_all_online_cpus(void)
+{
+	mutex_lock(&trace_types_lock);
+	tracing_reset_all_online_cpus_unlocked();
+	mutex_unlock(&trace_types_lock);
+}
+
 /*
  * The tgid_map array maps from pid to tgid; i.e. the value stored at index i
  * is the tgid last observed corresponding to pid=i.
kernel/trace/trace.h +1 -0
index 54ee5711c729..d42e24507152 100644
@@ -580,6 +580,7 @@ int tracing_is_enabled(void);
 void tracing_reset_online_cpus(struct array_buffer *buf);
 void tracing_reset_current(int cpu);
 void tracing_reset_all_online_cpus(void);
+void tracing_reset_all_online_cpus_unlocked(void);
 int tracing_open_generic(struct inode *inode, struct file *filp);
 int tracing_open_generic_tr(struct inode *inode, struct file *filp);
 bool tracing_is_disabled(void);
kernel/trace/trace_events.c +1 -1
index 0356cae0cf74..78cd19e31dba 100644
@@ -2972,7 +2972,7 @@ static void trace_module_remove_events(struct module *mod)
 	 * over from this module may be passed to the new module events and
 	 * unexpected results may occur.
 	 */
-	tracing_reset_all_online_cpus();
+	tracing_reset_all_online_cpus_unlocked();
 }
 
 static int trace_module_notify(struct notifier_block *self,
kernel/trace/trace_events_synth.c +0 -2
index 29fbfb27c2b2..c3b582d19b62 100644
@@ -1425,7 +1425,6 @@ int synth_event_delete(const char *event_name)
 	mutex_unlock(&event_mutex);
 
 	if (mod) {
-		mutex_lock(&trace_types_lock);
 		/*
 		 * It is safest to reset the ring buffer if the module
 		 * being unloaded registered any events that were
@@ -1437,7 +1436,6 @@ int synth_event_delete(const char *event_name)
 		 * occur.
 		 */
 		tracing_reset_all_online_cpus();
-		mutex_unlock(&trace_types_lock);
 	}
 
 	return ret;
Signature · 1 line
2.35.1