Received: from n169-111.mail.139.com (n169-111.mail.139.com [120.232.169.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C571368961 for ; Sat, 28 Feb 2026 06:55:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=120.232.169.111 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772261710; cv=none; b=KjLDc78M5lrF3RKUPFndIYb18p6XH+EAX0IXNZWIv3eUWtf4hbcSoIhO+X1WT+AwKJxWRIaHWpP0cq1A+6ffkhH0H8G1H8tTQ0fAjElNI1bH3gtnBKuuo8Aa4DqsK4wkUNeyGUNq87CJ81BfFIAE6uQg1S7o96gqEk2YeRzFBNA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772261710; c=relaxed/simple; bh=j/er/PgEopEct1Wb/x35Mf0Ak3xW0Vh8r2w6YYUSBBQ=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=eN4Mla3zuwuuTzR+uGLBJVe18EMj6f8ewpm2Go4hnrVuRRMon0IZ6GSSfwWarot9DxBKozY2i1tND/0gr6eC4OArXTT/mvIyynySSrgeO7lvSA4Sg3WX4/h6x9GJcf2etXLM3Xs/SCue8GrSrWJeTEc4HEhdiDCNj8Zq2DgDy2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com; spf=pass smtp.mailfrom=139.com; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b=otBlYWt3; arc=none smtp.client-ip=120.232.169.111 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=139.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=139.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=139.com header.i=@139.com header.b="otBlYWt3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=139.com; s=dkim; l=0; h=from:subject:message-id:to:mime-version; bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=; b=otBlYWt378cEeHiuKIADXkzywF6cgpFtx6p3AhEZXrmpTg5P/5HtYwAfT6nE7nJh9fKY6jD62qxz7 2zh+Ovn7G+3D3vQZjYm474eomf+28d5v1hUBrjx8IFn/GQpbbEbfMp4BXr5oTeirXUMNj9/ClooYhE 5gUpKnsH0FiuHZ4U= X-RM-TagInfo: emlType=0 X-RM-SPAM: X-RM-SPAM-FLAG:00000000 Received:from China-Mobile-Kernel-Team (unknown[223.104.3.195]) by rmsmtp-lg-appmail-15-12004 (RichMail) with SMTP id 2ee469a2914365d-5621d; Sat, 28 Feb 2026 14:55:02 +0800 (CST) X-RM-TRANSID:2ee469a2914365d-5621d From: Leon Chen To: mhiramat@kernel.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, joel@joelfernandes.org, paulmck@kernel.org, boqun.feng@gmail.com, stable@vger.kernel.org Subject: [PATCH 6.6.y] tracing: Add recursion protection in kernel stack trace recording Date: Sat, 28 Feb 2026 14:55:00 +0800 Message-Id: <20260228065500.8610-1-leonchen.oss@139.com> X-Mailer: git-send-email 2.35.3 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Steven Rostedt [ Upstream commit 5f1ef0dfcb5b7f4a91a9b0e0ba533efd9f7e2cdb ] A bug was reported about an infinite recursion caused by tracing the rcu events with the kernel stack trace trigger enabled. The stack trace code called back into RCU which then called the stack trace again. Expand the ftrace recursion protection to add a set of bits to protect events from recursion. Each bit represents the context that the event is in (normal, softirq, interrupt and NMI). Have the stack trace code use the interrupt context to protect against recursion. Note, the bug showed an issue in both the RCU code as well as the tracing stacktrace code. This only handles the tracing stack trace side of the bug. The RCU fix will be handled separately. Link: https://lore.kernel.org/all/20260102122807.7025fc87@gandalf.local.home/ Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Joel Fernandes Cc: "Paul E. McKenney" Cc: Boqun Feng Link: https://patch.msgid.link/20260105203141.515cd49f@gandalf.local.home Reported-by: Yao Kai Tested-by: Yao Kai Fixes: 5f5fa7ea89dc ("rcu: Don't use negative nesting depth in __rcu_read_unlock()") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Leon Chen --- include/linux/trace_recursion.h | 9 +++++++++ kernel/trace/trace.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/trace_recursion.h b/include/linux/trace_recursion.h index d48cd92d2364..67e6a9923d56 100644 --- a/include/linux/trace_recursion.h +++ b/include/linux/trace_recursion.h @@ -34,6 +34,13 @@ enum { TRACE_INTERNAL_SIRQ_BIT, TRACE_INTERNAL_TRANSITION_BIT, + /* Internal event use recursion bits */ + TRACE_INTERNAL_EVENT_BIT, + TRACE_INTERNAL_EVENT_NMI_BIT, + TRACE_INTERNAL_EVENT_IRQ_BIT, + TRACE_INTERNAL_EVENT_SIRQ_BIT, + TRACE_INTERNAL_EVENT_TRANSITION_BIT, + TRACE_BRANCH_BIT, /* * Abuse of the trace_recursion. @@ -97,6 +104,8 @@ enum { #define TRACE_LIST_START TRACE_INTERNAL_BIT +#define TRACE_EVENT_START TRACE_INTERNAL_EVENT_BIT + #define TRACE_CONTEXT_MASK ((1 << (TRACE_LIST_START + TRACE_CONTEXT_BITS)) - 1) /* diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index a111be83c369..3e0be2baeed1 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3105,6 +3105,11 @@ static void __ftrace_trace_stack(struct trace_buffer *buffer, struct ftrace_stack *fstack; struct stack_entry *entry; int stackidx; + int bit; + + bit = trace_test_and_set_recursion(_THIS_IP_, _RET_IP_, TRACE_EVENT_START); + if (bit < 0) + return; /* * Add one, for this function and the call to save_stack_trace() @@ -3162,6 +3167,7 @@ static void __ftrace_trace_stack(struct trace_buffer *buffer, __this_cpu_dec(ftrace_stack_reserve); preempt_enable_notrace(); + trace_clear_recursion(bit); } static inline void ftrace_trace_stack(struct trace_array *tr, -- 2.35.3