2007-07-21 23:10:01 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Andi Kleen, SUSE Labs.
|
|
|
|
* Subject to the GPL, v.2
|
2014-09-24 01:50:57 +08:00
|
|
|
*
|
|
|
|
* This contains most of the x86 vDSO kernel-side code.
|
2007-07-21 23:10:01 +08:00
|
|
|
*/
|
|
|
|
#include <linux/mm.h>
|
2007-07-30 06:36:13 +08:00
|
|
|
#include <linux/err.h>
|
2007-07-21 23:10:01 +08:00
|
|
|
#include <linux/sched.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2007-07-21 23:10:01 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/random.h>
|
2009-04-12 23:07:25 +08:00
|
|
|
#include <linux/elf.h>
|
2014-09-24 01:50:52 +08:00
|
|
|
#include <linux/cpu.h>
|
2007-07-21 23:10:01 +08:00
|
|
|
#include <asm/vgtod.h>
|
|
|
|
#include <asm/proto.h>
|
2008-01-30 20:30:41 +08:00
|
|
|
#include <asm/vdso.h>
|
2014-09-24 01:50:57 +08:00
|
|
|
#include <asm/vvar.h>
|
2011-07-22 03:47:10 +08:00
|
|
|
#include <asm/page.h>
|
2014-05-06 03:19:35 +08:00
|
|
|
#include <asm/hpet.h>
|
2014-09-24 01:50:52 +08:00
|
|
|
#include <asm/desc.h>
|
2007-07-21 23:10:01 +08:00
|
|
|
|
2014-03-18 06:22:08 +08:00
|
|
|
#if defined(CONFIG_X86_64)
|
2014-05-06 03:19:32 +08:00
|
|
|
unsigned int __read_mostly vdso64_enabled = 1;
|
2014-03-18 06:22:08 +08:00
|
|
|
#endif
|
2012-02-20 03:38:06 +08:00
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 03:19:34 +08:00
|
|
|
void __init init_vdso_image(const struct vdso_image *image)
|
2012-02-20 03:38:06 +08:00
|
|
|
{
|
|
|
|
int i;
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 03:19:34 +08:00
|
|
|
int npages = (image->size) / PAGE_SIZE;
|
2012-02-20 03:38:06 +08:00
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 03:19:34 +08:00
|
|
|
BUG_ON(image->size % PAGE_SIZE != 0);
|
|
|
|
for (i = 0; i < npages; i++)
|
2014-05-20 06:58:33 +08:00
|
|
|
image->text_mapping.pages[i] =
|
|
|
|
virt_to_page(image->data + i*PAGE_SIZE);
|
2012-02-20 03:38:06 +08:00
|
|
|
|
x86, vdso: Reimplement vdso.so preparation in build-time C
Currently, vdso.so files are prepared and analyzed by a combination
of objcopy, nm, some linker script tricks, and some simple ELF
parsers in the kernel. Replace all of that with plain C code that
runs at build time.
All five vdso images now generate .c files that are compiled and
linked in to the kernel image.
This should cause only one userspace-visible change: the loaded vDSO
images are stripped more heavily than they used to be. Everything
outside the loadable segment is dropped. In particular, this causes
the section table and section name strings to be missing. This
should be fine: real dynamic loaders don't load or inspect these
tables anyway. The result is roughly equivalent to eu-strip's
--strip-sections option.
The purpose of this change is to enable the vvar and hpet mappings
to be moved to the page following the vDSO load segment. Currently,
it is possible for the section table to extend into the page after
the load segment, so, if we map it, it risks overlapping the vvar or
hpet page. This happens whenever the load segment is just under a
multiple of PAGE_SIZE.
The only real subtlety here is that the old code had a C file with
inline assembler that did 'call VDSO32_vsyscall' and a linker script
that defined 'VDSO32_vsyscall = __kernel_vsyscall'. This most
likely worked by accident: the linker script entry defines a symbol
associated with an address as opposed to an alias for the real
dynamic symbol __kernel_vsyscall. That caused ld to relocate the
reference at link time instead of leaving an interposable dynamic
relocation. Since the VDSO32_vsyscall hack is no longer needed, I
now use 'call __kernel_vsyscall', and I added -Bsymbolic to make it
work. vdso2c will generate an error and abort the build if the
resulting image contains any dynamic relocations, so we won't
silently generate bad vdso images.
(Dynamic relocations are a problem because nothing will even attempt
to relocate the vdso.)
Signed-off-by: Andy Lutomirski <luto@amacapital.net>
Link: http://lkml.kernel.org/r/2c4fcf45524162a34d87fdda1eb046b2a5cecee7.1399317206.git.luto@amacapital.net
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-05-06 03:19:34 +08:00
|
|
|
apply_alternatives((struct alt_instr *)(image->data + image->alt),
|
|
|
|
(struct alt_instr *)(image->data + image->alt +
|
|
|
|
image->alt_len));
|
2012-02-20 03:38:06 +08:00
|
|
|
}
|
2011-07-13 21:24:11 +08:00
|
|
|
|
2007-07-21 23:10:01 +08:00
|
|
|
struct linux_binprm;
|
|
|
|
|
|
|
|
/* Put the vdso above the (randomized) stack with another randomized offset.
|
|
|
|
This way there is no hole in the middle of address space.
|
|
|
|
To save memory make sure it is still in the same PTE as the stack top.
|
2014-05-06 03:19:35 +08:00
|
|
|
This doesn't give that many random bits.
|
|
|
|
|
|
|
|
Only used for the 64-bit and x32 vdsos. */
|
2007-07-21 23:10:01 +08:00
|
|
|
static unsigned long vdso_addr(unsigned long start, unsigned len)
|
|
|
|
{
|
2014-07-03 22:35:07 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
return 0;
|
|
|
|
#else
|
2007-07-21 23:10:01 +08:00
|
|
|
unsigned long addr, end;
|
|
|
|
unsigned offset;
|
|
|
|
end = (start + PMD_SIZE - 1) & PMD_MASK;
|
2009-02-21 06:32:28 +08:00
|
|
|
if (end >= TASK_SIZE_MAX)
|
|
|
|
end = TASK_SIZE_MAX;
|
2007-07-21 23:10:01 +08:00
|
|
|
end -= len;
|
|
|
|
/* This loses some more bits than a modulo, but is cheaper */
|
|
|
|
offset = get_random_int() & (PTRS_PER_PTE - 1);
|
|
|
|
addr = start + (offset << PAGE_SHIFT);
|
|
|
|
if (addr >= end)
|
|
|
|
addr = end;
|
2011-08-05 21:15:08 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* page-align it here so that get_unmapped_area doesn't
|
|
|
|
* align it wrongfully again to the next page. addr can come in 4K
|
|
|
|
* unaligned here as a result of stack start randomization.
|
|
|
|
*/
|
|
|
|
addr = PAGE_ALIGN(addr);
|
2012-12-12 08:01:52 +08:00
|
|
|
addr = align_vdso_addr(addr);
|
2011-08-05 21:15:08 +08:00
|
|
|
|
2007-07-21 23:10:01 +08:00
|
|
|
return addr;
|
2014-07-03 22:35:07 +08:00
|
|
|
#endif
|
2007-07-21 23:10:01 +08:00
|
|
|
}
|
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
static int map_vdso(const struct vdso_image *image, bool calculate_addr)
|
2007-07-21 23:10:01 +08:00
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->mm;
|
2014-05-06 03:19:35 +08:00
|
|
|
struct vm_area_struct *vma;
|
2014-07-11 09:13:15 +08:00
|
|
|
unsigned long addr, text_start;
|
2014-05-06 03:19:35 +08:00
|
|
|
int ret = 0;
|
2014-05-20 06:58:31 +08:00
|
|
|
static struct page *no_pages[] = {NULL};
|
2014-05-20 06:58:33 +08:00
|
|
|
static struct vm_special_mapping vvar_mapping = {
|
|
|
|
.name = "[vvar]",
|
|
|
|
.pages = no_pages,
|
|
|
|
};
|
2007-07-21 23:10:01 +08:00
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
if (calculate_addr) {
|
|
|
|
addr = vdso_addr(current->mm->start_stack,
|
2014-07-11 09:13:15 +08:00
|
|
|
image->size - image->sym_vvar_start);
|
2014-05-06 03:19:35 +08:00
|
|
|
} else {
|
|
|
|
addr = 0;
|
|
|
|
}
|
2007-07-21 23:10:01 +08:00
|
|
|
|
|
|
|
down_write(&mm->mmap_sem);
|
2014-05-06 03:19:35 +08:00
|
|
|
|
2014-07-11 09:13:15 +08:00
|
|
|
addr = get_unmapped_area(NULL, addr,
|
|
|
|
image->size - image->sym_vvar_start, 0, 0);
|
2007-07-21 23:10:01 +08:00
|
|
|
if (IS_ERR_VALUE(addr)) {
|
|
|
|
ret = addr;
|
|
|
|
goto up_fail;
|
|
|
|
}
|
|
|
|
|
2014-07-11 09:13:15 +08:00
|
|
|
text_start = addr - image->sym_vvar_start;
|
|
|
|
current->mm->context.vdso = (void __user *)text_start;
|
2009-06-05 20:04:51 +08:00
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
/*
|
|
|
|
* MAYWRITE to allow gdb to COW and set breakpoints
|
|
|
|
*/
|
2014-05-20 06:58:33 +08:00
|
|
|
vma = _install_special_mapping(mm,
|
2014-07-11 09:13:15 +08:00
|
|
|
text_start,
|
2014-05-20 06:58:33 +08:00
|
|
|
image->size,
|
|
|
|
VM_READ|VM_EXEC|
|
|
|
|
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
|
|
|
&image->text_mapping);
|
2014-05-06 03:19:35 +08:00
|
|
|
|
2014-05-20 06:58:33 +08:00
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
2014-05-06 03:19:35 +08:00
|
|
|
goto up_fail;
|
2014-05-20 06:58:33 +08:00
|
|
|
}
|
2014-05-06 03:19:35 +08:00
|
|
|
|
|
|
|
vma = _install_special_mapping(mm,
|
2014-07-11 09:13:15 +08:00
|
|
|
addr,
|
|
|
|
-image->sym_vvar_start,
|
2014-07-26 07:27:01 +08:00
|
|
|
VM_READ|VM_MAYREAD,
|
2014-05-20 06:58:33 +08:00
|
|
|
&vvar_mapping);
|
2014-05-06 03:19:35 +08:00
|
|
|
|
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
ret = PTR_ERR(vma);
|
2007-07-21 23:10:01 +08:00
|
|
|
goto up_fail;
|
2009-06-05 20:04:51 +08:00
|
|
|
}
|
2007-07-21 23:10:01 +08:00
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
if (image->sym_vvar_page)
|
|
|
|
ret = remap_pfn_range(vma,
|
2014-07-11 09:13:15 +08:00
|
|
|
text_start + image->sym_vvar_page,
|
2014-05-06 03:19:35 +08:00
|
|
|
__pa_symbol(&__vvar_page) >> PAGE_SHIFT,
|
|
|
|
PAGE_SIZE,
|
|
|
|
PAGE_READONLY);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto up_fail;
|
|
|
|
|
|
|
|
#ifdef CONFIG_HPET_TIMER
|
|
|
|
if (hpet_address && image->sym_hpet_page) {
|
|
|
|
ret = io_remap_pfn_range(vma,
|
2014-07-11 09:13:15 +08:00
|
|
|
text_start + image->sym_hpet_page,
|
2014-05-06 03:19:35 +08:00
|
|
|
hpet_address >> PAGE_SHIFT,
|
|
|
|
PAGE_SIZE,
|
|
|
|
pgprot_noncached(PAGE_READONLY));
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto up_fail;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-07-21 23:10:01 +08:00
|
|
|
up_fail:
|
2014-05-06 03:19:35 +08:00
|
|
|
if (ret)
|
|
|
|
current->mm->context.vdso = NULL;
|
|
|
|
|
2007-07-21 23:10:01 +08:00
|
|
|
up_write(&mm->mmap_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
#if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
|
|
|
|
static int load_vdso32(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (vdso32_enabled != 1) /* Other values all mean "disabled" */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = map_vdso(selected_vdso32, false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
|
|
|
|
current_thread_info()->sysenter_return =
|
|
|
|
current->mm->context.vdso +
|
|
|
|
selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
2012-02-20 03:38:06 +08:00
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
|
|
|
{
|
2014-05-06 03:19:35 +08:00
|
|
|
if (!vdso64_enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return map_vdso(&vdso_image_64, true);
|
2012-02-20 03:38:06 +08:00
|
|
|
}
|
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
|
|
|
|
int uses_interp)
|
|
|
|
{
|
2012-02-20 03:38:06 +08:00
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
2014-05-06 03:19:35 +08:00
|
|
|
if (test_thread_flag(TIF_X32)) {
|
|
|
|
if (!vdso64_enabled)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return map_vdso(&vdso_image_x32, true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return load_vdso32();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
2012-02-20 03:38:06 +08:00
|
|
|
{
|
2014-05-06 03:19:35 +08:00
|
|
|
return load_vdso32();
|
2012-02-20 03:38:06 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-06 03:19:35 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2007-07-21 23:10:01 +08:00
|
|
|
static __init int vdso_setup(char *s)
|
|
|
|
{
|
2014-05-06 03:19:32 +08:00
|
|
|
vdso64_enabled = simple_strtoul(s, NULL, 0);
|
2007-07-21 23:10:01 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__setup("vdso=", vdso_setup);
|
2014-03-18 06:22:08 +08:00
|
|
|
#endif
|
2014-09-24 01:50:52 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
2014-09-24 01:50:57 +08:00
|
|
|
static void vgetcpu_cpu_init(void *arg)
|
2014-09-24 01:50:52 +08:00
|
|
|
{
|
2014-09-24 01:50:57 +08:00
|
|
|
int cpu = smp_processor_id();
|
2014-11-02 04:18:26 +08:00
|
|
|
struct desc_struct d = { };
|
2014-09-24 01:50:52 +08:00
|
|
|
unsigned long node = 0;
|
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
node = cpu_to_node(cpu);
|
|
|
|
#endif
|
|
|
|
if (cpu_has(&cpu_data(cpu), X86_FEATURE_RDTSCP))
|
|
|
|
write_rdtscp_aux((node << 12) | cpu);
|
|
|
|
|
|
|
|
/*
|
2014-09-24 01:50:53 +08:00
|
|
|
* Store cpu number in limit so that it can be loaded
|
|
|
|
* quickly in user space in vgetcpu. (12 bits for the CPU
|
|
|
|
* and 8 bits for the node)
|
2014-09-24 01:50:52 +08:00
|
|
|
*/
|
2014-11-02 04:18:26 +08:00
|
|
|
d.limit0 = cpu | ((node & 0xf) << 12);
|
|
|
|
d.limit = node >> 4;
|
|
|
|
d.type = 5; /* RO data, expand down, accessed */
|
|
|
|
d.dpl = 3; /* Visible to user code */
|
|
|
|
d.s = 1; /* Not a system segment */
|
|
|
|
d.p = 1; /* Present */
|
|
|
|
d.d = 1; /* 32-bit */
|
2014-09-24 01:50:52 +08:00
|
|
|
|
|
|
|
write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_PER_CPU, &d, DESCTYPE_S);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-24 01:50:57 +08:00
|
|
|
vgetcpu_cpu_notifier(struct notifier_block *n, unsigned long action, void *arg)
|
2014-09-24 01:50:52 +08:00
|
|
|
{
|
|
|
|
long cpu = (long)arg;
|
|
|
|
|
|
|
|
if (action == CPU_ONLINE || action == CPU_ONLINE_FROZEN)
|
2014-09-24 01:50:57 +08:00
|
|
|
smp_call_function_single(cpu, vgetcpu_cpu_init, NULL, 1);
|
2014-09-24 01:50:52 +08:00
|
|
|
|
|
|
|
return NOTIFY_DONE;
|
|
|
|
}
|
|
|
|
|
2014-09-24 01:50:57 +08:00
|
|
|
static int __init init_vdso(void)
|
2014-09-24 01:50:52 +08:00
|
|
|
{
|
2014-09-24 01:50:57 +08:00
|
|
|
init_vdso_image(&vdso_image_64);
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_X32_ABI
|
|
|
|
init_vdso_image(&vdso_image_x32);
|
|
|
|
#endif
|
|
|
|
|
2014-09-24 01:50:52 +08:00
|
|
|
cpu_notifier_register_begin();
|
|
|
|
|
2014-09-24 01:50:57 +08:00
|
|
|
on_each_cpu(vgetcpu_cpu_init, NULL, 1);
|
2014-09-24 01:50:52 +08:00
|
|
|
/* notifier priority > KVM */
|
2014-09-24 01:50:57 +08:00
|
|
|
__hotcpu_notifier(vgetcpu_cpu_notifier, 30);
|
2014-09-24 01:50:52 +08:00
|
|
|
|
|
|
|
cpu_notifier_register_done();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-09-24 01:50:57 +08:00
|
|
|
subsys_initcall(init_vdso);
|
|
|
|
#endif /* CONFIG_X86_64 */
|