mirror-linux/arch/loongarch/include/asm
Xi Ruoyao e4878c37f6 LoongArch: vDSO: Emit GNU_EH_FRAME correctly
With -fno-asynchronous-unwind-tables and --no-eh-frame-hdr (the default
of the linker), the GNU_EH_FRAME segment (specified by vdso.lds.S) is
empty.  This is not valid, as the current DWARF specification mandates
the first byte of the EH frame to be the version number 1.  It causes
some unwinders to complain, for example the ClickHouse query profiler
spams the log with messages:

    clickhouse-server[365854]: libunwind: unsupported .eh_frame_hdr
    version: 127 at 7ffffffb0000

Here "127" is just the byte located at the p_vaddr (0, i.e. the
beginning of the vDSO) of the empty GNU_EH_FRAME segment. Cross-
checking with /proc/365854/maps has also proven 7ffffffb0000 is the
start of vDSO in the process VM image.

In LoongArch the -fno-asynchronous-unwind-tables option seems just a
MIPS legacy, and MIPS only uses this option to satisfy the MIPS-specific
"genvdso" program, per the commit cfd75c2db1 ("MIPS: VDSO: Explicitly
use -fno-asynchronous-unwind-tables").  IIRC it indicates some inherent
limitation of the MIPS ELF ABI and has nothing to do with LoongArch.  So
we can simply flip it over to -fasynchronous-unwind-tables and pass
--eh-frame-hdr for linking the vDSO, allowing the profilers to unwind the
stack for statistics even if the sample point is taken when the PC is in
the vDSO.

However simply adjusting the options above would exploit an issue: when
the libgcc unwinder saw the invalid GNU_EH_FRAME segment, it silently
falled back to a machine-specific routine to match the code pattern of
rt_sigreturn() and extract the registers saved in the sigframe if the
code pattern is matched.  As unwinding from signal handlers is vital for
libgcc to support pthread cancellation etc., the fall-back routine had
been silently keeping the LoongArch Linux systems functioning since
Linux 5.19.  But when we start to emit GNU_EH_FRAME with the correct
format, fall-back routine will no longer be used and libgcc will fail
to unwind the sigframe, and unwinding from signal handlers will no
longer work, causing dozens of glibc test failures.  To make it possible
to unwind from signal handlers again, it's necessary to code the unwind
info in __vdso_rt_sigreturn via .cfi_* directives.

The offsets in the .cfi_* directives depend on the layout of struct
sigframe, notably the offset of sigcontext in the sigframe.  To use the
offset in the assembly file, factor out struct sigframe into a header to
allow asm-offsets.c to output the offset for assembly.

To work around a long-term issue in the libgcc unwinder (the pc is
unconditionally substracted by 1: doing so is technically incorrect for
a signal frame), a nop instruction is included with the two real
instructions in __vdso_rt_sigreturn in the same FDE PC range.  The same
hack has been used on x86 for a long time.

Cc: stable@vger.kernel.org
Fixes: c6b99bed6b ("LoongArch: Add VDSO and VSYSCALL support")
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
2026-03-26 14:29:09 +08:00
..
vdso LoongArch: Adjust VDSO/VSYSCALL for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
Kbuild LoongArch: Adjust system call for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
acenv.h LoongArch: Align ACPI structures if ARCH_STRICT_ALIGN enabled 2025-09-18 19:44:01 +08:00
acpi.h LoongArch: Increase max supported CPUs up to 2048 2025-05-30 21:45:43 +08:00
addrspace.h LoongArch: Adjust memory management for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
alternative-asm.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
alternative.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
asm-extable.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
asm-offsets.h
asm-prototypes.h LoongArch: entry: Migrate ret_from_fork() to C 2025-04-29 08:27:10 +02:00
asm.h LoongArch: Adjust common macro definitions for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
asmmacro.h LoongArch: Adjust common macro definitions for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
atomic-amo.h LoongArch: Add atomic operations for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
atomic-llsc.h LoongArch: Add atomic operations for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
atomic.h LoongArch: Add atomic operations for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
barrier.h LoongArch: Support dbar with different hints 2023-06-29 20:58:44 +08:00
bitops.h LoongArch: Adjust misc routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
bitrev.h LoongArch: Simplify __arch_bitrev32() implementation 2025-12-06 10:39:39 +08:00
bootinfo.h LoongArch: Get correct cores_per_package for SMT systems 2024-10-21 22:11:18 +08:00
branch.h
bug.h bugs/LoongArch: Concatenate 'cond_str' with '__FILE__' in __BUG_ENTRY(), to extend WARN_ON/BUG_ON output 2025-07-28 08:01:23 +02:00
cache.h LoongArch: Increase ARCH_DMA_MINALIGN up to 16 2025-03-30 16:31:09 +08:00
cacheflush.h LoongArch: Remove superfluous flush_dcache_page() definition 2024-03-19 15:50:34 +08:00
cacheops.h
checksum.h LoongArch: Adjust misc routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
clocksource.h
cmpxchg.h LoongArch: Only use SC.Q when supported by the assembler 2026-03-16 10:36:00 +08:00
cpu-features.h LoongArch: Add detection for SC.Q support 2026-02-10 19:31:06 +08:00
cpu-info.h LoongArch: Remove the deprecated notifier hook mechanism 2025-02-13 12:02:40 +08:00
cpu.h LoongArch: Add detection for SC.Q support 2026-02-10 19:31:06 +08:00
cpufeature.h
crash_reserve.h LoongArch: Fix Kconfig item and left code related to CRASH_CORE 2024-04-24 12:36:07 +08:00
delay.h
dma.h
dmi.h LoongArch: Adjust boot & setup for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
efi.h efi/loongarch: Directly position the loaded image file 2023-12-19 11:16:37 +01:00
elf.h LoongArch: Adjust process management for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
entry-common.h LoongArch: Enable HAVE_ARCH_STACKLEAK 2025-05-30 21:45:42 +08:00
exception.h LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00
exec.h
extable.h
fixmap.h
fpregdef.h LoongArch: Prepare for assemblers with proper FCSR class support 2023-06-29 20:58:43 +08:00
fprobe.h fprobe: Add fprobe_header encoding feature 2024-12-26 10:50:05 -05:00
fpu.h LoongArch: Handle fp, lsx, lasx and lbt assembly symbols 2025-04-26 09:58:12 +08:00
ftrace.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
futex.h
gpr-num.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
hardirq.h LoongArch: Architectural preparation for AVEC irqchip 2024-08-23 20:40:27 +02:00
hugetlb.h mm/hugetlb: remove prepare_hugepage_range() 2025-07-13 16:38:19 -07:00
hw_breakpoint.h LoongArch: Use correct accessor to read FWPC/MWPC 2025-11-10 08:37:06 +08:00
hw_irq.h LoongArch: Define ARCH_IRQ_INIT_FLAGS as IRQ_NOPROBE 2024-08-26 23:11:32 +08:00
idle.h
image.h LoongArch: Add EFI binary support for kexec_file 2025-10-02 22:39:07 +08:00
inst.h LoongArch: Adjust process management for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
io.h LoongArch: Consolidate early_ioremap()/ioremap_prot() 2025-11-10 08:37:06 +08:00
irq.h LoongArch: Adjust boot & setup for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
irq_regs.h
irq_work.h LoongArch: Add irq_work support via self IPIs 2024-07-20 22:40:58 +08:00
irqflags.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
jump_label.h LoongArch: Adjust misc routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
kasan.h kasan: introduce ARCH_DEFER_KASAN and unify static key across modes 2025-09-21 14:21:58 -07:00
kdebug.h LoongArch: Remove five DIE_* definitions in kdebug.h 2023-06-29 20:58:44 +08:00
kexec.h LoongArch: Add ELF binary support for kexec_file 2025-10-02 22:39:08 +08:00
kfence.h LoongArch: Use accessors to page table entries instead of direct dereference 2024-08-07 17:37:11 +08:00
kgdb.h LoongArch: Add basic KGDB & KDB support 2023-09-06 22:53:55 +08:00
kprobes.h LoongArch: Use larch_insn_gen_break() for kprobes 2023-06-29 20:58:44 +08:00
kvm_csr.h LoongArch: KVM: Add PMU support for guest 2024-09-12 20:53:40 +08:00
kvm_eiointc.h LoongArch: KVM: Use 64-bit register definition for EIOINTC 2025-11-27 11:00:18 +08:00
kvm_host.h LoongArch: KVM: Add paravirt preempt feature in hypervisor side 2026-02-06 09:28:01 +08:00
kvm_ipi.h LoongArch: KVM: Add IPI read and write function 2024-11-13 16:18:27 +08:00
kvm_mmu.h LoongArch: KVM: Fix VM migration failure with PTW enabled 2025-09-18 19:44:22 +08:00
kvm_para.h LoongArch: KVM: Add paravirt preempt feature in hypervisor side 2026-02-06 09:28:01 +08:00
kvm_pch_pic.h LoongArch: KVM: Set version information at initial stage 2025-09-23 23:37:09 +08:00
kvm_types.h LoongArch: KVM: Add kvm related header files 2023-10-02 10:01:20 +08:00
kvm_vcpu.h LoongArch: KVM: Add AVEC basic support 2025-11-27 11:00:18 +08:00
lbt.h LoongArch: Handle fp, lsx, lasx and lbt assembly symbols 2025-04-26 09:58:12 +08:00
linkage.h LoongArch: vDSO: Emit GNU_EH_FRAME correctly 2026-03-26 14:29:09 +08:00
local.h LoongArch: Add atomic operations for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
loongarch.h LoongArch: KVM: Handle LOONGARCH_CSR_IPR during vCPU context switch 2026-02-06 09:27:46 +08:00
loongson.h
mmu.h
mmu_context.h LoongArch: Improve hardware page table walker 2024-09-24 15:32:20 +08:00
module.h LoongArch: Adjust module loader for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
module.lds.h LoongArch: module: set section addresses to 0x0 2023-04-18 19:38:58 +08:00
numa.h LoongArch: Introduce the numa_memblks conversion 2025-05-30 21:45:43 +08:00
orc_header.h LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00
orc_lookup.h LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00
orc_types.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
page.h treewide: provide a generic clear_user_page() variant 2026-01-20 19:24:39 -08:00
paravirt.h loongarch/paravirt: Use common code for paravirt_steal_clock() 2026-01-12 16:47:20 +01:00
pci.h
percpu.h LoongArch: Adjust module loader for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
perf_event.h LoongArch: Fix callchain parse error with kernel tracepoint events again 2024-05-14 12:24:18 +08:00
pgalloc.h LoongArch: mm: enable MMU_GATHER_RCU_TABLE_FREE 2026-02-06 15:47:18 -08:00
pgtable-bits.h LoongArch: Adjust memory management for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
pgtable.h arch, mm: consolidate initialization of nodes, zones and memory map 2026-01-26 20:02:18 -08:00
prefetch.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
processor.h LoongArch: Add Loongson Binary Translation (LBT) extension support 2023-09-06 22:53:55 +08:00
ptrace.h LoongArch: Fix MAX_REG_OFFSET calculation 2025-05-14 22:17:43 +08:00
qspinlock.h LoongArch: KVM: Add paravirt vcpu_is_preempted() support in guest side 2026-02-06 09:28:01 +08:00
regdef.h
seccomp.h
serial.h
set_memory.h arch: introduce set_direct_map_valid_noflush() 2024-11-07 14:25:15 -08:00
setup.h LoongArch: Handle percpu handler address for ORC unwinder 2026-02-10 19:31:13 +08:00
sigframe.h LoongArch: vDSO: Emit GNU_EH_FRAME correctly 2026-03-26 14:29:09 +08:00
smp.h LoongArch: Handle KCOV __init vs inline mismatches 2025-06-26 20:07:18 +08:00
sparsemem.h LoongArch: Introduce the numa_memblks conversion 2025-05-30 21:45:43 +08:00
spinlock.h
spinlock_types.h
stackframe.h LoongArch: Adjust common macro definitions for 32BIT/64BIT 2025-12-06 10:40:32 +08:00
stackprotector.h
stacktrace.h LoongArch: Enable HAVE_ARCH_STACKLEAK 2025-05-30 21:45:42 +08:00
string.h LoongArch: Adjust misc routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
suspend.h LoongArch: Export some arch-specific pm interfaces 2023-06-29 20:58:44 +08:00
switch_to.h LoongArch: Add Loongson Binary Translation (LBT) extension support 2023-09-06 22:53:55 +08:00
syscall.h syscall.h: introduce syscall_set_nr() 2025-05-11 17:48:15 -07:00
thread_info.h LoongArch: Fix bitflag conflict for TIF_FIXADE 2025-09-20 09:55:56 +02:00
time.h
timex.h LoongArch: Adjust time routines for 32BIT/64BIT 2025-12-08 18:09:17 +08:00
tlb.h LoongArch: Fix a build error due to __tlb_remove_tlb_entry() 2024-04-24 12:36:07 +08:00
tlbflush.h
topology.h LoongArch: Make cpumask_of_node() robust against NUMA_NO_NODE 2026-02-10 19:31:12 +08:00
types.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
uaccess.h LoongArch: Give more information if kmem access failed 2026-03-16 10:36:01 +08:00
unistd.h LoongArch: Wire up memfd_secret system call 2026-02-10 19:31:12 +08:00
unwind.h LoongArch: Add ORC stack unwinder support 2024-03-11 22:23:47 +08:00
unwind_hints.h LoongArch: Replace __ASSEMBLY__ with __ASSEMBLER__ in headers 2025-06-26 20:07:10 +08:00
uprobes.h LoongArch: uprobes: Remove redundant code about resume_era 2025-05-14 22:18:10 +08:00
vdso.h LoongArch: vDSO: Switch to generic storage implementation 2025-02-21 09:54:02 +01:00
vermagic.h
video.h arch: Rename fbdev header and source files 2024-05-03 17:07:50 +02:00
vmalloc.h
xor.h LoongArch: Add SIMD-optimized XOR routines 2023-09-06 22:53:55 +08:00
xor_simd.h LoongArch: Add SIMD-optimized XOR routines 2023-09-06 22:53:55 +08:00