x86: Add x86 32 bit VDSO time function support
Subsystems (5)
v23 cover x86: Add x86 32 bit VDSO time function support
This patch add the functions vdso_gettimeofday(), vdso_clock_gettime() and vdso_time() to the x86 32 bit VDSO.
The reason to do this was to get a fast reliable time stamp. Many developers uses TSC to get a fast time stamp, without knowing the pitfalls. VDSO time functions a fast and a reliable way, because the kernel knows the best time source and the P- and C-state of the CPU.
The helper library to use the VDSO functions can be download at
http://http://seibold.net/vdso.c
The libary is very small, only 228 lines of code. Compile it with gcc -Wall -O3 -fpic vdso.c -lrt -shared -o libvdso.so and use it with LD_PRELOAD=<path>/libvdso.so
There is also a patch http://seibold.net/glibc.patch for glibc 2.19 which also works for glibc 2.18. This patch must be integrated into glibc.
Some linux 32 bit kernel benchmark results (all measurements are in nano seconds):
Intel(R) Celeron(TM) CPU 400MHz
Average time kernel call:
gettimeofday(): 1039
clock_gettime(): 1578
time(): 526
Average time VDSO call:
gettimeofday(): 378
clock_gettime(): 303
time(): 60
Celeron(R) Dual-Core CPU T3100 1.90GHz
Average time kernel call:
gettimeofday(): 209
clock_gettime(): 406
time(): 135
Average time VDSO call:
gettimeofday(): 51
clock_gettime(): 43
time(): 10
So you can see a performance increase between 4 and 13, depending on the CPU and the function.
The IA32 Emulation uses the whole 4 GB address space, so there is no fixed address available.
The VDSO for a 32 bit application has now three pages:
^ Higher Address
|
+----------------------------------------+ + VDSO page (includes code) ro+x + +----------------------------------------+ + VVAR page (export kernel variables) ro + +----------------------------------------+ + HPET page (mapped registers) ro +----------------------------------------+ |
^ Lower Address
The VDSO page for a 32 bit resided still on 0xffffe000, the the VVAR and HPET page are mapped before.
In the non compat mode the VMA of the VDSO is now 3 pages for a 32 bit kernel. So this decrease the available logical address room by 2 pages.
The patch is against tip x86/vdso (1f2cbcf648962cdcf511d234cb39745baa9f5d07)
Changelog:
25.11.2012 - first release and proof of concept for linux 3.4 11.12.2012 - Port to linux 3.7 and code cleanup
12.12.2012 - fixes suggested by Andy Lutomirski
- fixes suggested by John Stultz
- use call VDSO32_vsyscall instead of int 80
- code cleanup
17.12.2012 - support for IA32_EMULATION, this includes
- code cleanup
- include cleanup to fix compile warnings and errors
- move out seqcount from seqlock, enable use in VDSO
- map FIXMAP and HPET into the 32 bit address space
18.12.2012 - split into separate patches
30.01.2014 - revamp the code
- code clean up
- VDSO layout changed
- no fixed addresses
- port to 3.14
01.02.2014 - code cleanup
02.02.2014 - code cleanup
- split into more patches
- use HPET_COUNTER instead of hard coded value
- fix changelog to the right year ;-)
02.02.2014 - reverse the mapping, this make the new VDSO 32 bit support
full compatible.
03.02.2014 - code cleanup
- fix comment
- fix ABI break in vdso32.lds.S
04.02.2014 - revamp IA32 emulation support
- introduce VVAR macro
- rearranged vsyscall_gtod_data struture for IA32 emulation support
- code cleanup
05.02.2014 - revamp IA32 emulation support
- replace seqcount_t by an unsigned, to make the vsyscall_gtod_data structure independed of kernel config and functions.
08.02.2014 - revamp IA32 emulation support
- replace all internal structures by fix size elements
10.02.2014 - code cleanup
- add commets
- revamp inline assembly
12.02.2014 - add conditional fixmap of vvar and hpet pages for 32 bit kernel 14.02.2014 - fix CONFIG_PARAVIRT_CLOCK, which is not supported in 32 bit VDSO 15.02.2014 - fix tsc
code cleanup
tested make ARCH=i386 allyesconfig and make allyesconfig
16.02.2014 - code cleanup
- fix all C=1 warnings, also some one not introduced by this patch
- hack to fix C=1 32 bit VDSO spinlock for a 64 bit kernel
- fix VDSO Makefile for newer gcc
tested for gcc 4.3.4 and 4.8.1
tested ARCH=i386 allyesconfig, defconfig and allmodconfig tested X86_64 allyesconfig, defconfig and allmodconfig
17.02.2014 - In case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel
configuration.
19.02.2014 - Add missing #undef and #define to fake proper 32 bit kernel config
Add a missing #ifdef CONFIG_HPET_TIMER
tested again ARCH=i386 allyesconfig, defconfig and allmodconfig tested again ARCH=X86_64 allyesconfig, defconfig and allmodconfig
02.03.2014 - Add fixes suggested by Andy Lutomirski
- Patch alternatives in the 32 bit VDSO
- Use the default ABI for the 32 bit VDSO
- Inline the CLOCK MONOTONIC VDSO code
- Zero pad the VVAR page
- fix "patch alternatives" compile for 32 bit kernel
03.03.2014 - Add glibc.patch http://seibold.net/glibc.patch
Add reviewed-by tags
17.03.2014 - Rebase on tip x86/vdso 1f2cbcf648962cdcf511d234cb39745baa9f5d07
remove fixmap and compat mode dependencies
PATCH v23 1/13 x86, vdso: Make vsyscall_gtod_data handling x86 generic
This patch move the vsyscall_gtod_data handling out of vsyscall_64.c into an additonal file vsyscall_gtod.c to make the functionality available for x86 32 bit kernel.
It also adds a new vsyscall_32.c which setup the VVAR page.
--- arch/x86/Kconfig | 4 +-- arch/x86/include/asm/clocksource.h | 4 --- arch/x86/include/asm/vvar.h | 12 ++++++-- arch/x86/kernel/Makefile | 2 +- arch/x86/kernel/hpet.c | 2 -- arch/x86/kernel/tsc.c | 2 -- arch/x86/kernel/vmlinux.lds.S | 3 -- arch/x86/kernel/vsyscall_64.c | 45 ----------------------------- arch/x86/kernel/vsyscall_gtod.c | 59 ++++++++++++++++++++++++++++++++++++++ arch/x86/tools/relocs.c | 2 +- 10 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 arch/x86/kernel/vsyscall_gtod.c
arch/x86/Kconfig +2 -2
@@ -107,9 +107,9 @@ config X86 select HAVE_ARCH_SOFT_DIRTY select CLOCKSOURCE_WATCHDOG select GENERIC_CLOCKEVENTS - select ARCH_CLOCKSOURCE_DATA if X86_64 + select ARCH_CLOCKSOURCE_DATA select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC) - select GENERIC_TIME_VSYSCALL if X86_64 + select GENERIC_TIME_VSYSCALL select KTIME_SCALAR if X86_32 select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER
arch/x86/include/asm/clocksource.h +0 -4
@@ -3,8 +3,6 @@#ifndef _ASM_X86_CLOCKSOURCE_H#define _ASM_X86_CLOCKSOURCE_H -#ifdef CONFIG_X86_64 -#define VCLOCK_NONE 0/* No vDSO clock available. */ #define VCLOCK_TSC 1/* vDSO should use vread_tsc. */ #define VCLOCK_HPET 2/* vDSO should use vread_hpet. */
@@ -14,6 +12,4 @@ struct arch_clocksource_data { int vclock_mode; }; -#endif /* CONFIG_X86_64 */ -#endif /* _ASM_X86_CLOCKSOURCE_H */
arch/x86/include/asm/vvar.h +9 -3
@@ -16,9 +16,6 @@* you mess up, the linker will catch it.) */ -/* Base address of vvars. This is not ABI. */ -#define VVAR_ADDRESS (-10*1024*1024 - 4096) -#if defined(__VVAR_KERNEL_LDS)/* The kernel linker script defines its own magic to put vvars in the
@@ -29,6 +26,15 @@#else +extern char __vvar_page; + +/* Base address of vvars. This is not ABI. */ +#ifdef CONFIG_X86_64 +#define VVAR_ADDRESS (-10*1024*1024 - 4096) +#else +#define VVAR_ADDRESS (&__vvar_page) +#endif +#define DECLARE_VVAR (offset, type, name) \ static type const * const vvaraddr_ ## name = \ (void *)(VVAR_ADDRESS + (offset));
arch/x86/kernel/Makefile +1 -1
@@ -26,7 +26,7 @@ obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o obj-$(CONFIG_X86_32) += i386_ksyms_32.o obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o -obj-y += syscall_$(BITS).o +obj-y += syscall_$(BITS).o vsyscall_gtod.o obj-$(CONFIG_X86_64) += vsyscall_64.o obj-$(CONFIG_X86_64) += vsyscall_emu_64.o obj-$(CONFIG_SYSFS) += ksysfs.o
arch/x86/kernel/hpet.c +0 -2
@@ -752,9 +752,7 @@ static struct clocksource clocksource_hpet = { .mask = HPET_MASK, .flags = CLOCK_SOURCE_IS_CONTINUOUS, .resume = hpet_resume_counter, -#ifdef CONFIG_X86_64 .archdata = { .vclock_mode = VCLOCK_HPET }, -#endif };static int hpet_clocksource_register (void )
arch/x86/kernel/tsc.c +0 -2
@@ -985,9 +985,7 @@ static struct clocksource clocksource_tsc = { .mask = CLOCKSOURCE_MASK(64), .flags =CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_MUST_VERIFY, -#ifdef CONFIG_X86_64 .archdata = { .vclock_mode = VCLOCK_TSC }, -#endif };void mark_tsc_unstable (char *reason)
arch/x86/kernel/vmlinux.lds.S +0 -3
@@ -147,7 +147,6 @@ SECTIONS _edata = .; } :data -#ifdef CONFIG_X86_64 . = ALIGN(PAGE_SIZE); __vvar_page = .;
@@ -169,8 +168,6 @@ SECTIONS . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE); -#endif /* CONFIG_X86_64 */ - /* Init code and data - will be freed after init */ . = ALIGN(PAGE_SIZE); .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
arch/x86/kernel/vsyscall_64.c +0 -45
69 lines not on this page · raw message
arch/x86/kernel/vsyscall_gtod.c new file +59 -0
59 lines not on this page · raw message
arch/x86/tools/relocs.c +1 -1
@@ -69,8 +69,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {"__per_cpu_load|" "init_per_cpu__.*|" "__end_rodata_hpage_align|" - "__vvar_page|"#endif +"__vvar_page|" "_end)$" };
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Make vsyscall_gtod_data handling x86 generic
x86, vdso: Make vsyscall_gtod_data handling x86 generic
Commit-ID: d2312e3379d581d2c3603357a0181046448e1de3 Gitweb: http://git.kernel.org/tip/d2312e3379d581d2c3603357a0181046448e1de3 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:01 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:51:52 -0700
x86, vdso: Make vsyscall_gtod_data handling x86 generic
This patch move the vsyscall_gtod_data handling out of vsyscall_64.c into an additonal file vsyscall_gtod.c to make the functionality available for x86 32 bit kernel.
It also adds a new vsyscall_32.c which setup the VVAR page.
--- arch/x86/Kconfig | 4 +-- arch/x86/include/asm/clocksource.h | 4 --- arch/x86/include/asm/vvar.h | 12 ++++++-- arch/x86/kernel/Makefile | 2 +- arch/x86/kernel/hpet.c | 2 -- arch/x86/kernel/tsc.c | 2 -- arch/x86/kernel/vmlinux.lds.S | 3 -- arch/x86/kernel/vsyscall_64.c | 45 ----------------------------- arch/x86/kernel/vsyscall_gtod.c | 59 ++++++++++++++++++++++++++++++++++++++ arch/x86/tools/relocs.c | 2 +- 10 files changed, 72 insertions(+), 63 deletions(-)
arch/x86/Kconfig +2 -2
@@ -107,9 +107,9 @@ config X86 select HAVE_ARCH_SOFT_DIRTY select CLOCKSOURCE_WATCHDOG select GENERIC_CLOCKEVENTS - select ARCH_CLOCKSOURCE_DATA if X86_64 + select ARCH_CLOCKSOURCE_DATA select GENERIC_CLOCKEVENTS_BROADCAST if X86_64 || (X86_32 && X86_LOCAL_APIC) - select GENERIC_TIME_VSYSCALL if X86_64 + select GENERIC_TIME_VSYSCALL select KTIME_SCALAR if X86_32 select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER
arch/x86/include/asm/clocksource.h +0 -4
@@ -3,8 +3,6 @@#ifndef _ASM_X86_CLOCKSOURCE_H#define _ASM_X86_CLOCKSOURCE_H -#ifdef CONFIG_X86_64 -#define VCLOCK_NONE 0/* No vDSO clock available. */ #define VCLOCK_TSC 1/* vDSO should use vread_tsc. */ #define VCLOCK_HPET 2/* vDSO should use vread_hpet. */
@@ -14,6 +12,4 @@ struct arch_clocksource_data { int vclock_mode; }; -#endif /* CONFIG_X86_64 */ -#endif /* _ASM_X86_CLOCKSOURCE_H */
arch/x86/include/asm/vvar.h +9 -3
@@ -16,9 +16,6 @@* you mess up, the linker will catch it.) */ -/* Base address of vvars. This is not ABI. */ -#define VVAR_ADDRESS (-10*1024*1024 - 4096) -#if defined(__VVAR_KERNEL_LDS)/* The kernel linker script defines its own magic to put vvars in the
@@ -29,6 +26,15 @@#else +extern char __vvar_page; + +/* Base address of vvars. This is not ABI. */ +#ifdef CONFIG_X86_64 +#define VVAR_ADDRESS (-10*1024*1024 - 4096) +#else +#define VVAR_ADDRESS (&__vvar_page) +#endif +#define DECLARE_VVAR (offset, type, name) \ static type const * const vvaraddr_ ## name = \ (void *)(VVAR_ADDRESS + (offset));
arch/x86/kernel/Makefile +1 -1
@@ -26,7 +26,7 @@ obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-y += probe_roms.o obj-$(CONFIG_X86_32) += i386_ksyms_32.o obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o -obj-y += syscall_$(BITS).o +obj-y += syscall_$(BITS).o vsyscall_gtod.o obj-$(CONFIG_X86_64) += vsyscall_64.o obj-$(CONFIG_X86_64) += vsyscall_emu_64.o obj-$(CONFIG_SYSFS) += ksysfs.o
arch/x86/kernel/hpet.c +0 -2
@@ -752,9 +752,7 @@ static struct clocksource clocksource_hpet = { .mask = HPET_MASK, .flags = CLOCK_SOURCE_IS_CONTINUOUS, .resume = hpet_resume_counter, -#ifdef CONFIG_X86_64 .archdata = { .vclock_mode = VCLOCK_HPET }, -#endif };static int hpet_clocksource_register (void )
arch/x86/kernel/tsc.c +0 -2
@@ -985,9 +985,7 @@ static struct clocksource clocksource_tsc = { .mask = CLOCKSOURCE_MASK(64), .flags =CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_MUST_VERIFY, -#ifdef CONFIG_X86_64 .archdata = { .vclock_mode = VCLOCK_TSC }, -#endif };void mark_tsc_unstable (char *reason)
arch/x86/kernel/vmlinux.lds.S +0 -3
@@ -147,7 +147,6 @@ SECTIONS _edata = .; } :data -#ifdef CONFIG_X86_64 . = ALIGN(PAGE_SIZE); __vvar_page = .;
@@ -169,8 +168,6 @@ SECTIONS . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE); -#endif /* CONFIG_X86_64 */ - /* Init code and data - will be freed after init */ . = ALIGN(PAGE_SIZE); .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
arch/x86/kernel/vsyscall_64.c +0 -45
69 lines not on this page · raw message
arch/x86/kernel/vsyscall_gtod.c new file +59 -0
59 lines not on this page · raw message
arch/x86/tools/relocs.c +1 -1
@@ -69,8 +69,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {"__per_cpu_load|" "init_per_cpu__.*|" "__end_rodata_hpage_align|" - "__vvar_page|"#endif +"__vvar_page|" "_end)$" };
PATCH v23 2/13 mm: Add new func _install_special_mapping() to mmap.c
In reply to Stefani SeiboldThe _install_special_mapping() is the new base function for install_special_mapping(). This function will return a pointer of the created VMA or a error code in an ERR_PTR()
This new function will be needed by the for the vdso 32 bit support to map the additonal vvar and hpet pages into the 32 bit address space. This will be done with io_remap_pfn_range() and remap_pfn_range, which requieres a vm_area_struct.
--- include/linux/mm.h | 3 +++ mm/mmap.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)
include/linux/mm.h +3 -0
@@ -1750,6 +1750,9 @@ extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);extern struct file *get_mm_exe_file (struct mm_struct *mm);extern int may_expand_vm (struct mm_struct *mm,unsigned long npages); +extern struct vm_area_struct *_install_special_mapping (struct mm_struct *mm, +unsigned long addr,unsigned long len, +unsigned long flags,struct page **pages);extern int install_special_mapping (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long flags,struct page **pages);
mm/mmap.c +16 -4
@@ -2918,7 +2918,7 @@ static const struct vm_operations_struct special_mapping_vmops = {* The array pointer and the pages it points to are assumed to stay alive * for as long as this mapping might exist. */ -int install_special_mapping (struct mm_struct *mm, +struct vm_area_struct *_install_special_mapping (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long vm_flags,struct page **pages) {
@@ -2927,7 +2927,7 @@ int install_special_mapping(struct mm_struct *mm, vma =kmem_cache_zalloc (vm_area_cachep,GFP_KERNEL );if (unlikely (vma ==NULL )) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );INIT_LIST_HEAD (&vma->anon_vma_chain); vma->vm_mm = mm;
@@ -2948,11 +2948,23 @@ int install_special_mapping(struct mm_struct *mm,perf_event_mmap (vma); -return 0 ; +return vma; out:kmem_cache_free (vm_area_cachep, vma); -return ret; +return ERR_PTR (ret); +} + +int install_special_mapping (struct mm_struct *mm, +unsigned long addr,unsigned long len, +unsigned long vm_flags,struct page **pages) +{ +struct vm_area_struct *vma =_install_special_mapping (mm, + addr, len, vm_flags, pages); + +if (IS_ERR (vma)) +return PTR_ERR (vma); +return 0 ; }static DEFINE_MUTEX (mm_all_locks_mutex);
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] mm: Add new func _install_special_mapping() to mmap.c
mm: Add new func _install_special_mapping() to mmap.c
Commit-ID: 3935ed6a3a533c1736e3ca65bff72afd1773be27 Gitweb: http://git.kernel.org/tip/3935ed6a3a533c1736e3ca65bff72afd1773be27 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:02 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:51:56 -0700
mm: Add new func _install_special_mapping() to mmap.c
The _install_special_mapping() is the new base function for install_special_mapping(). This function will return a pointer of the created VMA or a error code in an ERR_PTR()
This new function will be needed by the for the vdso 32 bit support to map the additonal vvar and hpet pages into the 32 bit address space. This will be done with io_remap_pfn_range() and remap_pfn_range, which requieres a vm_area_struct.
--- include/linux/mm.h | 3 +++ mm/mmap.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-)
include/linux/mm.h +3 -0
@@ -1750,6 +1750,9 @@ extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);extern struct file *get_mm_exe_file (struct mm_struct *mm);extern int may_expand_vm (struct mm_struct *mm,unsigned long npages); +extern struct vm_area_struct *_install_special_mapping (struct mm_struct *mm, +unsigned long addr,unsigned long len, +unsigned long flags,struct page **pages);extern int install_special_mapping (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long flags,struct page **pages);
mm/mmap.c +16 -4
@@ -2918,7 +2918,7 @@ static const struct vm_operations_struct special_mapping_vmops = {* The array pointer and the pages it points to are assumed to stay alive * for as long as this mapping might exist. */ -int install_special_mapping (struct mm_struct *mm, +struct vm_area_struct *_install_special_mapping (struct mm_struct *mm,unsigned long addr,unsigned long len,unsigned long vm_flags,struct page **pages) {
@@ -2927,7 +2927,7 @@ int install_special_mapping(struct mm_struct *mm, vma =kmem_cache_zalloc (vm_area_cachep,GFP_KERNEL );if (unlikely (vma ==NULL )) -return -ENOMEM ; +return ERR_PTR (-ENOMEM );INIT_LIST_HEAD (&vma->anon_vma_chain); vma->vm_mm = mm;
@@ -2948,11 +2948,23 @@ int install_special_mapping(struct mm_struct *mm,perf_event_mmap (vma); -return 0 ; +return vma; out:kmem_cache_free (vm_area_cachep, vma); -return ret; +return ERR_PTR (ret); +} + +int install_special_mapping (struct mm_struct *mm, +unsigned long addr,unsigned long len, +unsigned long vm_flags,struct page **pages) +{ +struct vm_area_struct *vma =_install_special_mapping (mm, + addr, len, vm_flags, pages); + +if (IS_ERR (vma)) +return PTR_ERR (vma); +return 0 ; }static DEFINE_MUTEX (mm_all_locks_mutex);
PATCH v23 3/13 x86, vdso: Revamp vclock_gettime.c
In reply to Stefani SeiboldThis intermediate patch revamps the vclock_gettime.c by moving some functions around. It is only for spliting purpose, to make whole the 32 bit vdso timer patch easier to review.
--- arch/x86/vdso/vclock_gettime.c | 85 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 43 deletions(-)
arch/x86/vdso/vclock_gettime.c +42 -43
@@ -26,41 +26,26 @@#define gtod (&VVAR(vsyscall_gtod_data)) -notrace static cycle_t vread_tsc(void) +static notrace cycle_t vread_hpet(void) { -cycle_t ret; -u64 last; - -/* -* Empirically, a fence (of type that depends on the CPU) -* before rdtsc is enough to ensure that rdtsc is ordered -* with respect to loads. The various CPU manuals are unclear -* as to whether rdtsc can be reordered with later loads, -* but no one has ever seen it happen. -*/ -rdtsc_barrier (); - ret = (cycle_t )vget_cycles (); - - last =VVAR (vsyscall_gtod_data).clock.cycle_last; - -if (likely (ret >= last)) -return ret; +return readl ((const void __iomem *)fix_to_virt (VSYSCALL_HPET ) +HPET_COUNTER ); +} -/* -* GCC likes to generate cmov here, but this branch is extremely -* predictable (it's just a funciton of time and the likely is -* very likely) and there's a data dependence, so force GCC -* to generate a branch instead. I don't barrier() because -* we don't actually need a barrier, and if this function -* ever gets inlined it will generate worse code. -*/ - asmvolatile ("" ); -return last; +notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) +{ +long ret; + asm("syscall" :"=a" (ret) : +"0" (__NR_clock_gettime),"D" (clock),"S" (ts) :"memory" ); +return ret; } -static notrace cycle_t vread_hpet(void) +notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) { -return readl ((const void __iomem *)fix_to_virt (VSYSCALL_HPET ) +HPET_COUNTER ); +long ret; + + asm("syscall" :"=a" (ret) : +"0" (__NR_gettimeofday),"D" (tv),"S" (tz) :"memory" ); +return ret; }#ifdef CONFIG_PARAVIRT_CLOCK
@@ -133,23 +118,37 @@ static notrace cycle_t vread_pvclock(int *mode) }#endif -notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) +notrace static cycle_t vread_tsc(void) { -long ret; - asm("syscall" :"=a" (ret) : -"0" (__NR_clock_gettime),"D" (clock),"S" (ts) :"memory" ); -return ret; -} +cycle_t ret; +u64 last; -notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) -{ -long ret; +/* +* Empirically, a fence (of type that depends on the CPU) +* before rdtsc is enough to ensure that rdtsc is ordered +* with respect to loads. The various CPU manuals are unclear +* as to whether rdtsc can be reordered with later loads, +* but no one has ever seen it happen. +*/ +rdtsc_barrier (); + ret = (cycle_t )vget_cycles (); - asm("syscall" :"=a" (ret) : -"0" (__NR_gettimeofday),"D" (tv),"S" (tz) :"memory" ); -return ret; -} + last =VVAR (vsyscall_gtod_data).clock.cycle_last; +if (likely (ret >= last)) +return ret; + +/* +* GCC likes to generate cmov here, but this branch is extremely +* predictable (it's just a funciton of time and the likely is +* very likely) and there's a data dependence, so force GCC +* to generate a branch instead. I don't barrier() because +* we don't actually need a barrier, and if this function +* ever gets inlined it will generate worse code. +*/ + asmvolatile ("" ); +return last; +} notrace static inline u64 vgetsns(int *mode) {
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Revamp vclock_gettime.c
x86, vdso: Revamp vclock_gettime.c
Commit-ID: 411f790cd7e91fac0db80d3cf789cb6deeac298e Gitweb: http://git.kernel.org/tip/411f790cd7e91fac0db80d3cf789cb6deeac298e Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:03 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:51:59 -0700
x86, vdso: Revamp vclock_gettime.c
This intermediate patch revamps the vclock_gettime.c by moving some functions around. It is only for spliting purpose, to make whole the 32 bit vdso timer patch easier to review.
--- arch/x86/vdso/vclock_gettime.c | 85 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 43 deletions(-)
arch/x86/vdso/vclock_gettime.c +42 -43
@@ -26,41 +26,26 @@#define gtod (&VVAR(vsyscall_gtod_data)) -notrace static cycle_t vread_tsc(void) +static notrace cycle_t vread_hpet(void) { -cycle_t ret; -u64 last; - -/* -* Empirically, a fence (of type that depends on the CPU) -* before rdtsc is enough to ensure that rdtsc is ordered -* with respect to loads. The various CPU manuals are unclear -* as to whether rdtsc can be reordered with later loads, -* but no one has ever seen it happen. -*/ -rdtsc_barrier (); - ret = (cycle_t )vget_cycles (); - - last =VVAR (vsyscall_gtod_data).clock.cycle_last; - -if (likely (ret >= last)) -return ret; +return readl ((const void __iomem *)fix_to_virt (VSYSCALL_HPET ) +HPET_COUNTER ); +} -/* -* GCC likes to generate cmov here, but this branch is extremely -* predictable (it's just a funciton of time and the likely is -* very likely) and there's a data dependence, so force GCC -* to generate a branch instead. I don't barrier() because -* we don't actually need a barrier, and if this function -* ever gets inlined it will generate worse code. -*/ - asmvolatile ("" ); -return last; +notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) +{ +long ret; + asm("syscall" :"=a" (ret) : +"0" (__NR_clock_gettime),"D" (clock),"S" (ts) :"memory" ); +return ret; } -static notrace cycle_t vread_hpet(void) +notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) { -return readl ((const void __iomem *)fix_to_virt (VSYSCALL_HPET ) +HPET_COUNTER ); +long ret; + + asm("syscall" :"=a" (ret) : +"0" (__NR_gettimeofday),"D" (tv),"S" (tz) :"memory" ); +return ret; }#ifdef CONFIG_PARAVIRT_CLOCK
@@ -133,23 +118,37 @@ static notrace cycle_t vread_pvclock(int *mode) }#endif -notrace static long vdso_fallback_gettime(long clock, struct timespec *ts) +notrace static cycle_t vread_tsc(void) { -long ret; - asm("syscall" :"=a" (ret) : -"0" (__NR_clock_gettime),"D" (clock),"S" (ts) :"memory" ); -return ret; -} +cycle_t ret; +u64 last; -notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz) -{ -long ret; +/* +* Empirically, a fence (of type that depends on the CPU) +* before rdtsc is enough to ensure that rdtsc is ordered +* with respect to loads. The various CPU manuals are unclear +* as to whether rdtsc can be reordered with later loads, +* but no one has ever seen it happen. +*/ +rdtsc_barrier (); + ret = (cycle_t )vget_cycles (); - asm("syscall" :"=a" (ret) : -"0" (__NR_gettimeofday),"D" (tv),"S" (tz) :"memory" ); -return ret; -} + last =VVAR (vsyscall_gtod_data).clock.cycle_last; +if (likely (ret >= last)) +return ret; + +/* +* GCC likes to generate cmov here, but this branch is extremely +* predictable (it's just a funciton of time and the likely is +* very likely) and there's a data dependence, so force GCC +* to generate a branch instead. I don't barrier() because +* we don't actually need a barrier, and if this function +* ever gets inlined it will generate worse code. +*/ + asmvolatile ("" ); +return last; +} notrace static inline u64 vgetsns(int *mode) {
PATCH v23 4/13 x86, vdso: __vdso_clock_gettime() cleanup
In reply to Stefani SeiboldThis patch is a small code cleanup for the __vdso_clock_gettime() function.
It removes the unneeded return values from do_monotonic_coarse() and do_realtime_coarse() and add a fallback label for doing the kernel gettimeofday() system call.
--- arch/x86/vdso/vclock_gettime.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
arch/x86/vdso/vclock_gettime.c +14 -13
@@ -209,7 +209,7 @@ notrace static int do_monotonic(struct timespec *ts)return mode; } -notrace static int do_realtime_coarse(struct timespec *ts) +notrace static void do_realtime_coarse(struct timespec *ts) {unsigned long seq; do {
@@ -217,10 +217,9 @@ notrace static int do_realtime_coarse(struct timespec *ts) ts->tv_sec = gtod->wall_time_coarse.tv_sec; ts->tv_nsec = gtod->wall_time_coarse.tv_nsec; }while (unlikely (read_seqcount_retry (>od->seq, seq))); -return 0 ; } -notrace static int do_monotonic_coarse(struct timespec *ts) +notrace static void do_monotonic_coarse(struct timespec *ts) {unsigned long seq; do {
@@ -228,30 +227,32 @@ notrace static int do_monotonic_coarse(struct timespec *ts) ts->tv_sec = gtod->monotonic_time_coarse.tv_sec; ts->tv_nsec = gtod->monotonic_time_coarse.tv_nsec; }while (unlikely (read_seqcount_retry (>od->seq, seq))); - -return 0 ; } notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) { -int ret =VCLOCK_NONE ; -switch (clock) {case CLOCK_REALTIME : - ret =do_realtime (ts); +if (do_realtime (ts) ==VCLOCK_NONE ) + goto fallback;break ;case CLOCK_MONOTONIC : - ret =do_monotonic (ts); +if (do_monotonic (ts) ==VCLOCK_NONE ) + goto fallback;break ;case CLOCK_REALTIME_COARSE : -return do_realtime_coarse (ts); +do_realtime_coarse (ts); +break ;case CLOCK_MONOTONIC_COARSE : -return do_monotonic_coarse (ts); +do_monotonic_coarse (ts); +break ; +default : + goto fallback; } -if (ret ==VCLOCK_NONE ) -return vdso_fallback_gettime (clock, ts);return 0 ; +fallback: +return vdso_fallback_gettime (clock, ts); }int clock_gettime (clockid_t ,struct timespec *) __attribute__((weak,alias ("__vdso_clock_gettime" )));
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: __vdso_clock_gettime() cleanup
x86, vdso: __vdso_clock_gettime() cleanup
Commit-ID: ce39c64028a075d14af32bfb8336bfe1370c0443 Gitweb: http://git.kernel.org/tip/ce39c64028a075d14af32bfb8336bfe1370c0443 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:04 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:01 -0700
x86, vdso: __vdso_clock_gettime() cleanup
This patch is a small code cleanup for the __vdso_clock_gettime() function.
It removes the unneeded return values from do_monotonic_coarse() and do_realtime_coarse() and add a fallback label for doing the kernel gettimeofday() system call.
--- arch/x86/vdso/vclock_gettime.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-)
arch/x86/vdso/vclock_gettime.c +14 -13
@@ -209,7 +209,7 @@ notrace static int do_monotonic(struct timespec *ts)return mode; } -notrace static int do_realtime_coarse(struct timespec *ts) +notrace static void do_realtime_coarse(struct timespec *ts) {unsigned long seq; do {
@@ -217,10 +217,9 @@ notrace static int do_realtime_coarse(struct timespec *ts) ts->tv_sec = gtod->wall_time_coarse.tv_sec; ts->tv_nsec = gtod->wall_time_coarse.tv_nsec; }while (unlikely (read_seqcount_retry (>od->seq, seq))); -return 0 ; } -notrace static int do_monotonic_coarse(struct timespec *ts) +notrace static void do_monotonic_coarse(struct timespec *ts) {unsigned long seq; do {
@@ -228,30 +227,32 @@ notrace static int do_monotonic_coarse(struct timespec *ts) ts->tv_sec = gtod->monotonic_time_coarse.tv_sec; ts->tv_nsec = gtod->monotonic_time_coarse.tv_nsec; }while (unlikely (read_seqcount_retry (>od->seq, seq))); - -return 0 ; } notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts) { -int ret =VCLOCK_NONE ; -switch (clock) {case CLOCK_REALTIME : - ret =do_realtime (ts); +if (do_realtime (ts) ==VCLOCK_NONE ) + goto fallback;break ;case CLOCK_MONOTONIC : - ret =do_monotonic (ts); +if (do_monotonic (ts) ==VCLOCK_NONE ) + goto fallback;break ;case CLOCK_REALTIME_COARSE : -return do_realtime_coarse (ts); +do_realtime_coarse (ts); +break ;case CLOCK_MONOTONIC_COARSE : -return do_monotonic_coarse (ts); +do_monotonic_coarse (ts); +break ; +default : + goto fallback; } -if (ret ==VCLOCK_NONE ) -return vdso_fallback_gettime (clock, ts);return 0 ; +fallback: +return vdso_fallback_gettime (clock, ts); }int clock_gettime (clockid_t ,struct timespec *) __attribute__((weak,alias ("__vdso_clock_gettime" )));
PATCH v23 5/13 x86, vdso: Replace VVAR(vsyscall_gtod_data) by gtod macro
In reply to Stefani SeiboldThere a currently more than 30 users of the gtod macro, so replace the last VVAR(vsyscall_gtod_data) by gtod macro.
--- arch/x86/vdso/vclock_gettime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/vdso/vclock_gettime.c +3 -3
@@ -109,7 +109,7 @@ static notrace cycle_t vread_pvclock(int *mode) *mode =VCLOCK_NONE ;/* refer to tsc.c read_tsc() comment for rationale */ - last =VVAR (vsyscall_gtod_data).clock.cycle_last; + last = gtod->clock.cycle_last;if (likely (ret >= last))return ret;
@@ -133,7 +133,7 @@ notrace static cycle_t vread_tsc(void)rdtsc_barrier (); ret = (cycle_t )vget_cycles (); - last =VVAR (vsyscall_gtod_data).clock.cycle_last; + last = gtod->clock.cycle_last;if (likely (ret >= last))return ret;
@@ -288,7 +288,7 @@ int gettimeofday(struct timeval *, struct timezone *) notrace time_t __vdso_time(time_t *t) {/* This is atomic on x86_64 so we don't need any locks. */ -time_t result =ACCESS_ONCE (VVAR (vsyscall_gtod_data).wall_time_sec); +time_t result =ACCESS_ONCE (gtod->wall_time_sec);if (t) *t = result;
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Replace VVAR(vsyscall_gtod_data) by gtod macro
x86, vdso: Replace VVAR(vsyscall_gtod_data) by gtod macro
Commit-ID: af8c93d8d9809c3cf71cae2c398069399e64efa3 Gitweb: http://git.kernel.org/tip/af8c93d8d9809c3cf71cae2c398069399e64efa3 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:05 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:03 -0700
x86, vdso: Replace VVAR(vsyscall_gtod_data) by gtod macro
There a currently more than 30 users of the gtod macro, so replace the last VVAR(vsyscall_gtod_data) by gtod macro.
--- arch/x86/vdso/vclock_gettime.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/vdso/vclock_gettime.c +3 -3
@@ -109,7 +109,7 @@ static notrace cycle_t vread_pvclock(int *mode) *mode =VCLOCK_NONE ;/* refer to tsc.c read_tsc() comment for rationale */ - last =VVAR (vsyscall_gtod_data).clock.cycle_last; + last = gtod->clock.cycle_last;if (likely (ret >= last))return ret;
@@ -133,7 +133,7 @@ notrace static cycle_t vread_tsc(void)rdtsc_barrier (); ret = (cycle_t )vget_cycles (); - last =VVAR (vsyscall_gtod_data).clock.cycle_last; + last = gtod->clock.cycle_last;if (likely (ret >= last))return ret;
@@ -288,7 +288,7 @@ int gettimeofday(struct timeval *, struct timezone *) notrace time_t __vdso_time(time_t *t) {/* This is atomic on x86_64 so we don't need any locks. */ -time_t result =ACCESS_ONCE (VVAR (vsyscall_gtod_data).wall_time_sec); +time_t result =ACCESS_ONCE (gtod->wall_time_sec);if (t) *t = result;
PATCH v23 6/13 x86, vdso: Cleanup __vdso_gettimeofday()
In reply to Stefani SeiboldThis patch do a little cleanup for the __vdso_gettimeofday() function.
It kicks out an unneeded ret local variable and makes the code faster if only the timezone is needed (an admittedly rare case.)
--- arch/x86/vdso/vclock_gettime.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/vdso/vclock_gettime.c +2 -5
@@ -259,13 +259,12 @@ int clock_gettime(clockid_t, struct timespec *) notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) { -long ret =VCLOCK_NONE ; -if (likely (tv !=NULL )) {BUILD_BUG_ON (offsetof(struct timeval , tv_usec) != offsetof(struct timespec , tv_nsec) ||sizeof (*tv) !=sizeof (struct timespec )); - ret =do_realtime ((struct timespec *)tv); +if (unlikely (do_realtime ((struct timespec *)tv) ==VCLOCK_NONE )) +return vdso_fallback_gtod (tv, tz); tv->tv_usec /=1000 ; }if (unlikely (tz !=NULL )) {
@@ -274,8 +273,6 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) tz->tz_dsttime = gtod->sys_tz.tz_dsttime; } -if (ret ==VCLOCK_NONE ) -return vdso_fallback_gtod (tv, tz);return 0 ; }int gettimeofday (struct timeval *,struct timezone *)
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Cleanup __vdso_gettimeofday()
x86, vdso: Cleanup __vdso_gettimeofday()
Commit-ID: 0df1ea2b7955d3cb311a549c44ed482452b859ff Gitweb: http://git.kernel.org/tip/0df1ea2b7955d3cb311a549c44ed482452b859ff Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:06 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:26 -0700
x86, vdso: Cleanup __vdso_gettimeofday()
This patch cleans up the __vdso_gettimeofday() function a little.
It kicks out an unneeded ret local variable and makes the code faster if only the timezone is needed (an admittedly rare case.)
--- arch/x86/vdso/vclock_gettime.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/x86/vdso/vclock_gettime.c +2 -5
@@ -259,13 +259,12 @@ int clock_gettime(clockid_t, struct timespec *) notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) { -long ret =VCLOCK_NONE ; -if (likely (tv !=NULL )) {BUILD_BUG_ON (offsetof(struct timeval , tv_usec) != offsetof(struct timespec , tv_nsec) ||sizeof (*tv) !=sizeof (struct timespec )); - ret =do_realtime ((struct timespec *)tv); +if (unlikely (do_realtime ((struct timespec *)tv) ==VCLOCK_NONE )) +return vdso_fallback_gtod (tv, tz); tv->tv_usec /=1000 ; }if (unlikely (tz !=NULL )) {
@@ -274,8 +273,6 @@ notrace int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz) tz->tz_dsttime = gtod->sys_tz.tz_dsttime; } -if (ret ==VCLOCK_NONE ) -return vdso_fallback_gtod (tv, tz);return 0 ; }int gettimeofday (struct timeval *,struct timezone *)
PATCH v23 7/13 x86, vdso: Introduce VVAR marco for vdso32
In reply to Stefani SeiboldThis patch revamps the vvar.h for introduce the VVAR macro for vdso32.
--- arch/x86/include/asm/vvar.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/include/asm/vvar.h +12 -2
@@ -26,6 +26,15 @@#else +#ifdef BUILD_VDSO32 + +#define DECLARE_VVAR (offset, type, name) \ + extern type vvar_ ## name __attribute__((visibility("hidden"))); + +#define VVAR (name) (vvar_ ## name) + +#else +extern char __vvar_page;/* Base address of vvars. This is not ABI. */
@@ -39,12 +48,13 @@ extern char __vvar_page; static type const * const vvaraddr_ ## name = \ (void *)(VVAR_ADDRESS + (offset)); +#define VVAR (name) (*vvaraddr_ ## name) +#endif +#define DEFINE_VVAR (type, name) \ type name \ __attribute__((section(".vvar_" #name), aligned(16))) __visible -#define VVAR (name) (*vvaraddr_ ## name) -#endif /* DECLARE_VVAR(offset, type, name) */
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Introduce VVAR marco for vdso32
x86, vdso: Introduce VVAR marco for vdso32
Commit-ID: ef721987aef0cc0abba08c88810f2155f76b0b1f Gitweb: http://git.kernel.org/tip/ef721987aef0cc0abba08c88810f2155f76b0b1f Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:07 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:29 -0700
x86, vdso: Introduce VVAR marco for vdso32
This patch revamps the vvar.h for introduce the VVAR macro for vdso32.
--- arch/x86/include/asm/vvar.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/x86/include/asm/vvar.h +12 -2
@@ -26,6 +26,15 @@#else +#ifdef BUILD_VDSO32 + +#define DECLARE_VVAR (offset, type, name) \ + extern type vvar_ ## name __attribute__((visibility("hidden"))); + +#define VVAR (name) (vvar_ ## name) + +#else +extern char __vvar_page;/* Base address of vvars. This is not ABI. */
@@ -39,12 +48,13 @@ extern char __vvar_page; static type const * const vvaraddr_ ## name = \ (void *)(VVAR_ADDRESS + (offset)); +#define VVAR (name) (*vvaraddr_ ## name) +#endif +#define DEFINE_VVAR (type, name) \ type name \ __attribute__((section(".vvar_" #name), aligned(16))) __visible -#define VVAR (name) (*vvaraddr_ ## name) -#endif /* DECLARE_VVAR(offset, type, name) */
PATCH v23 8/13 x86, vdso: Patch alternatives in the 32-bit VDSO
In reply to Stefani SeiboldFrom: Andy Lutomirski <[email protected]>
We need the alternatives mechanism for rdtsc_barrier() to work.
--- arch/x86/include/asm/vdso.h | 2 ++ arch/x86/vdso/Makefile | 3 ++- arch/x86/vdso/vdso32-setup.c | 23 ++++++++++++----------- arch/x86/vdso/vma.c | 13 ++++++++++--- 4 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/include/asm/vdso.h +2 -0
@@ -28,4 +28,6 @@ extern const char vdso32_int80_start, vdso32_int80_end;extern const char vdso32_syscall_start, vdso32_syscall_end;extern const char vdso32_sysenter_start, vdso32_sysenter_end; +void __init patch_vdso32 (void *vdso,size_t len); +#endif /* _ASM_X86_VDSO_H */
arch/x86/vdso/Makefile +2 -1
@@ -21,7 +21,8 @@ vobjs-$(VDSOX32-y) += $(vobjx32s-compat) vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y)) # files to link into kernel -obj-$(VDSO64-y) += vma.o vdso.o +obj-y += vma.o +obj-$(VDSO64-y) += vdso.o obj-$(VDSOX32-y) += vdsox32.o obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
arch/x86/vdso/vdso32-setup.c +12 -11
@@ -112,24 +112,25 @@ void enable_sep_cpu(void)int __init sysenter_setup (void ) { -void *syscall_page = (void *)get_zeroed_page (GFP_ATOMIC ); -const void *vsyscall; -size_t vsyscall_len; +void *vdso_page = (void *)get_zeroed_page (GFP_ATOMIC ); +const void *vdso; +size_t vdso_len; - vdso32_pages[0 ] =virt_to_page (syscall_page); + vdso32_pages[0 ] =virt_to_page (vdso_page);if (vdso32_syscall ()) { - vsyscall = &vdso32_syscall_start; - vsyscall_len = &vdso32_syscall_end - &vdso32_syscall_start; + vdso = &vdso32_syscall_start; + vdso_len = &vdso32_syscall_end - &vdso32_syscall_start; }else if (vdso32_sysenter ()){ - vsyscall = &vdso32_sysenter_start; - vsyscall_len = &vdso32_sysenter_end - &vdso32_sysenter_start; + vdso = &vdso32_sysenter_start; + vdso_len = &vdso32_sysenter_end - &vdso32_sysenter_start; }else { - vsyscall = &vdso32_int80_start; - vsyscall_len = &vdso32_int80_end - &vdso32_int80_start; + vdso = &vdso32_int80_start; + vdso_len = &vdso32_int80_end - &vdso32_int80_start; } -memcpy (syscall_page, vsyscall, vsyscall_len); +memcpy (vdso_page, vdso, vdso_len); +patch_vdso32 (vdso_page, vdso_len);return 0 ; }
arch/x86/vdso/vma.c +10 -3
@@ -16,6 +16,7 @@#include <asm/vdso.h> #include <asm/page.h> +#if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso_enabled =1 ;extern char vdso_start[], vdso_end[];
@@ -28,8 +29,12 @@ static unsigned vdso_size;extern char vdsox32_start[], vdsox32_end[];extern struct page *vdsox32_pages[];static unsigned vdsox32_size; +#endif +#endif -static void __init patch_vdsox32 (void *vdso,size_t len) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_X32_ABI ) || \ + defined(CONFIG_COMPAT ) +void __init patch_vdso32 (void *vdso,size_t len) {Elf32_Ehdr *hdr = vdso;Elf32_Shdr *sechdrs, *alt_sec =0 ;
@@ -52,7 +57,7 @@ static void __init patch_vdsox32(void *vdso, size_t len) }/* If we get here, it's probably a bug. */ -pr_warning ("patch_vdsox32: .altinstructions not found\n" ); +pr_warning ("patch_vdso32: .altinstructions not found\n" );return ;/* nothing to patch */ found:
@@ -61,6 +66,7 @@ found: }#endif +#if defined(CONFIG_X86_64 )static void __init patch_vdso64 (void *vdso,size_t len) {Elf64_Ehdr *hdr = vdso;
@@ -104,7 +110,7 @@ static int __init init_vdso(void) vdso_pages[i] =virt_to_page (vdso_start + i*PAGE_SIZE );#ifdef CONFIG_X86_X32_ABI -patch_vdsox32 (vdsox32_start, vdsox32_end - vdsox32_start); +patch_vdso32 (vdsox32_start, vdsox32_end - vdsox32_start); npages = (vdsox32_end - vdsox32_start +PAGE_SIZE -1 ) /PAGE_SIZE ; vdsox32_size = npages <<PAGE_SHIFT ;for (i =0 ; i < npages; i++)
@@ -204,3 +210,4 @@ static __init int vdso_setup(char *s) return 0; }__setup ("vdso=" , vdso_setup); +#endif
Signature · 1 line
1.9.0
tip-bot for Andy Lutomirski
merge bot[tip:x86/vdso] x86, vdso: Patch alternatives in the 32-bit VDSO
x86, vdso: Patch alternatives in the 32-bit VDSO
Commit-ID: b4b541a610c4db8643b36030ee5012203ca65778 Gitweb: http://git.kernel.org/tip/b4b541a610c4db8643b36030ee5012203ca65778 Author: Andy Lutomirski <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:08 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:33 -0700
x86, vdso: Patch alternatives in the 32-bit VDSO
We need the alternatives mechanism for rdtsc_barrier() to work.
--- arch/x86/include/asm/vdso.h | 2 ++ arch/x86/vdso/Makefile | 3 ++- arch/x86/vdso/vdso32-setup.c | 23 ++++++++++++----------- arch/x86/vdso/vma.c | 13 ++++++++++--- 4 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/include/asm/vdso.h +2 -0
@@ -28,4 +28,6 @@ extern const char vdso32_int80_start, vdso32_int80_end;extern const char vdso32_syscall_start, vdso32_syscall_end;extern const char vdso32_sysenter_start, vdso32_sysenter_end; +void __init patch_vdso32 (void *vdso,size_t len); +#endif /* _ASM_X86_VDSO_H */
arch/x86/vdso/Makefile +2 -1
@@ -21,7 +21,8 @@ vobjs-$(VDSOX32-y) += $(vobjx32s-compat) vobj64s := $(filter-out $(vobjx32s-compat),$(vobjs-y)) # files to link into kernel -obj-$(VDSO64-y) += vma.o vdso.o +obj-y += vma.o +obj-$(VDSO64-y) += vdso.o obj-$(VDSOX32-y) += vdsox32.o obj-$(VDSO32-y) += vdso32.o vdso32-setup.o
arch/x86/vdso/vdso32-setup.c +12 -11
@@ -112,24 +112,25 @@ void enable_sep_cpu(void)int __init sysenter_setup (void ) { -void *syscall_page = (void *)get_zeroed_page (GFP_ATOMIC ); -const void *vsyscall; -size_t vsyscall_len; +void *vdso_page = (void *)get_zeroed_page (GFP_ATOMIC ); +const void *vdso; +size_t vdso_len; - vdso32_pages[0 ] =virt_to_page (syscall_page); + vdso32_pages[0 ] =virt_to_page (vdso_page);if (vdso32_syscall ()) { - vsyscall = &vdso32_syscall_start; - vsyscall_len = &vdso32_syscall_end - &vdso32_syscall_start; + vdso = &vdso32_syscall_start; + vdso_len = &vdso32_syscall_end - &vdso32_syscall_start; }else if (vdso32_sysenter ()){ - vsyscall = &vdso32_sysenter_start; - vsyscall_len = &vdso32_sysenter_end - &vdso32_sysenter_start; + vdso = &vdso32_sysenter_start; + vdso_len = &vdso32_sysenter_end - &vdso32_sysenter_start; }else { - vsyscall = &vdso32_int80_start; - vsyscall_len = &vdso32_int80_end - &vdso32_int80_start; + vdso = &vdso32_int80_start; + vdso_len = &vdso32_int80_end - &vdso32_int80_start; } -memcpy (syscall_page, vsyscall, vsyscall_len); +memcpy (vdso_page, vdso, vdso_len); +patch_vdso32 (vdso_page, vdso_len);return 0 ; }
arch/x86/vdso/vma.c +10 -3
@@ -16,6 +16,7 @@#include <asm/vdso.h> #include <asm/page.h> +#if defined(CONFIG_X86_64 )unsigned int __read_mostly vdso_enabled =1 ;extern char vdso_start[], vdso_end[];
@@ -28,8 +29,12 @@ static unsigned vdso_size;extern char vdsox32_start[], vdsox32_end[];extern struct page *vdsox32_pages[];static unsigned vdsox32_size; +#endif +#endif -static void __init patch_vdsox32 (void *vdso,size_t len) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_X86_X32_ABI ) || \ + defined(CONFIG_COMPAT ) +void __init patch_vdso32 (void *vdso,size_t len) {Elf32_Ehdr *hdr = vdso;Elf32_Shdr *sechdrs, *alt_sec =0 ;
@@ -52,7 +57,7 @@ static void __init patch_vdsox32(void *vdso, size_t len) }/* If we get here, it's probably a bug. */ -pr_warning ("patch_vdsox32: .altinstructions not found\n" ); +pr_warning ("patch_vdso32: .altinstructions not found\n" );return ;/* nothing to patch */ found:
@@ -61,6 +66,7 @@ found: }#endif +#if defined(CONFIG_X86_64 )static void __init patch_vdso64 (void *vdso,size_t len) {Elf64_Ehdr *hdr = vdso;
@@ -104,7 +110,7 @@ static int __init init_vdso(void) vdso_pages[i] =virt_to_page (vdso_start + i*PAGE_SIZE );#ifdef CONFIG_X86_X32_ABI -patch_vdsox32 (vdsox32_start, vdsox32_end - vdsox32_start); +patch_vdso32 (vdsox32_start, vdsox32_end - vdsox32_start); npages = (vdsox32_end - vdsox32_start +PAGE_SIZE -1 ) /PAGE_SIZE ; vdsox32_size = npages <<PAGE_SHIFT ;for (i =0 ; i < npages; i++)
@@ -204,3 +210,4 @@ static __init int vdso_setup(char *s) return 0; }__setup ("vdso=" , vdso_setup); +#endif
PATCH v23 9/13 x86, vdso: Add 32 bit VDSO time support for 32 bit kernel
In reply to Stefani SeiboldThis patch add the time support for 32 bit a VDSO to a 32 bit kernel.
For 32 bit programs running on a 32 bit kernel, the same mechanism is used as for 64 bit programs running on a 64 bit kernel.
--- arch/x86/include/asm/vdso.h | 5 +++ arch/x86/include/asm/vdso32.h | 11 +++++ arch/x86/vdso/Makefile | 8 ++++ arch/x86/vdso/vclock_gettime.c | 76 +++++++++++++++++++++++++++++++---- arch/x86/vdso/vdso-layout.lds.S | 22 ++++++++++ arch/x86/vdso/vdso32-setup.c | 47 ++++++++++++++++++++-- arch/x86/vdso/vdso32/vclock_gettime.c | 9 +++++ arch/x86/vdso/vdso32/vdso32.lds.S | 11 +++++ 8 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 arch/x86/include/asm/vdso32.h create mode 100644 arch/x86/vdso/vdso32/vclock_gettime.c
arch/x86/include/asm/vdso.h +5 -0
@@ -2,6 +2,11 @@#define _ASM_X86_VDSO_H#if definedCONFIG_X86_32 || definedCONFIG_COMPAT + +#include <asm/vdso32.h> + +extern const char VDSO32_PRELINK []; +/* * Given a pointer to the vDSO image, find the pointer to VDSO32_name * as that symbol is defined in the vDSO sources or linker script.
arch/x86/include/asm/vdso32.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _ASM_X86_VDSO32_H +#define _ASM_X86_VDSO32_H + +#define VDSO_BASE_PAGE 0 +#define VDSO_VVAR_PAGE 1 +#define VDSO_HPET_PAGE 2 +#define VDSO_PAGES 3 +#define VDSO_PREV_PAGES 2 +#define VDSO_OFFSET (x) ((x) * PAGE_SIZE) + +#endif
arch/x86/vdso/Makefile +8 -0
@@ -146,8 +146,16 @@ KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) $(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) $(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32 +KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) +KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic +$(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) + $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \ $(obj)/vdso32/vdso32.lds \ + $(obj)/vdso32/vclock_gettime.o \ $(obj)/vdso32/note.o \ $(obj)/vdso32/%.o $(call if_changed,vdso)
arch/x86/vdso/vclock_gettime.c +69 -7
133 lines not on this page · raw message
arch/x86/vdso/vdso-layout.lds.S +22 -0
@@ -6,6 +6,24 @@ SECTIONS { +#ifdef BUILD_VDSO32 +#include <asm/vdso32.h> + + .hpet_sect : { + hpet_page = . - VDSO_OFFSET(VDSO_HPET_PAGE); + } :text :hpet_sect + + .vvar_sect : { + vvar = . - VDSO_OFFSET(VDSO_VVAR_PAGE); + + /* Place all vvars at the offsets in asm/vvar.h. */ +#define EMIT_VVAR(name, offset) vvar_ ## name = vvar + offset; +#define __VVAR_KERNEL_LDS +#include <asm/vvar.h> +#undef __VVAR_KERNEL_LDS +#undef EMIT_VVAR + } :text :vvar_sect +#endif . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -61,4 +79,8 @@ PHDRS dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ note PT_NOTE FLAGS(4); /* PF_R */ eh_frame_hdr PT_GNU_EH_FRAME; +#ifdef BUILD_VDSO32 + vvar_sect PT_NULL FLAGS(4); /* PF_R */ + hpet_sect PT_NULL FLAGS(4); /* PF_R */ +#endif }
arch/x86/vdso/vdso32-setup.c +43 -4
69 lines not on this page · raw message
arch/x86/vdso/vdso32/vclock_gettime.c new file +9 -0
@@ -0,0 +1,9 @@ +#define BUILD_VDSO32 + +#ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE +#undef CONFIG_OPTIMIZE_INLINING +#endif + +#undef CONFIG_X86_PPRO_FENCE + +#include "../vclock_gettime.c"
arch/x86/vdso/vdso32/vdso32.lds.S +11 -0
@@ -8,6 +8,11 @@ * values visible using the asm-x86/vdso.h macros from the kernel proper. */ +#include <asm/page.h> + +#define BUILD_VDSO32 +#define VDSO_PRELINK 0 + #include "../vdso-layout.lds.S" /* The ELF entry point can be used to set the AT_SYSINFO value. */
@@ -23,6 +28,9 @@ VERSION __kernel_vsyscall; __kernel_sigreturn; __kernel_rt_sigreturn; + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; local: *; }; }
@@ -33,3 +41,6 @@ VERSION VDSO32_vsyscall = __kernel_vsyscall; VDSO32_sigreturn = __kernel_sigreturn; VDSO32_rt_sigreturn = __kernel_rt_sigreturn; +VDSO32_clock_gettime = clock_gettime; +VDSO32_gettimeofday = gettimeofday; +VDSO32_time = time;
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Add 32 bit VDSO time support for 32 bit kernel
x86, vdso: Add 32 bit VDSO time support for 32 bit kernel
Commit-ID: 7a59ed415f5b57469e22e41fc4188d5399e0b194 Gitweb: http://git.kernel.org/tip/7a59ed415f5b57469e22e41fc4188d5399e0b194 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:09 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:37 -0700
x86, vdso: Add 32 bit VDSO time support for 32 bit kernel
This patch add the time support for 32 bit a VDSO to a 32 bit kernel.
For 32 bit programs running on a 32 bit kernel, the same mechanism is used as for 64 bit programs running on a 64 bit kernel.
--- arch/x86/include/asm/vdso.h | 5 +++ arch/x86/include/asm/vdso32.h | 11 +++++ arch/x86/vdso/Makefile | 8 ++++ arch/x86/vdso/vclock_gettime.c | 76 +++++++++++++++++++++++++++++++---- arch/x86/vdso/vdso-layout.lds.S | 22 ++++++++++ arch/x86/vdso/vdso32-setup.c | 47 ++++++++++++++++++++-- arch/x86/vdso/vdso32/vclock_gettime.c | 9 +++++ arch/x86/vdso/vdso32/vdso32.lds.S | 11 +++++ 8 files changed, 178 insertions(+), 11 deletions(-)
arch/x86/include/asm/vdso.h +5 -0
@@ -2,6 +2,11 @@#define _ASM_X86_VDSO_H#if definedCONFIG_X86_32 || definedCONFIG_COMPAT + +#include <asm/vdso32.h> + +extern const char VDSO32_PRELINK []; +/* * Given a pointer to the vDSO image, find the pointer to VDSO32_name * as that symbol is defined in the vDSO sources or linker script.
arch/x86/include/asm/vdso32.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _ASM_X86_VDSO32_H +#define _ASM_X86_VDSO32_H + +#define VDSO_BASE_PAGE 0 +#define VDSO_VVAR_PAGE 1 +#define VDSO_HPET_PAGE 2 +#define VDSO_PAGES 3 +#define VDSO_PREV_PAGES 2 +#define VDSO_OFFSET (x) ((x) * PAGE_SIZE) + +#endif
arch/x86/vdso/Makefile +8 -0
@@ -146,8 +146,16 @@ KBUILD_AFLAGS_32 := $(filter-out -m64,$(KBUILD_AFLAGS)) $(vdso32-images:%=$(obj)/%.dbg): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32) $(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32 +KBUILD_CFLAGS_32 := $(filter-out -m64,$(KBUILD_CFLAGS)) +KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic +$(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) + $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \ $(obj)/vdso32/vdso32.lds \ + $(obj)/vdso32/vclock_gettime.o \ $(obj)/vdso32/note.o \ $(obj)/vdso32/%.o $(call if_changed,vdso)
arch/x86/vdso/vclock_gettime.c +69 -7
133 lines not on this page · raw message
arch/x86/vdso/vdso-layout.lds.S +22 -0
@@ -6,6 +6,24 @@ SECTIONS { +#ifdef BUILD_VDSO32 +#include <asm/vdso32.h> + + .hpet_sect : { + hpet_page = . - VDSO_OFFSET(VDSO_HPET_PAGE); + } :text :hpet_sect + + .vvar_sect : { + vvar = . - VDSO_OFFSET(VDSO_VVAR_PAGE); + + /* Place all vvars at the offsets in asm/vvar.h. */ +#define EMIT_VVAR(name, offset) vvar_ ## name = vvar + offset; +#define __VVAR_KERNEL_LDS +#include <asm/vvar.h> +#undef __VVAR_KERNEL_LDS +#undef EMIT_VVAR + } :text :vvar_sect +#endif . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -61,4 +79,8 @@ PHDRS dynamic PT_DYNAMIC FLAGS(4); /* PF_R */ note PT_NOTE FLAGS(4); /* PF_R */ eh_frame_hdr PT_GNU_EH_FRAME; +#ifdef BUILD_VDSO32 + vvar_sect PT_NULL FLAGS(4); /* PF_R */ + hpet_sect PT_NULL FLAGS(4); /* PF_R */ +#endif }
arch/x86/vdso/vdso32-setup.c +43 -4
69 lines not on this page · raw message
arch/x86/vdso/vdso32/vclock_gettime.c new file +9 -0
@@ -0,0 +1,9 @@ +#define BUILD_VDSO32 + +#ifndef CONFIG_CC_OPTIMIZE_FOR_SIZE +#undef CONFIG_OPTIMIZE_INLINING +#endif + +#undef CONFIG_X86_PPRO_FENCE + +#include "../vclock_gettime.c"
arch/x86/vdso/vdso32/vdso32.lds.S +11 -0
@@ -8,6 +8,11 @@ * values visible using the asm-x86/vdso.h macros from the kernel proper. */ +#include <asm/page.h> + +#define BUILD_VDSO32 +#define VDSO_PRELINK 0 + #include "../vdso-layout.lds.S" /* The ELF entry point can be used to set the AT_SYSINFO value. */
@@ -23,6 +28,9 @@ VERSION __kernel_vsyscall; __kernel_sigreturn; __kernel_rt_sigreturn; + __vdso_clock_gettime; + __vdso_gettimeofday; + __vdso_time; local: *; }; }
@@ -33,3 +41,6 @@ VERSION VDSO32_vsyscall = __kernel_vsyscall; VDSO32_sigreturn = __kernel_sigreturn; VDSO32_rt_sigreturn = __kernel_rt_sigreturn; +VDSO32_clock_gettime = clock_gettime; +VDSO32_gettimeofday = gettimeofday; +VDSO32_time = time;
PATCH v23 10/13 x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
In reply to Stefani SeiboldThis patch add the VDSO time support for the IA32 Emulation Layer.
Due the nature of the kernel headers and the LP64 compiler where the size of a long and a pointer differs against a 32 bit compiler, there is some type hacking necessary for optimal performance.
The vsyscall_gtod_data struture must be a rearranged to serve 32- and 64-bit code access at the same time:
- The seqcount_t was replaced by an unsigned, this makes the vsyscall_gtod_data intedepend of kernel configuration and internal functions.
- All kernel internal structures are replaced by fix size elements which works for 32- and 64-bit access
- The inner struct clock was removed to pack the whole struct.
The "unsigned seq" would be handled by functions derivated from seqcount_t.
--- arch/x86/include/asm/vgtod.h | 71 +++++++++++++++++++++------ arch/x86/include/asm/vvar.h | 5 ++ arch/x86/kernel/vsyscall_gtod.c | 34 ++++++++----- arch/x86/vdso/vclock_gettime.c | 91 +++++++++++++++++++---------------- arch/x86/vdso/vdso32/vclock_gettime.c | 21 ++++++++ 5 files changed, 155 insertions(+), 67 deletions(-)
arch/x86/include/asm/vgtod.h +57 -14
@@ -1,30 +1,73 @@#ifndef _ASM_X86_VGTOD_H#define _ASM_X86_VGTOD_H -#include <asm/vsyscall.h> +#include <linux/compiler.h> #include <linux/clocksource.h> +#ifdef BUILD_VDSO32_64 +typedef u64 gtod_long_t ; +#else +typedef unsigned long gtod_long_t ; +#endif +/* +* vsyscall_gtod_data will be accessed by 32 and 64 bit code at the same time +* so be carefull by modifying this structure. +*/ struct vsyscall_gtod_data { -seqcount_t seq; +unsigned seq; -struct {/* extract of a clocksource struct */ -int vclock_mode; -cycle_t cycle_last; -cycle_t mask; -u32 mult; -u32 shift; - } clock; +int vclock_mode; +cycle_t cycle_last; +cycle_t mask; +u32 mult; +u32 shift;/* open coded 'struct timespec' */ -time_t wall_time_sec;u64 wall_time_snsec; +gtod_long_t wall_time_sec; +gtod_long_t monotonic_time_sec;u64 monotonic_time_snsec; -time_t monotonic_time_sec; +gtod_long_t wall_time_coarse_sec; +gtod_long_t wall_time_coarse_nsec; +gtod_long_t monotonic_time_coarse_sec; +gtod_long_t monotonic_time_coarse_nsec; -struct timezone sys_tz; -struct timespec wall_time_coarse; -struct timespec monotonic_time_coarse; +int tz_minuteswest; +int tz_dsttime; };extern struct vsyscall_gtod_data vsyscall_gtod_data; +static inline unsigned gtod_read_begin (const struct vsyscall_gtod_data *s) +{ +unsigned ret; + +repeat: + ret =ACCESS_ONCE (s->seq); +if (unlikely (ret &1 )) { +cpu_relax (); + goto repeat; + } +smp_rmb (); +return ret; +} + +static inline int gtod_read_retry (const struct vsyscall_gtod_data *s, +unsigned start) +{ +smp_rmb (); +return unlikely (s->seq != start); +} + +static inline void gtod_write_begin (struct vsyscall_gtod_data *s) +{ + ++s->seq; +smp_wmb (); +} + +static inline void gtod_write_end (struct vsyscall_gtod_data *s) +{ +smp_wmb (); + ++s->seq; +} +#endif /* _ASM_X86_VGTOD_H */
arch/x86/include/asm/vvar.h +5 -0
@@ -16,6 +16,9 @@* you mess up, the linker will catch it.) */ +#ifndef _ASM_X86_VVAR_H +#define _ASM_X86_VVAR_H +#if defined(__VVAR_KERNEL_LDS)/* The kernel linker script defines its own magic to put vvars in the
@@ -64,3 +67,5 @@ DECLARE_VVAR(16, int, vgetcpu_mode) DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)#undef DECLARE_VVAR + +#endif
arch/x86/kernel/vsyscall_gtod.c +22 -12
@@ -4,6 +4,7 @@* * Modified for x86 32 bit architecture by * Stefani Seibold <[email protected]> +* sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany * * Thanks to [email protected] for some useful hint. * Special thanks to Ingo Molnar for his early experience with
@@ -13,26 +14,28 @@#include <linux/timekeeper_internal.h> #include <asm/vgtod.h> +#include <asm/vvar.h> DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);void update_vsyscall_tz (void ) { - vsyscall_gtod_data.sys_tz = sys_tz; + vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest; + vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime; }void update_vsyscall (struct timekeeper *tk) {struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data; -write_seqcount_begin (&vdata->seq); +gtod_write_begin (vdata);/* copy vsyscall data */ - vdata->clock.vclock_mode = tk->clock->archdata.vclock_mode; - vdata->clock.cycle_last = tk->clock->cycle_last; - vdata->clock.mask = tk->clock->mask; - vdata->clock.mult = tk->mult; - vdata->clock.shift = tk->shift; + vdata->vclock_mode = tk->clock->archdata.vclock_mode; + vdata->cycle_last = tk->clock->cycle_last; + vdata->mask = tk->clock->mask; + vdata->mult = tk->mult; + vdata->shift = tk->shift; vdata->wall_time_sec = tk->xtime_sec; vdata->wall_time_snsec = tk->xtime_nsec;
@@ -49,11 +52,18 @@ void update_vsyscall(struct timekeeper *tk) vdata->monotonic_time_sec++; } - vdata->wall_time_coarse.tv_sec = tk->xtime_sec; - vdata->wall_time_coarse.tv_nsec = (long )(tk->xtime_nsec >> tk->shift); + vdata->wall_time_coarse_sec = tk->xtime_sec; + vdata->wall_time_coarse_nsec = (long )(tk->xtime_nsec >> tk->shift); - vdata->monotonic_time_coarse =timespec_add (vdata->wall_time_coarse, - tk->wall_to_monotonic); + vdata->monotonic_time_coarse_sec = + vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec; + vdata->monotonic_time_coarse_nsec = + vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec; -write_seqcount_end (&vdata->seq); +while (vdata->monotonic_time_coarse_nsec >=NSEC_PER_SEC ) { + vdata->monotonic_time_coarse_nsec -=NSEC_PER_SEC ; + vdata->monotonic_time_coarse_sec++; + } + +gtod_write_end (vdata); }
arch/x86/vdso/vclock_gettime.c +50 -41
188 lines not on this page · raw message
arch/x86/vdso/vdso32/vclock_gettime.c +21 -0
@@ -6,4 +6,25 @@#undef CONFIG_X86_PPRO_FENCE +#ifdef CONFIG_X86_64 + +/* +* in case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel +* configuration +*/ +#undef CONFIG_64BIT +#undef CONFIG_X86_64 +#undef CONFIG_ILLEGAL_POINTER_VALUE +#undef CONFIG_SPARSEMEM_VMEMMAP +#undef CONFIG_NR_CPUS + +#define CONFIG_X86_32 1 +#define CONFIG_PAGE_OFFSET 0 +#define CONFIG_ILLEGAL_POINTER_VALUE 0 +#define CONFIG_NR_CPUS 1 + +#define BUILD_VDSO32_64 + +#endif +#include "../vclock_gettime.c"
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
Commit-ID: 7c03156f34d113f885f045d8fb8cc3efd9e64751 Gitweb: http://git.kernel.org/tip/7c03156f34d113f885f045d8fb8cc3efd9e64751 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:10 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:41 -0700
x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
This patch add the VDSO time support for the IA32 Emulation Layer.
Due the nature of the kernel headers and the LP64 compiler where the size of a long and a pointer differs against a 32 bit compiler, there is some type hacking necessary for optimal performance.
The vsyscall_gtod_data struture must be a rearranged to serve 32- and 64-bit code access at the same time:
- The seqcount_t was replaced by an unsigned, this makes the vsyscall_gtod_data intedepend of kernel configuration and internal functions.
- All kernel internal structures are replaced by fix size elements which works for 32- and 64-bit access
- The inner struct clock was removed to pack the whole struct.
The "unsigned seq" would be handled by functions derivated from seqcount_t.
--- arch/x86/include/asm/vgtod.h | 71 +++++++++++++++++++++------ arch/x86/include/asm/vvar.h | 5 ++ arch/x86/kernel/vsyscall_gtod.c | 34 ++++++++----- arch/x86/vdso/vclock_gettime.c | 91 +++++++++++++++++++---------------- arch/x86/vdso/vdso32/vclock_gettime.c | 21 ++++++++ 5 files changed, 155 insertions(+), 67 deletions(-)
arch/x86/include/asm/vgtod.h +57 -14
@@ -1,30 +1,73 @@#ifndef _ASM_X86_VGTOD_H#define _ASM_X86_VGTOD_H -#include <asm/vsyscall.h> +#include <linux/compiler.h> #include <linux/clocksource.h> +#ifdef BUILD_VDSO32_64 +typedef u64 gtod_long_t ; +#else +typedef unsigned long gtod_long_t ; +#endif +/* +* vsyscall_gtod_data will be accessed by 32 and 64 bit code at the same time +* so be carefull by modifying this structure. +*/ struct vsyscall_gtod_data { -seqcount_t seq; +unsigned seq; -struct {/* extract of a clocksource struct */ -int vclock_mode; -cycle_t cycle_last; -cycle_t mask; -u32 mult; -u32 shift; - } clock; +int vclock_mode; +cycle_t cycle_last; +cycle_t mask; +u32 mult; +u32 shift;/* open coded 'struct timespec' */ -time_t wall_time_sec;u64 wall_time_snsec; +gtod_long_t wall_time_sec; +gtod_long_t monotonic_time_sec;u64 monotonic_time_snsec; -time_t monotonic_time_sec; +gtod_long_t wall_time_coarse_sec; +gtod_long_t wall_time_coarse_nsec; +gtod_long_t monotonic_time_coarse_sec; +gtod_long_t monotonic_time_coarse_nsec; -struct timezone sys_tz; -struct timespec wall_time_coarse; -struct timespec monotonic_time_coarse; +int tz_minuteswest; +int tz_dsttime; };extern struct vsyscall_gtod_data vsyscall_gtod_data; +static inline unsigned gtod_read_begin (const struct vsyscall_gtod_data *s) +{ +unsigned ret; + +repeat: + ret =ACCESS_ONCE (s->seq); +if (unlikely (ret &1 )) { +cpu_relax (); + goto repeat; + } +smp_rmb (); +return ret; +} + +static inline int gtod_read_retry (const struct vsyscall_gtod_data *s, +unsigned start) +{ +smp_rmb (); +return unlikely (s->seq != start); +} + +static inline void gtod_write_begin (struct vsyscall_gtod_data *s) +{ + ++s->seq; +smp_wmb (); +} + +static inline void gtod_write_end (struct vsyscall_gtod_data *s) +{ +smp_wmb (); + ++s->seq; +} +#endif /* _ASM_X86_VGTOD_H */
arch/x86/include/asm/vvar.h +5 -0
@@ -16,6 +16,9 @@* you mess up, the linker will catch it.) */ +#ifndef _ASM_X86_VVAR_H +#define _ASM_X86_VVAR_H +#if defined(__VVAR_KERNEL_LDS)/* The kernel linker script defines its own magic to put vvars in the
@@ -64,3 +67,5 @@ DECLARE_VVAR(16, int, vgetcpu_mode) DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data)#undef DECLARE_VVAR + +#endif
arch/x86/kernel/vsyscall_gtod.c +22 -12
@@ -4,6 +4,7 @@* * Modified for x86 32 bit architecture by * Stefani Seibold <[email protected]> +* sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany * * Thanks to [email protected] for some useful hint. * Special thanks to Ingo Molnar for his early experience with
@@ -13,26 +14,28 @@#include <linux/timekeeper_internal.h> #include <asm/vgtod.h> +#include <asm/vvar.h> DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);void update_vsyscall_tz (void ) { - vsyscall_gtod_data.sys_tz = sys_tz; + vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest; + vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime; }void update_vsyscall (struct timekeeper *tk) {struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data; -write_seqcount_begin (&vdata->seq); +gtod_write_begin (vdata);/* copy vsyscall data */ - vdata->clock.vclock_mode = tk->clock->archdata.vclock_mode; - vdata->clock.cycle_last = tk->clock->cycle_last; - vdata->clock.mask = tk->clock->mask; - vdata->clock.mult = tk->mult; - vdata->clock.shift = tk->shift; + vdata->vclock_mode = tk->clock->archdata.vclock_mode; + vdata->cycle_last = tk->clock->cycle_last; + vdata->mask = tk->clock->mask; + vdata->mult = tk->mult; + vdata->shift = tk->shift; vdata->wall_time_sec = tk->xtime_sec; vdata->wall_time_snsec = tk->xtime_nsec;
@@ -49,11 +52,18 @@ void update_vsyscall(struct timekeeper *tk) vdata->monotonic_time_sec++; } - vdata->wall_time_coarse.tv_sec = tk->xtime_sec; - vdata->wall_time_coarse.tv_nsec = (long )(tk->xtime_nsec >> tk->shift); + vdata->wall_time_coarse_sec = tk->xtime_sec; + vdata->wall_time_coarse_nsec = (long )(tk->xtime_nsec >> tk->shift); - vdata->monotonic_time_coarse =timespec_add (vdata->wall_time_coarse, - tk->wall_to_monotonic); + vdata->monotonic_time_coarse_sec = + vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec; + vdata->monotonic_time_coarse_nsec = + vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec; -write_seqcount_end (&vdata->seq); +while (vdata->monotonic_time_coarse_nsec >=NSEC_PER_SEC ) { + vdata->monotonic_time_coarse_nsec -=NSEC_PER_SEC ; + vdata->monotonic_time_coarse_sec++; + } + +gtod_write_end (vdata); }
arch/x86/vdso/vclock_gettime.c +50 -41
188 lines not on this page · raw message
arch/x86/vdso/vdso32/vclock_gettime.c +21 -0
@@ -6,4 +6,25 @@#undef CONFIG_X86_PPRO_FENCE +#ifdef CONFIG_X86_64 + +/* +* in case of a 32 bit VDSO for a 64 bit kernel fake a 32 bit kernel +* configuration +*/ +#undef CONFIG_64BIT +#undef CONFIG_X86_64 +#undef CONFIG_ILLEGAL_POINTER_VALUE +#undef CONFIG_SPARSEMEM_VMEMMAP +#undef CONFIG_NR_CPUS + +#define CONFIG_X86_32 1 +#define CONFIG_PAGE_OFFSET 0 +#define CONFIG_ILLEGAL_POINTER_VALUE 0 +#define CONFIG_NR_CPUS 1 + +#define BUILD_VDSO32_64 + +#endif +#include "../vclock_gettime.c"
Re: [PATCH v23 10/13] x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
In reply to Stefani SeiboldQuoted 9 lines · Stefani Seibold
This patch add the VDSO time support for the IA32 Emulation Layer.
Due the nature of the kernel headers and the LP64 compiler where the size of a long and a pointer differs against a 32 bit compiler, there is some type hacking necessary for optimal performance.
The
vsyscall_gtod_datastruture must be a rearranged to serve 32- and 64-bit code access at the same time:
Quoted 7 lines
- The
seqcount_twas replaced by an unsigned, this makes thevsyscall_gtod_dataintedepend of kernel configuration and internal functions.
- All kernel internal structures are replaced by fix size elements which works for 32- and 64-bit access
- The inner struct clock was removed to pack the whole struct.The "unsigned seq" would be handled by functions derivated from
seqcount_t.
Sorry for being a bit late on the review here. I've been focused on some other things and figured I'd leave things to the x86 maintainers, since it didn't touch any core timekeeping code. But Andy pinged me after LSF-MM and so I'm trying to take a closer look.
I know this has gone through tons of iterations, and I really am glad for Stefani's persistence. Also I do realize its already in the tip tree, so my thoughts here are probably too late to be worth much.
Quoted 8 lines
Signed-off-by Stefani Seibold <[email protected]>--- arch/x86/include/asm/vgtod.h | 71 +++++++++++++++++++++------ arch/x86/include/asm/vvar.h | 5 ++ arch/x86/kernel/vsyscall_gtod.c | 34 ++++++++----- arch/x86/vdso/vclock_gettime.c | 91 +++++++++++++++++++---------------- arch/x86/vdso/vdso32/vclock_gettime.c | 21 ++++++++ 5 files changed, 155 insertions(+), 67 deletions(-)
My initial issue with this patch is it is doing quite a few things that could have been split up a bit. There's a number of separate cleanups:
seqlock change, the read_hpet_counter() cleanup, the vsyscall_gtod_data structure rework, and finally the gtod_long_t and VDSO32_64 changes.
Its probably too late now, but in the future it might be good to try to split these sorts of things up in smaller chunks.
Overall, I don't see any obvious correctness issues with the code, so it looks ok to me, but I really worry the amount of open-coded logic and the quirkiness of trying to make the vsyscall_gtod_data structure usable for both architectures at the same time really makes this code quite fragile. Looking over this there were lots of "oh, that's broken.. wait.. no.. actually that will work" moments. So I'm worried about the maintenance burden in the future from it.
Having separate structures that are filled by update_vsyscall might be nice to avoid needing the open-coded bits, but that would require basically making a copy of all the data in the structure each update, so that might not be worth the cost.
So as long as the x86 folks are ok with being on the hook for it, I'll not get in the way (most other arches have quirky/ugly implementations for their vdso/vsyscall/fsyscall/etc, so why not join the club :).
I did run this through my timekeeping test suite and on 64bit nothing broke w/ either 32 or 64bit binaries, but I also don't have the glibc changes to enable the 32bit vdso, so all that says is its not showing any regressions for my existing setup.
thanks
-john
Re: [PATCH v23 10/13] x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
Quoted 53 lines · John Stultz
Quoted 9 lines · Stefani Seibold
This patch add the VDSO time support for the IA32 Emulation Layer.
Due the nature of the kernel headers and the LP64 compiler where the size of a long and a pointer differs against a 32 bit compiler, there is some type hacking necessary for optimal performance.
The
vsyscall_gtod_datastruture must be a rearranged to serve 32- and 64-bit code access at the same time:Quoted 7 lines
- The
seqcount_twas replaced by an unsigned, this makes thevsyscall_gtod_dataintedepend of kernel configuration and internal functions.
- All kernel internal structures are replaced by fix size elements which works for 32- and 64-bit access
- The inner struct clock was removed to pack the whole struct.The "unsigned seq" would be handled by functions derivated from
seqcount_t.Sorry for being a bit late on the review here. I've been focused on some other things and figured I'd leave things to the x86 maintainers, since it didn't touch any core timekeeping code. But Andy pinged me after LSF-MM and so I'm trying to take a closer look.
I know this has gone through tons of iterations, and I really am glad for Stefani's persistence. Also I do realize its already in the tip tree, so my thoughts here are probably too late to be worth much.
Quoted 8 lines
Signed-off-by Stefani Seibold <[email protected]>--- arch/x86/include/asm/vgtod.h | 71 +++++++++++++++++++++------ arch/x86/include/asm/vvar.h | 5 ++ arch/x86/kernel/vsyscall_gtod.c | 34 ++++++++----- arch/x86/vdso/vclock_gettime.c | 91 +++++++++++++++++++---------------- arch/x86/vdso/vdso32/vclock_gettime.c | 21 ++++++++ 5 files changed, 155 insertions(+), 67 deletions(-)My initial issue with this patch is it is doing quite a few things that could have been split up a bit. There's a number of separate cleanups:
seqlock change, theread_hpet_counter()cleanup, thevsyscall_gtod_datastructure rework, and finally thegtod_long_tandVDSO32_64changes.Its probably too late now, but in the future it might be good to try to split these sorts of things up in smaller chunks.
Overall, I don't see any obvious correctness issues with the code, so it looks ok to me, but I really worry the amount of open-coded logic and the quirkiness of trying to make the
vsyscall_gtod_datastructure usable for both architectures at the same time really makes this code quite fragile. Looking over this there were lots of "oh, that's broken.. wait.. no.. actually that will work" moments. So I'm worried about the maintenance burden in the future from it.
Quoted 4 lines
Having separate structures that are filled by
update_vsyscallmight be nice to avoid needing the open-coded bits, but that would require basically making a copy of all the data in the structure each update, so that might not be worth the cost.
This may actually enable a future cleanup: currently, the x32 vdso is built with gcc in 64-bit mode, and objcopy turns the result into a 32-bit file. This structure munging, along with a cleanup I'm working on, will eliminate the need to do that.
Quoted 9 lines
So as long as the x86 folks are ok with being on the hook for it, I'll not get in the way (most other arches have quirky/ugly implementations for their vdso/vsyscall/fsyscall/etc, so why not join the club :).
I did run this through my timekeeping test suite and on 64bit nothing broke w/ either 32 or 64bit binaries, but I also don't have the glibc changes to enable the 32bit vdso, so all that says is its not showing any regressions for my existing setup.
Thanks for looking!
--Andy
H. Peter Anvin
reviewerRe: [PATCH v23 10/13] x86, vdso: Add 32 bit VDSO time support for 64 bit kernel
In reply to John StultzI am hoping that we well get further cleanups, but art this point I'm not sure it is worth blocking it for 3.15 over that
Quoted 77 lines · John Stultz
Quoted 11 lines · Stefani Seibold
This patch add the VDSO time support for the IA32 Emulation Layer.
Due the nature of the kernel headers and the LP64 compiler where the size of a long and a pointer differs against a 32 bit compiler, there is some type hacking necessary for optimal performance.
The
vsyscall_gtod_datastruture must be a rearranged to serve 32- and 64-bit code access at the same time:- The
seqcount_twas replaced by an unsigned, this makes thevsyscall_gtod_dataintedepend of kernel configuration and internalfunctions.
Quoted 5 lines
- All kernel internal structures are replaced by fix size elements which works for 32- and 64-bit access
- The inner struct clock was removed to pack the whole struct.The "unsigned seq" would be handled by functions derivated from
seqcount_t.Sorry for being a bit late on the review here. I've been focused on some
other things and figured I'd leave things to the x86 maintainers, since it didn't touch any core timekeeping code. But Andy pinged me after LSF-MM and so I'm trying to take a closer look.I know this has gone through tons of iterations, and I really am glad for Stefani's persistence. Also I do realize its already in the tip tree, so my thoughts here are probably too late to be worth much.
Quoted 3 lines
Signed-off-by Stefani Seibold <[email protected]>--- arch/x86/include/asm/vgtod.h | 71+++++++++++++++++++++------
Quoted 3 lines
arch/x86/include/asm/vvar.h | 5 ++ arch/x86/kernel/vsyscall_gtod.c | 34 ++++++++----- arch/x86/vdso/vclock_gettime.c | 91+++++++++++++++++++----------------
Quoted 2 lines
arch/x86/vdso/vdso32/vclock_gettime.c | 21 ++++++++ 5 files changed, 155 insertions(+), 67 deletions(-)My initial issue with this patch is it is doing quite a few things that could have been split up a bit. There's a number of separate cleanups:
seqlock change, theread_hpet_counter()cleanup, thevsyscall_gtod_datastructure rework, and finally thegtod_long_tandVDSO32_64changes.Its probably too late now, but in the future it might be good to try to split these sorts of things up in smaller chunks.
Overall, I don't see any obvious correctness issues with the code, so it
looks ok to me, but I really worry the amount of open-coded logic and the quirkiness of trying to make thevsyscall_gtod_datastructure usable
for both architectures at the same time really makes this code quite fragile. Looking over this there were lots of "oh, that's broken.. wait.. no.. actually that will work" moments. So I'm worried about the maintenance burden in the future from it.Having separate structures that are filled by
update_vsyscallmight be nice to avoid needing the open-coded bits, but that would require basically making a copy of all the data in the structure each update, so
that might not be worth the cost.So as long as the x86 folks are ok with being on the hook for it, I'll not get in the way (most other arches have quirky/ugly implementations for their vdso/vsyscall/fsyscall/etc, so why not join the club :).
I did run this through my timekeeping test suite and on 64bit nothing broke w/ either 32 or 64bit binaries, but I also don't have the glibc changes to enable the 32bit vdso, so all that says is its not showing any regressions for my existing setup.
thanks
-john
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
PATCH v23 11/13 x86, vdso: Zero-pad the VVAR page
In reply to Stefani SeiboldFrom: Andy Lutomirski <[email protected]>
By coincidence, the VVAR page is at the end of an ELF segment. As a result, if it ends up being a partial page, the kernel loader will leave garbage behind at the end of the vvar page. Zero-pad it to a full page to fix this issue.
This has probably been broken since the VVAR page was introduced. On QEMU, if you dump the run-time contents of the VVAR page, you can find entertaining strings from seabios left behind.
It's remotely possible that this is a security bug -- conceivably there's some BIOS out there that leaves something sensitive in the few K of memory that is exposed to userspace.
--- arch/x86/kernel/vmlinux.lds.S | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/vmlinux.lds.S +5 -0
@@ -164,6 +164,11 @@ SECTIONS #undef __VVAR_KERNEL_LDS #undef EMIT_VVAR + /* + * Pad the rest of the page with zeros. Otherwise the loader + * can leave garbage here. + */ + . = __vvar_beginning_hack + PAGE_SIZE; } :data . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
Signature · 1 line
1.9.0
tip-bot for Andy Lutomirski
merge bot[tip:x86/vdso] x86, vdso: Zero-pad the VVAR page
x86, vdso: Zero-pad the VVAR page
Commit-ID: 309944be296efbb3ca4737d12ef49d2ba97cbecc Gitweb: http://git.kernel.org/tip/309944be296efbb3ca4737d12ef49d2ba97cbecc Author: Andy Lutomirski <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:11 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:44 -0700
x86, vdso: Zero-pad the VVAR page
By coincidence, the VVAR page is at the end of an ELF segment. As a result, if it ends up being a partial page, the kernel loader will leave garbage behind at the end of the vvar page. Zero-pad it to a full page to fix this issue.
This has probably been broken since the VVAR page was introduced. On QEMU, if you dump the run-time contents of the VVAR page, you can find entertaining strings from seabios left behind.
It's remotely possible that this is a security bug -- conceivably there's some BIOS out there that leaves something sensitive in the few K of memory that is exposed to userspace.
--- arch/x86/kernel/vmlinux.lds.S | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/vmlinux.lds.S +5 -0
@@ -164,6 +164,11 @@ SECTIONS #undef __VVAR_KERNEL_LDS #undef EMIT_VVAR + /* + * Pad the rest of the page with zeros. Otherwise the loader + * can leave garbage here. + */ + . = __vvar_beginning_hack + PAGE_SIZE; } :data . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
PATCH v23 12/13 x86, vdso32: Disable stack protector, adjust optimizations
In reply to Stefani SeiboldFrom: "H. Peter Anvin" <[email protected]>
For the 32-bit VDSO, match the 64-bit VDSO in:
1. Disable the stack protector.
2. Use -fno-omit-frame-pointer for user space debugging sanity.
3. Use -foptimize-sibling-calls like the 64-bit VDSO does.
--- arch/x86/vdso/Makefile | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/vdso/Makefile +3 -0
@@ -151,6 +151,9 @@ KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic +KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) +KBUILD_CFLAGS_32 += -fno-omit-frame-pointer $(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
Signature · 1 line
1.9.0
tip-bot for H. Peter Anvin
merge bot[tip:x86/vdso] x86, vdso32: Disable stack protector, adjust optimizations
x86, vdso32: Disable stack protector, adjust optimizations
Commit-ID: 008cc907de327d83a0be609cd495fccb0e5dfa4c Gitweb: http://git.kernel.org/tip/008cc907de327d83a0be609cd495fccb0e5dfa4c Author: H. Peter Anvin <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:12 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:48 -0700
x86, vdso32: Disable stack protector, adjust optimizations
For the 32-bit VDSO, match the 64-bit VDSO in:
1. Disable the stack protector.
2. Use -fno-omit-frame-pointer for user space debugging sanity.
3. Use -foptimize-sibling-calls like the 64-bit VDSO does.
--- arch/x86/vdso/Makefile | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/vdso/Makefile +3 -0
@@ -151,6 +151,9 @@ KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic +KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector) +KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) +KBUILD_CFLAGS_32 += -fno-omit-frame-pointer $(vdso32-images:%=$(obj)/%.dbg): KBUILD_CFLAGS = $(KBUILD_CFLAGS_32) $(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
PATCH v23 13/13 x86, vdso32: handle 32 bit vDSO larger one page
In reply to Stefani SeiboldThis patch enables 32 bit vDSO which are larger than a page.
--- arch/x86/vdso/vdso32-setup.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
arch/x86/vdso/vdso32-setup.c +15 -7
@@ -16,6 +16,7 @@#include <linux/mm.h> #include <linux/err.h> #include <linux/module.h> +#include <linux/slab.h> #include <asm/cpufeature.h> #include <asm/msr.h>
@@ -69,7 +70,8 @@ __setup_param("vdso=", vdso32_setup, vdso_setup, 0);EXPORT_SYMBOL_GPL (vdso_enabled);#endif -static struct page *vdso32_pages[1 ]; +static struct page **vdso32_pages; +static unsigned int vdso32_size;#ifdef CONFIG_X86_64
@@ -115,11 +117,10 @@ void enable_sep_cpu(void)int __init sysenter_setup (void ) { -void *vdso_page = (void *)get_zeroed_page (GFP_ATOMIC ); +void *vdso_pages;const void *vdso;size_t vdso_len; - - vdso32_pages[0 ] =virt_to_page (vdso_page); +unsigned int i;if (vdso32_syscall ()) { vdso = &vdso32_syscall_start;
@@ -132,8 +133,15 @@ int __init sysenter_setup(void) vdso_len = &vdso32_int80_end - &vdso32_int80_start; } -memcpy (vdso_page, vdso, vdso_len); -patch_vdso32 (vdso_page, vdso_len); + vdso32_size = (vdso_len +PAGE_SIZE -1 ) /PAGE_SIZE ; + vdso32_pages =kmalloc (sizeof (*vdso32_pages) * vdso32_size,GFP_ATOMIC ); + vdso_pages =kmalloc (VDSO_OFFSET (vdso32_size),GFP_ATOMIC ); + +for (i =0 ; i != vdso32_size; ++i) + vdso32_pages[i] =virt_to_page (vdso_pages +VDSO_OFFSET (i)); + +memcpy (vdso_pages, vdso, vdso_len); +patch_vdso32 (vdso_pages, vdso_len);return 0 ; }
@@ -169,7 +177,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ ret =install_special_mapping (mm, addr, -VDSO_OFFSET (VDSO_PAGES -VDSO_PREV_PAGES ), +VDSO_OFFSET (vdso32_size),VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso32_pages);
Signature · 1 line
1.9.0
tip-bot for Stefani Seibold
merge bot[tip:x86/vdso] x86, vdso32: handle 32 bit vDSO larger one page
x86, vdso32: handle 32 bit vDSO larger one page
Commit-ID: 4e40112c4ff6a577dd06d92b2a54cdf06265bf74 Gitweb: http://git.kernel.org/tip/4e40112c4ff6a577dd06d92b2a54cdf06265bf74 Author: Stefani Seibold <[email protected]> AuthorDate: Mon, 17 Mar 2014 23:22:13 +0100 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 18 Mar 2014 12:52:54 -0700
x86, vdso32: handle 32 bit vDSO larger one page
This patch enables 32 bit vDSO which are larger than a page.
--- arch/x86/vdso/vdso32-setup.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
arch/x86/vdso/vdso32-setup.c +15 -7
@@ -16,6 +16,7 @@#include <linux/mm.h> #include <linux/err.h> #include <linux/module.h> +#include <linux/slab.h> #include <asm/cpufeature.h> #include <asm/msr.h>
@@ -69,7 +70,8 @@ __setup_param("vdso=", vdso32_setup, vdso_setup, 0);EXPORT_SYMBOL_GPL (vdso_enabled);#endif -static struct page *vdso32_pages[1 ]; +static struct page **vdso32_pages; +static unsigned int vdso32_size;#ifdef CONFIG_X86_64
@@ -115,11 +117,10 @@ void enable_sep_cpu(void)int __init sysenter_setup (void ) { -void *vdso_page = (void *)get_zeroed_page (GFP_ATOMIC ); +void *vdso_pages;const void *vdso;size_t vdso_len; - - vdso32_pages[0 ] =virt_to_page (vdso_page); +unsigned int i;if (vdso32_syscall ()) { vdso = &vdso32_syscall_start;
@@ -132,8 +133,15 @@ int __init sysenter_setup(void) vdso_len = &vdso32_int80_end - &vdso32_int80_start; } -memcpy (vdso_page, vdso, vdso_len); -patch_vdso32 (vdso_page, vdso_len); + vdso32_size = (vdso_len +PAGE_SIZE -1 ) /PAGE_SIZE ; + vdso32_pages =kmalloc (sizeof (*vdso32_pages) * vdso32_size,GFP_ATOMIC ); + vdso_pages =kmalloc (VDSO_OFFSET (vdso32_size),GFP_ATOMIC ); + +for (i =0 ; i != vdso32_size; ++i) + vdso32_pages[i] =virt_to_page (vdso_pages +VDSO_OFFSET (i)); + +memcpy (vdso_pages, vdso, vdso_len); +patch_vdso32 (vdso_pages, vdso_len);return 0 ; }
@@ -169,7 +177,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)*/ ret =install_special_mapping (mm, addr, -VDSO_OFFSET (VDSO_PAGES -VDSO_PREV_PAGES ), +VDSO_OFFSET (vdso32_size),VM_READ |VM_EXEC |VM_MAYREAD |VM_MAYWRITE |VM_MAYEXEC , vdso32_pages);