mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [for-next][PATCH 0/4] ring-buffer: Updates for 6.15
@ 2025-03-23  5:09 Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 1/4] tracing: Fix a compilation error without CONFIG_MODULES Steven Rostedt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-23  5:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton

  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
ring-buffer/for-next

Head SHA1: 0e5d1a4b22bca3d9a9a2d2ba79ed67c5e74607d7


Jiapeng Chong (1):
      ring-buffer: Remove the unused variable bmeta

Masami Hiramatsu (Google) (2):
      tracing: Fix a compilation error without CONFIG_MODULES
      tracing: Skip update_last_data() if cleared and remove active check for save_mod()

Steven Rostedt (1):
      tracing: Initialize scratch_size to zero to prevent UB

----
 kernel/trace/ring_buffer.c |  3 ---
 kernel/trace/trace.c       | 35 ++++++++++++++++-------------------
 2 files changed, 16 insertions(+), 22 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [for-next][PATCH 1/4] tracing: Fix a compilation error without CONFIG_MODULES
  2025-03-23  5:09 [for-next][PATCH 0/4] ring-buffer: Updates for 6.15 Steven Rostedt
@ 2025-03-23  5:09 ` Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 2/4] tracing: Initialize scratch_size to zero to prevent UB Steven Rostedt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-23  5:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton

From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>

There are some code which depends on CONFIG_MODULES. #ifdef
to enclose it.

Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/174230515367.2909896.8132122175220657625.stgit@mhiramat.tok.corp.google.com
Fixes: dca91c1c5468 ("tracing: Have persistent trace instances save module addresses")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index c3c79908766e..68abea81e51a 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6001,6 +6001,7 @@ struct trace_scratch {
 
 static DEFINE_MUTEX(scratch_mutex);
 
+#ifdef CONFIG_MODULES
 static int save_mod(struct module *mod, void *data)
 {
 	struct trace_array *tr = data;
@@ -6025,6 +6026,12 @@ static int save_mod(struct module *mod, void *data)
 
 	return 0;
 }
+#else
+static int save_mod(struct module *mod, void *data)
+{
+	return 0;
+}
+#endif
 
 static void update_last_data(struct trace_array *tr)
 {
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [for-next][PATCH 2/4] tracing: Initialize scratch_size to zero to prevent UB
  2025-03-23  5:09 [for-next][PATCH 0/4] ring-buffer: Updates for 6.15 Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 1/4] tracing: Fix a compilation error without CONFIG_MODULES Steven Rostedt
@ 2025-03-23  5:09 ` Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 3/4] tracing: Skip update_last_data() if cleared and remove active check for save_mod() Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 4/4] ring-buffer: Remove the unused variable bmeta Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-23  5:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Dan Carpenter

From: Steven Rostedt <rostedt@goodmis.org>

In allocate_trace_buffer() the following code:

  buf->buffer = ring_buffer_alloc_range(size, rb_flags, 0,
				      tr->range_addr_start,
				      tr->range_addr_size,
				      struct_size(tscratch, entries, 128));

  tscratch = ring_buffer_meta_scratch(buf->buffer, &scratch_size);
  setup_trace_scratch(tr, tscratch, scratch_size);

Has undefined behavior if ring_buffer_alloc_range() fails because
"scratch_size" is not initialize. If the allocation fails, then
buf->buffer will be NULL. The ring_buffer_meta_scratch() will return
NULL immediately if it is passed a NULL buffer and it will not update
scratch_size. Then setup_trace_scratch() will return immediately if
tscratch is NULL.

Although there's no real issue here, but it is considered undefined
behavior to pass an uninitialized variable to a function as input, and
UBSan may complain about it.

Just initialize scratch_size to zero to make the code defined behavior and
a little more robust.

Link: https://lore.kernel.org/all/44c5deaa-b094-4852-90f9-52f3fb10e67a@stanley.mountain/

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 68abea81e51a..be97465485b3 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -9394,7 +9394,7 @@ allocate_trace_buffer(struct trace_array *tr, struct array_buffer *buf, int size
 {
 	enum ring_buffer_flags rb_flags;
 	struct trace_scratch *tscratch;
-	unsigned int scratch_size;
+	unsigned int scratch_size = 0;
 
 	rb_flags = tr->trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
 
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [for-next][PATCH 3/4] tracing: Skip update_last_data() if cleared and remove active check for save_mod()
  2025-03-23  5:09 [for-next][PATCH 0/4] ring-buffer: Updates for 6.15 Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 1/4] tracing: Fix a compilation error without CONFIG_MODULES Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 2/4] tracing: Initialize scratch_size to zero to prevent UB Steven Rostedt
@ 2025-03-23  5:09 ` Steven Rostedt
  2025-03-23  5:09 ` [for-next][PATCH 4/4] ring-buffer: Remove the unused variable bmeta Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-23  5:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton

From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>

If the last boot data is already cleared, there is no reason to update it
again. Skip if the TRACE_ARRAY_FL_LAST_BOOT is cleared.
Also, for calling save_mod() when module loading, we don't need to check
the trace is active or not because any module address can be on the
stacktrace.

Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://lore.kernel.org/174165660328.1173316.15529357882704817499.stgit@devnote2
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/trace.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index be97465485b3..0be048fecc89 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6040,6 +6040,12 @@ static void update_last_data(struct trace_array *tr)
 	if (!(tr->flags & TRACE_ARRAY_FL_BOOT))
 		return;
 
+	if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
+		return;
+
+	/* Only if the buffer has previous boot data clear and update it. */
+	tr->flags &= ~TRACE_ARRAY_FL_LAST_BOOT;
+
 	/* Reset the module list and reload them */
 	if (tr->scratch) {
 		struct trace_scratch *tscratch = tr->scratch;
@@ -6052,9 +6058,6 @@ static void update_last_data(struct trace_array *tr)
 		module_for_each_mod(save_mod, tr);
 	}
 
-	if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT))
-		return;
-
 	/*
 	 * Need to clear all CPU buffers as there cannot be events
 	 * from the previous boot mixed with events with this boot
@@ -6077,7 +6080,6 @@ static void update_last_data(struct trace_array *tr)
 #else
 	tscratch->kaslr_addr = 0;
 #endif
-	tr->flags &= ~TRACE_ARRAY_FL_LAST_BOOT;
 }
 
 /**
@@ -10099,15 +10101,6 @@ static void trace_module_remove_evals(struct module *mod)
 static inline void trace_module_remove_evals(struct module *mod) { }
 #endif /* CONFIG_TRACE_EVAL_MAP_FILE */
 
-static bool trace_array_active(struct trace_array *tr)
-{
-	if (tr->current_trace != &nop_trace)
-		return true;
-
-	/* 0 is no events, 1 is all disabled */
-	return trace_events_enabled(tr, NULL) > 1;
-}
-
 static void trace_module_record(struct module *mod)
 {
 	struct trace_array *tr;
@@ -10116,11 +10109,8 @@ static void trace_module_record(struct module *mod)
 		/* Update any persistent trace array that has already been started */
 		if ((tr->flags & (TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT)) ==
 		    TRACE_ARRAY_FL_BOOT) {
-			/* Only update if the trace array is active */
-			if (trace_array_active(tr)) {
-				guard(mutex)(&scratch_mutex);
-				save_mod(mod, tr);
-			}
+			guard(mutex)(&scratch_mutex);
+			save_mod(mod, tr);
 		}
 	}
 }
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [for-next][PATCH 4/4] ring-buffer: Remove the unused variable bmeta
  2025-03-23  5:09 [for-next][PATCH 0/4] ring-buffer: Updates for 6.15 Steven Rostedt
                   ` (2 preceding siblings ...)
  2025-03-23  5:09 ` [for-next][PATCH 3/4] tracing: Skip update_last_data() if cleared and remove active check for save_mod() Steven Rostedt
@ 2025-03-23  5:09 ` Steven Rostedt
  3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2025-03-23  5:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Abaci Robot, Jiapeng Chong

From: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

Variable bmeta is not effectively used, so delete it.

kernel/trace/ring_buffer.c:1952:27: warning: variable ‘bmeta’ set but not used.

Link: https://lore.kernel.org/20250317015524.3902-1-jiapeng.chong@linux.alibaba.com
Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=19524
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 94be81edffd2..302b1404213c 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1949,7 +1949,6 @@ static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
 static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages, int scratch_size)
 {
 	struct ring_buffer_cpu_meta *meta;
-	struct ring_buffer_meta *bmeta;
 	unsigned long *subbuf_mask;
 	unsigned long delta;
 	void *subbuf;
@@ -1964,8 +1963,6 @@ static void rb_range_meta_init(struct trace_buffer *buffer, int nr_pages, int sc
 	if (rb_meta_init(buffer, scratch_size))
 		valid = true;
 
-	bmeta = buffer->meta;
-
 	for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
 		void *next_meta;
 
-- 
2.47.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-23  5:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-23  5:09 [for-next][PATCH 0/4] ring-buffer: Updates for 6.15 Steven Rostedt
2025-03-23  5:09 ` [for-next][PATCH 1/4] tracing: Fix a compilation error without CONFIG_MODULES Steven Rostedt
2025-03-23  5:09 ` [for-next][PATCH 2/4] tracing: Initialize scratch_size to zero to prevent UB Steven Rostedt
2025-03-23  5:09 ` [for-next][PATCH 3/4] tracing: Skip update_last_data() if cleared and remove active check for save_mod() Steven Rostedt
2025-03-23  5:09 ` [for-next][PATCH 4/4] ring-buffer: Remove the unused variable bmeta Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®