Skip to contentSkip to conversation

tracing: Fix the unusable problem caused by non-empty pipe_cpumask

PATCH In review Chuang Wang 3 participants 3 messages Sep 1, 2023 – Sep 2, 2023

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

PATCH 1/1 tracing: Fix the unusable problem caused by non-empty pipe_cpumask

There is a problem in the linux-6.5 when I execute the following command:

 $ perf ftrace -t irqsoff
 failed to open trace_pipe

At the same time, when I open this file, the same error occurs.

Therefore, after carefully looking at the code, the open function of 'trace_pipe' returns -EBUSY in open_pipe_on_cpu() because no clearing operation was performed when 'trace_array->pipe_cpumask' was allocated.

With this patch, Use zalloc_cpumask_var() to ensure that 'trace_array->pipe_cpumask' is reset to 0 when allocated.

Fixes c2489bb7e6be ("tracing: Introduce pipe_cpumask to avoid race on trace_pipes")
---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index d8233d34b5a0..c0b8a72f3466 100644
@@ -9461,7 +9461,7 @@ static struct trace_array *trace_array_create(const char *name)
 	if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
-	if (!alloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
 	tr->trace_flags = global_trace.trace_flags & ~ZEROED_TRACE_FLAGS;
@@ -10406,7 +10406,7 @@ __init static int tracer_alloc_buffers(void)
 	if (trace_create_savedcmd() < 0)
 		goto out_free_temp_buffer;
 
-	if (!alloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
 		goto out_free_savedcmd;
 
 	/* TODO: make the number of buffers hot pluggable with CPUS */
Signature · 1 line
2.39.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · On Fri, 1 Sep 2023 15:26:26 +0800 Chuang Wang <[email protected]> wrote:

There is a problem in the linux-6.5 when I execute the following command:

 $ perf ftrace -t irqsoff
 failed to open trace_pipe
Quoted 8 lines

At the same time, when I open this file, the same error occurs.

Therefore, after carefully looking at the code, the open function of 'trace_pipe' returns -EBUSY in open_pipe_on_cpu() because no clearing operation was performed when 'trace_array->pipe_cpumask' was allocated.

With this patch, Use zalloc_cpumask_var() to ensure that 'trace_array->pipe_cpumask' is reset to 0 when allocated.

Good catch. This looks good to me.

Quoted 33 lines
Fixes c2489bb7e6be ("tracing: Introduce pipe_cpumask to avoid race on trace_pipes")
---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index d8233d34b5a0..c0b8a72f3466 100644
@@ -9461,7 +9461,7 @@ static struct trace_array *trace_array_create(const char *name)
 	if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
-	if (!alloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
 	tr->trace_flags = global_trace.trace_flags & ~ZEROED_TRACE_FLAGS;
@@ -10406,7 +10406,7 @@ __init static int tracer_alloc_buffers(void)
 	if (trace_create_savedcmd() < 0)
 		goto out_free_temp_buffer;
 
-	if (!alloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
 		goto out_free_savedcmd;
 
 	/* TODO: make the number of buffers hot pluggable with CPUS */
Signature · 1 line
2.39.2
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
maintainer
#2 lore raw
Quoted 9 lines · On Fri, 1 Sep 2023 23:02:06 +0900 Masami Hiramatsu (Google)…
Quoted 6 lines · On Fri, 1 Sep 2023 15:26:26 +0800 Chuang Wang <[email protected]> wrote:

There is a problem in the linux-6.5 when I execute the following command:

 $ perf ftrace -t irqsoff
 failed to open trace_pipe
Quoted 8 lines
Quoted 8 lines

At the same time, when I open this file, the same error occurs.

Therefore, after carefully looking at the code, the open function of 'trace_pipe' returns -EBUSY in open_pipe_on_cpu() because no clearing operation was performed when 'trace_array->pipe_cpumask' was allocated.

With this patch, Use zalloc_cpumask_var() to ensure that 'trace_array->pipe_cpumask' is reset to 0 when allocated.

Brian Foster beat you to it.

https://lore.kernel.org/linux-trace-kernel/[email protected]

Quoted 5 lines

Good catch. This looks good to me.

Masami, I'll add your Reviewed-by to that commit.

Thanks!

-- Steve

Quoted 35 lines
Quoted 33 lines
Fixes c2489bb7e6be ("tracing: Introduce pipe_cpumask to avoid race on trace_pipes")
---
 kernel/trace/trace.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
index d8233d34b5a0..c0b8a72f3466 100644
@@ -9461,7 +9461,7 @@ static struct trace_array *trace_array_create(const char *name)
 	if (!alloc_cpumask_var(&tr->tracing_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
-	if (!alloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&tr->pipe_cpumask, GFP_KERNEL))
 		goto out_free_tr;
 
 	tr->trace_flags = global_trace.trace_flags & ~ZEROED_TRACE_FLAGS;
@@ -10406,7 +10406,7 @@ __init static int tracer_alloc_buffers(void)
 	if (trace_create_savedcmd() < 0)
 		goto out_free_temp_buffer;
 
-	if (!alloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
+	if (!zalloc_cpumask_var(&global_trace.pipe_cpumask, GFP_KERNEL))
 		goto out_free_savedcmd;
 
 	/* TODO: make the number of buffers hot pluggable with CPUS */
Signature · 1 line
2.39.2