Re: [PATCH v14 05/19] unwind_user/sframe: Add support for reading .sframe contents

Jens Remus <[email protected]> Tue, 12 May 2026 15:35:09 +0200
Newsgroups dev.linux.lists.sashiko,org.kernel.vger.bpf
Organization IBM Deutschland Research & Development GmbH
Message-ID <[email protected]>
On 5/6/2026 5:01 PM, Steven Rostedt wrote:
> On Wed, 6 May 2026 16:34:34 +0200
> Jens Remus <[email protected]> wrote:
> 
>>>> +static __always_inline int __read_fre(struct sframe_section *sec,
>>>> +				      struct sframe_fde_internal *fde,
>>>> +				      unsigned long fre_addr,
>>>> +				      struct sframe_fre_internal *fre)
>>>> +{  
>>> [ ... ]  
>>>> +	if (fre_addr + addr_size + 1 > sec->fres_end)
>>>> +		return -EFAULT;
>>>> +
>>>> +	UNSAFE_GET_USER_INC(ip_off, cur, addr_size, Efault);  
>>>
>>> Will this cause alignment faults on architectures with strict alignment
>>> requirements?
>>>
>>> The .sframe format uses packed structures and variable-length datawords. The
>>> cur pointer might be unaligned here, and UNSAFE_GET_USER_INC() performs
>>> 16-bit or 32-bit reads via unsafe_get_user().  
>>
>> IIUC this should not be an issue for x86-64, s390, and arm64.
> 
> Do we have a way to make sure that sframe support will always be for
> architectures that can handle alignment issues like this? There should
> be something to force this via configs or something that will trigger a
> warning or bug if this is built for architectures that can't handle
> this alignment.

Config option HAVE_EFFICIENT_UNALIGNED_ACCESS seems to be the one that
is used for exactly this purpose.


IIUC config options that get selected should not depend on.  So the
following would not be ok, although it seems to work?

diff --git a/arch/Kconfig b/arch/Kconfig
@@ -495,6 +495,8 @@ config HAVE_UNWIND_USER_FP

 config HAVE_UNWIND_USER_SFRAME
	bool
+	depends on 64BIT
+	depends on HAVE_EFFICIENT_UNALIGNED_ACCESS
	select UNWIND_USER

 config SFRAME_VALIDATION

This would trigger a warning if HAVE_UNWIND_USER_SFRAME is enabled when
64BIT and/or HAVE_EFFICIENT_UNALIGNED_ACCESS are not enabled (disabled
on purpose for testing below):

$ PATH=$HOME/temp/binutils-sframe/bin:$PATH make defconfig W=e
*** Default configuration is based on 'defconfig'

WARNING: unmet direct dependencies detected for HAVE_UNWIND_USER_SFRAME
  Depends on [n]: 64BIT [=y] && HAVE_EFFICIENT_UNALIGNED_ACCESS [=n]
  Selected by [y]:
  - S390 [=y]


Shall I better use BUILD_BUG_ON(!IS_ENABLED(CONFIG_...)) instead?  Would
I add that to all functions that are affected (i.e. __read_fre(),
__read_default_fre_datawords(), and __read_flex_fde_fre_datawords()),
duplicating the build-time error message, or would I better introduce a
dummy function to check this precondition (and 64-bit arch), for
instance:

diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c
@@ -886,3 +904,20 @@ void sframe_free_mm(struct mm_struct *mm)

        mtree_destroy(&mm->sframe_mt);
 }
+
+void __init sframe_check(void);
+
+/*
+ * Dummy function to break the build if preconditions not met.
+ */
+void __init sframe_check(void)
+{
+       /* SFrame V3 is only supported on 64-bit architectures */
+       BUILD_BUG_ON(!IS_ENABLED(CONFIG_64BIT));
+
+       /*
+        * Unaligned access to 16/32-bit SFrame FRE fields and datawords
+        * using unsafe_get_user() via UNSAFE_GET_USER_INC()
+        */
+       BUILD_BUG_ON(!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS));
+}

Thanks and regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
[email protected] / [email protected]

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/