Re: [PATCH v2 03/11] unwind: Introduce SFrame user space unwinding

From: Josh Poimboeuf
Date: Sun Oct 27 2024 - 13:49:43 EST


On Wed, Oct 23, 2024 at 03:59:53PM +0200, Jens Remus wrote:
> > +++ b/arch/Kconfig
> > @@ -428,6 +428,9 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
> > config HAVE_USER_UNWIND
> > bool
> > +config HAVE_USER_UNWIND_SFRAME
> > + bool
>
> I found this unwinder of userspace using SFrame to depend on your generic
> unwinder of userspace framework. Does this warrant to add:

Based on your other suggestion I now have:

config UNWIND_USER
bool

config HAVE_UNWIND_USER_FP
bool
select UNWIND_USER

config HAVE_UNWIND_USER_SFRAME
bool
select UNWIND_USER

The arches set HAVE_*, which in turn sets UNWIND_USER.

> > +static int find_fre(struct sframe_section *sec, struct sframe_fde *fde,
> > + unsigned long ip, struct user_unwind_frame *frame)
> > +{
> > + unsigned char fde_type = SFRAME_FUNC_FDE_TYPE(fde->info);
> > + unsigned char fre_type = SFRAME_FUNC_FRE_TYPE(fde->info);
> > + s32 fre_ip_off, cfa_off, ra_off, fp_off, ip_off;
>
> Doesn't fre_ip_off need to be u32 (see also below)? The SFrame format
> specification states the FRE sfre_start_address is either u8, u16, or u32:
> https://sourceware.org/binutils/docs/sframe-spec.html#The-SFrame-FRE-Types

Indeed, I also noticed that.

> > + SFRAME_GET_USER_UNSIGNED(cfa_off, f, offset_size);
>
> As far as I know the CFA offset from CFA base register is signed in the
> SFrame file format. See Binutils include/sframe-api.h,
> sframe_fre_get_cfa_offset(). Therefore use SFRAME_GET_USER_SIGNED(). Both
> cfa_off and struct user_unwind_frame cfa_off are already defined as s32.

Good catch. There's no need to have separate SIGNED/UNSIGNED variants
anyway, I'll simplify that into SFRAME_GET_USER().

> > +++ b/mm/init-mm.c
> > @@ -11,6 +11,7 @@
> > #include <linux/atomic.h>
> > #include <linux/user_namespace.h>
> > #include <linux/iommu.h>
> > +#include <linux/sframe.h>
> > #include <asm/mmu.h>
> > #ifndef INIT_MM_CONTEXT
> > @@ -44,7 +45,8 @@ struct mm_struct init_mm = {
> > #endif
> > .user_ns = &init_user_ns,
> > .cpu_bitmap = CPU_BITS_NONE,
> > - INIT_MM_CONTEXT(init_mm)
> > + INIT_MM_CONTEXT(init_mm),
> > + INIT_MM_SFRAME,
>
> This does not compile on s390, as INIT_MM_CONTEXT() is defined with a
> trailing comma, leading to two consecutive commas. Already reported by the
> kernel test robot for other architectures.
> Same if INIT_MM_SFRAME expands into nothing there would be two consecutive
> commas.

Yeah, I saw those build errors and I've got that fixed now.

Thanks for the review!

--
Josh