Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] trace/hwlat: Add WARN_ON in move_to_next_cpu()
@ 2025-08-11  8:01 Fushuai Wang
  2025-08-14 19:06 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Fushuai Wang @ 2025-08-11  8:01 UTC (permalink / raw)
  To: linux-trace-kernel, linux-kernel
  Cc: rostedt, mhiramat, mathieu.desnoyers, Fushuai Wang

Add a WARN_ON check in move_to_next_cpu(). Next_cpu should
never be greater than or equal to nr_cpu_ids.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 kernel/trace/trace_hwlat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
index 2f7b94e98317..5024b0dcdbba 100644
--- a/kernel/trace/trace_hwlat.c
+++ b/kernel/trace/trace_hwlat.c
@@ -328,7 +328,7 @@ static void move_to_next_cpu(void)
 	next_cpu = cpumask_next_wrap(raw_smp_processor_id(), current_mask);
 	cpus_read_unlock();
 
-	if (next_cpu >= nr_cpu_ids) /* Shouldn't happen! */
+	if (WARN_ON(next_cpu >= nr_cpu_ids)) /* Shouldn't happen! */
 		goto change_mode;
 
 	cpumask_clear(current_mask);
-- 
2.36.1


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

* Re: [PATCH] trace/hwlat: Add WARN_ON in move_to_next_cpu()
  2025-08-11  8:01 [PATCH] trace/hwlat: Add WARN_ON in move_to_next_cpu() Fushuai Wang
@ 2025-08-14 19:06 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2025-08-14 19:06 UTC (permalink / raw)
  To: Fushuai Wang
  Cc: linux-trace-kernel, linux-kernel, mhiramat, mathieu.desnoyers

On Mon, 11 Aug 2025 16:01:09 +0800
Fushuai Wang <wangfushuai@baidu.com> wrote:

> Add a WARN_ON check in move_to_next_cpu(). Next_cpu should
> never be greater than or equal to nr_cpu_ids.
> 
> Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
> ---
>  kernel/trace/trace_hwlat.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c
> index 2f7b94e98317..5024b0dcdbba 100644
> --- a/kernel/trace/trace_hwlat.c
> +++ b/kernel/trace/trace_hwlat.c
> @@ -328,7 +328,7 @@ static void move_to_next_cpu(void)
>  	next_cpu = cpumask_next_wrap(raw_smp_processor_id(), current_mask);
>  	cpus_read_unlock();
>  
> -	if (next_cpu >= nr_cpu_ids) /* Shouldn't happen! */
> +	if (WARN_ON(next_cpu >= nr_cpu_ids)) /* Shouldn't happen! */
>  		goto change_mode;

Yeah, it shouldn't happen but it doesn't mean we need to add a WARN_ON().
It might even happen if user space is messing with the tracing_cpumask at
the same time. It shouldn't happen but it doesn't mean it will not happen.

We do not add WARN_ON() for things that could be trigger by user space.

-- Steve


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

end of thread, other threads:[~2025-08-14 19:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11  8:01 [PATCH] trace/hwlat: Add WARN_ON in move_to_next_cpu() Fushuai Wang
2025-08-14 19:06 ` Steven Rostedt

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