On Fri, Oct 24, 2025 at 04:54:02PM +0200, Peter Zijlstra wrote:
On Fri, Oct 24, 2025 at 04:51:56PM +0200, Peter Zijlstra wrote:
quoted
--- a/arch/x86/include/asm/unwind_user.h
+++ b/arch/x86/include/asm/unwind_user.h
@@ -3,6 +3,7 @@
#define _ASM_X86_UNWIND_USER_H
#include <asm/ptrace.h>
+#include <asm/uprobes.h>
#define ARCH_INIT_USER_FP_FRAME(ws) \
.cfa_off = 2*(ws), \
@@ -10,6 +11,12 @@
.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 */@@ -22,4 +29,9 @@ static inline int unwind_user_word_size(
return sizeof(long);
}
+static inline bool unwind_user_at_function_start(struct pt_regs *regs)
+{
+ return is_uprobe_at_func_entry(regs);
+}
+
#endif /* _ASM_X86_UNWIND_USER_H */
quoted
--- a/include/linux/unwind_user_types.h
+++ b/include/linux/unwind_user_types.h
@@ -39,6 +39,7 @@ struct unwind_user_state {
unsigned int ws;
enum unwind_user_type current_type;
unsigned int available_types;
+ bool topmost;
bool done;
};
--- a/kernel/unwind/user.c
+++ b/kernel/unwind/user.c
quoted
+static int unwind_user_next_fp(struct unwind_user_state *state)
+{
+ struct pt_regs *regs = task_pt_regs(current);
+
+ const struct unwind_user_frame fp_frame = {
+ ARCH_INIT_USER_FP_FRAME(state->ws)
+ };
+ const struct unwind_user_frame fp_entry_frame = {
+ ARCH_INIT_USER_FP_ENTRY_FRAME(state->ws)
+ };
+
+ if (state->topmost && unwind_user_at_function_start(regs))
+ return unwind_user_next_common(state, &fp_entry_frame);
+
+ return unwind_user_next_common(state, &fp_frame);
+}
+
static int unwind_user_next(struct unwind_user_state *state)
{
unsigned long iter_mask = state->available_types;@@ -118,6 +134,7 @@ static int unwind_user_start(struct unwi
state->done = true;
return -EINVAL;
}
+ state->topmost = true;
return 0;
}
And right before sending this; I realized we could do the
unwind_user_at_function_start() in unwind_user_start() and set something
like state->entry = true instead of topmost.
That saves having to do task_pt_regs() in unwind_user_next_fp().
Does that make sense?
Urgh, that makes us call that weird hack for sframe too, which isn't
needed. Oh well, ignore this.