Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH] tracing: Fix soft lockup when lseeking trace file
@ 2026-02-09  9:31 Tengda Wu
  2026-02-09 16:10 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Tengda Wu @ 2026-02-09  9:31 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu
  Cc: Mathieu Desnoyers, Ingo Molnar, Thomas Gleixner,
	Arnaldo Carvalho de Melo, linux-trace-kernel, linux-kernel,
	Tengda Wu

A soft lockup may occur when accessing trace file via lseek while
tracing is active and a large offset is provided. The call trace
is shown below:

watchdog: BUG: soft lockup - CPU#3 stuck for 26s! [poc:141]
CPU: 3 UID: 0 PID: 141 Comm: poc Not tainted 6.19.0 #1 PREEMPT(none)
Call Trace:
  ring_buffer_iter_peek
  peek_next_entry
  __find_next_entry
  trace_find_next_entry_inc
  s_next
  traverse.part.0
  seq_lseek
  tracing_lseek
  __x64_sys_lseek
  do_syscall_64
  entry_SYSCALL_64_after_hwframe

The root cause is that the lseek implementation for trace files
is based on seq_lseek, which contains a loop that repeatedly calls
show() and next() functions until the position reaches the target
offset. Since no scheduling point is set within this loop, a large
offset can cause the CPU to be stuck in the loop for an extended
period, triggering the soft lockup detector.

Fixed by adding cond_resched() in s_next().

Fixes: bc0c38d139ec ("ftrace: latency tracer infrastructure")
Signed-off-by: Tengda Wu <wutengda@huaweicloud.com>
---
 kernel/trace/trace.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8bd4ec08fb36..3afe148ef683 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3928,6 +3928,8 @@ static void *s_next(struct seq_file *m, void *v, loff_t *pos)
 
 	iter->pos = *pos;
 
+	cond_resched();
+
 	return ent;
 }
 
-- 
2.34.1


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

end of thread, other threads:[~2026-02-09 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09  9:31 [PATCH] tracing: Fix soft lockup when lseeking trace file Tengda Wu
2026-02-09 16:10 ` Steven Rostedt

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