mirror of https://gitee.com/openkylin/linux.git
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. Reviewed-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: Stefani Seibold <stefani@seibold.net> Link: http://lkml.kernel.org/r/1395094933-14252-10-git-send-email-stefani@seibold.net Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This commit is contained in:
parent
b4b541a610
commit
7a59ed415f
|
@ -2,6 +2,11 @@
|
||||||
#define _ASM_X86_VDSO_H
|
#define _ASM_X86_VDSO_H
|
||||||
|
|
||||||
#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
|
#if defined CONFIG_X86_32 || defined CONFIG_COMPAT
|
||||||
|
|
||||||
|
#include <asm/vdso32.h>
|
||||||
|
|
||||||
|
extern const char VDSO32_PRELINK[];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Given a pointer to the vDSO image, find the pointer to VDSO32_name
|
* 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.
|
* as that symbol is defined in the vDSO sources or linker script.
|
||||||
|
|
|
@ -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
|
|
@ -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): KBUILD_AFLAGS = $(KBUILD_AFLAGS_32)
|
||||||
$(vdso32-images:%=$(obj)/%.dbg): asflags-$(CONFIG_X86_64) += -m32
|
$(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 \
|
$(vdso32-images:%=$(obj)/%.dbg): $(obj)/vdso32-%.so.dbg: FORCE \
|
||||||
$(obj)/vdso32/vdso32.lds \
|
$(obj)/vdso32/vdso32.lds \
|
||||||
|
$(obj)/vdso32/vclock_gettime.o \
|
||||||
$(obj)/vdso32/note.o \
|
$(obj)/vdso32/note.o \
|
||||||
$(obj)/vdso32/%.o
|
$(obj)/vdso32/%.o
|
||||||
$(call if_changed,vdso)
|
$(call if_changed,vdso)
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
*
|
*
|
||||||
* Fast user context implementation of clock_gettime, gettimeofday, and time.
|
* Fast user context implementation of clock_gettime, gettimeofday, and time.
|
||||||
*
|
*
|
||||||
|
* 32 Bit compat layer by Stefani Seibold <stefani@seibold.net>
|
||||||
|
* sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany
|
||||||
|
*
|
||||||
* The code should have no internal unresolved relocations.
|
* The code should have no internal unresolved relocations.
|
||||||
* Check with readelf after changing.
|
* Check with readelf after changing.
|
||||||
*/
|
*/
|
||||||
|
@ -12,13 +15,11 @@
|
||||||
#define DISABLE_BRANCH_PROFILING
|
#define DISABLE_BRANCH_PROFILING
|
||||||
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/posix-timers.h>
|
#include <uapi/linux/time.h>
|
||||||
#include <linux/time.h>
|
|
||||||
#include <linux/string.h>
|
#include <linux/string.h>
|
||||||
#include <asm/vsyscall.h>
|
#include <asm/vsyscall.h>
|
||||||
#include <asm/fixmap.h>
|
#include <asm/fixmap.h>
|
||||||
#include <asm/vgtod.h>
|
#include <asm/vgtod.h>
|
||||||
#include <asm/timex.h>
|
|
||||||
#include <asm/hpet.h>
|
#include <asm/hpet.h>
|
||||||
#include <asm/unistd.h>
|
#include <asm/unistd.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
@ -26,6 +27,12 @@
|
||||||
|
|
||||||
#define gtod (&VVAR(vsyscall_gtod_data))
|
#define gtod (&VVAR(vsyscall_gtod_data))
|
||||||
|
|
||||||
|
extern int __vdso_clock_gettime(clockid_t clock, struct timespec *ts);
|
||||||
|
extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||||
|
extern time_t __vdso_time(time_t *t);
|
||||||
|
|
||||||
|
#ifndef BUILD_VDSO32
|
||||||
|
|
||||||
static notrace cycle_t vread_hpet(void)
|
static notrace cycle_t vread_hpet(void)
|
||||||
{
|
{
|
||||||
return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + HPET_COUNTER);
|
return readl((const void __iomem *)fix_to_virt(VSYSCALL_HPET) + HPET_COUNTER);
|
||||||
|
@ -118,6 +125,59 @@ static notrace cycle_t vread_pvclock(int *mode)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
extern u8 hpet_page
|
||||||
|
__attribute__((visibility("hidden")));
|
||||||
|
|
||||||
|
#ifdef CONFIG_HPET_TIMER
|
||||||
|
static notrace cycle_t vread_hpet(void)
|
||||||
|
{
|
||||||
|
return readl((const void __iomem *)(&hpet_page + HPET_COUNTER));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
notrace static long vdso_fallback_gettime(long clock, struct timespec *ts)
|
||||||
|
{
|
||||||
|
long ret;
|
||||||
|
|
||||||
|
asm(
|
||||||
|
"mov %%ebx, %%edx \n"
|
||||||
|
"mov %2, %%ebx \n"
|
||||||
|
"call VDSO32_vsyscall \n"
|
||||||
|
"mov %%edx, %%ebx \n"
|
||||||
|
: "=a" (ret)
|
||||||
|
: "0" (__NR_clock_gettime), "g" (clock), "c" (ts)
|
||||||
|
: "memory", "edx");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
notrace static long vdso_fallback_gtod(struct timeval *tv, struct timezone *tz)
|
||||||
|
{
|
||||||
|
long ret;
|
||||||
|
|
||||||
|
asm(
|
||||||
|
"mov %%ebx, %%edx \n"
|
||||||
|
"mov %2, %%ebx \n"
|
||||||
|
"call VDSO32_vsyscall \n"
|
||||||
|
"mov %%edx, %%ebx \n"
|
||||||
|
: "=a" (ret)
|
||||||
|
: "0" (__NR_gettimeofday), "g" (tv), "c" (tz)
|
||||||
|
: "memory", "edx");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_PARAVIRT_CLOCK
|
||||||
|
|
||||||
|
static notrace cycle_t vread_pvclock(int *mode)
|
||||||
|
{
|
||||||
|
*mode = VCLOCK_NONE;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
notrace static cycle_t vread_tsc(void)
|
notrace static cycle_t vread_tsc(void)
|
||||||
{
|
{
|
||||||
cycle_t ret;
|
cycle_t ret;
|
||||||
|
@ -131,7 +191,7 @@ notrace static cycle_t vread_tsc(void)
|
||||||
* but no one has ever seen it happen.
|
* but no one has ever seen it happen.
|
||||||
*/
|
*/
|
||||||
rdtsc_barrier();
|
rdtsc_barrier();
|
||||||
ret = (cycle_t)vget_cycles();
|
ret = (cycle_t)__native_read_tsc();
|
||||||
|
|
||||||
last = gtod->clock.cycle_last;
|
last = gtod->clock.cycle_last;
|
||||||
|
|
||||||
|
@ -152,12 +212,14 @@ notrace static cycle_t vread_tsc(void)
|
||||||
|
|
||||||
notrace static inline u64 vgetsns(int *mode)
|
notrace static inline u64 vgetsns(int *mode)
|
||||||
{
|
{
|
||||||
long v;
|
u64 v;
|
||||||
cycles_t cycles;
|
cycles_t cycles;
|
||||||
if (gtod->clock.vclock_mode == VCLOCK_TSC)
|
if (gtod->clock.vclock_mode == VCLOCK_TSC)
|
||||||
cycles = vread_tsc();
|
cycles = vread_tsc();
|
||||||
|
#ifdef CONFIG_HPET_TIMER
|
||||||
else if (gtod->clock.vclock_mode == VCLOCK_HPET)
|
else if (gtod->clock.vclock_mode == VCLOCK_HPET)
|
||||||
cycles = vread_hpet();
|
cycles = vread_hpet();
|
||||||
|
#endif
|
||||||
#ifdef CONFIG_PARAVIRT_CLOCK
|
#ifdef CONFIG_PARAVIRT_CLOCK
|
||||||
else if (gtod->clock.vclock_mode == VCLOCK_PVCLOCK)
|
else if (gtod->clock.vclock_mode == VCLOCK_PVCLOCK)
|
||||||
cycles = vread_pvclock(mode);
|
cycles = vread_pvclock(mode);
|
||||||
|
@ -189,7 +251,7 @@ notrace static int __always_inline do_realtime(struct timespec *ts)
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
notrace static int do_monotonic(struct timespec *ts)
|
notrace static int __always_inline do_monotonic(struct timespec *ts)
|
||||||
{
|
{
|
||||||
unsigned long seq;
|
unsigned long seq;
|
||||||
u64 ns;
|
u64 ns;
|
||||||
|
@ -284,7 +346,7 @@ int gettimeofday(struct timeval *, struct timezone *)
|
||||||
*/
|
*/
|
||||||
notrace time_t __vdso_time(time_t *t)
|
notrace time_t __vdso_time(time_t *t)
|
||||||
{
|
{
|
||||||
/* This is atomic on x86_64 so we don't need any locks. */
|
/* This is atomic on x86 so we don't need any locks. */
|
||||||
time_t result = ACCESS_ONCE(gtod->wall_time_sec);
|
time_t result = ACCESS_ONCE(gtod->wall_time_sec);
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
|
|
|
@ -6,6 +6,24 @@
|
||||||
|
|
||||||
SECTIONS
|
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;
|
. = SIZEOF_HEADERS;
|
||||||
|
|
||||||
.hash : { *(.hash) } :text
|
.hash : { *(.hash) } :text
|
||||||
|
@ -61,4 +79,8 @@ PHDRS
|
||||||
dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
|
dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
|
||||||
note PT_NOTE FLAGS(4); /* PF_R */
|
note PT_NOTE FLAGS(4); /* PF_R */
|
||||||
eh_frame_hdr PT_GNU_EH_FRAME;
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include <asm/tlbflush.h>
|
#include <asm/tlbflush.h>
|
||||||
#include <asm/vdso.h>
|
#include <asm/vdso.h>
|
||||||
#include <asm/proto.h>
|
#include <asm/proto.h>
|
||||||
|
#include <asm/fixmap.h>
|
||||||
|
#include <asm/hpet.h>
|
||||||
|
#include <asm/vvar.h>
|
||||||
|
|
||||||
#ifdef CONFIG_COMPAT_VDSO
|
#ifdef CONFIG_COMPAT_VDSO
|
||||||
#define VDSO_DEFAULT 0
|
#define VDSO_DEFAULT 0
|
||||||
|
@ -141,6 +144,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
||||||
struct mm_struct *mm = current->mm;
|
struct mm_struct *mm = current->mm;
|
||||||
unsigned long addr;
|
unsigned long addr;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
struct vm_area_struct *vma;
|
||||||
|
|
||||||
#ifdef CONFIG_X86_X32_ABI
|
#ifdef CONFIG_X86_X32_ABI
|
||||||
if (test_thread_flag(TIF_X32))
|
if (test_thread_flag(TIF_X32))
|
||||||
|
@ -163,7 +167,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
||||||
/*
|
/*
|
||||||
* MAYWRITE to allow gdb to COW and set breakpoints
|
* MAYWRITE to allow gdb to COW and set breakpoints
|
||||||
*/
|
*/
|
||||||
ret = install_special_mapping(mm, addr, PAGE_SIZE,
|
ret = install_special_mapping(mm,
|
||||||
|
addr,
|
||||||
|
VDSO_OFFSET(VDSO_PAGES - VDSO_PREV_PAGES),
|
||||||
VM_READ|VM_EXEC|
|
VM_READ|VM_EXEC|
|
||||||
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
||||||
vdso32_pages);
|
vdso32_pages);
|
||||||
|
@ -171,6 +177,39 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto up_fail;
|
goto up_fail;
|
||||||
|
|
||||||
|
vma = _install_special_mapping(mm,
|
||||||
|
addr - VDSO_OFFSET(VDSO_PREV_PAGES),
|
||||||
|
VDSO_OFFSET(VDSO_PREV_PAGES),
|
||||||
|
VM_READ,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
if (IS_ERR(vma)) {
|
||||||
|
ret = PTR_ERR(vma);
|
||||||
|
goto up_fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = remap_pfn_range(vma,
|
||||||
|
addr - VDSO_OFFSET(VDSO_VVAR_PAGE),
|
||||||
|
__pa_symbol(&__vvar_page) >> PAGE_SHIFT,
|
||||||
|
PAGE_SIZE,
|
||||||
|
PAGE_READONLY);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto up_fail;
|
||||||
|
|
||||||
|
#ifdef CONFIG_HPET_TIMER
|
||||||
|
if (hpet_address) {
|
||||||
|
ret = io_remap_pfn_range(vma,
|
||||||
|
addr - VDSO_OFFSET(VDSO_HPET_PAGE),
|
||||||
|
hpet_address >> PAGE_SHIFT,
|
||||||
|
PAGE_SIZE,
|
||||||
|
pgprot_noncached(PAGE_READONLY));
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
goto up_fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
current_thread_info()->sysenter_return =
|
current_thread_info()->sysenter_return =
|
||||||
VDSO32_SYMBOL(addr, SYSENTER_RETURN);
|
VDSO32_SYMBOL(addr, SYSENTER_RETURN);
|
||||||
|
|
||||||
|
|
|
@ -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"
|
|
@ -8,6 +8,11 @@
|
||||||
* values visible using the asm-x86/vdso.h macros from the kernel proper.
|
* 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"
|
#include "../vdso-layout.lds.S"
|
||||||
|
|
||||||
/* The ELF entry point can be used to set the AT_SYSINFO value. */
|
/* The ELF entry point can be used to set the AT_SYSINFO value. */
|
||||||
|
@ -23,6 +28,9 @@ VERSION
|
||||||
__kernel_vsyscall;
|
__kernel_vsyscall;
|
||||||
__kernel_sigreturn;
|
__kernel_sigreturn;
|
||||||
__kernel_rt_sigreturn;
|
__kernel_rt_sigreturn;
|
||||||
|
__vdso_clock_gettime;
|
||||||
|
__vdso_gettimeofday;
|
||||||
|
__vdso_time;
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,3 +41,6 @@ VERSION
|
||||||
VDSO32_vsyscall = __kernel_vsyscall;
|
VDSO32_vsyscall = __kernel_vsyscall;
|
||||||
VDSO32_sigreturn = __kernel_sigreturn;
|
VDSO32_sigreturn = __kernel_sigreturn;
|
||||||
VDSO32_rt_sigreturn = __kernel_rt_sigreturn;
|
VDSO32_rt_sigreturn = __kernel_rt_sigreturn;
|
||||||
|
VDSO32_clock_gettime = clock_gettime;
|
||||||
|
VDSO32_gettimeofday = gettimeofday;
|
||||||
|
VDSO32_time = time;
|
||||||
|
|
Loading…
Reference in New Issue