[PATCH v2 1/2] stacktrace: Provide arch_in_event_entry_text() hook
From: Yuanhe Shu
Date: Mon Aug 31 2026 - 08:07:44 EST
in_irqentry_text() decides whether a stack address belongs to interrupt
entry code by checking the .irqentry.text and .softirqentry.text section
ranges. filter_irq_stacks() uses it to truncate interrupt stacks at the
entry point, which stack depot depends on to deduplicate them: traces
that continue past the interrupt entry lead to unbounded depot growth,
see commit e94006608949 ("lib/stackdepot: always do filter_irq_stacks()
in stack_depot_save()").
An architecture may deliver interrupts through entry code that cannot be
placed in .irqentry.text. in_irqentry_text() then never recognizes the
entry point and the truncation silently stops happening. The markers are
meant to cover all interrupt entry functions; when they do not, the depot
fills with unfiltered stacks:
https://lore.kernel.org/all/CACT4Y+aReMGLYua2rCLHgFpS9io5cZC04Q8GLs-uNmrn1ezxYQ@xxxxxxxxxxxxxx/
Add an optional arch_in_event_entry_text() hook, consulted in addition to
the section range checks. An architecture overrides it by defining a
macro of the same name in <asm/sections.h>, next to the section markers
it tests; the default here is a static inline returning false, which
folds away entirely on every architecture that does not opt in. This
mirrors the existing arch hook pattern of arch_nmi_enter() in
<linux/hardirq.h>. The fallback sits next to the hook's only user, so
no generic header gains a new dependency.
Rename in_irqentry_text() to in_event_entry_text() at the same time and
name the hook after it: the ranges it tests are not necessarily irq-only
- on x86 they also cover the exception entry stubs - and what
filter_irq_stacks() asks of them is where a trace entered the kernel.
The helper is file local with a single caller, so the rename stays inside
kernel/stacktrace.c; filter_irq_stacks() keeps its name as it is exported
and used treewide.
No functional change on its own.
The first user is the FRED fix in the follow-up patch. Both carry the
same Fixes: tag and are Cc'ed to stable so that they are picked up as a
pair.
Fixes: 14619d912b65 ("x86/fred: FRED entry/exit and dispatch code")
Cc: stable@xxxxxxxxxxxxxxx # v6.9+
Signed-off-by: Yuanhe Shu <xiangzao@xxxxxxxxxxxxxxxxx>
---
kernel/stacktrace.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c
index afb3c116da91..487ab2c858ca 100644
--- a/kernel/stacktrace.c
+++ b/kernel/stacktrace.c
@@ -14,6 +14,7 @@
#include <linux/kallsyms.h>
#include <linux/stacktrace.h>
#include <linux/interrupt.h>
+#include <asm/sections.h>
/**
* stack_trace_print - Print the entries in the stack trace
@@ -374,12 +375,27 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size)
#endif /* !CONFIG_ARCH_STACKWALK */
-static inline bool in_irqentry_text(unsigned long ptr)
+/*
+ * Optional arch hook for event entry text which cannot be placed in
+ * .irqentry.text. filter_irq_stacks() uses this and the section checks
+ * below to find where a trace entered the kernel, so the ranges are not
+ * necessarily irq-only: on x86 they also cover the exception entry stubs,
+ * and an architecture may deliver syscalls through the same entry text.
+ * A caller that has to tell interrupt entry and syscall entry apart
+ * cannot use this. An architecture overrides it by defining a macro of
+ * the same name in <asm/sections.h>, next to the markers it tests.
+ */
+#ifndef arch_in_event_entry_text
+static inline bool arch_in_event_entry_text(unsigned long addr) { return false; }
+#endif
+
+static inline bool in_event_entry_text(unsigned long ptr)
{
return (ptr >= (unsigned long)&__irqentry_text_start &&
ptr < (unsigned long)&__irqentry_text_end) ||
(ptr >= (unsigned long)&__softirqentry_text_start &&
- ptr < (unsigned long)&__softirqentry_text_end);
+ ptr < (unsigned long)&__softirqentry_text_end) ||
+ arch_in_event_entry_text(ptr);
}
/**
@@ -394,7 +410,7 @@ unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries)
unsigned int i;
for (i = 0; i < nr_entries; i++) {
- if (in_irqentry_text(entries[i])) {
+ if (in_event_entry_text(entries[i])) {
/* Include the irqentry function into the stack. */
return i + 1;
}
--
2.43.7