mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/4] unwind_user: Cleanups
@ 2025-12-08 16:03 Jens Remus
  2025-12-08 16:03 ` [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Jens Remus @ 2025-12-08 16:03 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, Linus Torvalds

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.

Patch 4 (new in v4) simplifies unwind_user_word_size().

Regards,
Jens

Jens Remus (4):
  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
  x86/unwind_user: Simplify unwind_user_word_size()

 arch/x86/include/asm/unwind_user.h | 27 ++++++++++++++-------------
 include/linux/unwind_user.h        | 18 ++++++++++++++++--
 kernel/unwind/user.c               | 12 ++++--------
 3 files changed, 34 insertions(+), 23 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA
  2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
@ 2025-12-08 16:03 ` Jens Remus
  2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
  2025-12-08 16:03 ` [PATCH v4 2/4] unwind_user/fp: Use dummies instead of ifdef Jens Remus
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2025-12-08 16:03 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, Linus Torvalds

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	[flat|nested] 11+ messages in thread

* [PATCH v4 2/4] unwind_user/fp: Use dummies instead of ifdef
  2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
  2025-12-08 16:03 ` [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
@ 2025-12-08 16:03 ` Jens Remus
  2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
  2025-12-08 16:03 ` [PATCH v4 3/4] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2025-12-08 16:03 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, Linus Torvalds

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 v3:
    - Remove comment on #endif. (Ingo)
    
    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..64618618febd 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
+
+#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	[flat|nested] 11+ messages in thread

* [PATCH v4 3/4] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER
  2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
  2025-12-08 16:03 ` [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
  2025-12-08 16:03 ` [PATCH v4 2/4] unwind_user/fp: Use dummies instead of ifdef Jens Remus
@ 2025-12-08 16:03 ` Jens Remus
  2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
  2025-12-08 16:03 ` [PATCH v4 4/4] x86/unwind_user: Simplify unwind_user_word_size() Jens Remus
  2025-12-08 19:36 ` [PATCH v4 0/4] unwind_user: Cleanups Peter Zijlstra
  4 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2025-12-08 16:03 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, Linus Torvalds

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>
---

Notes (jremus):
    Changes in v3:
    - Move includes into more common UNWIND_USER guard at the top of the
      source.  asm/ptrace.h is required for struct pt_regs.

 arch/x86/include/asm/unwind_user.h | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 971ffe937d50..7f1229b33d06 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -2,23 +2,11 @@
 #ifndef _ASM_X86_UNWIND_USER_H
 #define _ASM_X86_UNWIND_USER_H
 
-#ifdef CONFIG_HAVE_UNWIND_USER_FP
+#ifdef CONFIG_UNWIND_USER
 
 #include <asm/ptrace.h>
 #include <asm/uprobes.h>
 
-#define ARCH_INIT_USER_FP_FRAME(ws)			\
-	.cfa_off	=  2*(ws),			\
-	.ra_off		= -1*(ws),			\
-	.fp_off		= -2*(ws),			\
-	.use_fp		= true,
-
-#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)		\
-	.cfa_off	=  1*(ws),			\
-	.ra_off		= -1*(ws),			\
-	.fp_off		= 0,				\
-	.use_fp		= false,
-
 static inline int unwind_user_word_size(struct pt_regs *regs)
 {
 	/* We can't unwind VM86 stacks */
@@ -31,6 +19,22 @@ static inline int unwind_user_word_size(struct pt_regs *regs)
 	return sizeof(long);
 }
 
+#endif /* CONFIG_UNWIND_USER */
+
+#ifdef CONFIG_HAVE_UNWIND_USER_FP
+
+#define ARCH_INIT_USER_FP_FRAME(ws)			\
+	.cfa_off	=  2*(ws),			\
+	.ra_off		= -1*(ws),			\
+	.fp_off		= -2*(ws),			\
+	.use_fp		= true,
+
+#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)		\
+	.cfa_off	=  1*(ws),			\
+	.ra_off		= -1*(ws),			\
+	.fp_off		= 0,				\
+	.use_fp		= false,
+
 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	[flat|nested] 11+ messages in thread

* [PATCH v4 4/4] x86/unwind_user: Simplify unwind_user_word_size()
  2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
                   ` (2 preceding siblings ...)
  2025-12-08 16:03 ` [PATCH v4 3/4] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
@ 2025-12-08 16:03 ` Jens Remus
  2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
  2025-12-08 19:36 ` [PATCH v4 0/4] unwind_user: Cleanups Peter Zijlstra
  4 siblings, 1 reply; 11+ messages in thread
From: Jens Remus @ 2025-12-08 16:03 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, Linus Torvalds

Get rid of superfluous ifdef and return explicit word size depending on
32-bit or 64-bit mode.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---

Notes (jremus):
    Changes in v4:
    - New patch. (Linus)
      https://lore.kernel.org/all/CAHk-=wh4_BPvniQZqvEQ4cCC3WfvQqruWk0b1Yek+0d5S1LuxQ@mail.gmail.com/
    
    This aligns to sizeof_long() in arch/x86/kernel/uprobes.c.

 arch/x86/include/asm/unwind_user.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 7f1229b33d06..6e469044e4de 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -12,11 +12,7 @@ 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);
+	return user_64bit_mode(regs) ? 8 : 4;
 }
 
 #endif /* CONFIG_UNWIND_USER */
-- 
2.51.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 0/4] unwind_user: Cleanups
  2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
                   ` (3 preceding siblings ...)
  2025-12-08 16:03 ` [PATCH v4 4/4] x86/unwind_user: Simplify unwind_user_word_size() Jens Remus
@ 2025-12-08 19:36 ` Peter Zijlstra
  2025-12-09  9:10   ` Jens Remus
  4 siblings, 1 reply; 11+ messages in thread
From: Peter Zijlstra @ 2025-12-08 19:36 UTC (permalink / raw)
  To: Jens Remus
  Cc: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
	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, Linus Torvalds

On Mon, Dec 08, 2025 at 05:03:48PM +0100, Jens Remus wrote:
> 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.

Right, that should be empty now :-)


> Jens Remus (4):
>   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
>   x86/unwind_user: Simplify unwind_user_word_size()
> 
>  arch/x86/include/asm/unwind_user.h | 27 ++++++++++++++-------------
>  include/linux/unwind_user.h        | 18 ++++++++++++++++--
>  kernel/unwind/user.c               | 12 ++++--------
>  3 files changed, 34 insertions(+), 23 deletions(-)

I'll go stick these patches in tip/perf/core after rc1 or so, no real
hurry with these, right?

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 0/4] unwind_user: Cleanups
  2025-12-08 19:36 ` [PATCH v4 0/4] unwind_user: Cleanups Peter Zijlstra
@ 2025-12-09  9:10   ` Jens Remus
  0 siblings, 0 replies; 11+ messages in thread
From: Jens Remus @ 2025-12-09  9:10 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, linux-trace-kernel, x86, Steven Rostedt,
	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, Linus Torvalds

Hello Peter!

On 12/8/2025 8:36 PM, Peter Zijlstra wrote:
> On Mon, Dec 08, 2025 at 05:03:48PM +0100, Jens Remus wrote:

>> Jens Remus (4):
>>   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
>>   x86/unwind_user: Simplify unwind_user_word_size()
>>
>>  arch/x86/include/asm/unwind_user.h | 27 ++++++++++++++-------------
>>  include/linux/unwind_user.h        | 18 ++++++++++++++++--
>>  kernel/unwind/user.c               | 12 ++++--------
>>  3 files changed, 34 insertions(+), 23 deletions(-)
> 
> I'll go stick these patches in tip/perf/core after rc1 or so, no real
> hurry with these, right?
Perfect, that is fine with me.

Thanks and regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip: perf/core] x86/unwind_user: Simplify unwind_user_word_size()
  2025-12-08 16:03 ` [PATCH v4 4/4] x86/unwind_user: Simplify unwind_user_word_size() Jens Remus
@ 2025-12-17 12:38   ` tip-bot2 for Jens Remus
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Jens Remus @ 2025-12-17 12:38 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Linus Torvalds, Jens Remus, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     3c48808408af11d6f173c65eee9bd5ca4c53667c
Gitweb:        https://git.kernel.org/tip/3c48808408af11d6f173c65eee9bd5ca4c53667c
Author:        Jens Remus <jremus@linux.ibm.com>
AuthorDate:    Mon, 08 Dec 2025 17:03:52 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 17 Dec 2025 13:31:08 +01:00

x86/unwind_user: Simplify unwind_user_word_size()

Get rid of superfluous ifdef and return explicit word size depending on
32-bit or 64-bit mode.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251208160352.1363040-5-jremus@linux.ibm.com
---
 arch/x86/include/asm/unwind_user.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 7f1229b..6e46904 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -12,11 +12,7 @@ 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);
+	return user_64bit_mode(regs) ? 8 : 4;
 }
 
 #endif /* CONFIG_UNWIND_USER */

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip: perf/core] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER
  2025-12-08 16:03 ` [PATCH v4 3/4] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
@ 2025-12-17 12:38   ` tip-bot2 for Jens Remus
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Jens Remus @ 2025-12-17 12:38 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Jens Remus, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     aa6047ef7204ea1faa346b9123439abed0546f7e
Gitweb:        https://git.kernel.org/tip/aa6047ef7204ea1faa346b9123439abed0546f7e
Author:        Jens Remus <jremus@linux.ibm.com>
AuthorDate:    Mon, 08 Dec 2025 17:03:51 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 17 Dec 2025 13:31:08 +01:00

x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251208160352.1363040-4-jremus@linux.ibm.com
---
 arch/x86/include/asm/unwind_user.h | 30 ++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/arch/x86/include/asm/unwind_user.h b/arch/x86/include/asm/unwind_user.h
index 971ffe9..7f1229b 100644
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -2,23 +2,11 @@
 #ifndef _ASM_X86_UNWIND_USER_H
 #define _ASM_X86_UNWIND_USER_H
 
-#ifdef CONFIG_HAVE_UNWIND_USER_FP
+#ifdef CONFIG_UNWIND_USER
 
 #include <asm/ptrace.h>
 #include <asm/uprobes.h>
 
-#define ARCH_INIT_USER_FP_FRAME(ws)			\
-	.cfa_off	=  2*(ws),			\
-	.ra_off		= -1*(ws),			\
-	.fp_off		= -2*(ws),			\
-	.use_fp		= true,
-
-#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)		\
-	.cfa_off	=  1*(ws),			\
-	.ra_off		= -1*(ws),			\
-	.fp_off		= 0,				\
-	.use_fp		= false,
-
 static inline int unwind_user_word_size(struct pt_regs *regs)
 {
 	/* We can't unwind VM86 stacks */
@@ -31,6 +19,22 @@ static inline int unwind_user_word_size(struct pt_regs *regs)
 	return sizeof(long);
 }
 
+#endif /* CONFIG_UNWIND_USER */
+
+#ifdef CONFIG_HAVE_UNWIND_USER_FP
+
+#define ARCH_INIT_USER_FP_FRAME(ws)			\
+	.cfa_off	=  2*(ws),			\
+	.ra_off		= -1*(ws),			\
+	.fp_off		= -2*(ws),			\
+	.use_fp		= true,
+
+#define ARCH_INIT_USER_FP_ENTRY_FRAME(ws)		\
+	.cfa_off	=  1*(ws),			\
+	.ra_off		= -1*(ws),			\
+	.fp_off		= 0,				\
+	.use_fp		= false,
+
 static inline bool unwind_user_at_function_start(struct pt_regs *regs)
 {
 	return is_uprobe_at_func_entry(regs);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip: perf/core] unwind_user/fp: Use dummies instead of ifdef
  2025-12-08 16:03 ` [PATCH v4 2/4] unwind_user/fp: Use dummies instead of ifdef Jens Remus
@ 2025-12-17 12:38   ` tip-bot2 for Jens Remus
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Jens Remus @ 2025-12-17 12:38 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Jens Remus, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     2652f9a4b019e34fbbde8dcd1396f1f00ec4844f
Gitweb:        https://git.kernel.org/tip/2652f9a4b019e34fbbde8dcd1396f1f00ec4844f
Author:        Jens Remus <jremus@linux.ibm.com>
AuthorDate:    Mon, 08 Dec 2025 17:03:50 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 17 Dec 2025 13:31:07 +01:00

unwind_user/fp: Use dummies instead of ifdef

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251208160352.1363040-3-jremus@linux.ibm.com
---
 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 1206428..971ffe9 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 7f72825..6461861 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
+
+#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 0ca434f..90ab3c1 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)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [tip: perf/core] unwind_user: Enhance comments on get CFA, FP, and RA
  2025-12-08 16:03 ` [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
@ 2025-12-17 12:38   ` tip-bot2 for Jens Remus
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot2 for Jens Remus @ 2025-12-17 12:38 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Jens Remus, Peter Zijlstra (Intel), x86, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     2d6ad925fb2386f3ee1d26f5022f7ea71bbc1541
Gitweb:        https://git.kernel.org/tip/2d6ad925fb2386f3ee1d26f5022f7ea71bbc1541
Author:        Jens Remus <jremus@linux.ibm.com>
AuthorDate:    Mon, 08 Dec 2025 17:03:49 +01:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Wed, 17 Dec 2025 13:31:07 +01:00

unwind_user: Enhance comments on get CFA, FP, and RA

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251208160352.1363040-2-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 39e2707..0ca434f 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;
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-12-17 12:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-08 16:03 [PATCH v4 0/4] unwind_user: Cleanups Jens Remus
2025-12-08 16:03 ` [PATCH v4 1/4] unwind_user: Enhance comments on get CFA, FP, and RA Jens Remus
2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
2025-12-08 16:03 ` [PATCH v4 2/4] unwind_user/fp: Use dummies instead of ifdef Jens Remus
2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
2025-12-08 16:03 ` [PATCH v4 3/4] x86/unwind_user: Guard unwind_user_word_size() by UNWIND_USER Jens Remus
2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
2025-12-08 16:03 ` [PATCH v4 4/4] x86/unwind_user: Simplify unwind_user_word_size() Jens Remus
2025-12-17 12:38   ` [tip: perf/core] " tip-bot2 for Jens Remus
2025-12-08 19:36 ` [PATCH v4 0/4] unwind_user: Cleanups Peter Zijlstra
2025-12-09  9:10   ` Jens Remus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®