From: Jens Remus <jremus@linux.ibm.com>
To: Dylan Hatch <dylanbhatch@google.com>,
Roman Gushchin <roman.gushchin@linux.dev>,
Weinan Liu <wnliu@google.com>, Will Deacon <will@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Indu Bhagat <ibhagatgnu@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Jiri Kosina <jikos@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Prasanna Kumar T S M <ptsm@linux.microsoft.com>,
Puranjay Mohan <puranjay@kernel.org>, Song Liu <song@kernel.org>,
joe.lawrence@redhat.com, linux-toolchains@vger.kernel.org,
linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
Randy Dunlap <rdunlap@infradead.org>,
Heiko Carstens <hca@linux.ibm.com>
Subject: Re: [PATCH v4 1/8] sframe: Allow kernelspace sframe sections
Date: Wed, 22 Apr 2026 16:08:31 +0200 [thread overview]
Message-ID: <38c9d976-6205-409c-8874-4c9757b25fd6@linux.ibm.com> (raw)
In-Reply-To: <20260421225200.1198447-2-dylanbhatch@google.com>
On 4/22/2026 12:51 AM, Dylan Hatch wrote:
> Generalize the sframe lookup code to support kernelspace sections. This
> is done by defining a SFRAME_LOOKUP option that can be activated
> separate from HAVE_UNWIND_USER_SFRAME, as there will be other client to
> this library than just userspace unwind.
>
> Sframe section location is now tracked in a separate sec_type field to
> determine whether user-access functions are necessary to read the sframe
> data. Relevant type delarations are moved and renamed to reflect the
> non-user sframe support.
>
> Signed-off-by: Dylan Hatch <dylanbhatch@google.com>
With return -EFAULT changed to goto label in DATA_COPY() and DATA_GET():
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
> ---
> MAINTAINERS | 2 +-
> arch/Kconfig | 4 +
> .../{unwind_user_sframe.h => unwind_sframe.h} | 6 +-
> arch/x86/include/asm/unwind_user.h | 12 +-
> include/linux/sframe.h | 48 ++--
> include/linux/unwind_types.h | 46 +++
> include/linux/unwind_user_types.h | 41 ---
> kernel/unwind/Makefile | 2 +-
> kernel/unwind/sframe.c | 270 ++++++++++++------
> kernel/unwind/user.c | 41 +--
> 10 files changed, 293 insertions(+), 179 deletions(-)
> rename arch/x86/include/asm/{unwind_user_sframe.h => unwind_sframe.h} (50%)
> create mode 100644 include/linux/unwind_types.h
> diff --git a/include/linux/sframe.h b/include/linux/sframe.h
> +enum sframe_sec_type {
> + SFRAME_KERNEL,
> + SFRAME_USER,
> +};
> struct sframe_section {
> - struct rcu_head rcu;
> + struct rcu_head rcu;
> #ifdef CONFIG_DYNAMIC_DEBUG
> - const char *filename;
> + const char *filename;
> #endif
> - unsigned long sframe_start;
> - unsigned long sframe_end;
> - unsigned long text_start;
> - unsigned long text_end;
> -
> - unsigned long fdes_start;
> - unsigned long fres_start;
> - unsigned long fres_end;
> - unsigned int num_fdes;
> -
> - signed char ra_off;
> - signed char fp_off;
> + enum sframe_sec_type sec_type;
> + unsigned long sframe_start;
> + unsigned long sframe_end;
> + unsigned long text_start;
> + unsigned long text_end;
> +
> + unsigned long fdes_start;
> + unsigned long fres_start;
> + unsigned long fres_end;
> + unsigned int num_fdes;
> +
> + signed char ra_off;
> + signed char fp_off;
> };
> diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c
> +#define DATA_COPY(sec, to, from, size, label) \
> +({ \
> + switch (sec->sec_type) { \
> + case SFRAME_KERNEL: \
> + KERNEL_COPY(to, from, size, label); \
> + break; \
> + case SFRAME_USER: \
> + UNSAFE_USER_COPY(to, from, size, label); \
> + break; \
I wonder whether it would be worthwhile to come up with an approach
where this would get evaluated at compile time instead at run time?
Or is this overengineering? Of course such improvement could be
made later on, so no need to solve that now.
Options that came into my mind:
A) Introduce and pass through a "bool user" parameter, whose value is
specified in sframe_find_user() and sframe_find_kernel(). Due to
inlining I would expect that to get any conditions based on that
to get evaluated at compile time. See below. Downside is the
ugly additional parameter.
B) Introduce lightweight .c wrappers, e.g. sframe_kernel.c and
sframe_user.c, that define DATA_GET() and DATA_COPY() and include
sframe.c. All HAVE_UNWIND_KERNEL_SFRAME code would be moved into
sframe_kernel.c and likewise all HAVE_UNWIND_USER_SFRAME code into
sframe_user.c.
> + default: \
> + return -EFAULT; \
goto label; \
Users of DATA_COPY() do expect the macro to branch to the label in case
of an error and therefore do not evaluate any return value. The
wrapping then needs also be changed from "({ .. })" to
"do { ... } while (0)".
> + } \
> +})
> +
> +#define DATA_GET(sec, to, from, type, label) \
> +({ \
> + switch (sec->sec_type) { \
> + case SFRAME_KERNEL: \
> + KERNEL_GET(to, from, type, label); \
> + break; \
> + case SFRAME_USER: \
> + UNSAFE_USER_GET(to, from, type, label); \
> + break; \
> + default: \
> + return -EFAULT; \
Likewise.
> + } \
> +})
> +#ifdef CONFIG_HAVE_UNWIND_USER_SFRAME
> +
> +int sframe_find_user(unsigned long ip, struct unwind_frame *frame)
> +{
> + struct mm_struct *mm = current->mm;
> + struct sframe_section *sec;
> + int ret;
> +
> + if (!mm)
> + return -EINVAL;
> +
> + guard(srcu)(&sframe_srcu);
> +
> + sec = mtree_load(&mm->sframe_mt, ip);
> + if (!sec)
> + return -EINVAL;
> +
> + if (!user_read_access_begin((void __user *)sec->sframe_start,
> + sec->sframe_end - sec->sframe_start))
> + return -EFAULT;
> +
> + ret = __sframe_find(sec, ip, frame);
In sframe_find_user() sec->sec_type must be SFRAME_USER. Likewise in
sframe_find_kernel() it must be SFRAME_KERNEL. So instead of
introducing sec_type, we could add a parameter
__sframe_find(..., bool user) and do:
ret = __sframe_find(sec, ip, frame, true);
The downside is that this then requires to pass that flag through
everywhere... (see below).
> +
> + user_read_access_end();
> +
> + if (ret == -EFAULT) {
> + dbg_sec("removing bad .sframe section\n");
> + WARN_ON_ONCE(sframe_remove_section(sec->sframe_start));
> + }
> +
> + return ret;
> +}
Regards,
Jens
--
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com
IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
next prev parent reply other threads:[~2026-04-22 14:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 22:51 [PATCH v4 0/8] unwind, arm64: add sframe unwinder for kernel Dylan Hatch
2026-04-21 22:51 ` [PATCH v4 1/8] sframe: Allow kernelspace sframe sections Dylan Hatch
2026-04-22 14:08 ` Jens Remus [this message]
2026-04-22 15:15 ` Dylan Hatch
2026-04-21 22:51 ` [PATCH v4 2/8] arm64, unwind: build kernel with sframe V3 info Dylan Hatch
2026-04-22 14:15 ` Jens Remus
2026-04-21 22:51 ` [PATCH v4 3/8] arm64: entry: add unwind info for various kernel entries Dylan Hatch
2026-04-22 14:18 ` Jens Remus
2026-04-21 22:51 ` [PATCH v4 4/8] sframe: Provide PC lookup for vmlinux .sframe section Dylan Hatch
2026-04-21 22:51 ` [PATCH v4 5/8] sframe: Allow unsorted FDEs Dylan Hatch
2026-04-21 22:51 ` [PATCH v4 6/8] arm64/module, sframe: Add sframe support for modules Dylan Hatch
2026-04-21 22:51 ` [PATCH v4 7/8] sframe: Introduce in-kernel SFRAME_VALIDATION Dylan Hatch
2026-04-22 14:11 ` Jens Remus
2026-04-21 22:52 ` [PATCH v4 8/8] unwind: arm64: Use sframe to unwind interrupt frames Dylan Hatch
2026-04-22 14:25 ` Jens Remus
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=38c9d976-6205-409c-8874-4c9757b25fd6@linux.ibm.com \
--to=jremus@linux.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=dylanbhatch@google.com \
--cc=hca@linux.ibm.com \
--cc=ibhagatgnu@gmail.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-toolchains@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=peterz@infradead.org \
--cc=ptsm@linux.microsoft.com \
--cc=puranjay@kernel.org \
--cc=rdunlap@infradead.org \
--cc=roman.gushchin@linux.dev \
--cc=rostedt@goodmis.org \
--cc=song@kernel.org \
--cc=will@kernel.org \
--cc=wnliu@google.com \
/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