* [PATCH v2 0/3] unwind_user: Cleanups
@ 2025-12-01 12:54 Jens Remus
2025-12-01 12:54 ` [PATCH v2 1/3] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jens Remus @ 2025-12-01 12:54 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
Peter Zijlstra
Cc: Jens Remus, Josh Poimboeuf, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Mathieu Desnoyers,
Indu Bhagat, Jose E. Marchesi, Heiko Carstens, Vasily Gorbik,
Ilya Leoshkevich
This patch series applies on top of Peter Zijlstras' latest unwind user
enhancements (and perf deferred callchain support) on his tip perf/core
branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
Which has already been merged to tip/master and linux-next/master.
Patch 1 enhances a few comments in unwind_user_next_common().
Patch 2 gets rid of an ifdef in unwind_user_next_fp() by moving it to
linux/unwind_user.h. Additionally it provides a common fallback for
unwind_user_at_function_start().
Patch 3 ensures the x86 unwind_user_word_size() implementation is
available whenever config option UNWIND_USER is enabled, as it is
required by unwind user in general and is not specific to its FP
unwind method.
Regards,
Jens
Jens Remus (3):
unwind_user: Enhance comments on get CFA, FP, and RA
unwind_user/fp: Use dummies instead of ifdef
x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER
arch/x86/include/asm/unwind_user.h | 29 +++++++++++++++++------------
include/linux/unwind_user.h | 18 ++++++++++++++++--
kernel/unwind/user.c | 12 ++++--------
3 files changed, 37 insertions(+), 22 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/3] unwind_user: Enhance comments on get CFA, FP, and RA
2025-12-01 12:54 [PATCH v2 0/3] unwind_user: Cleanups Jens Remus
@ 2025-12-01 12:54 ` Jens Remus
2025-12-01 12:54 ` [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef Jens Remus
2025-12-01 12:54 ` [PATCH v2 3/3] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
2 siblings, 0 replies; 5+ messages in thread
From: Jens Remus @ 2025-12-01 12:54 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
Peter Zijlstra
Cc: Jens Remus, Josh Poimboeuf, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Mathieu Desnoyers,
Indu Bhagat, Jose E. Marchesi, Heiko Carstens, Vasily Gorbik,
Ilya Leoshkevich
Move the comment "Get the Canonical Frame Address (CFA)" to the top
of the sequence of statements that actually get the CFA. Reword the
comment "Find the Return Address (RA)" to "Get ...", as the statements
actually get the RA. Add a respective comment to the statements that
get the FP. This will be useful once future commits extend the logic
to get the RA and FP.
While at it align the comment on the "stack going in wrong direction"
check to the following one on the "address is word aligned" check.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
kernel/unwind/user.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/kernel/unwind/user.c b/kernel/unwind/user.c
index 39e270789444..0ca434f86e73 100644
--- a/kernel/unwind/user.c
+++ b/kernel/unwind/user.c
@@ -31,6 +31,7 @@ static int unwind_user_next_common(struct unwind_user_state *state,
{
unsigned long cfa, fp, ra;
+ /* Get the Canonical Frame Address (CFA) */
if (frame->use_fp) {
if (state->fp < state->sp)
return -EINVAL;
@@ -38,11 +39,9 @@ static int unwind_user_next_common(struct unwind_user_state *state,
} else {
cfa = state->sp;
}
-
- /* Get the Canonical Frame Address (CFA) */
cfa += frame->cfa_off;
- /* stack going in wrong direction? */
+ /* Make sure that stack is not going in wrong direction */
if (cfa <= state->sp)
return -EINVAL;
@@ -50,10 +49,11 @@ static int unwind_user_next_common(struct unwind_user_state *state,
if (cfa & (state->ws - 1))
return -EINVAL;
- /* Find the Return Address (RA) */
+ /* Get the Return Address (RA) */
if (get_user_word(&ra, cfa, frame->ra_off, state->ws))
return -EINVAL;
+ /* Get the Frame Pointer (FP) */
if (frame->fp_off && get_user_word(&fp, cfa, frame->fp_off, state->ws))
return -EINVAL;
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef
2025-12-01 12:54 [PATCH v2 0/3] unwind_user: Cleanups Jens Remus
2025-12-01 12:54 ` [PATCH v2 1/3] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
@ 2025-12-01 12:54 ` Jens Remus
2025-12-01 20:30 ` Ingo Molnar
2025-12-01 12:54 ` [PATCH v2 3/3] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
2 siblings, 1 reply; 5+ messages in thread
From: Jens Remus @ 2025-12-01 12:54 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
Peter Zijlstra
Cc: Jens Remus, Josh Poimboeuf, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Mathieu Desnoyers,
Indu Bhagat, Jose E. Marchesi, Heiko Carstens, Vasily Gorbik,
Ilya Leoshkevich
This simplifies the code. unwind_user_next_fp() does not need to
return -EINVAL if config option HAVE_UNWIND_USER_FP is disabled, as
unwind_user_start() will then not select this unwind method and
unwind_user_next() will therefore not call it.
Provide (1) a dummy definition of ARCH_INIT_USER_FP_FRAME, if the unwind
user method HAVE_UNWIND_USER_FP is not enabled, (2) a common fallback
definition of unwind_user_at_function_start() which returns false, and
(3) a common dummy definition of ARCH_INIT_USER_FP_ENTRY_FRAME.
Note that enabling the config option HAVE_UNWIND_USER_FP without
defining ARCH_INIT_USER_FP_FRAME triggers a compile error, which is
helpful when implementing support for this unwind user method in an
architecture. Enabling the config option when providing an arch-
specific unwind_user_at_function_start() definition makes it necessary
to also provide an arch-specific ARCH_INIT_USER_FP_ENTRY_FRAME
definition.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
Notes (jremus):
Changes in v2:
- Add parameter ws to ARCH_INIT_USER_{FP_FRAME|FP_ENTRY_FRAME}.
- Provide common fallback of unwind_user_at_function_start().
- Provide common dummy of ARCH_INIT_USER_FP_ENTRY_FRAME.
- Reword commit message accordingly.
arch/x86/include/asm/unwind_user.h | 1 +
include/linux/unwind_user.h | 18 ++++++++++++++++--
kernel/unwind/user.c | 4 ----
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 12064284bc4e..971ffe937d50 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -35,6 +35,7 @@ static inline bool unwind_user_at_function_start(struct pt_regs *regs)
{
return is_uprobe_at_func_entry(regs);
}
+#define unwind_user_at_function_start unwind_user_at_function_start
#endif /* CONFIG_HAVE_UNWIND_USER_FP */
diff --git a/include/linux/unwind_user.h b/include/linux/unwind_user.h
index 7f7282516bf5..e3e65c2955cf 100644
--- a/include/linux/unwind_user.h
+++ b/include/linux/unwind_user.h
@@ -5,8 +5,22 @@
#include <linux/unwind_user_types.h>
#include <asm/unwind_user.h>
-#ifndef ARCH_INIT_USER_FP_FRAME
- #define ARCH_INIT_USER_FP_FRAME
+#ifndef CONFIG_HAVE_UNWIND_USER_FP
+
+#define ARCH_INIT_USER_FP_FRAME(ws)
+
+#endif /* !CONFIG_HAVE_UNWIND_USER_FP */
+
+#ifndef ARCH_INIT_USER_FP_ENTRY_FRAME
+#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)
+#endif
+
+#ifndef unwind_user_at_function_start
+static inline bool unwind_user_at_function_start(struct pt_regs *regs)
+{
+ return false;
+}
+#define unwind_user_at_function_start unwind_user_at_function_start
#endif
int unwind_user(struct unwind_stacktrace *trace, unsigned int max_entries);
diff --git a/kernel/unwind/user.c b/kernel/unwind/user.c
index 0ca434f86e73..90ab3c1a205e 100644
--- a/kernel/unwind/user.c
+++ b/kernel/unwind/user.c
@@ -67,7 +67,6 @@ static int unwind_user_next_common(struct unwind_user_state *state,
static int unwind_user_next_fp(struct unwind_user_state *state)
{
-#ifdef CONFIG_HAVE_UNWIND_USER_FP
struct pt_regs *regs = task_pt_regs(current);
if (state->topmost && unwind_user_at_function_start(regs)) {
@@ -81,9 +80,6 @@ static int unwind_user_next_fp(struct unwind_user_state *state)
ARCH_INIT_USER_FP_FRAME(state->ws)
};
return unwind_user_next_common(state, &fp_frame);
-#else
- return -EINVAL;
-#endif
}
static int unwind_user_next(struct unwind_user_state *state)
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER
2025-12-01 12:54 [PATCH v2 0/3] unwind_user: Cleanups Jens Remus
2025-12-01 12:54 ` [PATCH v2 1/3] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
2025-12-01 12:54 ` [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef Jens Remus
@ 2025-12-01 12:54 ` Jens Remus
2 siblings, 0 replies; 5+ messages in thread
From: Jens Remus @ 2025-12-01 12:54 UTC (permalink / raw)
To: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
Peter Zijlstra
Cc: Jens Remus, Josh Poimboeuf, Thomas Gleixner, Ingo Molnar,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Mathieu Desnoyers,
Indu Bhagat, Jose E. Marchesi, Heiko Carstens, Vasily Gorbik,
Ilya Leoshkevich
The unwind user framework in general requires an architecture-specific
implementation of unwind_user_word_size() to be present for any unwind
method, whether that is fp or a future other method, such as potentially
sframe.
Guard unwind_user_word_size() by the availability of the UNWIND_USER
framework instead of the specific HAVE_UNWIND_USER_FP method.
This facilitates to selectively disable HAVE_UNWIND_USER_FP on x86
(e.g. for test purposes) once a new unwind method is added to unwind
user.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
arch/x86/include/asm/unwind_user.h | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 971ffe937d50..e1137eb67ab2 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -2,6 +2,22 @@
#ifndef _ASM_X86_UNWIND_USER_H
#define _ASM_X86_UNWIND_USER_H
+#ifdef CONFIG_UNWIND_USER
+
+static inline int unwind_user_word_size(struct pt_regs *regs)
+{
+ /* We can't unwind VM86 stacks */
+ if (regs->flags & X86_VM_MASK)
+ return 0;
+#ifdef CONFIG_X86_64
+ if (!user_64bit_mode(regs))
+ return sizeof(int);
+#endif
+ return sizeof(long);
+}
+
+#endif /* CONFIG_UNWIND_USER */
+
#ifdef CONFIG_HAVE_UNWIND_USER_FP
#include <asm/ptrace.h>
@@ -19,18 +35,6 @@
.fp_off = 0, \
.use_fp = false,
-static inline int unwind_user_word_size(struct pt_regs *regs)
-{
- /* We can't unwind VM86 stacks */
- if (regs->flags & X86_VM_MASK)
- return 0;
-#ifdef CONFIG_X86_64
- if (!user_64bit_mode(regs))
- return sizeof(int);
-#endif
- return sizeof(long);
-}
-
static inline bool unwind_user_at_function_start(struct pt_regs *regs)
{
return is_uprobe_at_func_entry(regs);
--
2.51.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef
2025-12-01 12:54 ` [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef Jens Remus
@ 2025-12-01 20:30 ` Ingo Molnar
0 siblings, 0 replies; 5+ messages in thread
From: Ingo Molnar @ 2025-12-01 20:30 UTC (permalink / raw)
To: Jens Remus
Cc: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
Peter Zijlstra, Josh Poimboeuf, Thomas Gleixner, Borislav Petkov,
Dave Hansen, H. Peter Anvin, Mathieu Desnoyers, Indu Bhagat,
Jose E. Marchesi, Heiko Carstens, Vasily Gorbik, Ilya Leoshkevich
* Jens Remus <jremus@linux.ibm.com> wrote:
> -#ifndef ARCH_INIT_USER_FP_FRAME
> - #define ARCH_INIT_USER_FP_FRAME
> +#ifndef CONFIG_HAVE_UNWIND_USER_FP
> +
> +#define ARCH_INIT_USER_FP_FRAME(ws)
> +
> +#endif /* !CONFIG_HAVE_UNWIND_USER_FP */
Just a nit, there's no need for the closing /* !.. */
comment for such a short CPP block - just like it's
done in the next couple of lines:
> +#ifndef ARCH_INIT_USER_FP_ENTRY_FRAME
> +#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)
> +#endif
Thanks,
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-12-01 20:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-01 12:54 [PATCH v2 0/3] unwind_user: Cleanups Jens Remus
2025-12-01 12:54 ` [PATCH v2 1/3] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
2025-12-01 12:54 ` [PATCH v2 2/3] unwind_user/fp: Use dummies instead of ifdef Jens Remus
2025-12-01 20:30 ` Ingo Molnar
2025-12-01 12:54 ` [PATCH v2 3/3] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).