parisc: Add initial vDSO support
Subsystems (2)
Helge Deller
maintainerPATCH 1/1 parisc: Add initial vDSO support
Add minimal vDSO support, which provides the signal trampoline helpers, but none of the userspace syscall helpers like time functions.
The big benefit of this vDSO implementation is, that we now don't need an executeable stack any longer. PA-RISC is one of the last architectures where an executeable stack was needed in oder to implement the signal trampolines by putting assembly instructions on the stack which then gets executed. With this implementation the kernel will utilize the assembler statements in the vDSO page which is mapped into each userspace application instead and just put the pointers to the signal information on the stack.
By dropping the need for executable stacks we now avoid running into issues with various applications in Debian which nowadays want non-executable stacks for security reasons. Additionally, alternative stacks are supported better as well.
This code is based on an initial implementation by Randolph Chung from 2006:
https://lore.kernel.org/linux-parisc/[email protected]/
I did the porting and lifted the code to current code base. Dave fixed the unwind code so that gdb and glibc are able to backtrace through the code. An additional patch to gdb will be pushed upstream by Dave.
Dave Anglin <[email protected]>
--- arch/parisc/Kconfig | 1 + arch/parisc/Makefile | 32 +++ arch/parisc/include/asm/elf.h | 15 ++ arch/parisc/include/asm/mmu.h | 6 +- arch/parisc/include/asm/mmu_context.h | 16 +- arch/parisc/include/asm/page.h | 2 + arch/parisc/include/asm/pgtable.h | 7 +- arch/parisc/include/asm/processor.h | 2 +- arch/parisc/include/asm/rt_sigframe.h | 10 +- arch/parisc/include/asm/tlbflush.h | 2 +- arch/parisc/include/asm/unistd.h | 4 - arch/parisc/include/asm/vdso.h | 24 ++ arch/parisc/include/uapi/asm/auxvec.h | 8 + arch/parisc/kernel/Makefile | 9 +- arch/parisc/kernel/asm-offsets.c | 9 + arch/parisc/kernel/cache.c | 10 +- arch/parisc/kernel/signal.c | 227 +++++++++--------- arch/parisc/kernel/signal32.h | 19 +- arch/parisc/kernel/vdso.c | 125 ++++++++++ arch/parisc/kernel/vdso32/Makefile | 53 ++++ arch/parisc/kernel/vdso32/gen_vdso_offsets.sh | 15 ++ arch/parisc/kernel/vdso32/note.S | 26 ++ arch/parisc/kernel/vdso32/restart_syscall.S | 32 +++ arch/parisc/kernel/vdso32/sigtramp.S | 195 +++++++++++++++ arch/parisc/kernel/vdso32/vdso32.lds.S | 111 +++++++++ arch/parisc/kernel/vdso32/vdso32_wrapper.S | 14 ++ arch/parisc/kernel/vdso64/Makefile | 48 ++++ arch/parisc/kernel/vdso64/gen_vdso_offsets.sh | 15 ++ arch/parisc/kernel/vdso64/note.S | 2 + arch/parisc/kernel/vdso64/restart_syscall.S | 3 + arch/parisc/kernel/vdso64/sigtramp.S | 166 +++++++++++++ arch/parisc/kernel/vdso64/vdso64.lds.S | 109 +++++++++ arch/parisc/kernel/vdso64/vdso64_wrapper.S | 14 ++ 33 files changed, 1166 insertions(+), 165 deletions(-) create mode 100644 arch/parisc/include/asm/vdso.h create mode 100644 arch/parisc/include/uapi/asm/auxvec.h create mode 100644 arch/parisc/kernel/vdso.c create mode 100644 arch/parisc/kernel/vdso32/Makefile create mode 100755 arch/parisc/kernel/vdso32/gen_vdso_offsets.sh create mode 100644 arch/parisc/kernel/vdso32/note.S create mode 100644 arch/parisc/kernel/vdso32/restart_syscall.S create mode 100644 arch/parisc/kernel/vdso32/sigtramp.S create mode 100644 arch/parisc/kernel/vdso32/vdso32.lds.S create mode 100644 arch/parisc/kernel/vdso32/vdso32_wrapper.S create mode 100644 arch/parisc/kernel/vdso64/Makefile create mode 100755 arch/parisc/kernel/vdso64/gen_vdso_offsets.sh create mode 100644 arch/parisc/kernel/vdso64/note.S create mode 100644 arch/parisc/kernel/vdso64/restart_syscall.S create mode 100644 arch/parisc/kernel/vdso64/sigtramp.S create mode 100644 arch/parisc/kernel/vdso64/vdso64.lds.S create mode 100644 arch/parisc/kernel/vdso64/vdso64_wrapper.S
arch/parisc/Kconfig +1 -0
@@ -10,6 +10,7 @@ config PARISC select ARCH_HAS_ELF_RANDOMIZE select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_UBSAN_SANITIZE_ALL + select ARCH_HAS_PTE_SPECIAL select ARCH_NO_SG_CHAIN select ARCH_SUPPORTS_HUGETLBFS if PA20 select ARCH_SUPPORTS_MEMORY_FAILURE
arch/parisc/Makefile +32 -0
@@ -44,6 +44,16 @@ endif export LD_BFD +# Set default 32 bits cross compilers for vdso +CC_ARCHES_32 = hppa hppa2.0 hppa1.1 +CC_SUFFIXES = linux linux-gnu unknown-linux-gnu +CROSS32_COMPILE := $(call cc-cross-prefix, \ + $(foreach a,$(CC_ARCHES_32), \ + $(foreach s,$(CC_SUFFIXES),$(a)-$(s)-))) +CROSS32CC := $(CROSS32_COMPILE)gcc +export CROSS32CC + +# Set default cross compiler for kernel build ifdef cross_compiling ifeq ($(CROSS_COMPILE),) CC_SUFFIXES = linux linux-gnu unknown-linux-gnu
@@ -163,6 +173,28 @@ vmlinuz: vmlinux @$(KGZIP) -cf -9 $< > $@ endif +ifeq ($(KBUILD_EXTMOD),) +# We need to generate vdso-offsets.h before compiling certain files in kernel/. +# In order to do that, we should use the archprepare target, but we can't since +# asm-offsets.h is included in some files used to generate vdso-offsets.h, and +# asm-offsets.h is built in prepare0, for which archprepare is a dependency. +# Therefore we need to generate the header after prepare0 has been made, hence +# this hack. +prepare: vdso_prepare +vdso_prepare: prepare0 + $(if $(CONFIG_64BIT),$(Q)$(MAKE) \ + $(build)=arch/parisc/kernel/vdso64 include/generated/vdso64-offsets.h) + $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 include/generated/vdso32-offsets.h +endif + + + +PHONY += vdso_install + +vdso_install: + $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso $@ + $(if $(CONFIG_COMPAT_VDSO), \ + $(Q)$(MAKE) $(build)=arch/parisc/kernel/vdso32 $@) install: $(CONFIG_SHELL) $(srctree)/arch/parisc/install.sh \ $(KERNELRELEASE) vmlinux System.map "$(INSTALL_PATH)"
arch/parisc/include/asm/elf.h +15 -0
@@ -359,4 +359,19 @@ struct mm_struct;extern unsigned long arch_randomize_brk (struct mm_struct *);#define arch_randomize_brk arch_randomize_brk + +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 +struct linux_binprm ; +extern int arch_setup_additional_pages (struct linux_binprm *bprm, +int executable_stack); +#define VDSO_AUX_ENT (a, b) NEW_AUX_ENT(a, b) +#define VDSO_CURRENT_BASE current->mm->context.vdso_base + +#define ARCH_DLINFO \ +do { \ + if (VDSO_CURRENT_BASE) { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, VDSO_CURRENT_BASE);\ + } \ +} while (0) +#endif
arch/parisc/include/asm/mmu.h +4 -2
@@ -2,7 +2,9 @@#ifndef _PARISC_MMU_H_#define _PARISC_MMU_H_ -/* On parisc, we store the space id here */ -typedef unsigned long mm_context_t ; +typedef struct { +unsigned long space_id; +unsigned long vdso_base; +}mm_context_t ;#endif /* _PARISC_MMU_H_ */
arch/parisc/include/asm/mmu_context.h +8 -8
@@ -20,7 +20,7 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm) {BUG_ON (atomic_read (&mm->mm_users) !=1 ); - mm->context =alloc_sid (); + mm->context.space_id =alloc_sid ();return 0 ; }
@@ -28,22 +28,22 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)static inline void destroy_context (struct mm_struct *mm) { -free_sid (mm->context); - mm->context =0 ; +free_sid (mm->context.space_id); + mm->context.space_id =0 ; }static inline unsigned long __space_to_prot (mm_context_t context) {#if SPACEID_SHIFT ==0 -return context <<1 ; +return context.space_id <<1 ;#else -return context >> (SPACEID_SHIFT -1 ); +return context.space_id >> (SPACEID_SHIFT -1 );#endif }static inline void load_context (mm_context_t context) { -mtsp (context,3 ); +mtsp (context.space_id,3 );mtctl (__space_to_prot (context),8 ); }
@@ -89,8 +89,8 @@ static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)BUG_ON (next == &init_mm);/* Should never happen */ -if (next->context ==0 ) - next->context =alloc_sid (); +if (next->context.space_id ==0 ) + next->context.space_id =alloc_sid ();switch_mm (prev,next,current); }
arch/parisc/include/asm/page.h +2 -0
@@ -179,6 +179,8 @@ extern int npmem_ranges;#define page_to_phys (page) (page_to_pfn(page) << PAGE_SHIFT)#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) +#define virt_to_pfn (kaddr) (phys_to_pfn(__pa(kaddr))) +#define phys_to_pfn (paddr) ((paddr) >> PAGE_SHIFT)#include <asm-generic/memory_model.h> #include <asm-generic/getorder.h>
arch/parisc/include/asm/pgtable.h +5 -2
@@ -70,7 +70,7 @@ static inline void purge_tlb_entries(struct mm_struct *mm, unsigned long addr)unsigned long flags;purge_tlb_start (flags); -mtsp (mm->context,1 ); +mtsp (mm->context.space_id,1 );pdtlb (addr);pitlb (addr);purge_tlb_end (flags);
@@ -219,9 +219,10 @@ extern void __update_cache(pte_t pte);#define _PAGE_PRESENT (1 << xlate_pabit(_PAGE_PRESENT_BIT))#define _PAGE_HUGE (1 << xlate_pabit(_PAGE_HPAGE_BIT))#define _PAGE_USER (1 << xlate_pabit(_PAGE_USER_BIT)) +#define _PAGE_SPECIAL (_PAGE_DMB)#define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_DIRTY | _PAGE_ACCESSED) -#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) +#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_SPECIAL)#define _PAGE_KERNEL_RO (_PAGE_PRESENT | _PAGE_READ | _PAGE_DIRTY | _PAGE_ACCESSED)#define _PAGE_KERNEL_EXEC (_PAGE_KERNEL_RO | _PAGE_EXEC)#define _PAGE_KERNEL_RWX (_PAGE_KERNEL_EXEC | _PAGE_WRITE)
@@ -348,6 +349,7 @@ static inline void pud_clear(pud_t *pud) {static inline int pte_dirty (pte_t pte) {return pte_val (pte) & _PAGE_DIRTY; }static inline int pte_young (pte_t pte) {return pte_val (pte) & _PAGE_ACCESSED; }static inline int pte_write (pte_t pte) {return pte_val (pte) & _PAGE_WRITE; } +static inline int pte_special (pte_t pte) {return pte_val (pte) & _PAGE_SPECIAL; }static inline pte_t pte_mkclean (pte_t pte) {pte_val (pte) &= ~_PAGE_DIRTY;return pte; }static inline pte_t pte_mkold (pte_t pte) {pte_val (pte) &= ~_PAGE_ACCESSED;return pte; }
@@ -355,6 +357,7 @@ static inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~_PAGE_WRITE; retstatic inline pte_t pte_mkdirty (pte_t pte) {pte_val (pte) |= _PAGE_DIRTY;return pte; }static inline pte_t pte_mkyoung (pte_t pte) {pte_val (pte) |= _PAGE_ACCESSED;return pte; }static inline pte_t pte_mkwrite (pte_t pte) {pte_val (pte) |= _PAGE_WRITE;return pte; } +static inline pte_t pte_mkspecial (pte_t pte) {pte_val (pte) |= _PAGE_SPECIAL;return pte; }/* * Huge pte definitions.
arch/parisc/include/asm/processor.h +1 -1
@@ -236,7 +236,7 @@ on downward growing arches, it looks like this:#define start_thread (regs, new_pc, new_sp) do { \ elf_addr_t *sp = (elf_addr_t *)new_sp; \ - __u32 spaceid = (__u32)current->mm->context; \ + __u32 spaceid = (__u32)current->mm->context.space_id; \ elf_addr_t pc = (elf_addr_t)new_pc | 3; \ elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1; \ \
arch/parisc/include/asm/rt_sigframe.h +1 -9
@@ -2,16 +2,8 @@#ifndef _ASM_PARISC_RT_SIGFRAME_H#define _ASM_PARISC_RT_SIGFRAME_H -#define SIGRETURN_TRAMP 4 -#define SIGRESTARTBLOCK_TRAMP 5 -#define TRAMP_SIZE (SIGRETURN_TRAMP + SIGRESTARTBLOCK_TRAMP) -struct rt_sigframe { -/* XXX: Must match trampoline size in arch/parisc/kernel/signal.c -Secondary to that it must protect the ERESTART_RESTARTBLOCK -trampoline we left on the stack (we were bad and didn't -change sp so we could run really fast.) */ -unsigned int tramp[TRAMP_SIZE ]; +unsigned int tramp[2 ];/* holds original return address */ struct siginfo info;struct ucontext uc; };
arch/parisc/include/asm/tlbflush.h +1 -1
@@ -17,7 +17,7 @@ int __flush_tlb_range(unsigned long sid, unsigned long start, unsigned long end);#define flush_tlb_range (vma, start, end) \ - __flush_tlb_range((vma)->vm_mm->context, start, end) + __flush_tlb_range((vma)->vm_mm->context.space_id, start, end)#define flush_tlb_kernel_range (start, end) \ __flush_tlb_range(0, start, end)
arch/parisc/include/asm/unistd.h +0 -4
@@ -63,10 +63,6 @@ ); \ __sys_res = (long )__res; \ } \ -if ( (unsigned long )__sys_res >= (unsigned long )-4095 ){ \ - errno = -__sys_res; \ - __sys_res =-1 ; \ - } \ __sys_res; \ })
arch/parisc/include/asm/vdso.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __PARISC_VDSO_H__ +#define __PARISC_VDSO_H__ + +#ifndef __ASSEMBLY__ + +#ifdef CONFIG_64BIT +#include <generated/vdso64-offsets.h> +#endif +#include <generated/vdso32-offsets.h> + +#define VDSO64_SYMBOL (tsk, name) ((tsk)->mm->context.vdso_base + (vdso64_offset_##name)) +#define VDSO32_SYMBOL (tsk, name) ((tsk)->mm->context.vdso_base + (vdso32_offset_##name)) + +extern struct vdso_data *vdso_data; + +#endif /* __ASSEMBLY __ */ + +/* Default link addresses for the vDSOs */ +#define VDSO_LBASE 0 + +#define VDSO_VERSION_STRING LINUX_5.18 + +#endif /* __PARISC_VDSO_H__ */
arch/parisc/include/uapi/asm/auxvec.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_PARISC_AUXVEC_H +#define _UAPI_PARISC_AUXVEC_H + +/* The vDSO location. */ +#define AT_SYSINFO_EHDR 33 + +#endif /* _UAPI_PARISC_AUXVEC_H */
arch/parisc/kernel/Makefile +7 -2
@@ -10,7 +10,7 @@ obj-y := cache.o pacache.o setup.o pdt.o traps.o time.o irq.o \ ptrace.o hardware.o inventory.o drivers.o alternative.o \ signal.o hpmc.o real2.o parisc_ksyms.o unaligned.o \ process.o processor.o pdc_cons.o pdc_chassis.o unwind.o \ - patch.o toc.o toc_asm.o + patch.o toc.o toc_asm.o vdso.o ifdef CONFIG_FUNCTION_TRACER # Do not profile debug and lowlevel utilities
@@ -30,7 +30,7 @@ obj-$(CONFIG_STACKTRACE)+= stacktrace.o obj-$(CONFIG_AUDIT) += audit.o obj64-$(CONFIG_AUDIT) += compat_audit.o # only supported for PCX-W/U in 64-bit mode at the moment -obj-$(CONFIG_64BIT) += perf.o perf_asm.o $(obj64-y) +obj-$(CONFIG_64BIT) += perf.o perf_asm.o $(obj64-y) vdso64/ obj-$(CONFIG_PARISC_CPU_TOPOLOGY) += topology.o obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += ftrace.o
@@ -39,3 +39,8 @@ obj-$(CONFIG_KGDB) += kgdb.o obj-$(CONFIG_KPROBES) += kprobes.o obj-$(CONFIG_KEXEC_CORE) += kexec.o relocate_kernel.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o +obj-$(CONFIG_TOC) += toc.o toc_asm.o + +# vdso +obj-$(CONFIG_64BIT) += vdso64/ +obj-y += vdso32/
arch/parisc/kernel/asm-offsets.c +9 -0
@@ -26,7 +26,11 @@#include <asm/ptrace.h> #include <asm/processor.h> #include <asm/pdc.h> +#include <uapi/asm/sigcontext.h> +#include <asm/ucontext.h> +#include <asm/rt_sigframe.h> #include <linux/uaccess.h> +#include "signal32.h" /* Add FRAME_SIZE to the size x and align it to y. All definitions * that use align_frame will include space for a frame.
@@ -218,6 +222,11 @@ int main(void)DEFINE (TI_FLAGS , offsetof(struct thread_info , flags)); DEFINE(TI_PRE_COUNT, offsetof(struct task_struct, thread_info.preempt_count));BLANK (); +DEFINE (ASM_SIGFRAME_SIZE ,PARISC_RT_SIGFRAME_SIZE ); + DEFINE(SIGFRAME_CONTEXT_REGS, offsetof(struct rt_sigframe, uc.uc_mcontext) - PARISC_RT_SIGFRAME_SIZE); +DEFINE (ASM_SIGFRAME_SIZE32 ,PARISC_RT_SIGFRAME_SIZE32 ); + DEFINE(SIGFRAME_CONTEXT_REGS32, offsetof(struct compat_rt_sigframe, uc.uc_mcontext) - PARISC_RT_SIGFRAME_SIZE32); +BLANK ();DEFINE (ICACHE_BASE , offsetof(struct pdc_cache_info , ic_base));DEFINE (ICACHE_STRIDE , offsetof(struct pdc_cache_info , ic_stride));DEFINE (ICACHE_COUNT , offsetof(struct pdc_cache_info , ic_count));
arch/parisc/kernel/cache.c +5 -5
@@ -575,14 +575,14 @@ void flush_cache_mm(struct mm_struct *mm)rp3440, etc. So, avoid it if the mm isn't too big. */ if ((!IS_ENABLED (CONFIG_SMP ) || !arch_irqs_disabled ()) &&mm_total_size (mm) >= parisc_cache_flush_threshold) { -if (mm->context) +if (mm->context.space_id)flush_tlb_all ();flush_cache_all ();return ; }preempt_disable (); -if (mm->context ==mfsp (3 )) { +if (mm->context.space_id ==mfsp (3 )) {for (vma = mm->mmap; vma; vma = vma->vm_next)flush_user_cache_tlb (vma, vma->vm_start, vma->vm_end);preempt_enable ();
@@ -599,14 +599,14 @@ void flush_cache_range(struct vm_area_struct *vma, {if ((!IS_ENABLED (CONFIG_SMP ) || !arch_irqs_disabled ()) && end - start >= parisc_cache_flush_threshold) { -if (vma->vm_mm->context) +if (vma->vm_mm->context.space_id)flush_tlb_range (vma, start, end);flush_cache_all ();return ; }preempt_disable (); -if (vma->vm_mm->context ==mfsp (3 )) { +if (vma->vm_mm->context.space_id ==mfsp (3 )) {flush_user_cache_tlb (vma, start, end);preempt_enable ();return ;
@@ -620,7 +620,7 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn) { if (pfn_valid(pfn)) { - if (likely(vma->vm_mm->context)) { + if (likely(vma->vm_mm->context.space_id)) {flush_tlb_page (vma, vmaddr);__flush_cache_page (vma, vmaddr,PFN_PHYS (pfn)); } else {
arch/parisc/kernel/signal.c +110 -117
468 lines not on this page · raw message
arch/parisc/kernel/signal32.h +5 -14
@@ -36,21 +36,12 @@ struct compat_regfile {compat_int_t rf_sar; }; -#define COMPAT_SIGRETURN_TRAMP 4 -#define COMPAT_SIGRESTARTBLOCK_TRAMP 5 -#define COMPAT_TRAMP_SIZE (COMPAT_SIGRETURN_TRAMP + \ - COMPAT_SIGRESTARTBLOCK_TRAMP) -struct compat_rt_sigframe { -/* XXX: Must match trampoline size in arch/parisc/kernel/signal.c -Secondary to that it must protect the ERESTART_RESTARTBLOCK -trampoline we left on the stack (we were bad and didn't -change sp so we could run really fast.) */ -compat_uint_t tramp[COMPAT_TRAMP_SIZE ]; -compat_siginfo_t info; -struct compat_ucontext uc; -/* Hidden location of truncated registers, *must* be last. */ -struct compat_regfile regs; +unsigned int tramp[2 ];/* holds original return address */ +compat_siginfo_t info; +struct compat_ucontext uc; +/* Hidden location of truncated registers, *must* be last. */ +struct compat_regfile regs; };/*
arch/parisc/kernel/vdso.c new file +125 -0
125 lines not on this page · raw message
arch/parisc/kernel/vdso32/Makefile new file +53 -0
53 lines not on this page · raw message
arch/parisc/kernel/vdso32/gen_vdso_offsets.sh new file +15 -0
@@ -0,0 +1,15 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +# +# Match symbols in the DSO that look like VDSO_*; produce a header file +# of constant offsets into the shared object. +# +# Doing this inside the Makefile will break the $(filter-out) function, +# causing Kbuild to rebuild the vdso-offsets header file every time. +# +# Inspired by arm64 version. +# + +LC_ALL=C +sed -n 's/\([0-9a-f]*\) . __kernel_\(.*\)/\#define vdso32_offset_\2\t0x\1/p'
arch/parisc/kernel/vdso32/note.S new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text. + * Here we can supply some information useful to userland. + */ + +#include <linux/uts.h> +#include <linux/version.h> + +#define ASM_ELF_NOTE_BEGIN(name, flags, vendor, type) \ + .section name, flags; \ + .balign 4; \ + .long 1f - 0f; /* name length */ \ + .long 3f - 2f; /* data length */ \ + .long type; /* note type */ \ +0: .asciz vendor; /* vendor name */ \ +1: .balign 4; \ +2: + +#define ASM_ELF_NOTE_END \ +3: .balign 4; /* pad out section */ \ + .previous + + ASM_ELF_NOTE_BEGIN(".note.kernel-version", "a", UTS_SYSNAME, 0) + .long LINUX_VERSION_CODE + ASM_ELF_NOTE_END
arch/parisc/kernel/vdso32/restart_syscall.S new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Syscall restart trampoline for 32 and 64 bits processes. + * + * Copyright (C) 2018-2022 Helge Deller <[email protected]> + * Copyright (C) 2022 John David Anglin <[email protected]> + */ + +#include <asm/unistd.h> +#include <asm/vdso.h> + +#include <linux/linkage.h> + + .text + +ENTRY_CFI(__kernel_restart_syscall) + /* + * Setup a trampoline to restart the syscall + * with __NR_restart_syscall + */ + + /* load return pointer */ +#if defined(__VDSO64__) + ldd 0(%sp), %r31 +#elif defined(__VDSO32__) + ldw 0(%sp), %r31 +#endif + + be 0x100(%sr2, %r0) + ldi __NR_restart_syscall, %r20 + +ENDPROC_CFI(__kernel_restart_syscall)
arch/parisc/kernel/vdso32/sigtramp.S new file +195 -0
195 lines not on this page · raw message
arch/parisc/kernel/vdso32/vdso32.lds.S new file +111 -0
111 lines not on this page · raw message
arch/parisc/kernel/vdso32/vdso32_wrapper.S new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/linkage.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdso32_start, vdso32_end + .balign PAGE_SIZE +vdso32_start: + .incbin "arch/parisc/kernel/vdso32/vdso32.so" + .balign PAGE_SIZE +vdso32_end: + + .previous
arch/parisc/kernel/vdso64/Makefile new file +48 -0
48 lines not on this page · raw message
arch/parisc/kernel/vdso64/gen_vdso_offsets.sh new file +15 -0
@@ -0,0 +1,15 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +# +# Match symbols in the DSO that look like VDSO_*; produce a header file +# of constant offsets into the shared object. +# +# Doing this inside the Makefile will break the $(filter-out) function, +# causing Kbuild to rebuild the vdso-offsets header file every time. +# +# Inspired by arm64 version. +# + +LC_ALL=C +sed -n 's/\([0-9a-f]*\) . __kernel_\(.*\)/\#define vdso64_offset_\2\t0x\1/p'
arch/parisc/kernel/vdso64/note.S new file +2 -0
@@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include "../vdso32/note.S"
arch/parisc/kernel/vdso64/restart_syscall.S new file +3 -0
@@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include "../vdso32/restart_syscall.S"
arch/parisc/kernel/vdso64/sigtramp.S new file +166 -0
166 lines not on this page · raw message
arch/parisc/kernel/vdso64/vdso64.lds.S new file +109 -0
109 lines not on this page · raw message
arch/parisc/kernel/vdso64/vdso64_wrapper.S new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/linkage.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdso64_start, vdso64_end + .balign PAGE_SIZE +vdso64_start: + .incbin "arch/parisc/kernel/vdso64/vdso64.so" + .balign PAGE_SIZE +vdso64_end: + + .previous
--
2.34.1
Am Samstag, 29. Januar 2022, 12:03:42 CET schrieb Helge Deller:
Quoted 15 lines
Add minimal vDSO support, which provides the signal trampoline helpers, but none of the userspace syscall helpers like time functions.
The big benefit of this vDSO implementation is, that we now don't need an executeable stack any longer. PA-RISC is one of the last architectures where an executeable stack was needed in oder to implement the signal trampolines by putting assembly instructions on the stack which then gets executed. With this implementation the kernel will utilize the assembler statements in the vDSO page which is mapped into each userspace application instead and just put the pointers to the signal information on the stack. By dropping the need for executable stacks we now avoid running into issues with various applications in Debian which nowadays want non-executable stacks for security reasons. Additionally, alternative stacks are supported better as well.
Quoted 6 lines
This code is based on an initial implementation by Randolph Chung from 2006:
https://lore.kernel.org/linux-parisc/[email protected]/I did the porting and lifted the code to current code base. Dave fixed the unwind code so that gdb and glibc are able to backtrace through the code. An additional patch to gdb will be pushed upstream by Dave.
There are a few extra newlines in the first few files which you may or may not want to remove.
OTOH I would split out the change to mm_context_t into it's own patch, without adding the vdso_base there. This would reduce the overall size of the actual vdso patch and eases review.
Eike
Helge Deller
maintainerHi Rolf,
Quoted 19 lines · Rolf Eike Beer
Am Samstag, 29. Januar 2022, 12:03:42 CET schrieb Helge Deller:
Quoted 18 lines
Add minimal vDSO support, which provides the signal trampoline helpers, but none of the userspace syscall helpers like time functions.
The big benefit of this vDSO implementation is, that we now don't need an executeable stack any longer. PA-RISC is one of the last architectures where an executeable stack was needed in oder to implement the signal trampolines by putting assembly instructions on the stack which then gets executed. With this implementation the kernel will utilize the assembler statements in the vDSO page which is mapped into each userspace application instead and just put the pointers to the signal information on the stack. By dropping the need for executable stacks we now avoid running into issues with various applications in Debian which nowadays want non-executable stacks for security reasons. Additionally, alternative stacks are supported better as well.
This code is based on an initial implementation by Randolph Chung from 2006:
https://lore.kernel.org/linux-parisc/[email protected]/
Quoted 6 lines
Quoted 3 lines
I did the porting and lifted the code to current code base. Dave fixed the unwind code so that gdb and glibc are able to backtrace through the code. An additional patch to gdb will be pushed upstream by Dave.
There are a few extra newlines in the first few files which you may or may not want to remove.
Thanks for noticing.
I fixed them up now.
Quoted 3 lines
OTOH I would split out the change to
mm_context_tinto it's own patch, without adding thevdso_basethere. This would reduce the overall size of the actual vdso patch and eases review.
Yes, maybe I'll do that. Not sure yet.
Helge