Skip to contentSkip to conversation

ftrace: Fix softlockup in ftrace_module_enable

PATCH In review Vladimir Riabchun 1 participant 2 messages Sep 12, 2025 – Sep 22, 2025

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

PATCH v2 1/1 ftrace: Fix softlockup in ftrace_module_enable

A soft lockup was observed when loading amdgpu module.
If a module has a lot of tracable functions, multiple calls to kallsyms_lookup can spend too much time in RCU critical section and with disabled preemption, causing kernel panic. This is the same issue that was fixed in
commit d0b24b4e91fc ("ftrace: Prevent RCU stall on PREEMPT_VOLUNTARY kernels") and commit 42ea22e754ba ("ftrace: Add cond_resched() to ftrace_graph_set_hash()").

Fix it the same way by adding cond_resched() in ftrace_module_enable.

---
Changes since v1: https://lore.kernel.org/all/aMLPm__QGrQCwz1t@vova-pc/
- Move cond_resched below within_module check
- Add some details in commit description

kernel/trace/ftrace.c | 2 ++

 1 file changed, 2 insertions(+)
kernel/trace/ftrace.c +2 -0
index a69067367c29..42bd2ba68a82 100644
@@ -7535,6 +7535,8 @@ void ftrace_module_enable(struct module *mod)
 		if (!within_module(rec->ip, mod))
 			break;
 
+		cond_resched();
+
 		/* Weak functions should still be ignored */
 		if (!test_for_valid_rec(rec)) {
 			/* Clear all other flags. Should not be enabled anyway */
Signature · 1 line
2.43.0