From: Stian Halseth <stian@itx.no>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Andreas Larsson <andreas@gaisler.com>,
"David S. Miller" <davem@davemloft.net>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Magnus Lindholm <linmag7@gmail.com>,
linux-perf-users@vger.kernel.org, sparclinux@vger.kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Stian Halseth <stian@itx.no>
Subject: [RFC PATCH v3 1/3] perf/core: Let an arch prepare and locate the user stack dump
Date: Wed, 23 Sep 2026 11:04:26 +0200 [thread overview]
Message-ID: <20260923090429.2026529-2-stian@itx.no> (raw)
In-Reply-To: <20260923090429.2026529-1-stian@itx.no>
PERF_SAMPLE_STACK_USER copies the user stack as it is in memory,
starting at the user stack pointer. Two things about sparc64 do not
fit that.
The sampled window's %l and %i registers, including the frame pointer
and return address an unwinder starts from, may still be in the
register file: they only reach the stack when a window spills.
perf_callchain_user() already handles this for the callchain by calling
flushw_user() first; the user stack dump has no equivalent arch entry
point.
And a 64-bit stack pointer is biased by 2047: the stack starts at
%sp + 2047. Starting the dump at the register value spends a quarter of
an 8K dump on memory below the frame, and gives no dump at all when that
page has never been touched, as for a leaf frame at the deepest point a
thread's stack has reached.
Add two hooks in the style of perf_arch_misc_flags():
perf_arch_prepare_ustack(), a no-op by default, called from
perf_prepare_sample() before the dump size is computed, and
perf_arch_user_stack_pointer(), user_stack_pointer() by default, the
address the dump starts at. Flushing in the arch PMU interrupt handler
instead would not do: software events such as cpu-clock reach
perf_event_overflow() without passing through it.
Signed-off-by: Stian Halseth <stian@itx.no>
---
include/linux/perf_event.h | 11 +++++++++++
kernel/events/core.c | 2 ++
kernel/events/internal.h | 2 +-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 5842552294c1..49aa22db43c0 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1815,6 +1815,17 @@ extern unsigned long perf_instruction_pointer(struct perf_event *event,
#ifndef perf_arch_bpf_user_pt_regs
# define perf_arch_bpf_user_pt_regs(regs) regs
#endif
+/*
+ * Called before the user stack of the current task is dumped, for an arch
+ * that still holds part of the user's stack state in registers.
+ */
+#ifndef perf_arch_prepare_ustack
+static inline void perf_arch_prepare_ustack(void) { }
+#endif
+/* Where the user stack dump starts, for an arch with a biased stack pointer. */
+#ifndef perf_arch_user_stack_pointer
+# define perf_arch_user_stack_pointer(regs) user_stack_pointer(regs)
+#endif
#ifndef perf_arch_guest_misc_flags
static inline unsigned long perf_arch_guest_misc_flags(struct pt_regs *regs)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index db7b76d6b68a..90fb35c7d279 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8718,6 +8718,8 @@ void perf_prepare_sample(struct perf_sample_data *data,
u16 header_size = perf_sample_data_size(data, event);
u16 size = sizeof(u64);
+ if (data->regs_user.regs)
+ perf_arch_prepare_ustack();
stack_size = perf_sample_ustack_size(stack_size, header_size,
data->regs_user.regs);
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index c03c4f2eea57..01b5f53d01d7 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -236,7 +236,7 @@ static inline bool arch_perf_have_user_stack_dump(void)
return true;
}
-#define perf_user_stack_pointer(regs) user_stack_pointer(regs)
+#define perf_user_stack_pointer(regs) perf_arch_user_stack_pointer(regs)
#else
static inline bool arch_perf_have_user_stack_dump(void)
{
--
2.55.0
next prev parent reply other threads:[~2026-09-23 9:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 9:04 [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks Stian Halseth
2026-09-23 9:04 ` Stian Halseth [this message]
2026-09-23 9:04 ` [RFC PATCH v3 2/3] sparc64: Support PERF_SAMPLE_REGS_USER and PERF_SAMPLE_STACK_USER Stian Halseth
2026-09-23 9:04 ` [RFC PATCH v3 3/3] perf tools: Support sparc user register samples and dwarf unwinding Stian Halseth
2026-09-23 20:38 ` [RFC PATCH v3 0/3] perf: sparc64 user regs and stack dump, with arch hooks Ian Rogers
2026-09-23 20:56 ` Stian Halseth
2026-09-23 21:16 ` Ian Rogers
2026-09-24 17:09 ` Arnaldo Carvalho de Melo
2026-09-24 17:11 ` Arnaldo Carvalho de Melo
2026-09-25 7:33 ` Stian Halseth
2026-09-23 23:10 ` Magnus Lindholm
2026-09-24 8:20 ` Stian Halseth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923090429.2026529-2-stian@itx.no \
--to=stian@itx.no \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andreas@gaisler.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linmag7@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®