Re: [PATCH 2/2] x86/fred: Fix stack depot filtering of FRED event stacks

From: Peter Zijlstra

Date: Sat Aug 29 2026 - 05:42:39 EST


On Thu, Aug 27, 2026 at 11:00:22PM +0800, Yuanhe Shu wrote:

> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 15fd9ec5ecac..78b8eb4a925f 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -555,6 +555,7 @@ config X86_CPU_RESCTRL_INTEL_AET
> config X86_FRED
> bool "Flexible Return and Event Delivery"
> depends on X86_64
> + select ARCH_HAS_IN_IRQENTRY_TEXT
> help
> When enabled, use Flexible Return and Event Delivery
> instead of the legacy SYSCALL/SYSENTER/IDT architecture for

I'm not sold on this being a CONFIG symbol, we have far too many of
those. We have many other patterns that might work here.

A common one for example is:

#ifndef arch_in_irqentry_text
static inline bool arch_in_irqentry_text(unsigned long addr) { return false; }
#endif

And then have the arch/x86/include/asm/ header do:

#define arch_in_irqentry_text arch_in_irqentry_text.

> diff --git a/arch/x86/entry/entry_64_fred.S b/arch/x86/entry/entry_64_fred.S
> index b98f8945dfff..620def9039a3 100644
> --- a/arch/x86/entry/entry_64_fred.S
> +++ b/arch/x86/entry/entry_64_fred.S
> @@ -36,6 +36,17 @@
> */
> .align 4096
>
> +/*
> + * Bounds of the FRED event entry text. Every event delivered by FRED
> + * enters here, including events which the core entry code forwards
> + * through asm_fred_entry_from_kvm(). This is the FRED counterpart of
> + * __irqentry_text_start..__irqentry_text_end and lets
> + * in_irqentry_text() find the event entry point of a stack, see
> + * arch_in_irqentry_text().
> + */
> + .globl __fred_entry_text_start
> +__fred_entry_text_start:
> +
> SYM_CODE_START_NOALIGN(asm_fred_entrypoint_user)
> FRED_ENTER
> call fred_entry_from_user
> @@ -150,3 +161,6 @@ SYM_FUNC_START(asm_fred_entry_from_kvm)
>
> SYM_FUNC_END(asm_fred_entry_from_kvm)
> #endif
> +
> + .globl __fred_entry_text_end
> +__fred_entry_text_end:
> diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
> index 30e8ee7006f9..1b52239fcefd 100644
> --- a/arch/x86/include/asm/sections.h
> +++ b/arch/x86/include/asm/sections.h
> @@ -5,6 +5,7 @@
> #include <asm-generic/sections.h>
> #include <asm/extable.h>
>
> +extern char __fred_entry_text_start[], __fred_entry_text_end[];
> extern char __relocate_kernel_start[], __relocate_kernel_end[];
> extern char __brk_base[], __brk_limit[];
> extern char __end_rodata_aligned[];
> diff --git a/arch/x86/kernel/stacktrace.c b/arch/x86/kernel/stacktrace.c
> index ee117fcf46ed..4af7e52d9d97 100644
> --- a/arch/x86/kernel/stacktrace.c
> +++ b/arch/x86/kernel/stacktrace.c
> @@ -9,6 +9,7 @@
> #include <linux/stacktrace.h>
> #include <linux/export.h>
> #include <linux/uaccess.h>
> +#include <asm/sections.h>
> #include <asm/stacktrace.h>
> #include <asm/unwind.h>
>
> @@ -128,3 +129,15 @@ void arch_stack_walk_user(stack_trace_consume_fn consume_entry, void *cookie,
> }
> }
>
> +#ifdef CONFIG_X86_FRED
> +bool arch_in_irqentry_text(unsigned long addr)
> +{
> + /*
> + * FRED delivers events to entry points in .noinstr.text, which
> + * __irqentry_text_start..__irqentry_text_end does not cover. See
> + * __fred_entry_text_start in entry_64_fred.S.
> + */
> + return addr >= (unsigned long)__fred_entry_text_start &&
> + addr < (unsigned long)__fred_entry_text_end;
> +}
> +#endif

This is all confusing at best. __fred_entry_text covers all entries, it
cannot distinguish between irqentry and syscall. Why is that not a
problem?