arm: vdso: Convert sigpage to vdso implementation
Subsystems (3)
RFC 1/1 arm: vdso: Convert sigpage to vdso implementation
ARM has a special sigpage that is used for signal return trampolines. Its implementation is very similar to a VDSO conceptually in that it occupies a special mapping in user address space.
One could actually host the trampoline code in a VDSO instead with the added advantage that one could also host specialised routines there. One such routine could be gettimeofday where on ARM we have architected (and some vendor supplied) timers that can be queried entirely in userspace, obviating the need for an expensive syscall.
This patch converts the sigpage implementation to a VDSO. It is mostly a direct port from Will Deacon's arm64 implementation with the ARM signal trampoline plumbed in.
---
As can be inferred from this RFC, I am interested ultimately in implementing a syscall-less gettimeofday for ARM. Whilst researching possible vectors page or VDSO implementations, I came across the sigpage mechanism which is very similar to a VDSO.
The very simple function, __kernel_vdso_doubler, resolved in a test program automatically on my Arndale board (running Fedora 20) without any additional prodding.
IPC stress tests from LTP were executed to test the signal trampoline.
I would appreciate any comments on this approach of converting the sigpage to a VDSO. If this looks sane to people, I will work on the gettimeofday logic in a later patch.
Cheers,
Signature · 24 lines
Steve --- arch/arm/include/asm/elf.h | 11 +++- arch/arm/include/asm/mmu.h | 2 +- arch/arm/include/asm/vdso.h | 44 +++++++++++++ arch/arm/kernel/Makefile | 9 +++ arch/arm/kernel/process.c | 48 +++++--------- arch/arm/kernel/signal.c | 38 ++--------- arch/arm/kernel/vdso.c | 105 +++++++++++++++++++++++++++++++ arch/arm/kernel/vdso/.gitignore | 2 + arch/arm/kernel/vdso/Makefile | 72 +++++++++++++++++++++ arch/arm/kernel/vdso/gen_vdso_offsets.sh | 15 +++++ arch/arm/kernel/vdso/simple.S | 31 +++++++++ arch/arm/kernel/vdso/vdso.S | 35 +++++++++++ arch/arm/kernel/vdso/vdso.lds.S | 99 +++++++++++++++++++++++++++++ 13 files changed, 442 insertions(+), 69 deletions(-) create mode 100644 arch/arm/include/asm/vdso.h create mode 100644 arch/arm/kernel/vdso.c create mode 100644 arch/arm/kernel/vdso/.gitignore create mode 100644 arch/arm/kernel/vdso/Makefile create mode 100755 arch/arm/kernel/vdso/gen_vdso_offsets.sh create mode 100644 arch/arm/kernel/vdso/simple.S create mode 100644 arch/arm/kernel/vdso/vdso.S create mode 100644 arch/arm/kernel/vdso/vdso.lds.S
arch/arm/include/asm/elf.h +10 -1
@@ -132,6 +132,15 @@ extern unsigned long arch_randomize_brk(struct mm_struct *mm);#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1struct linux_binprm ;int arch_setup_additional_pages (struct linux_binprm *,int ); -#endif + +#define AT_SYSINFO_EHDR 33 +#define __HAVE_ARCH_GATE_AREA 1 + +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)current->mm->context.vdso); \ +} while (0) +#endif /* CONFIG_MMU */ #endif
arch/arm/include/asm/mmu.h +1 -1
@@ -10,7 +10,7 @@ typedef struct {int switch_pending;#endif unsigned int vmalloc_seq; -unsigned long sigpage; +unsigned long vdso; } mm_context_t;#ifdef CONFIG_CPU_HAS_ASID
arch/arm/include/asm/vdso.h new file +44 -0
44 lines not on this page · raw message
arch/arm/kernel/Makefile +9 -0
@@ -99,3 +99,12 @@ obj-$(CONFIG_SMP) += psci_smp.o endif extra-y := $(head-y) vmlinux.lds + +ifdef CONFIG_MMU +obj-y += vdso.o +obj-y += vdso/ + +# vDSO - this must be built first to generate the symbol offsets +$(call objectify,$(obj-y)): $(obj)/vdso/vdso-offsets.h +$(obj)/vdso/vdso-offsets.h: $(obj)/vdso +endif
arch/arm/kernel/process.c +15 -33
61 lines not on this page · raw message
arch/arm/kernel/signal.c +4 -34
@@ -20,11 +20,10 @@#include <asm/ucontext.h> #include <asm/unistd.h> #include <asm/vfp.h> +#include <asm/vdso.h> extern const unsigned long sigreturn_codes[7 ]; -static unsigned long signal_return_offset; -#ifdef CONFIG_CRUNCH static int preserve_crunch_context (struct crunch_sigframe __user *frame) {
@@ -395,8 +394,9 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,* except when the MPU has protected the vectors * page from PL0 */ - retcode = mm->context.sigpage + signal_return_offset + - (idx <<2 ) + thumb; + retcode = (unsigned long )VDSO_SYMBOL (mm->context.vdso, + sigtramp); + retcode += (idx <<2 ) + thumb; } else#endif {
@@ -600,33 +600,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall) }while (thread_flags & _TIF_WORK_MASK);return 0 ; } - -struct page *get_signal_page (void ) -{ -unsigned long ptr; -unsigned offset; -struct page *page; -void *addr; - - page =alloc_pages (GFP_KERNEL ,0 ); - -if (!page) -return NULL ; - - addr =page_address (page); - -/* Give the signal return code some randomness */ - offset =0x200 + (get_random_int () &0x7fc ); - signal_return_offset = offset; - -/* -* Copy signal return handlers into the vector page, and -* set sigreturn to be a pointer to these. -*/ -memcpy (addr + offset, sigreturn_codes,sizeof (sigreturn_codes)); - - ptr = (unsigned long )addr + offset; -flush_icache_range (ptr, ptr +sizeof (sigreturn_codes)); - -return page; -}
arch/arm/kernel/vdso.c new file +105 -0
105 lines not on this page · raw message
arch/arm/kernel/vdso/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +vdso.lds +vdso-offsets.h
arch/arm/kernel/vdso/Makefile new file +72 -0
72 lines not on this page · raw message
arch/arm/kernel/vdso/gen_vdso_offsets.sh new file +15 -0
@@ -0,0 +1,15 @@ +#!/bin/sh + +# +# 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. +# +# Author: Will Deacon <[email protected]> +# + +LC_ALL=C +sed -n -e 's/^00*/0/' -e \ +'s/^\([0-9a-fA-F]*\) . VDSO_\([a-zA-Z0-9_]*\)$/\#define vdso_offset_\2\t0x\1/p'
arch/arm/kernel/vdso/simple.S new file +31 -0
@@ -0,0 +1,31 @@ +/* + * Simple test function for VDSO implementation for ARM + * + * Copyright (C) 2014 Linaro Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include <linux/linkage.h> +#include <asm/unistd.h> + +/* + * An extremely simple test function: + * unsigned int __kernel_vdso_doubler(unsigned int arg); + */ + .text +ENTRY(__kernel_vdso_doubler) + lsl r0, r0, #1 + mov pc, lr +ENDPROC(__kernel_vdso_doubler)
arch/arm/kernel/vdso/vdso.S new file +35 -0
@@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 Linaro Ltd. + * + * Based on arm64 implementation by Will Deacon. + * Copyright (C) 2012 ARM Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/const.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdso_start, vdso_end + .balign PAGE_SIZE +vdso_start: + .incbin "arch/arm/kernel/vdso/vdso.so" + .balign PAGE_SIZE +vdso_end: + + .previous
arch/arm/kernel/vdso/vdso.lds.S new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Quoted 25 lines · Steve Capper
ARM has a special sigpage that is used for signal return trampolines. Its implementation is very similar to a VDSO conceptually in that it occupies a special mapping in user address space.
One could actually host the trampoline code in a VDSO instead with the added advantage that one could also host specialised routines there. One such routine could be gettimeofday where on ARM we have architected (and some vendor supplied) timers that can be queried entirely in userspace, obviating the need for an expensive syscall.
This patch converts the sigpage implementation to a VDSO. It is mostly a direct port from Will Deacon's arm64 implementation with the ARM signal trampoline plumbed in.
Signed-off-by Steve Capper <[email protected]>---
As can be inferred from this RFC, I am interested ultimately in implementing a syscall-less gettimeofday for ARM. Whilst researching possible vectors page or VDSO implementations, I came across the sigpage mechanism which is very similar to a VDSO.The very simple function,
__kernel_vdso_doubler, resolved in a test program automatically on my Arndale board (running Fedora 20) without any additional prodding.
Quoted 5 lines
IPC stress tests from LTP were executed to test the signal trampoline.
I would appreciate any comments on this approach of converting the sigpage to a VDSO. If this looks sane to people, I will work on the gettimeofday logic in a later patch.
I'm not happy with this removing much of the work I pushed into the kernel to work around the security issues which were identified with the fixed-address placement of stuff in the vectors page. Particularly the random placement of the signal return stubs within the new signal page is gone with the VDSO approach, which means if someone can discover the VDSO page, they can issue any system call they please by knowing the appropriate offset into the page to call.
While the VDSO page will be placed randomly, I'd also like to have the signal handlers placed randomly within that page as well - there's no need for them to be at a fixed offset. The only thing which needs to know where they are after all is the kernel.
I'm not sure about putting gettimeofday() into this - gettimeofday() would need to have various kernel variables exported into userspace for the VDSO page to then compute the current time of day from the timer value(s), and that's certainly not going to be at a fixed address.
I believe x86 eventually ended up going down the path of trapping and emulating calls to the VDSO page because VDSO became too much of a problem (though I think it does provide the option for having it back but not by default.)
Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up. Estimation in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad. Estimate before purchase was "up to 13.2Mbit".
Quoted 32 lines · Russell King - ARM Linux
Quoted 25 lines · Steve Capper
ARM has a special sigpage that is used for signal return trampolines. Its implementation is very similar to a VDSO conceptually in that it occupies a special mapping in user address space.
One could actually host the trampoline code in a VDSO instead with the added advantage that one could also host specialised routines there. One such routine could be gettimeofday where on ARM we have architected (and some vendor supplied) timers that can be queried entirely in userspace, obviating the need for an expensive syscall.
This patch converts the sigpage implementation to a VDSO. It is mostly a direct port from Will Deacon's arm64 implementation with the ARM signal trampoline plumbed in.
Signed-off-by Steve Capper <[email protected]>---
As can be inferred from this RFC, I am interested ultimately in implementing a syscall-less gettimeofday for ARM. Whilst researching possible vectors page or VDSO implementations, I came across the sigpage mechanism which is very similar to a VDSO.The very simple function,
__kernel_vdso_doubler, resolved in a test program automatically on my Arndale board (running Fedora 20) without any additional prodding.Quoted 5 lines
IPC stress tests from LTP were executed to test the signal trampoline.
I would appreciate any comments on this approach of converting the sigpage to a VDSO. If this looks sane to people, I will work on the gettimeofday logic in a later patch.
Quoted 7 lines
I'm not happy with this removing much of the work I pushed into the kernel to work around the security issues which were identified with the fixed-address placement of stuff in the vectors page. Particularly the random placement of the signal return stubs within the new signal page is gone with the VDSO approach, which means if someone can discover the VDSO page, they can issue any system call they please by knowing the appropriate offset into the page to call.
Hi Russell,
I didn't mean to undo you work.
Essentially I saw the sigpage was so close to being a vdso, it just needed a little nudge to contain other code too.
Quoted 5 lines
While the VDSO page will be placed randomly, I'd also like to have the signal handlers placed randomly within that page as well - there's no need for them to be at a fixed offset. The only thing which needs to know where they are after all is the kernel.
I was considering a larger segment containing the trampoline at random offset, but came to the conclusion that the VA randomisation of the vdso page location was in itself sufficient?
Quoted 6 lines
I'm not sure about putting
gettimeofday()into this -gettimeofday()would need to have various kernel variables exported into userspace for the VDSO page to then compute the current time of day from the timer value(s), and that's certainly not going to be at a fixed address.
I believe a vdso data page could house the variables, the offsets within the page could be fixed at compile time.
Quoted 5 lines
I believe x86 eventually ended up going down the path of trapping and emulating calls to the VDSO page because VDSO became too much of a problem (though I think it does provide the option for having it back but not by default.)
Cheers,
Signature · 1 line
Steve
Quoted 8 lines · Steve Capper
Quoted 7 lines · Russell King - ARM Linux
I'm not happy with this removing much of the work I pushed into the kernel to work around the security issues which were identified with the fixed-address placement of stuff in the vectors page. Particularly the random placement of the signal return stubs within the new signal page is gone with the VDSO approach, which means if someone can discover the VDSO page, they can issue any system call they please by knowing the appropriate offset into the page to call.
[...]
Quoted 8 lines
Quoted 4 lines
While the VDSO page will be placed randomly, I'd also like to have the signal handlers placed randomly within that page as well - there's no need for them to be at a fixed offset. The only thing which needs to know where they are after all is the kernel.
I was considering a larger segment containing the trampoline at random offset, but came to the conclusion that the VA randomisation of the vdso page location was in itself sufficient?
Whilst randomising within a page could potentially be beneficial, I question just how much use it is doing it only for the signal page. For example, for a system running a given version of libc, if you know where libc is mapped, then you can easily find syscall sequences in there. Similarly for gettimeofday() in the vDSO, there is a syscall fallback path too.
Dynamically randomising the layout of shared libraries is likely to confuse the dynamic linker and completely break debugging with GDB. It's also not something that I'm aware of being done by any other architectures in the kernel.
I think there's a trade-off between the measurable performance advantage of exporting functions such as gtod in the vDSO and the unclear security gains of randomising the sigreturn code within a page when the page address is already randomised.
Quoted 4 lines
Quoted 4 lines
I believe x86 eventually ended up going down the path of trapping and emulating calls to the VDSO page because VDSO became too much of a problem (though I think it does provide the option for having it back but not by default.)
Hmm, do you have any pointers to more information about that? I know that the vsyscall page went the way of the dodo because it was placed at a fixed address, but I thought that the vDSO was still alive and kicking.
Will
Hi Steve,
Quoted 25 lines · Steve Capper
ARM has a special sigpage that is used for signal return trampolines. Its implementation is very similar to a VDSO conceptually in that it occupies a special mapping in user address space.
One could actually host the trampoline code in a VDSO instead with the added advantage that one could also host specialised routines there. One such routine could be gettimeofday where on ARM we have architected (and some vendor supplied) timers that can be queried entirely in userspace, obviating the need for an expensive syscall.
This patch converts the sigpage implementation to a VDSO. It is mostly a direct port from Will Deacon's arm64 implementation with the ARM signal trampoline plumbed in.
Signed-off-by Steve Capper <[email protected]>---
As can be inferred from this RFC, I am interested ultimately in implementing a syscall-less gettimeofday for ARM. Whilst researching possible vectors page or VDSO implementations, I came across the sigpage mechanism which is very similar to a VDSO.The very simple function,
__kernel_vdso_doubler, resolved in a test program automatically on my Arndale board (running Fedora 20) without any additional prodding.
Quoted 5 lines
IPC stress tests from LTP were executed to test the signal trampoline.
I would appreciate any comments on this approach of converting the sigpage to a VDSO. If this looks sane to people, I will work on the gettimeofday logic in a later patch.
As it happens, I've been working on a vDSO implementation of gettimeofday/clock_gettime which does not mess with the signal page. I'll reply with the patch separately in a moment.
Quoted 30 lines · Nathan Lynch
Hi Steve,
Quoted 27 lines · Steve Capper
ARM has a special sigpage that is used for signal return trampolines. Its implementation is very similar to a VDSO conceptually in that it occupies a special mapping in user address space.
One could actually host the trampoline code in a VDSO instead with the added advantage that one could also host specialised routines there. One such routine could be gettimeofday where on ARM we have architected (and some vendor supplied) timers that can be queried entirely in userspace, obviating the need for an expensive syscall.
This patch converts the sigpage implementation to a VDSO. It is mostly a direct port from Will Deacon's arm64 implementation with the ARM signal trampoline plumbed in.
Signed-off-by Steve Capper <[email protected]>---
As can be inferred from this RFC, I am interested ultimately in implementing a syscall-less gettimeofday for ARM. Whilst researching possible vectors page or VDSO implementations, I came across the sigpage mechanism which is very similar to a VDSO.The very simple function,
__kernel_vdso_doubler, resolved in a test program automatically on my Arndale board (running Fedora 20) without any additional prodding.IPC stress tests from LTP were executed to test the signal trampoline.
Quoted 7 lines
Quoted 3 lines
I would appreciate any comments on this approach of converting the sigpage to a VDSO. If this looks sane to people, I will work on the gettimeofday logic in a later patch.
As it happens, I've been working on a vDSO implementation of gettimeofday/clock_gettime which does not mess with the signal page. I'll reply with the patch separately in a moment.
Cheers Nathan,
Signature · 1 line
Steve
Quoted 2 lines
[RFC/PATCH] ARM: vDSO gettimeofday using generic timer architecture
In reply to Steve CapperProvide fast userspace implementations of gettimeofday and clock_gettime on systems that implement the generic timers extension defined in ARMv7. This follows the example of arm64 in conception but significantly differs in some aspects of the implementation (C vs assembly, mainly).
Clocks supported:
- CLOCK_REALTIME
- CLOCK_MONOTONIC
- CLOCK_REALTIME_COARSE
- CLOCK_MONOTONIC_COARSE
This also provides clock_getres (as arm64 does).
Tested on OMAP5 UEVM (Cortex A15) using a LD_PRELOAD shim to redirect system calls to the vDSO. I plan to undertake adding proper support to glibc if the overall approach is acceptable.
Note that while the high-precision realtime and monotonic clock support depends on the generic timers extension, support for clock_getres and (I think) the coarse clocks is pretty much independent of the timer implementation in use and could be provided unconditionally.
I also hope to add getcpu to the vDSO, using something like TPIDRURO/TPIDRURW (although I believe these registers are claimed for other uses already -- suggestions welcome).
This is RFC-quality code at the moment -- I haven't tested this on a system lacking generic timers, nor have I done much build testing. I'm sure there is plenty of room for improvement.
Based on linux-next 20140124.
--- arch/arm/Kconfig | 1 + arch/arm/include/asm/arch_timer.h | 7 +- arch/arm/include/asm/auxvec.h | 7 + arch/arm/include/asm/elf.h | 6 + arch/arm/include/asm/mmu.h | 1 + arch/arm/include/asm/vdso.h | 26 +++ arch/arm/include/asm/vdso_datapage.h | 45 ++++++ arch/arm/kernel/Makefile | 3 +- arch/arm/kernel/process.c | 16 +- arch/arm/kernel/vdso.c | 157 ++++++++++++++++++ arch/arm/kernel/vdso/.gitignore | 2 + arch/arm/kernel/vdso/Makefile | 46 ++++++ arch/arm/kernel/vdso/vdso.S | 35 ++++ arch/arm/kernel/vdso/vdso.lds.S | 93 +++++++++++ arch/arm/kernel/vdso/vgettimeofday.c | 303 +++++++++++++++++++++++++++++++++++ 15 files changed, 742 insertions(+), 6 deletions(-) create mode 100644 arch/arm/include/asm/auxvec.h create mode 100644 arch/arm/include/asm/vdso.h create mode 100644 arch/arm/include/asm/vdso_datapage.h create mode 100644 arch/arm/kernel/vdso.c create mode 100644 arch/arm/kernel/vdso/.gitignore create mode 100644 arch/arm/kernel/vdso/Makefile create mode 100644 arch/arm/kernel/vdso/vdso.S create mode 100644 arch/arm/kernel/vdso/vdso.lds.S create mode 100644 arch/arm/kernel/vdso/vgettimeofday.c
arch/arm/Kconfig +1 -0
@@ -23,6 +23,7 @@ config ARM select GENERIC_SMP_IDLE_THREAD select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER + select GENERIC_TIME_VSYSCALL select HARDIRQS_SW_RESEND select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL select HAVE_ARCH_KGDB
arch/arm/include/asm/arch_timer.h +5 -2
@@ -102,13 +102,16 @@ static inline void arch_counter_set_user_access(void) {u32 cntkctl =arch_timer_get_cntkctl (); -/* Disable user access to both physical/virtual counters/timers */ +/* Disable user access to the timers and the physical counter */ /* Also disable virtual event stream */ cntkctl &= ~(ARCH_TIMER_USR_PT_ACCESS_EN |ARCH_TIMER_USR_VT_ACCESS_EN |ARCH_TIMER_VIRT_EVT_EN - |ARCH_TIMER_USR_VCT_ACCESS_EN |ARCH_TIMER_USR_PCT_ACCESS_EN ); + +/* Enable user access to the virtual counter */ + cntkctl |=ARCH_TIMER_USR_VCT_ACCESS_EN ; +arch_timer_set_cntkctl (cntkctl); }
arch/arm/include/asm/auxvec.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ASM_AUXVEC_H +#define __ASM_AUXVEC_H + +/* vDSO location */ +#define AT_SYSINFO_EHDR 33 + +#endif
arch/arm/include/asm/elf.h +6 -0
@@ -1,6 +1,7 @@#ifndef __ASMARM_ELF_H#define __ASMARM_ELF_H +#include <asm/auxvec.h> #include <asm/hwcap.h> /*
@@ -129,6 +130,11 @@ extern unsigned long arch_randomize_brk(struct mm_struct *mm);#define arch_randomize_brk arch_randomize_brk#ifdef CONFIG_MMU +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (elf_addr_t)current->mm->context.vdso); \ +} while (0)#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1struct linux_binprm ;int arch_setup_additional_pages (struct linux_binprm *,int );
arch/arm/include/asm/mmu.h +1 -0
@@ -11,6 +11,7 @@ typedef struct {#endif unsigned int vmalloc_seq;unsigned long sigpage; +unsigned long vdso; } mm_context_t;#ifdef CONFIG_CPU_HAS_ASID
arch/arm/include/asm/vdso.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef __ASM_VDSO_H +#define __ASM_VDSO_H + +#ifdef __KERNEL__ + +#ifndef __ASSEMBLY__ + +#include <linux/mm_types.h> +#include <asm/mmu.h> + +static inline bool vma_is_vdso (struct vm_area_struct *vma) +{ +if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso) +return true; +return false; +} + +void arm_install_vdso (void ); + +#endif /* __ASSEMBLY__ */ + +#define VDSO_LBASE 0x0 + +#endif /* __KERNEL__ */ + +#endif /* __ASM_VDSO_H */
arch/arm/include/asm/vdso_datapage.h new file +45 -0
45 lines not on this page · raw message
arch/arm/kernel/Makefile +2 -1
@@ -18,7 +18,8 @@ CFLAGS_REMOVE_return_address.o = -pg obj-y := elf.o entry-common.o irq.o opcodes.o \ process.o ptrace.o return_address.o \ setup.o signal.o sigreturn_codes.o \ - stacktrace.o sys_arm.o time.o traps.o + stacktrace.o sys_arm.o time.o traps.o \ + vdso.o vdso/ obj-$(CONFIG_ATAGS) += atags_parse.o obj-$(CONFIG_ATAGS_PROC) += atags_proc.o
arch/arm/kernel/process.c +13 -3
@@ -41,6 +41,7 @@#include <asm/stacktrace.h> #include <asm/mach/time.h> #include <asm/tls.h> +#include <asm/vdso.h> #ifdef CONFIG_CC_STACKPROTECTOR #include <linux/stackprotector.h>
@@ -472,9 +473,16 @@ int in_gate_area_no_mm(unsigned long addr)const char *arch_vma_name (struct vm_area_struct *vma) { -return is_gate_vma (vma) ?"[vectors]" : - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ? -"[sigpage]" :NULL ; +if (is_gate_vma (vma)) +return "[vectors]" ; + +if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) +return "[sigpage]" ; + +if (vma_is_vdso (vma)) +return "[vdso]" ; + +return NULL ; }static struct page *signal_page;
@@ -505,6 +513,8 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)if (ret ==0 ) mm->context.sigpage = addr; +arm_install_vdso (); + up_fail:up_write (&mm->mmap_sem);return ret;
arch/arm/kernel/vdso.c new file +157 -0
157 lines not on this page · raw message
arch/arm/kernel/vdso/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +vdso.lds +
arch/arm/kernel/vdso/Makefile new file +46 -0
46 lines not on this page · raw message
arch/arm/kernel/vdso/vdso.S new file +35 -0
@@ -0,0 +1,35 @@ +/* + * Adapted from arm64 version. + * + * Copyright (C) 2012 ARM Limited + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Author: Will Deacon <[email protected]> + */ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/const.h> +#include <asm/page.h> + + __PAGE_ALIGNED_DATA + + .globl vdso_start, vdso_end + .balign PAGE_SIZE +vdso_start: + .incbin "arch/arm/kernel/vdso/vdso.so" + .balign PAGE_SIZE +vdso_end: + + .previous
arch/arm/kernel/vdso/vdso.lds.S new file +93 -0
93 lines not on this page · raw message
arch/arm/kernel/vdso/vgettimeofday.c new file +303 -0
303 lines not on this page · raw message
Signature · 1 line
1.8.3.1
[RFC/PATCH] ARM: vDSO gettimeofday using generic timer architecture
arch/arm/kernel/vdso.c line 39
Quoted 5 lines · Nathan Lynch
arch/arm/kernel/vdso.c new file +5
-0+static union { +struct vdso_data data; +u8 page[PAGE_SIZE ]; +} vdso_data_store __page_aligned_data; +struct vdso_data *vdso_data = &vdso_data_store.data;
So this is in the kernel data segment.
Quoted 24 lines
arch/arm/kernel/vdso.c new file +24
-0+void update_vsyscall (struct timekeeper *tk) +{ +struct timespec xtime_coarse; +struct timespec wall_time =tk_xtime (tk); +struct timespec *wtm = &tk->wall_to_monotonic; +u32 use_syscall =strcmp (tk->clock->name,"arch_sys_counter" ); + + ++vdso_data->tb_seq_count; +smp_wmb (); + + xtime_coarse =__current_kernel_time (); + vdso_data->use_syscall = use_syscall; + vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec; + vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec; + +if (!use_syscall) { + vdso_data->cs_cycle_last = tk->clock->cycle_last; + vdso_data->xtime_clock_sec = wall_time.tv_sec; + vdso_data->xtime_clock_nsec = wall_time.tv_nsec; + vdso_data->cs_mult = tk->mult; + vdso_data->cs_shift = tk->shift; + vdso_data->wtm_clock_sec = wtm->tv_sec; + vdso_data->wtm_clock_nsec = wtm->tv_nsec; + }
arch/arm/kernel/vdso.c line 157
Quoted 10 lines
arch/arm/kernel/vdso.c new file +10
-0+ +smp_wmb (); + ++vdso_data->tb_seq_count; +} + +void update_vsyscall_tz (void ) +{ + vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; + vdso_data->tz_dsttime = sys_tz.tz_dsttime; +}
which gets written to directly, and read from userspace. This won't work with aliasing caches, of which we have VIVT caches on all ARMv4 and ARMv5 CPUs, and VIPT caches on some ARMv6.
Either this needs to be limited to just VIPT nonaliasing caches, or it needs cache handling.
The above also looks rather unsafe from the SMP perspective - how does vdso_data->tb_seq_count protect this data between CPUs?
Signature · 3 lines
FTTC broadband for 0.8mile line: 5.8Mbps down 500kbps up. Estimation in database were 13.1 to 19Mbit for a good line, about 7.5+ for a bad. Estimate before purchase was "up to 13.2Mbit".
[RFC/PATCH] ARM: vDSO gettimeofday using generic timer architecture
Quoted 48 lines · Russell King - ARM Linux
arch/arm/kernel/vdso.c line 39
Quoted 5 lines · Nathan Lynch
arch/arm/kernel/vdso.c new file +5
-0+static union { +struct vdso_data data; +u8 page[PAGE_SIZE ]; +} vdso_data_store __page_aligned_data; +struct vdso_data *vdso_data = &vdso_data_store.data;So this is in the kernel data segment.
Quoted 24 lines
arch/arm/kernel/vdso.c new file +24
-0+void update_vsyscall (struct timekeeper *tk) +{ +struct timespec xtime_coarse; +struct timespec wall_time =tk_xtime (tk); +struct timespec *wtm = &tk->wall_to_monotonic; +u32 use_syscall =strcmp (tk->clock->name,"arch_sys_counter" ); + + ++vdso_data->tb_seq_count; +smp_wmb (); + + xtime_coarse =__current_kernel_time (); + vdso_data->use_syscall = use_syscall; + vdso_data->xtime_coarse_sec = xtime_coarse.tv_sec; + vdso_data->xtime_coarse_nsec = xtime_coarse.tv_nsec; + +if (!use_syscall) { + vdso_data->cs_cycle_last = tk->clock->cycle_last; + vdso_data->xtime_clock_sec = wall_time.tv_sec; + vdso_data->xtime_clock_nsec = wall_time.tv_nsec; + vdso_data->cs_mult = tk->mult; + vdso_data->cs_shift = tk->shift; + vdso_data->wtm_clock_sec = wtm->tv_sec; + vdso_data->wtm_clock_nsec = wtm->tv_nsec; + }arch/arm/kernel/vdso.c line 157
Quoted 10 lines
arch/arm/kernel/vdso.c new file +10
-0+ +smp_wmb (); + ++vdso_data->tb_seq_count; +} + +void update_vsyscall_tz (void ) +{ + vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; + vdso_data->tz_dsttime = sys_tz.tz_dsttime; +}which gets written to directly, and read from userspace. This won't work with aliasing caches, of which we have VIVT caches on all ARMv4 and ARMv5 CPUs, and VIPT caches on some ARMv6.
Quoted 2 lines
Either this needs to be limited to just VIPT nonaliasing caches, or it needs cache handling.
Thanks, I will address this.
Quoted 3 lines
The above also looks rather unsafe from the SMP perspective - how does
vdso_data->tb_seq_countprotect this data between CPUs?
It doesn't -- it merely provides a mechanism for signaling the consistency of the data userspace reads from the page. It's basically a seqlock.
Looks like timekeeper_lock in kernel/time/timekeeping.c prevents concurrent calls to update_vsyscall. I could document that dependency...