Skip to contentSkip to conversation

x86/vdso: VDSO updates and fixes for sframes

PATCH Superseded Jens Remus 3 participants 14 messages Feb 6 – Feb 10

Subsystems (9)
Memory management x86 Kbuild BPF +5 more subsystems

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
author
#3 lore raw

PATCH v8 3/6 x86/asm: Use CFI_* macros in SYM_FUNC_* macros so they can be added to VDSO

In reply to Jens Remus

From: Josh Poimboeuf <[email protected]>

Add CFI_STARTPROC and CFI_ENDPROC annotations to the SYM_FUNC_* macros so the VDSO asm functions don't need to add them manually. Note this only affects VDSO, the CFI_* macros are empty for the kernel proper.

---

Notes (jremus):
Changes in v8:
- Reword commit subject to Steven's v6 one:
https://lore.kernel.org/all/[email protected]/
- Drop my changelog from the commit message, as the patch is now identical to Steven's v6.

 arch/x86/entry/vdso/common/vdso-layout.lds.S  |  2 +-
 .../x86/entry/vdso/vdso64/vgetrandom-chacha.S |  2 --
 arch/x86/entry/vdso/vdso64/vsgx.S             |  4 ---
 arch/x86/include/asm/linkage.h                | 33 +++++++++++++++----
 arch/x86/include/asm/vdso.h                   |  1 -
 5 files changed, 28 insertions(+), 14 deletions(-)
arch/x86/entry/vdso/common/vdso-layout.lds.S +1 -1
index a1e30be3e83d..856b8b9d278c 100644
@@ -1,5 +1,5 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#include <asm/vdso.h>
+#include <asm/page_types.h>
 #include <asm/vdso/vsyscall.h>
 #include <vdso/datapage.h>
 
arch/x86/entry/vdso/vdso64/vgetrandom-chacha.S +0 -2
index cc82da9216fb..a33212594731 100644
@@ -22,7 +22,6 @@ CONSTANTS:	.octa 0x6b20657479622d323320646e61707865
  *	rcx: number of 64-byte blocks to write to output
  */
 SYM_FUNC_START(__arch_chacha20_blocks_nostack)
-	CFI_STARTPROC
 .set	output,		%rdi
 .set	key,		%rsi
 .set	counter,	%rdx
@@ -175,5 +174,4 @@ SYM_FUNC_START(__arch_chacha20_blocks_nostack)
 	pxor		temp,temp
 
 	ret
-	CFI_ENDPROC
 SYM_FUNC_END(__arch_chacha20_blocks_nostack)
arch/x86/entry/vdso/vdso64/vsgx.S +0 -4
index 37a3d4c02366..c0342238c976 100644
@@ -24,8 +24,6 @@
 .section .text, "ax"
 
 SYM_FUNC_START(__vdso_sgx_enter_enclave)
-	/* Prolog */
-	.cfi_startproc
 	push	%rbp
 	.cfi_adjust_cfa_offset	8
 	.cfi_rel_offset		%rbp, 0
@@ -143,8 +141,6 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave)
 	jle	.Lout
 	jmp	.Lenter_enclave
 
-	.cfi_endproc
-
 _ASM_VDSO_EXTABLE_HANDLE(.Lenclu_eenter_eresume, .Lhandle_exception)
 
 SYM_FUNC_END(__vdso_sgx_enter_enclave)
arch/x86/include/asm/linkage.h +27 -6
index 9d38ae744a2e..9d7f90c57451 100644
@@ -40,6 +40,10 @@
 
 #ifdef __ASSEMBLER__
 
+#ifndef LINKER_SCRIPT
+#include <asm/dwarf2.h>
+#endif
+
 #if defined(CONFIG_MITIGATION_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO)
 #define RET	jmp __x86_return_thunk
 #else /* CONFIG_MITIGATION_RETPOLINE */
@@ -112,34 +116,51 @@
 # define SYM_FUNC_ALIAS_MEMFUNC	SYM_FUNC_ALIAS
 #endif
 
+#define __SYM_FUNC_START				\
+	CFI_STARTPROC ASM_NL
+
+#define __SYM_FUNC_END					\
+	CFI_ENDPROC ASM_NL
+
 /* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */
 #define SYM_TYPED_FUNC_START(name)				\
 	SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_F_ALIGN)	\
+	__SYM_FUNC_START					\
 	ENDBR
 
 /* SYM_FUNC_START -- use for global functions */
 #define SYM_FUNC_START(name)				\
-	SYM_START(name, SYM_L_GLOBAL, SYM_F_ALIGN)
+	SYM_START(name, SYM_L_GLOBAL, SYM_F_ALIGN)	\
+	__SYM_FUNC_START
 
 /* SYM_FUNC_START_NOALIGN -- use for global functions, w/o alignment */
 #define SYM_FUNC_START_NOALIGN(name)			\
-	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)
+	SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE)	\
+	__SYM_FUNC_START
 
 /* SYM_FUNC_START_LOCAL -- use for local functions */
 #define SYM_FUNC_START_LOCAL(name)			\
-	SYM_START(name, SYM_L_LOCAL, SYM_F_ALIGN)
+	SYM_START(name, SYM_L_LOCAL, SYM_F_ALIGN)	\
+	__SYM_FUNC_START
 
 /* SYM_FUNC_START_LOCAL_NOALIGN -- use for local functions, w/o alignment */
 #define SYM_FUNC_START_LOCAL_NOALIGN(name)		\
-	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)
+	SYM_START(name, SYM_L_LOCAL, SYM_A_NONE)	\
+	__SYM_FUNC_START
 
 /* SYM_FUNC_START_WEAK -- use for weak functions */
 #define SYM_FUNC_START_WEAK(name)			\
-	SYM_START(name, SYM_L_WEAK, SYM_F_ALIGN)
+	SYM_START(name, SYM_L_WEAK, SYM_F_ALIGN)	\
+	__SYM_FUNC_START
 
 /* SYM_FUNC_START_WEAK_NOALIGN -- use for weak functions, w/o alignment */
 #define SYM_FUNC_START_WEAK_NOALIGN(name)		\
-	SYM_START(name, SYM_L_WEAK, SYM_A_NONE)
+	SYM_START(name, SYM_L_WEAK, SYM_A_NONE)		\
+	__SYM_FUNC_START
+
+#define SYM_FUNC_END(name)				\
+	__SYM_FUNC_END					\
+	SYM_END(name, SYM_T_FUNC)
 
 /*
  * Expose 'sym' to the startup code in arch/x86/boot/startup/, by emitting an
arch/x86/include/asm/vdso.h +0 -1
index e8afbe9faa5b..498ac423741c 100644
@@ -2,7 +2,6 @@
 #ifndef _ASM_X86_VDSO_H
 #define _ASM_X86_VDSO_H
 
-#include <asm/page_types.h>
 #include <linux/linkage.h>
 #include <linux/init.h>
 
Signature · 1 line
2.51.0
author
#2 lore raw

PATCH v8 2/6 x86/asm: Avoid emitting DWARF CFI for non-VDSO

In reply to Jens Remus

From: Josh Poimboeuf <[email protected]>

It was decided years ago that .cfi_* annotations aren't maintainable in the kernel. They were replaced by objtool unwind hints. For the kernel proper, ensure the CFI_* macros don't do anything.

On the other hand the VDSO library *does* use them, so user space can unwind through it.

Make sure these macros only work for VDSO. They aren't actually being used outside of VDSO anyway, so there's no functional change.

[ Jens Remus: Define CFI_SIGNAL_FRAME for !BUILD_VDSO. ]

---

Notes (jremus):
Changes in v8:
- Define CFI_SIGNAL_FRAME for !BUILD_VDSO (new on tip:x86/entry).

 arch/x86/include/asm/dwarf2.h | 52 ++++++++++++++++++++++++-----------
 1 file changed, 36 insertions(+), 16 deletions(-)
arch/x86/include/asm/dwarf2.h +36 -16
index 09c9684d3ad6..13e2e64ef265 100644
@@ -6,6 +6,15 @@
 #warning "asm/dwarf2.h should be only included in pure assembly files"
 #endif
 
+#ifdef BUILD_VDSO
+
+	/*
+	 * For the vDSO, emit both runtime unwind information and debug
+	 * symbols for the .dbg file.
+	 */
+
+	.cfi_sections .eh_frame, .debug_frame
+
 #define CFI_STARTPROC		.cfi_startproc
 #define CFI_ENDPROC		.cfi_endproc
 #define CFI_DEF_CFA		.cfi_def_cfa
@@ -22,21 +31,32 @@
 #define CFI_ESCAPE		.cfi_escape
 #define CFI_SIGNAL_FRAME	.cfi_signal_frame
 
-#ifndef BUILD_VDSO
-	/*
-	 * Emit CFI data in .debug_frame sections, not .eh_frame sections.
-	 * The latter we currently just discard since we don't do DWARF
-	 * unwinding at runtime.  So only the offline DWARF information is
-	 * useful to anyone.  Note we should not use this directive if we
-	 * ever decide to enable DWARF unwinding at runtime.
-	 */
-	.cfi_sections .debug_frame
-#else
-	 /*
-	  * For the vDSO, emit both runtime unwind information and debug
-	  * symbols for the .dbg file.
-	  */
-	.cfi_sections .eh_frame, .debug_frame
-#endif
+#else /* !BUILD_VDSO */
+
+/*
+ * On x86, these macros aren't used outside VDSO.  As well they shouldn't be:
+ * they're fragile and very difficult to maintain.
+ */
+
+.macro nocfi args:vararg
+.endm
+
+#define CFI_STARTPROC		nocfi
+#define CFI_ENDPROC		nocfi
+#define CFI_DEF_CFA		nocfi
+#define CFI_DEF_CFA_REGISTER	nocfi
+#define CFI_DEF_CFA_OFFSET	nocfi
+#define CFI_ADJUST_CFA_OFFSET	nocfi
+#define CFI_OFFSET		nocfi
+#define CFI_REL_OFFSET		nocfi
+#define CFI_REGISTER		nocfi
+#define CFI_RESTORE		nocfi
+#define CFI_REMEMBER_STATE	nocfi
+#define CFI_RESTORE_STATE	nocfi
+#define CFI_UNDEFINED		nocfi
+#define CFI_ESCAPE		nocfi
+#define CFI_SIGNAL_FRAME	nocfi
+
+#endif /* !BUILD_VDSO */
 
 #endif /* _ASM_X86_DWARF2_H */
Signature · 1 line
2.51.0
author
#1 lore raw

PATCH v8 1/6 x86/vdso: Fix DWARF generation for getrandom()

In reply to Jens Remus

From: Josh Poimboeuf <[email protected]>

Add CFI annotations to the VDSO implementation of getrandom() so it will have valid DWARF unwinding metadata.

Fixes 33385150ac45 ("x86: vdso: Wire up getrandom() vDSO implementation")
---
 arch/x86/entry/vdso/vdso64/vgetrandom-chacha.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/entry/vdso/vdso64/vgetrandom-chacha.S +3 -2
index bcba5639b8ee..cc82da9216fb 100644
@@ -4,7 +4,7 @@
  */
 
 #include <linux/linkage.h>
-#include <asm/frame.h>
+#include <asm/dwarf2.h>
 
 .section	.rodata, "a"
 .align 16
@@ -22,7 +22,7 @@ CONSTANTS:	.octa 0x6b20657479622d323320646e61707865
  *	rcx: number of 64-byte blocks to write to output
  */
 SYM_FUNC_START(__arch_chacha20_blocks_nostack)
-
+	CFI_STARTPROC
 .set	output,		%rdi
 .set	key,		%rsi
 .set	counter,	%rdx
@@ -175,4 +175,5 @@ SYM_FUNC_START(__arch_chacha20_blocks_nostack)
 	pxor		temp,temp
 
 	ret
+	CFI_ENDPROC
 SYM_FUNC_END(__arch_chacha20_blocks_nostack)
Signature · 1 line
2.51.0
author
#5 lore raw

PATCH v8 5/6 x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

In reply to Jens Remus

From: Josh Poimboeuf <[email protected]>

Use the CFI macros instead of the raw .cfi_* directives to be consistent with the rest of the VDSO asm. It's also easier on the eyes.

No functional changes.

---

Notes (jremus):
Changes in v8:
- Remove SYM_F_ALIGN. (Josh)
https://lore.kernel.org/all/amh7fzsjx4p5nowy3b3j6blkty5ojqf7jawtlslexwzdbxrhc3@zersgacmcnai/

 arch/x86/entry/vdso/vdso64/vsgx.S | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vdso64/vsgx.S +6 -8
index c0342238c976..76efbeb1e287 100644
@@ -25,12 +25,12 @@
 
 SYM_FUNC_START(__vdso_sgx_enter_enclave)
 	push	%rbp
-	.cfi_adjust_cfa_offset	8
-	.cfi_rel_offset		%rbp, 0
+	CFI_ADJUST_CFA_OFFSET	8
+	CFI_REL_OFFSET		%rbp, 0
 	mov	%rsp, %rbp
-	.cfi_def_cfa_register	%rbp
+	CFI_DEF_CFA_REGISTER	%rbp
 	push	%rbx
-	.cfi_rel_offset		%rbx, -8
+	CFI_REL_OFFSET		%rbx, -8
 
 	mov	%ecx, %eax
 .Lenter_enclave:
@@ -77,13 +77,11 @@ SYM_FUNC_START(__vdso_sgx_enter_enclave)
 .Lout:
 	pop	%rbx
 	leave
-	.cfi_def_cfa		%rsp, 8
+	CFI_DEF_CFA		%rsp, 8
 	RET
 
-	/* The out-of-line code runs with the pre-leave stack frame. */
-	.cfi_def_cfa		%rbp, 16
-
 .Linvalid_input:
+	CFI_DEF_CFA		%rbp, 16
 	mov	$(-EINVAL), %eax
 	jmp	.Lout
 
Signature · 1 line
2.51.0

Jens Remus

author
#0 lore raw

v8 cover x86/vdso: VDSO updates and fixes for sframes

This enables generation of SFrame V3 stack trace information for VDSO on x86-64. It's a continuation of Josh's and Steve's work:

https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

This series focuses only on the VDSO code. They are helpful fixes and updates that doesn't rely on sframes (although the last patch is sframe related).

This series applies on top of tip:x86/entry:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/entry

Like the unwind user sframe series [1] it depends on the upcoming binutils 2.46 release to be used to build the VDSO with SFrame V3 stack trace information (using the assembler option --gsframe-3).

[1]: [PATCH v13 00/18] unwind_deferred: Implement sframe handling,

    https://lore.kernel.org/all/[email protected]/

Changes in v8 (see individual patch notes):
- Discard .sframe for x32 and x86-32 VDSOs. (Josh/Indu)
- Define CFI_SIGNAL_FRAME for !BUILD_VDSO.
- Drop .cfi_sections .sframe in dwarf2.h in favor of the explicitly specified more specific assembler option --gsframe-3.
- Incorporate missing changes and review feedback from Steven's v6 (I erroneously based my v6 on Steven's v5):
- Reword patch 3 commit subject to Steven's v6 one.
- Remove SYM_F_ALIGN in __vdso_sgx_enter_enclave(). (Josh)

Changes in v7 (see individual patch notes):
- Rebase on H. Peter Anvin's vDSO changes on tip:x86/entry. (Peter)
- Simplify adding assembler option -Wa,--gsframe-3. Add for vdso64 only.
- Align to .eh_frame and mark .sframe as KEEP in vDSO linker script. Note that GNU linker 2.46 will mark .sframe as KEEP in its default linker script as well.

Changes in v6:
- SFrame V3 support (SFrame V2 is not supported).
- Prevent GNU_SFRAME program table entry to empty .sframe section.
- Integrate v5 review feedback. (Josh)

I verified as follows on x86-64 using a binutils 2.46 pre-release build that only the x86-64 VDSO has an .sframe section and GNU_SFRAME program table entry:

$ make defconfig
*** Default configuration is based on 'x86_64_defconfig'
$ make arch/x86/entry/vdso/
  OBJCOPY arch/x86/entry/vdso/vdso64/vdso64.so
  VDSO2C  arch/x86/entry/vdso/vdso64/vdso64-image.c
  VDSO    arch/x86/entry/vdso/vdso32/vdso32.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso32/vdso32.so
$ readelf -WSl arch/x86/entry/vdso/vdso*/vdso*.so | egrep "File:|GNU_SFRAME"
File: arch/x86/entry/vdso/vdso32/vdso32.so
File: arch/x86/entry/vdso/vdso64/vdso64.so
  [13] .sframe           GNU_SFRAME      00000000000007e0 0007e0 00012b 00   A  0   0  8
  GNU_SFRAME     0x0007e0 0x00000000000007e0 0x00000000000007e0 0x00012b 0x00012b R   0x8
$ make defconfig
*** Default configuration is based on 'x86_64_defconfig'
$ ./scripts/config --enable X86_X32_ABI
$ make arch/x86/entry/vdso/
  VDSO    arch/x86/entry/vdso/vdso64/vdso64.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso64/vdso64.so
  VDSO    arch/x86/entry/vdso/vdso64/vdsox32.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso64/vdsox32.so
  VDSO    arch/x86/entry/vdso/vdso32/vdso32.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso32/vdso32.so
$ readelf -WSl arch/x86/entry/vdso/vdso*/vdso*.so | egrep "File:|GNU_SFRAME"
File: arch/x86/entry/vdso/vdso32/vdso32.so
File: arch/x86/entry/vdso/vdso64/vdso64.so
  [13] .sframe           GNU_SFRAME      00000000000007e0 0007e0 00012b 00   A  0   0  8
  GNU_SFRAME     0x0007e0 0x00000000000007e0 0x00000000000007e0 0x00012b 0x00012b R   0x8
File: arch/x86/entry/vdso/vdso64/vdsox32.so
$ make ARCH=i386 defconfig
*** Default configuration is based on 'i386_defconfig'
$ make ARCH=i386 arch/x86/entry/vdso/
  VDSO    arch/x86/entry/vdso/vdso32/vdso32.so.dbg
  OBJCOPY arch/x86/entry/vdso/vdso32/vdso32.so
$ readelf -WSl arch/x86/entry/vdso/vdso*/*.so | egrep "File:|GNU_SFRAME"

Regards,
Jens

Josh Poimboeuf (6):
x86/vdso: Fix DWARF generation for getrandom()
x86/asm: Avoid emitting DWARF CFI for non-VDSO
x86/asm: Use CFI_* macros in SYM_FUNC_* macros so they can be added to
VDSO
x86/vdso: Use SYM_FUNC_{START,END} in __kernel_vsyscall() x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave() x86/vdso: Enable sframe generation in VDSO

 arch/Kconfig                                  |  7 +++
 arch/x86/entry/vdso/common/vdso-layout.lds.S  | 17 +++++-
 arch/x86/entry/vdso/vdso32/system_call.S      | 10 +---
 arch/x86/entry/vdso/vdso64/Makefile           |  1 +
 arch/x86/entry/vdso/vdso64/vdso64.lds.S       |  4 ++
 .../x86/entry/vdso/vdso64/vgetrandom-chacha.S |  3 +-
 arch/x86/entry/vdso/vdso64/vsgx.S             | 18 +++----
 arch/x86/include/asm/dwarf2.h                 | 52 +++++++++++++------
 arch/x86/include/asm/linkage.h                | 33 +++++++++---
 arch/x86/include/asm/vdso.h                   |  1 -
 10 files changed, 100 insertions(+), 46 deletions(-)
Signature · 1 line
2.51.0
author
#4 lore raw

PATCH v8 4/6 x86/vdso: Use SYM_FUNC_{START,END} in __kernel_vsyscall()

From: Josh Poimboeuf <[email protected]>

Use SYM_FUNC_{START,END} instead of all the boilerplate. No functional change.

---
 arch/x86/entry/vdso/vdso32/system_call.S | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vdso32/system_call.S +2 -8
index 9157cf9c5749..a90f4f7de396 100644
@@ -9,11 +9,7 @@
 #include <asm/alternative.h>
 
 	.text
-	.globl __kernel_vsyscall
-	.type __kernel_vsyscall,@function
-	ALIGN
-__kernel_vsyscall:
-	CFI_STARTPROC
+SYM_FUNC_START(__kernel_vsyscall)
 
 	/*
 	 * If using int $0x80, there is no reason to muck about with the
@@ -85,7 +81,5 @@ SYM_INNER_LABEL(int80_landing_pad, SYM_L_GLOBAL)
 	CFI_RESTORE		ecx
 	CFI_ADJUST_CFA_OFFSET	-4
 	RET
-	CFI_ENDPROC
-
-	.size __kernel_vsyscall,.-__kernel_vsyscall
+SYM_FUNC_END(__kernel_vsyscall)
 	.previous
Signature · 1 line
2.51.0
author
#6 lore raw

PATCH v8 6/6 x86/vdso: Enable sframe generation in VDSO

In reply to Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

---

Notes (jremus):
Changes in v8:
- Discard .sframe for x32 and x86-32 VDSOs. (Josh/Indu) Note that the use of KEEP_SFRAME enables to define it for x86-64 VDSO only. Unlike CONFIG_AS_SFRAME, which may also be defined for x32 and x86-32 VDSO. In x32 VDSO it would result in superfluous .sframe (copied from the x86-64 build - could be removed in X32 build step). In x86-32 VDSO it would cause a bogus GNU_SFRAME program table entry.
- Reword commit message (append Josh's private fix).
- Drop .cfi_sections .sframe in dwarf2.h in favor of the explicitly specified more specific assembler option --gsframe-3. With this it is not necessary to undefine CONFIG_AS_SFRAME in fake_32bit_build.h.

 arch/Kconfig                                 |  7 +++++++
 arch/x86/entry/vdso/common/vdso-layout.lds.S | 15 +++++++++++++++
 arch/x86/entry/vdso/vdso64/Makefile          |  1 +
 arch/x86/entry/vdso/vdso64/vdso64.lds.S      |  4 ++++
 4 files changed, 27 insertions(+)
arch/Kconfig +7 -0
index 31220f512b16..8170e492a44c 100644
@@ -479,6 +479,13 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
 	  It uses the same command line parameters, and sysctl interface,
 	  as the generic hardlockup detectors.
 
+config AS_SFRAME
+	bool
+
+config AS_SFRAME3
+	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,-Wa$(comma)--gsframe-3)
+	select AS_SFRAME
+
 config UNWIND_USER
 	bool
 
arch/x86/entry/vdso/common/vdso-layout.lds.S +15 -0
index 856b8b9d278c..47e6a6a0560a 100644
@@ -60,6 +60,13 @@ SECTIONS
 		*(.eh_frame.*)
 	}					:text
 
+#ifdef KEEP_SFRAME
+	.sframe		: {
+		KEEP (*(.sframe))
+		*(.sframe.*)
+	}					:text	:sframe
+#endif
+
 	/*
 	 * Text is well-separated from actual data: there's plenty of
 	 * stuff that isn't used at runtime in between.
@@ -80,6 +87,10 @@ SECTIONS
 		*(.discard)
 		*(.discard.*)
 		*(__bug_table)
+#ifndef KEEP_SFRAME
+		*(.sframe)
+		*(.sframe.*)
+#endif
 	}
 }
 
@@ -89,6 +100,7 @@ SECTIONS
 #define PT_GNU_EH_FRAME	0x6474e550
 #define PT_GNU_STACK	0x6474e551
 #define PT_GNU_PROPERTY	0x6474e553
+#define PT_GNU_SFRAME	0x6474e554
 
 /*
  * We must supply the ELF program headers explicitly to get just one
@@ -104,6 +116,9 @@ PHDRS
 	dynamic		PT_DYNAMIC	PF_R;
 	note		PT_NOTE		PF_R;
 	eh_frame_hdr	PT_GNU_EH_FRAME PF_R;
+#ifdef KEEP_SFRAME
+	sframe		PT_GNU_SFRAME	PF_R;
+#endif
 	gnu_stack	PT_GNU_STACK	PF_RW;
 	gnu_property	PT_GNU_PROPERTY	PF_R;
 }
arch/x86/entry/vdso/vdso64/Makefile +1 -0
index bfffaf1aeecc..459f8026531e 100644
@@ -14,6 +14,7 @@ vobjs-$(CONFIG_X86_SGX)		+= vsgx.o
 
 # Compilation flags
 flags-y				:= -DBUILD_VDSO64 -m64 -mcmodel=small
+flags-$(CONFIG_AS_SFRAME3)	+= -Wa,--gsframe-3
 
 # The location of this include matters!
 include $(src)/../common/Makefile.include
arch/x86/entry/vdso/vdso64/vdso64.lds.S +4 -0
index 5ce3f2b6373a..13e30d3b4827 100644
@@ -9,6 +9,10 @@
 
 #define BUILD_VDSO64
 
+#ifdef CONFIG_AS_SFRAME
+# define KEEP_SFRAME
+#endif
+
 #include "common/vdso-layout.lds.S"
 
 /*
Signature · 1 line
2.51.0
#7 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

Quoted 11 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

This will not break the x86-32 build if the assembler encounters .sframe?

Quoted 9 lines

Notes (jremus):
Changes in v8:
- Discard .sframe for x32 and x86-32 VDSOs. (Josh/Indu) Note that the use of KEEP_SFRAME enables to define it for x86-64 VDSO only. Unlike CONFIG_AS_SFRAME, which may also be defined for x32 and x86-32 VDSO. In x32 VDSO it would result in superfluous .sframe (copied from the x86-64 build - could be removed in X32 build step). In x86-32 VDSO it would cause a bogus GNU_SFRAME program table entry.

For x32, this would be a "valid" sframe, right, even if the tools currently don't know how to consume it (and potentially never will)? If so, is there really any reason to explicitly remove it?

arch/x86/entry/vdso/common/vdso-layout.lds.S SECTIONS · line 93

Quoted 11 lines
arch/x86/entry/vdso/common/vdso-layout.lds.S +4 -0
 	/*
 	 * Text is well-separated from actual data: there's plenty of
 	 * stuff that isn't used at runtime in between.
@@ -80,6 +87,10 @@ SECTIONS
 		*(.discard)
 		*(.discard.*)
 		*(__bug_table)
+#ifndef KEEP_SFRAME
+		*(.sframe)
+		*(.sframe.*)
+#endif

This #ifndef is actually not necessary: if we have already "consumed" the .sframe* sections they will not be encountered here.

I would prefer to have KEEP_SFRAME always defined (as true or false, and using #if) instead of using #ifdef. I believe that also means you can do:

#define KEEP_SFRAME IS_ENABLED(CONFIG_AS_SFRAME)

... instead of #ifdef.

-hpa

author
#8 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

Quoted 8 lines
Quoted 6 lines

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

This will not break the x86-32 build if the assembler encounters .sframe?

I cannot follow. Assembler option --gsframe-3 is only specified in vdso64/Makefile if CONFIG_AS_SFRAME3, which affects the x86-64 and x32 VDSOs. The latter as the x32 VDSO is built from x86-64 objects converted to x86-32 objects using the X32 build step. Assembler directive ".cfi_sections .sframe" is no longer used in dwarf2.h, which affected the x86-32 VDSO if cross build on x86-64 (so that CONFIG_AS_SFRAME3=y).

The reason to discard .sframe in the common VDSO linker script if !KEEP_SFRAME is to remove it from x32 VDSO (built from x86-64 objects having .sframe). It should also prevent linker errors from linkers that do not support R_X86_64_PC64 in x32 mode, such as the meanwhile fixed GNU linker:
https://www.sourceware.org/bugzilla/show_bug.cgi?id=33807

Quoted 11 lines
Quoted 10 lines

Notes (jremus):
Changes in v8:
- Discard .sframe for x32 and x86-32 VDSOs. (Josh/Indu) Note that the use of KEEP_SFRAME enables to define it for x86-64 VDSO only. Unlike CONFIG_AS_SFRAME, which may also be defined for x32 and x86-32 VDSO. In x32 VDSO it would result in superfluous .sframe (copied from the x86-64 build - could be removed in X32 build step). In x86-32 VDSO it would cause a bogus GNU_SFRAME program table entry.

Quoted 3 lines

For x32, this would be a "valid" sframe, right, even if the tools currently don't know how to consume it (and potentially never will)? If so, is there really any reason to explicitly remove it?

I am not an x86 expert. IIUC the x32 ABI uses 4-byte pointers. But GCC with option -mx32 emits DWARF that suggests that at least the return address (RA) and frame pointer (FP; rbp) are still pushed as 8-byte values on the stack, which would be relevant for SFrame:

00000000 <foo>:

   0:   55                      push   %rbp
   1:   89 e5                   mov    %esp,%ebp

...

   LOC           CFA      rbp   ra
0000000000000000 rsp+8    u     c-8   <-- suggests RA is 8-bytes on stack
0000000000000001 rsp+16   c-16  c-8   <-- suggests FP is 8-bytes on stack

...

That could mean that technically the .sframe would be mostly valid. The fixed RA offset of -8 would be correct, the variable FP offset would be tracked, and the implicit SP rule SP=CFA should be correct as well. But the SFrame header would incorrectly specify AMD64 as ABI/arch ID instead of ILP32 (if I got the ELF x86-64-ABI psABI [1] correct).

AFAIK SFrame does not officially support ILP32. At least GNU assembler does not:

$ printf ".cfi_startproc\n.cfi_endproc\n" | as --gsframe-3 --x32 ; echo $?
Assembler messages:
{standard input}: Error: .sframe not supported for target
1

My take would be that it would be better to build x32 VDSO without .sframe (or discard .sframe from x32 VDSO), unless it is officially supported.

@Indu: What are your thoughts as SFrame maintainer?

[1]: ELF x86-64-ABI psABI,

     https://gitlab.com/x86-psABIs/x86-64-ABI
Quoted 6 lines
Quoted 6 lines
(quoted diff) +0 -0
 	/*
 	 * Text is well-separated from actual data: there's plenty of
 	 * stuff that isn't used at runtime in between.
@@ -80,6 +87,10 @@ SECTIONS
 		*(.discard)
 		*(.discard.*)
Quoted 8 lines

Review SECTIONS · line 93

Quoted 5 lines
(quoted diff) +4 -0
 		*(__bug_table)
+#ifndef KEEP_SFRAME
+		*(.sframe)
+		*(.sframe.*)
+#endif

This #ifndef is actually not necessary: if we have already "consumed" the .sframe* sections they will not be encountered here.

It is necessary to remove .sframe from x86-64 objects (created by the x86-64 VDSO build) converted to x86-32 objects in the X32 build step for x32 VDSO, provided SFrame is not supported for x32. The x86-64 VDSO has .sframe, as the x86-64 VDSO linker script defines KEEP_SFRAME. The x32 VDSO has .sframe removed, as the x32 linker script does not define KEEP_SFRAME.

An alternative to the #ifndef (or #if !KEEP_SFRAME) would be to remove the .sframe in the X32 build step:

arch/x86/entry/vdso/vdso64/Makefile +2 -2
@@ -23,14 +24,14 @@ include $(src)/../common/Makefile.include
 #
 # Build x32 vDSO image:
 # 1. Compile x32 vDSO as 64bit.
-# 2. Convert object files to x32.
+# 2. Convert object files to x32 and remove .sframe.
 # 3. Build x32 VDSO image with x32 objects, which contains 64bit codes
 # so that it can reach 64bit address space with 64bit pointers.
 #
 
 # Convert 64bit object file to x32 for x32 vDSO.
 quiet_cmd_x32 = X32     $@
-      cmd_x32 = $(OBJCOPY) -O elf32-x86-64 $< $@
+      cmd_x32 = $(OBJCOPY) -O elf32-x86-64 -R .sframe $< $@
 
 $(obj)/%-x32.o: $(obj)/%.o FORCE
	$(call if_changed,x32)

KEEP_SFRAME (or then maybe better HAVE_SFRAME) would then still be required to only emit a program table entry, if .sframe was generated.

Note that AS_SFRAME only indicates whether the assembler supports to generate .sframe. Not whether if it should actually be done. That is selected by adding the --gsframe-3 assembler option and defining KEEP_SFRAME to true, which is done in the respective VDSO Makefile and linker script.

Quoted 6 lines

I would prefer to have KEEP_SFRAME always defined (as true or false, and using #if) instead of using #ifdef. I believe that also means you can do:

#define KEEP_SFRAME IS_ENABLED(CONFIG_AS_SFRAME)

... instead of #ifdef.

The following works and indeed looks nicer with #if KEEP_SFRAME. Will wait for further feedback on whether or not to discard .sframe in x32 VDSO before sending a v9.

arch/x86/entry/vdso/common/vdso-layout.lds.S +3 -3
@@ -60,7 +60,7 @@ SECTIONS
 		*(.eh_frame.*)
 	}					:text
 
-#ifdef KEEP_SFRAME
+#if KEEP_SFRAME
 	.sframe		: {
 		KEEP (*(.sframe))
 		*(.sframe.*)
@@ -87,7 +87,7 @@ SECTIONS
 		*(.discard)
 		*(.discard.*)
 		*(__bug_table)
-#ifndef KEEP_SFRAME
+#if !KEEP_SFRAME
 		*(.sframe)
 		*(.sframe.*)
 #endif
@@ -116,7 +116,7 @@ PHDRS
 	dynamic		PT_DYNAMIC	PF_R;
 	note		PT_NOTE		PF_R;
 	eh_frame_hdr	PT_GNU_EH_FRAME PF_R;
-#ifdef KEEP_SFRAME
+#if KEEP_SFRAME
 	sframe		PT_GNU_SFRAME	PF_R;
 #endif
 	gnu_stack	PT_GNU_STACK	PF_RW;
arch/x86/entry/vdso/vdso32/vdso32.lds.S +1 -0
@@ -10,6 +10,7 @@
 #include <asm/page.h>
 
 #define BUILD_VDSO32
+#define KEEP_SFRAME	false
 
 #include "common/vdso-layout.lds.S"
 
arch/x86/entry/vdso/vdso64/vdso64.lds.S +1 -4
@@ -8,10 +8,7 @@
  */
 
 #define BUILD_VDSO64
-
-#ifdef CONFIG_AS_SFRAME
-# define KEEP_SFRAME
-#endif
+#define KEEP_SFRAME	(CONFIG_AS_SFRAME)
 
 #include "common/vdso-layout.lds.S"
 
arch/x86/entry/vdso/vdso64/vdsox32.lds.S +1 -0
@@ -8,6 +8,7 @@
  */
 
 #define BUILD_VDSOX32
+#define KEEP_SFRAME	false
 
 #include "common/vdso-layout.lds.S"
 

Thanks and regards,
Jens

Signature · 6 lines
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/
#9 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

Quoted 24 lines · Jens Remus
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

Quoted 8 lines
Quoted 6 lines

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

This will not break the x86-32 build if the assembler encounters .sframe?

I cannot follow. Assembler option --gsframe-3 is only specified in vdso64/Makefile if CONFIG_AS_SFRAME3, which affects the x86-64 and x32 VDSOs. The latter as the x32 VDSO is built from x86-64 objects converted to x86-32 objects using the X32 build step. Assembler directive ".cfi_sections .sframe" is no longer used in dwarf2.h, which affected the x86-32 VDSO if cross build on x86-64 (so that CONFIG_AS_SFRAME3=y).

Quoted 7 lines

The reason to discard .sframe in the common VDSO linker script if !KEEP_SFRAME is to remove it from x32 VDSO (built from x86-64 objects having .sframe). It should also prevent linker errors from linkers that do not support R_X86_64_PC64 in x32 mode, such as the meanwhile fixed GNU linker:
https://www.sourceware.org/bugzilla/show_bug.cgi?id=33807

OK, the linker not handing R_X86_64_PC64 is probably a good enough reason to discard .sframe.

The x32 ABI and object format is explicitly intended to be as close to the x86-64 as possible; it even uses the same architectural identifier. That's pretty much the reason we don't even bother recompiling the objects in the first place; the 64-bit objects can simply be downconverted from ELF64 to ELF32. This also means that the compiler doesn't need to support x32, although objcopy and ld does.

This also means the DWARF data is the one generated for 64 bits.

This works because the following is true for all vdso entrypoints:
- No vdso entry point access pointers or explicit "long"s *in memory*. (The latter formally violates POSIX for struct timespec, but that was a deliberate decision imposed by Linus at the time the x32 API was defined: "no 32-bit time_t in a new ABI.")
- No vdso entry point calls system calls that do, either.
- No vdso entry point takes a *signed* long as an argument.
- No vdso entry point calls system calls that differ in behavior between x86-64 and x32, making it OK to call the 64-bit system call from an x32 process.

"unsigned long" and pointers *can* be safely passed in argument registers (because the architecture will zero-extend those registers), and in addition "signed long" *can* be safely passed as returns.

If ANY of the constraints above were ever violated, OR the binary format would start diverging to the point that objcopy can't properly convert it, then we would need to start compiling the x32 binaries separately.

Quoted 3 lines

The following works and indeed looks nicer with #if KEEP_SFRAME. Will wait for further feedback on whether or not to discard .sframe in x32 VDSO before sending a v9.

I think ld tripping over a bug justifies dropping .sframe at this point. *Make sure* to document that in the checkin, and add a comment to vdso32.lds.S that that is the motivation, so that if x32 gains support for .sframe in the future (which should be simple enough, since the formats are so similar) we don't get stuck in some kind of cargo cult programming problem.

It also will avoid issues on the off chance .sframe ends up being defined differently for x32 for some reason, perhaps for consistency with other 32-bit platforms.

Include the version of binutils which fixed the problem in your comments.

-hpa

Quoted 39 lines
arch/x86/entry/vdso/common/vdso-layout.lds.S +3 -3
@@ -60,7 +60,7 @@ SECTIONS
 		*(.eh_frame.*)
 	}					:text
 
-#ifdef KEEP_SFRAME
+#if KEEP_SFRAME
 	.sframe		: {
 		KEEP (*(.sframe))
 		*(.sframe.*)
@@ -87,7 +87,7 @@ SECTIONS
 		*(.discard)
 		*(.discard.*)
 		*(__bug_table)
-#ifndef KEEP_SFRAME
+#if !KEEP_SFRAME
 		*(.sframe)
 		*(.sframe.*)
 #endif
@@ -116,7 +116,7 @@ PHDRS
 	dynamic		PT_DYNAMIC	PF_R;
 	note		PT_NOTE		PF_R;
 	eh_frame_hdr	PT_GNU_EH_FRAME PF_R;
-#ifdef KEEP_SFRAME
+#if KEEP_SFRAME
 	sframe		PT_GNU_SFRAME	PF_R;
 #endif
 	gnu_stack	PT_GNU_STACK	PF_RW;
arch/x86/entry/vdso/vdso32/vdso32.lds.S +1 -0
@@ -10,6 +10,7 @@
 #include <asm/page.h>
 
 #define BUILD_VDSO32
+#define KEEP_SFRAME	false
 
 #include "common/vdso-layout.lds.S"
 

arch/x86/entry/vdso/vdso64/vdso64.lds.S line 11

Quoted 8 lines
arch/x86/entry/vdso/vdso64/vdso64.lds.S +1 -4
@@ -8,10 +8,7 @@
  */
 
 #define BUILD_VDSO64
-
-#ifdef CONFIG_AS_SFRAME
-# define KEEP_SFRAME
-#endif
+#define KEEP_SFRAME	(CONFIG_AS_SFRAME)

This needs to be IS_ENABLED(CONFIG_AS_SFRAME). Otherwise you get either "y" or "CONFIG_AS_SFRAME", neither of which are what you want.

arch/x86/entry/vdso/vdso64/vdsox32.lds.S line 11

Quoted 8 lines
arch/x86/entry/vdso/vdso64/vdso64.lds.S +0 -0
 #include "common/vdso-layout.lds.S"
 
arch/x86/entry/vdso/vdso64/vdsox32.lds.S +1 -0
@@ -8,6 +8,7 @@
  */
 
 #define BUILD_VDSOX32
+#define KEEP_SFRAME	false

Is "false" supported by all appropriate cpp versions? "0" is probably a safer choice, and matches the IS_ENABLED() output anyway.

-hpa

author
#10 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

Quoted 33 lines · H. Peter Anvin
Quoted 24 lines · Jens Remus
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

Quoted 8 lines
Quoted 6 lines

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

This will not break the x86-32 build if the assembler encounters .sframe?

I cannot follow. Assembler option --gsframe-3 is only specified in vdso64/Makefile if CONFIG_AS_SFRAME3, which affects the x86-64 and x32 VDSOs. The latter as the x32 VDSO is built from x86-64 objects converted to x86-32 objects using the X32 build step. Assembler directive ".cfi_sections .sframe" is no longer used in dwarf2.h, which affected the x86-32 VDSO if cross build on x86-64 (so that CONFIG_AS_SFRAME3=y).

Quoted 7 lines

The reason to discard .sframe in the common VDSO linker script if !KEEP_SFRAME is to remove it from x32 VDSO (built from x86-64 objects having .sframe). It should also prevent linker errors from linkers that do not support R_X86_64_PC64 in x32 mode, such as the meanwhile fixed GNU linker:
https://www.sourceware.org/bugzilla/show_bug.cgi?id=33807

Quoted 2 lines

OK, the linker not handing R_X86_64_PC64 is probably a good enough reason to discard .sframe.

For clarification:

Binutils < 2.46 assembler generates SFrame V2, which uses PC32 relocations.
Binutils 2.46+ assembler will generate SFrame V3, which uses PC64 relocations, which the GNU linker will also support for x32.

The intent is to only support SFrame V3 in unwind user sframe and therefore also only enable .sframe generation in VDSO using SFrame V3.

Quoted 20 lines

The x32 ABI and object format is explicitly intended to be as close to the x86-64 as possible; it even uses the same architectural identifier. That's pretty much the reason we don't even bother recompiling the objects in the first place; the 64-bit objects can simply be downconverted from ELF64 to ELF32. This also means that the compiler doesn't need to support x32, although objcopy and ld does.

This also means the DWARF data is the one generated for 64 bits.

This works because the following is true for all vdso entrypoints:
- No vdso entry point access pointers or explicit "long"s *in memory*. (The latter formally violates POSIX for struct timespec, but that was a deliberate decision imposed by Linus at the time the x32 API was defined: "no 32-bit time_t in a new ABI.")
- No vdso entry point calls system calls that do, either.
- No vdso entry point takes a *signed* long as an argument.
- No vdso entry point calls system calls that differ in behavior between x86-64 and x32, making it OK to call the 64-bit system call from an x32 process.

Quoted 7 lines

"unsigned long" and pointers *can* be safely passed in argument registers (because the architecture will zero-extend those registers), and in addition "signed long" *can* be safely passed as returns.

If ANY of the constraints above were ever violated, OR the binary format would start diverging to the point that objcopy can't properly convert it, then we would need to start compiling the x32 binaries separately.

Thank you for the detailed explanation!

Quoted 10 lines
Quoted 3 lines

The following works and indeed looks nicer with #if KEEP_SFRAME. Will wait for further feedback on whether or not to discard .sframe in x32 VDSO before sending a v9.

I think ld tripping over a bug justifies dropping .sframe at this point. *Make sure* to document that in the checkin, and add a comment to vdso32.lds.S that that is the motivation, so that if x32 gains support for .sframe in the future (which should be simple enough, since the formats are so similar) we don't get stuck in some kind of cargo cult programming problem.

Quoted 6 lines

It also will avoid issues on the off chance .sframe ends up being defined differently for x32 for some reason, perhaps for consistency with other 32-bit platforms.

Include the version of binutils which fixed the problem in your comments.

Ok, will do.

Quoted 4 lines
Quoted 4 lines
arch/x86/entry/vdso/vdso64/vdso64.lds.S +0 -0
@@ -8,10 +8,7 @@
  */
 
Quoted 9 lines

arch/x86/entry/vdso/vdso64/vdso64.lds.S line 11

Quoted 6 lines
arch/x86/entry/vdso/vdso64/vdso64.lds.S +1 -4
 #define BUILD_VDSO64
-
-#ifdef CONFIG_AS_SFRAME
-# define KEEP_SFRAME
-#endif
+#define KEEP_SFRAME	(CONFIG_AS_SFRAME)

This needs to be IS_ENABLED(CONFIG_AS_SFRAME). Otherwise you get either "y" or "CONFIG_AS_SFRAME", neither of which are what you want.

Good catch! Will fix.

Quoted 7 lines
Quoted 7 lines
arch/x86/entry/vdso/vdso64/vdso64.lds.S +0 -0
 #include "common/vdso-layout.lds.S"
 
arch/x86/entry/vdso/vdso64/vdsox32.lds.S +0 -0
@@ -8,6 +8,7 @@
  */
 
Quoted 5 lines

arch/x86/entry/vdso/vdso64/vdsox32.lds.S line 11

Quoted 2 lines
arch/x86/entry/vdso/vdso64/vdsox32.lds.S +1 -0
 #define BUILD_VDSOX32
+#define KEEP_SFRAME	false

Is "false" supported by all appropriate cpp versions? "0" is probably a safer choice, and matches the IS_ENABLED() output anyway.

Will do. I assumed "true" / "false" would be supported, given there are a few instances:

  $ git grep "#define.*\(false\|true\)" -- arch/x86/

Regards,
Jens

Signature · 6 lines
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/
author
#11 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

In reply to Jens Remus
Quoted 18 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

arch/Kconfig config HAVE_HARDLOCKUP_DETECTOR_ARCH · line 486

Quoted 8 lines
arch/Kconfig +5 -0
@@ -479,6 +479,13 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
 	  It uses the same command line parameters, and sysctl interface,
 	  as the generic hardlockup detectors.
 
+config AS_SFRAME
+	bool
+
+config AS_SFRAME3
+	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,-Wa$(comma)--gsframe-3)

Above tests whether the assembler supports --gsframe-3 to generate .sframe in SFrame V3 format. GNU assembler only supports to generate SFrame for x86-64. If the assembler is built for i386 (x86-32) the test will fail unless option --64 is specified. I wonder whether that could happen in (the rather hypothetical?) case, when the kernel is cross built for x86-64 on i386? Should this therefore be changed to the following?

config AS_SFRAME_64

	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,$(m64-flag) -Wa$(comma)--gsframe)

An alternative would be to enable as-instr64 to accept an optional flag operand, similar to as-instr, and use as-instr64 instead of as-instr.

Or is this not required, as in a cross build for 64-bit on a 32-bit platform (or inverse) a respective cross toolchain is a prerequisite and the m64-flag (or m32-flag) is not used?

I tried to simulate this using docker and an i386 image and then using the i386 tool in the container to switch "uname -m" to "i686". But both of my following attempts to build for x86-64 on i386 fail with fixdep not found:

$ docker run -it --rm -v "$HOME/linux:$HOME/linux" --platform i386 public.ecr.aws/docker/library/debian:13.3
# sed -i -s 's/^Types: deb/& deb-src/' /etc/apt/sources.list.d/debian.sources
# apt update
# apt -y build-dep linux
# make mrproper
# i386 make ARCH=x86_64 defconfig
# i386 make ARCH=x86_64 arch/x86/entry/vdso/
# make mrproper
# apt -y install gcc-x86-64-linux-gnu
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- defconfig
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- arch/x86/entry/vdso/

arch/x86/entry/vdso/vdso64/Makefile vobjs-$(CONFIG_X86_SGX) += vsgx.o · line 17

Quoted 12 lines
arch/Kconfig +2 -0
+	select AS_SFRAME
+
 config UNWIND_USER
 	bool
 
arch/x86/entry/vdso/vdso64/Makefile +1 -0
@@ -14,6 +14,7 @@ vobjs-$(CONFIG_X86_SGX)		+= vsgx.o
 
 # Compilation flags
 flags-y				:= -DBUILD_VDSO64 -m64 -mcmodel=small
+flags-$(CONFIG_AS_SFRAME3)	+= -Wa,--gsframe-3

flags-$(CONFIG_AS_SFRAME3_64) += -Wa,--gsframe-3

arch/x86/entry/vdso/vdso64/Makefile vobjs-$(CONFIG_X86_SGX) += vsgx.o · line 20

Quoted 3 lines
arch/x86/entry/vdso/vdso64/Makefile +0 -0
 # The location of this include matters!
 include $(src)/../common/Makefile.include

Thanks and regards,
Jens

Signature · 6 lines
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/
#12 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

Quoted 80 lines · Jens Remus
Quoted 18 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

arch/Kconfig config HAVE_HARDLOCKUP_DETECTOR_ARCH · line 486

Quoted 8 lines
arch/Kconfig +5 -0
@@ -479,6 +479,13 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
 	  It uses the same command line parameters, and sysctl interface,
 	  as the generic hardlockup detectors.
 
+config AS_SFRAME
+	bool
+
+config AS_SFRAME3
+	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,-Wa$(comma)--gsframe-3)

Above tests whether the assembler supports --gsframe-3 to generate .sframe in SFrame V3 format. GNU assembler only supports to generate SFrame for x86-64. If the assembler is built for i386 (x86-32) the test will fail unless option --64 is specified. I wonder whether that could happen in (the rather hypothetical?) case, when the kernel is cross built for x86-64 on i386? Should this therefore be changed to the following?

config AS_SFRAME_64

	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,$(m64-flag) -Wa$(comma)--gsframe)

An alternative would be to enable as-instr64 to accept an optional flag operand, similar to as-instr, and use as-instr64 instead of as-instr.

Or is this not required, as in a cross build for 64-bit on a 32-bit platform (or inverse) a respective cross toolchain is a prerequisite and the m64-flag (or m32-flag) is not used?

I tried to simulate this using docker and an i386 image and then using the i386 tool in the container to switch "uname -m" to "i686". But both of my following attempts to build for x86-64 on i386 fail with fixdep not found:

$ docker run -it --rm -v "$HOME/linux:$HOME/linux" --platform i386 public.ecr.aws/docker/library/debian:13.3
# sed -i -s 's/^Types: deb/& deb-src/' /etc/apt/sources.list.d/debian.sources
# apt update
# apt -y build-dep linux
# make mrproper
# i386 make ARCH=x86_64 defconfig
# i386 make ARCH=x86_64 arch/x86/entry/vdso/
# make mrproper
# apt -y install gcc-x86-64-linux-gnu
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- defconfig
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- arch/x86/entry/vdso/

arch/x86/entry/vdso/vdso64/Makefile vobjs-$(CONFIG_X86_SGX) += vsgx.o · line 17

Quoted 12 lines
arch/Kconfig +2 -0
+	select AS_SFRAME
+
 config UNWIND_USER
 	bool
 
arch/x86/entry/vdso/vdso64/Makefile +1 -0
@@ -14,6 +14,7 @@ vobjs-$(CONFIG_X86_SGX)		+= vsgx.o
 
 # Compilation flags
 flags-y				:= -DBUILD_VDSO64 -m64 -mcmodel=small
+flags-$(CONFIG_AS_SFRAME3)	+= -Wa,--gsframe-3

flags-$(CONFIG_AS_SFRAME3_64) += -Wa,--gsframe-3

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

# The location of this include matters!
include $(src)/../common/Makefile.include

Thanks and regards,
Jens

I think we can worry about that later.

maintainer
#13 lore raw

Re: [PATCH v8 6/6] x86/vdso: Enable sframe generation in VDSO

In reply to Jens Remus
Quoted 55 lines · Jens Remus
Quoted 18 lines · Jens Remus

From: Josh Poimboeuf <[email protected]>

Enable sframe generation in the VDSO library so kernel and user space can unwind through it.

SFrame isn't supported for x32 or x86-32. Discard .sframe sections for those VDSOs.

[ Jens Remus: Add support for SFrame V3. Prevent GNU_SFRAME program table entry to empty .sframe section. ]

arch/Kconfig config HAVE_HARDLOCKUP_DETECTOR_ARCH · line 486

Quoted 8 lines
arch/Kconfig +5 -0
@@ -479,6 +479,13 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
 	  It uses the same command line parameters, and sysctl interface,
 	  as the generic hardlockup detectors.
 
+config AS_SFRAME
+	bool
+
+config AS_SFRAME3
+	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,-Wa$(comma)--gsframe-3)

Above tests whether the assembler supports --gsframe-3 to generate .sframe in SFrame V3 format. GNU assembler only supports to generate SFrame for x86-64. If the assembler is built for i386 (x86-32) the test will fail unless option --64 is specified. I wonder whether that could happen in (the rather hypothetical?) case, when the kernel is cross built for x86-64 on i386? Should this therefore be changed to the following?

config AS_SFRAME_64

	def_bool $(as-instr,.cfi_startproc\n.cfi_endproc,$(m64-flag) -Wa$(comma)--gsframe)

An alternative would be to enable as-instr64 to accept an optional flag operand, similar to as-instr, and use as-instr64 instead of as-instr.

Or is this not required, as in a cross build for 64-bit on a 32-bit platform (or inverse) a respective cross toolchain is a prerequisite and the m64-flag (or m32-flag) is not used?

I tried to simulate this using docker and an i386 image and then using the i386 tool in the container to switch "uname -m" to "i686". But both of my following attempts to build for x86-64 on i386 fail with fixdep not found:

$ docker run -it --rm -v "$HOME/linux:$HOME/linux" --platform i386 public.ecr.aws/docker/library/debian:13.3
# sed -i -s 's/^Types: deb/& deb-src/' /etc/apt/sources.list.d/debian.sources
# apt update
# apt -y build-dep linux
Quoted 8 lines
# make mrproper
# i386 make ARCH=x86_64 defconfig
# i386 make ARCH=x86_64 arch/x86/entry/vdso/
# make mrproper
# apt -y install gcc-x86-64-linux-gnu
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- defconfig
# i386 make ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- arch/x86/entry/vdso/

Hm, I think I broke that with

a808a2b35f66 ("tools build: Fix fixdep dependencies")

... though it's been broken almost a year, maybe nobody cares.

Regardless, we do need to fix "make clean" and "make mrproper" for objtool, which would be something like so:

Makefile +10 -1
index d3a8482bdbd0..ed850044491d 100644
@@ -1474,6 +1474,15 @@ ifneq ($(wildcard $(resolve_btfids_O)),)
 	$(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
 endif
 
+PHONY += objtool_clean
+
+objtool_O = $(abspath $(objtree))/tools/objtool
+
+objtool_clean:
+ifneq ($(wildcard $(objtool_O)),)
+	$(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) clean
+endif
+
 tools/: FORCE
 	$(Q)mkdir -p $(objtree)/tools
 	$(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
@@ -1637,7 +1646,7 @@ vmlinuxclean:
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
 	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
 
-clean: archclean vmlinuxclean resolve_btfids_clean
+clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
 
 # mrproper - Delete all generated files, including .config
 #
tools/objtool/Makefile +2 -0
index a40f30232929..6964175abdfd 100644
@@ -29,6 +29,8 @@ srctree := $(patsubst %/,%,$(dir $(CURDIR)))
 srctree := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
+RM ?= rm -f
+
 LIBSUBCMD_DIR = $(srctree)/tools/lib/subcmd/
 ifneq ($(OUTPUT),)
   LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd