public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v22 00/12] Add 32 bit VDSO time function support
@ 2014-03-03 21:12 Stefani Seibold
  2014-03-03 21:12 ` [Patch v22 01/12] x86: Make vsyscall_gtod_data handling x86 generic Stefani Seibold
                   ` (10 more replies)
  0 siblings, 11 replies; 25+ messages in thread
From: Stefani Seibold @ 2014-03-03 21:12 UTC (permalink / raw)
  To: gregkh, linux-kernel, x86, tglx, mingo, hpa, ak, aarcange,
	john.stultz, luto, xemul, gorcunov, andriy.shevchenko
  Cc: Martin.Runge, Andreas.Brief, Stefani Seibold

This patch add the functions vdso_gettimeofday(), vdso_clock_gettime()
and vdso_time() to the 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 address layout of the VDSO has changed, because there is no fixed
address space available on a x86 32 bit kernel, despite the name. Because
someone decided to add an offset to the __FIXADDR_TOP for virtualization.

Also the IA32 Emulation uses the whole 4 GB address space, so there is no
fixed address available.

This was the reason not depend on this kind of address and change the layout
of the VDSO. 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 kernel 3.14 (e7651b819e90da924991d727d3c007200a18670d)

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

^ permalink raw reply	[flat|nested] 25+ messages in thread
* [PATCH v23 11/13] x86, vdso: Zero-pad the VVAR page
@ 2014-03-17 22:22 Stefani Seibold
  2014-03-18 21:29 ` [tip:x86/vdso] " tip-bot for Andy Lutomirski
  0 siblings, 1 reply; 25+ messages in thread
From: Stefani Seibold @ 2014-03-17 22:22 UTC (permalink / raw)
  To: gregkh, linux-kernel, x86, tglx, mingo, hpa, ak, aarcange,
	john.stultz, luto, xemul, gorcunov, andriy.shevchenko
  Cc: Martin.Runge, Andreas.Brief, stefani

From: Andy Lutomirski <luto@amacapital.net>

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.

Signed-off-by: Stefani Seibold <stefani@seibold.net>
---
 arch/x86/kernel/vmlinux.lds.S | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 1d4897b..49edf2d 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -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);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-03-18 21:31 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-03 21:12 [PATCH v22 00/12] Add 32 bit VDSO time function support Stefani Seibold
2014-03-03 21:12 ` [Patch v22 01/12] x86: Make vsyscall_gtod_data handling x86 generic Stefani Seibold
2014-03-05 22:30   ` [tip:x86/vdso] x86, vdso: " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 02/12] x86: Add new func _install_special_mapping() to mmap.c Stefani Seibold
2014-03-05 22:30   ` [tip:x86/vdso] mm: " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 03/12] x86: revamp vclock_gettime.c Stefani Seibold
2014-03-05 22:30   ` [tip:x86/vdso] x86, vdso: Revamp vclock_gettime.c tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 04/12] x86: vclock_gettime.c __vdso_clock_gettime cleanup Stefani Seibold
2014-03-05 22:31   ` [tip:x86/vdso] x86, vdso: __vdso_clock_gettime() cleanup tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 05/12] x86: replace VVAR(vsyscall_gtod_data) by gtod macro Stefani Seibold
2014-03-05 22:31   ` [tip:x86/vdso] x86, vdso: Replace " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 06/12] x86: cleanup __vdso_gettimeofday Stefani Seibold
2014-03-05 22:31   ` [tip:x86/vdso] x86, vdso: Cleanup __vdso_gettimeofday() tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 07/12] x86: introduce VVAR marco for vdso32 Stefani Seibold
2014-03-05 22:31   ` [tip:x86/vdso] x86, vdso: Introduce " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 08/12] x86: Patch alternatives in the 32-bit vDSO Stefani Seibold
2014-03-05 22:31   ` [tip:x86/vdso] x86, vdso: Patch alternatives in the 32-bit VDSO tip-bot for Andy Lutomirski
2014-03-03 21:12 ` [Patch v22 09/12] x86: Add 32 bit VDSO time support for 32 bit kernel Stefani Seibold
2014-03-05 22:32   ` [tip:x86/vdso] x86, vdso: " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 10/12] x86: Add 32 bit VDSO time support for 64 " Stefani Seibold
2014-03-05 22:32   ` [tip:x86/vdso] x86, vdso: " tip-bot for Stefani Seibold
2014-03-03 21:12 ` [Patch v22 12/12] x86: Zero-pad the VVAR page Stefani Seibold
2014-03-05 22:32   ` [tip:x86/vdso] x86, vdso: " tip-bot for Andy Lutomirski
2014-03-06 17:51   ` [tip:x86/vdso] x86, vdso32: Disable stack protector, adjust optimizations tip-bot for H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2014-03-17 22:22 [PATCH v23 11/13] x86, vdso: Zero-pad the VVAR page Stefani Seibold
2014-03-18 21:29 ` [tip:x86/vdso] " tip-bot for Andy Lutomirski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox