Skip to contentSkip to conversation

x86/vdso: VDSO updates and fixes for sframes

PATCH In review Steven Rostedt 4 participants 15 messages Apr 25, 2025 – Oct 20, 2025

Subsystems (5)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

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

I'm currently working on getting sframe support from the kernel. In order to do that, it requires some fixes. Josh Poimboeuf did a lot of the hard work already, but he told me he doesn't have time to continue it so I'm picking it up where he left off.

His last series of v4 is here:

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

It covers a lot of topics as he found issues with other aspects of the kernel that needed to be fixed for sframes to work properly.

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).

I based this off of the latest tip/master:

commit 0c6ae66ef164c408daeab6a61aace4b86010369a

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

- Updated change log of patch 3 to make it more of a clean up than a fix.

- Replaced $(comma} with actual comma in Makefile of the last patch.

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                             |  3 ++
 arch/x86/entry/vdso/Makefile             | 10 ++++--
 arch/x86/entry/vdso/vdso-layout.lds.S    |  5 ++-
 arch/x86/entry/vdso/vdso32/system_call.S | 10 ++----
 arch/x86/entry/vdso/vgetrandom-chacha.S  |  3 +-
 arch/x86/entry/vdso/vsgx.S               | 19 +++++------
 arch/x86/include/asm/dwarf2.h            | 54 ++++++++++++++++++++++----------
 arch/x86/include/asm/linkage.h           | 33 +++++++++++++++----
 arch/x86/include/asm/vdso.h              |  1 -
 9 files changed, 89 insertions(+), 49 deletions(-)
author maintainer
#1 lore raw

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

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/vgetrandom-chacha.S | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/entry/vdso/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.47.2
author maintainer
#2 lore raw

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

In reply to Steven Rostedt

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.

---
 arch/x86/include/asm/dwarf2.h | 51 ++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 16 deletions(-)
arch/x86/include/asm/dwarf2.h +35 -16
index 302e11b15da8..65d958ef1178 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
@@ -21,21 +30,31 @@
 #define CFI_UNDEFINED		.cfi_undefined
 #define CFI_ESCAPE		.cfi_escape
 
-#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
+
+#endif /* !BUILD_VDSO */
 
 #endif /* _ASM_X86_DWARF2_H */
Signature · 1 line
2.47.2
author maintainer
#3 lore raw

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

In reply to Steven Rostedt

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.

[ Fixed rebased issues. ]
---
 arch/x86/entry/vdso/vdso-layout.lds.S   |  2 +-
 arch/x86/entry/vdso/vgetrandom-chacha.S |  2 --
 arch/x86/entry/vdso/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/vdso-layout.lds.S +1 -1
index ec1ac191a057..60747905de2b 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/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/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 b51d8a4673f5..1ba1f208414f 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)
 
 #endif /* _ASM_X86_LINKAGE_H */
 
arch/x86/include/asm/vdso.h +0 -1
index b7253ef3205a..c4290dadba66 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.47.2
author maintainer
#4 lore raw

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

In reply to Steven Rostedt

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 d33c6513fd2c..bdc576548240 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)
 	/*
 	 * Reshuffle regs so that all of any of the entry instructions
 	 * will preserve enough state.
@@ -79,7 +75,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.47.2
author maintainer
#5 lore raw

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

In reply to Steven Rostedt

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.

---
 arch/x86/entry/vdso/vsgx.S | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vsgx.S +7 -8
index c0342238c976..8d7b8eb45c50 100644
@@ -24,13 +24,14 @@
 .section .text, "ax"
 
 SYM_FUNC_START(__vdso_sgx_enter_enclave)
+	SYM_F_ALIGN
 	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 +78,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.47.2
#6 lore raw

Re: [PATCH 5/6] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

Quoted 7 lines · Steven Rostedt

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.

Although unrelated to the current intent of the patch, a question:

Why does the stub after .Linvoke_userspace_handler in vsgs.S not have
CFI directives ?

Quoted 45 lines
---
  arch/x86/entry/vdso/vsgx.S | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vsgx.S +7 -8
index c0342238c976..8d7b8eb45c50 100644
@@ -24,13 +24,14 @@
  .section .text, "ax"
 
  SYM_FUNC_START(__vdso_sgx_enter_enclave)
+	SYM_F_ALIGN
  	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 +78,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
 
#7 lore raw

Re: [PATCH 5/6] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

Quoted 6 lines · Indu Bhagat
Quoted 5 lines · Steven Rostedt

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.

Quoted 7 lines
Quoted 2 lines

No functional changes.

Although unrelated to the current intent of the patch, a question:

Why does the stub after .Linvoke_userspace_handler in vsgs.S not have CFI
directives ?

Yeah, looks like that stack alignment code needs some CFI.

Signature · 1 line
Josh
#8 lore raw

Re: [PATCH 5/6] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines · Indu Bhagat
Quoted 7 lines · Steven Rostedt

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.

Quoted 6 lines
Quoted 4 lines

Although unrelated to the current intent of the patch, a question:

Why does the stub after .Linvoke_userspace_handler in vsgs.S not have CFI
directives ?

Yeah, looks like that stack alignment code needs some CFI.

Actually, this function uses a frame pointer so I think the stack pointer alignment shouldn't affect the CFI?

Signature · 1 line
Josh
#9 lore raw

Re: [PATCH 5/6] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

Quoted 13 lines · Josh Poimboeuf
Quoted 12 lines · Josh Poimboeuf
Quoted 11 lines · Indu Bhagat
Quoted 7 lines · Steven Rostedt

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.

Although unrelated to the current intent of the patch, a question:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Why does the stub after .Linvoke_userspace_handler in vsgs.S not have CFI
directives ?

Yeah, looks like that stack alignment code needs some CFI.

Actually, this function uses a frame pointer so I think the stack pointer alignment shouldn't affect the CFI?

You are right. rbx is already handled too with the required CFI in the prologue.

#10 lore raw

Re: [PATCH 5/6] x86/vdso: Use CFI macros in __vdso_sgx_enter_enclave()

In reply to Steven Rostedt
Quoted 18 lines · Steven Rostedt

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.

---
 arch/x86/entry/vdso/vsgx.S | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/entry/vdso/vsgx.S +0 -0
index c0342238c976..8d7b8eb45c50 100644

arch/x86/entry/vdso/vsgx.S line 27

Quoted 4 lines
arch/x86/entry/vdso/vsgx.S +1 -0
@@ -24,13 +24,14 @@
 .section .text, "ax"
 
 SYM_FUNC_START(__vdso_sgx_enter_enclave)
+	SYM_F_ALIGN

I'm not sure why I had this SYM_F_ALIGN here, but it doesn't belong here and can be removed.

Signature · 1 line
Josh
author maintainer
#11 lore raw

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

In reply to Steven Rostedt

From: Josh Poimboeuf <[email protected]>

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

---
Changes since v5: https://lore.kernel.org/[email protected]

- Replace $(comma) with a comma in the Makefile
(Jens Remus)

 arch/Kconfig                          |  3 +++
 arch/x86/entry/vdso/Makefile          | 10 +++++++---
 arch/x86/entry/vdso/vdso-layout.lds.S |  3 +++
 arch/x86/include/asm/dwarf2.h         |  5 ++++-
 4 files changed, 17 insertions(+), 4 deletions(-)
arch/Kconfig +3 -0
index b0adb665041f..6e7d739e853b 100644
@@ -435,6 +435,9 @@ config HAVE_HARDLOCKUP_DETECTOR_ARCH
 	  It uses the same command line parameters, and sysctl interface,
 	  as the generic hardlockup detectors.
 
+config AS_SFRAME
+	def_bool $(as-instr,.cfi_sections .sframe\n.cfi_startproc\n.cfi_endproc)
+
 config HAVE_PERF_REGS
 	bool
 	help
arch/x86/entry/vdso/Makefile +7 -3
index 54d3e9774d62..2dc0e0ca19a7 100644
@@ -47,13 +47,17 @@ quiet_cmd_vdso2c = VDSO2C  $@
 $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
 	$(call if_changed,vdso2c)
 
+ifeq ($(CONFIG_AS_SFRAME),y)
+  SFRAME_CFLAGS := -Wa,-gsframe
+endif
+
 #
 # Don't omit frame pointers for ease of userspace debugging, but do
 # optimize sibling calls.
 #
 CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
        $(filter -g%,$(KBUILD_CFLAGS)) -fno-stack-protector \
-       -fno-omit-frame-pointer -foptimize-sibling-calls \
+       -fno-omit-frame-pointer $(SFRAME_CFLAGS) -foptimize-sibling-calls \
        -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
 
 ifdef CONFIG_MITIGATION_RETPOLINE
@@ -63,7 +67,7 @@ endif
 endif
 
 $(vobjs): KBUILD_CFLAGS := $(filter-out $(PADDING_CFLAGS) $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
-$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO
+$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO $(SFRAME_CFLAGS)
 
 #
 # vDSO code runs in userspace and -pg doesn't help with profiling anyway.
@@ -104,7 +108,7 @@ $(obj)/%-x32.o: $(obj)/%.o FORCE
 
 targets += vdsox32.lds $(vobjx32s-y)
 
-$(obj)/%.so: OBJCOPYFLAGS := -S --remove-section __ex_table
+$(obj)/%.so: OBJCOPYFLAGS := -g --remove-section __ex_table
 $(obj)/%.so: $(obj)/%.so.dbg FORCE
 	$(call if_changed,objcopy)
 
arch/x86/entry/vdso/vdso-layout.lds.S +3 -0
index 60747905de2b..24b92687597b 100644
@@ -59,6 +59,7 @@ SECTIONS
 	.eh_frame_hdr	: { *(.eh_frame_hdr) }		:text	:eh_frame_hdr
 	.eh_frame	: { KEEP (*(.eh_frame)) }	:text
 
+	.sframe		: { *(.sframe) }		:text	:sframe
 
 	/*
 	 * Text is well-separated from actual data: there's plenty of
@@ -87,6 +88,7 @@ SECTIONS
  * Very old versions of ld do not recognize this name token; use the constant.
  */
 #define PT_GNU_EH_FRAME	0x6474e550
+#define PT_GNU_SFRAME	0x6474e554
 
 /*
  * We must supply the ELF program headers explicitly to get just one
@@ -98,4 +100,5 @@ PHDRS
 	dynamic		PT_DYNAMIC	FLAGS(4);		/* PF_R */
 	note		PT_NOTE		FLAGS(4);		/* PF_R */
 	eh_frame_hdr	PT_GNU_EH_FRAME;
+	sframe		PT_GNU_SFRAME;
 }
arch/x86/include/asm/dwarf2.h +4 -1
index 65d958ef1178..ce294e6c9017 100644
@@ -12,8 +12,11 @@
 	 * For the vDSO, emit both runtime unwind information and debug
 	 * symbols for the .dbg file.
 	 */
-
+#if defined(__x86_64__) && defined(CONFIG_AS_SFRAME)
+	.cfi_sections .eh_frame, .debug_frame, .sframe
+#else
 	.cfi_sections .eh_frame, .debug_frame
+#endif
 
 #define CFI_STARTPROC		.cfi_startproc
 #define CFI_ENDPROC		.cfi_endproc
Signature · 1 line
2.47.2
#12 lore raw

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

Quoted 16 lines · Steven Rostedt

From: Josh Poimboeuf <[email protected]>

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

---
Changes since v5: https://lore.kernel.org/[email protected]

- Replace $(comma) with a comma in the Makefile
(Jens Remus)

arch/x86/entry/vdso/Makefile quiet_cmd_vdso2c = VDSO2C $@ · line 51

Quoted 5 lines
arch/x86/entry/vdso/Makefile +2 -0
@@ -47,13 +47,17 @@ quiet_cmd_vdso2c = VDSO2C  $@
 $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
 	$(call if_changed,vdso2c)
 
+ifeq ($(CONFIG_AS_SFRAME),y)
+  SFRAME_CFLAGS := -Wa,-gsframe

Nit: The GNU assembler (GAS) option as of "as --help" and "man as" is "--gsframe" (with two dashes). But as GAS uses getopt_long_only() it accepts long options prefixed with "--" as well as "-". I don't have any preference.

arch/x86/entry/vdso/Makefile quiet_cmd_vdso2c = VDSO2C $@ · line 53

Quoted 2 lines
arch/x86/entry/vdso/Makefile +2 -0
+endif
+

Regards,
Jens

Signature · 9 lines
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
[email protected]

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
#13 lore raw

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

In reply to Steven Rostedt
Quoted 19 lines · Steven Rostedt

From: Josh Poimboeuf <[email protected]>

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

arch/x86/entry/vdso/vdso-layout.lds.S +1 -0
@@ -87,6 +88,7 @@ SECTIONS
  * Very old versions of ld do not recognize this name token; use the constant.
  */
 #define PT_GNU_EH_FRAME	0x6474e550
+#define PT_GNU_SFRAME	0x6474e554
 
 /*
  * We must supply the ELF program headers explicitly to get just one

arch/x86/entry/vdso/vdso-layout.lds.S PHDRS · line 102

Quoted 3 lines
arch/x86/entry/vdso/vdso-layout.lds.S +0 -0
@@ -98,4 +100,5 @@ PHDRS
 	dynamic		PT_DYNAMIC	FLAGS(4);		/* PF_R */
 	note		PT_NOTE		FLAGS(4);		/* PF_R */
 	eh_frame_hdr	PT_GNU_EH_FRAME;

On s390 I found that the respective s390-change needs to be guarded to prevent the vDSO from erroneously getting generated with a bogus GNU_SFRAME program table entry, if CONFIG_AS_SFRAME is not enabled:

$ readelf -Wl arch/s390/kernel/vdso64/vdso64.so
...
Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x001508 0x001508 R E 0x1000
  DYNAMIC        0x001190 0x0000000000001190 0x0000000000001190 0x000100 0x000100 R   0x8
  NOTE           0x000420 0x0000000000000420 0x0000000000000420 0x00003c 0x00003c R   0x4
  GNU_EH_FRAME   0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000     0x8
  GNU_SFRAME     0x0014f0 0x00000000000014f0 0x00000000000014f0 0x000018 0x000018 RW  0x8
...
$ xxd arch/s390/kernel/vdso64/vdso64.so
...
000014f0: 0000 0000 0000 1190 0000 0000 0000 0000  ................
00001500: 0000 0000 0000 0000 4743 433a 2028 5562  ........GCC: (Ub
00001510: 756e 7475 2031 342e 322e 302d 3139 7562  untu 14.2.0-19ub
00001520: 756e 7475 3229 2031 342e 322e 3000 0000  untu2) 14.2.0...
...

Following would be the guard for x86 (same as the one used below in arch/x86/include/asm/dwarf2.h):

#if defined(__x86_64__) && defined(CONFIG_AS_SFRAME)

arch/x86/entry/vdso/vdso-layout.lds.S PHDRS · line 103

Quoted 1 line
arch/x86/entry/vdso/vdso-layout.lds.S +1 -0
+	sframe		PT_GNU_SFRAME;

#endif

Quoted 7 lines
arch/x86/entry/vdso/vdso-layout.lds.S +0 -0
 }
arch/x86/include/asm/dwarf2.h +0 -0
@@ -12,8 +12,11 @@
 	 * For the vDSO, emit both runtime unwind information and debug
 	 * symbols for the .dbg file.

arch/x86/include/asm/dwarf2.h line 22

Quoted 10 lines
arch/x86/include/asm/dwarf2.h +4 -1
 	 */
-
+#if defined(__x86_64__) && defined(CONFIG_AS_SFRAME)
+	.cfi_sections .eh_frame, .debug_frame, .sframe
+#else
 	.cfi_sections .eh_frame, .debug_frame
+#endif
 
 #define CFI_STARTPROC		.cfi_startproc
 #define CFI_ENDPROC		.cfi_endproc

Regards,
Jens

Signature · 9 lines
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
[email protected]

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/