2017-11-24 14:00:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-12-25 12:38:36 +00:00
|
|
|
/*
|
|
|
|
* vdso setup for s390
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2008
|
|
|
|
* Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
|
|
|
|
*/
|
|
|
|
|
2021-01-24 19:57:08 +00:00
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/compat.h>
|
|
|
|
#include <linux/elf.h>
|
2008-12-25 12:38:36 +00:00
|
|
|
#include <linux/errno.h>
|
2021-01-24 19:57:08 +00:00
|
|
|
#include <linux/init.h>
|
2008-12-25 12:38:36 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
2021-01-24 19:57:08 +00:00
|
|
|
#include <linux/smp.h>
|
2020-04-28 07:52:23 +00:00
|
|
|
#include <vdso/datapage.h>
|
2008-12-25 12:38:36 +00:00
|
|
|
#include <asm/vdso.h>
|
|
|
|
|
2021-01-24 19:22:29 +00:00
|
|
|
extern char vdso64_start[], vdso64_end[];
|
|
|
|
static unsigned int vdso_pages;
|
2008-12-25 12:38:36 +00:00
|
|
|
|
2021-01-24 19:57:08 +00:00
|
|
|
static union {
|
|
|
|
struct vdso_data data[CS_BASES];
|
|
|
|
u8 page[PAGE_SIZE];
|
|
|
|
} vdso_data_store __page_aligned_data;
|
|
|
|
|
|
|
|
struct vdso_data *vdso_data = vdso_data_store.data;
|
|
|
|
|
2008-12-25 12:38:36 +00:00
|
|
|
unsigned int __read_mostly vdso_enabled = 1;
|
|
|
|
|
2021-01-24 19:57:08 +00:00
|
|
|
static int __init vdso_setup(char *str)
|
|
|
|
{
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
if (!kstrtobool(str, &enabled))
|
|
|
|
vdso_enabled = enabled;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("vdso=", vdso_setup);
|
|
|
|
|
2021-01-24 21:01:16 +00:00
|
|
|
static vm_fault_t vvar_fault(const struct vm_special_mapping *sm,
|
|
|
|
struct vm_area_struct *vma, struct vm_fault *vmf)
|
|
|
|
{
|
|
|
|
if (vmf->pgoff == 0)
|
|
|
|
return vmf_insert_pfn(vma, vmf->address, virt_to_pfn(vdso_data));
|
|
|
|
return VM_FAULT_SIGBUS;
|
|
|
|
}
|
|
|
|
|
2017-05-15 08:23:38 +00:00
|
|
|
static int vdso_mremap(const struct vm_special_mapping *sm,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
current->mm->context.vdso_base = vma->vm_start;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-24 21:01:16 +00:00
|
|
|
static struct vm_special_mapping vvar_mapping = {
|
|
|
|
.name = "[vvar]",
|
|
|
|
.fault = vvar_fault,
|
|
|
|
};
|
|
|
|
|
2021-01-24 20:36:14 +00:00
|
|
|
static struct vm_special_mapping vdso_mapping = {
|
2017-05-15 08:23:38 +00:00
|
|
|
.name = "[vdso]",
|
|
|
|
.mremap = vdso_mremap,
|
|
|
|
};
|
|
|
|
|
2021-01-24 18:51:34 +00:00
|
|
|
int vdso_getcpu_init(void)
|
2020-11-16 07:06:41 +00:00
|
|
|
{
|
|
|
|
set_tod_programmable_field(smp_processor_id());
|
2021-01-24 18:51:34 +00:00
|
|
|
return 0;
|
2020-11-16 07:06:41 +00:00
|
|
|
}
|
2021-01-24 18:51:34 +00:00
|
|
|
early_initcall(vdso_getcpu_init); /* Must be called before SMP init */
|
2020-11-16 07:06:41 +00:00
|
|
|
|
2008-12-25 12:38:36 +00:00
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
|
|
|
|
{
|
2021-01-24 21:01:16 +00:00
|
|
|
unsigned long addr, vdso_text_start, vdso_text_len, vdso_mapping_len;
|
2008-12-25 12:38:36 +00:00
|
|
|
struct mm_struct *mm = current->mm;
|
2017-05-15 08:23:38 +00:00
|
|
|
struct vm_area_struct *vma;
|
2008-12-25 12:38:36 +00:00
|
|
|
int rc;
|
|
|
|
|
2021-01-24 19:57:08 +00:00
|
|
|
if (!vdso_enabled || is_compat_task())
|
2019-11-18 12:59:25 +00:00
|
|
|
return 0;
|
2020-06-09 04:33:25 +00:00
|
|
|
if (mmap_write_lock_killable(mm))
|
2016-05-23 23:25:54 +00:00
|
|
|
return -EINTR;
|
2021-01-24 21:01:16 +00:00
|
|
|
vdso_text_len = vdso_pages << PAGE_SHIFT;
|
|
|
|
vdso_mapping_len = vdso_text_len + PAGE_SIZE;
|
|
|
|
addr = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0);
|
|
|
|
rc = addr;
|
|
|
|
if (IS_ERR_VALUE(addr))
|
2021-01-24 19:57:08 +00:00
|
|
|
goto out;
|
2021-01-24 21:01:16 +00:00
|
|
|
/* VM_MAYWRITE for COW so gdb can set breakpoints */
|
|
|
|
vdso_text_start = addr;
|
|
|
|
vma = _install_special_mapping(mm, addr, vdso_text_len,
|
2017-05-15 08:23:38 +00:00
|
|
|
VM_READ|VM_EXEC|
|
|
|
|
VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
|
|
|
|
&vdso_mapping);
|
2021-01-24 19:57:08 +00:00
|
|
|
rc = PTR_ERR(vma);
|
|
|
|
if (IS_ERR(vma))
|
|
|
|
goto out;
|
2021-01-24 21:01:16 +00:00
|
|
|
addr += vdso_text_len;
|
|
|
|
vma = _install_special_mapping(mm, addr, PAGE_SIZE,
|
|
|
|
VM_READ|VM_MAYREAD|VM_PFNMAP,
|
|
|
|
&vvar_mapping);
|
|
|
|
if (IS_ERR(vma)) {
|
|
|
|
do_munmap(mm, vdso_text_start, vdso_text_len, NULL);
|
|
|
|
rc = PTR_ERR(vma);
|
|
|
|
} else {
|
|
|
|
current->mm->context.vdso_base = vdso_text_start;
|
|
|
|
rc = 0;
|
|
|
|
}
|
2021-01-24 19:57:08 +00:00
|
|
|
out:
|
2020-06-09 04:33:25 +00:00
|
|
|
mmap_write_unlock(mm);
|
2008-12-25 12:38:36 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init vdso_init(void)
|
|
|
|
{
|
2021-01-24 20:36:14 +00:00
|
|
|
struct page **pages;
|
2008-12-25 12:38:36 +00:00
|
|
|
int i;
|
|
|
|
|
2021-01-24 21:01:16 +00:00
|
|
|
vdso_pages = (vdso64_end - vdso64_start) >> PAGE_SHIFT;
|
2021-01-24 20:36:14 +00:00
|
|
|
pages = kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
|
|
|
|
if (!pages) {
|
2021-01-24 19:08:40 +00:00
|
|
|
vdso_enabled = 0;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2021-01-24 21:01:16 +00:00
|
|
|
for (i = 0; i < vdso_pages; i++)
|
2021-01-24 20:36:14 +00:00
|
|
|
pages[i] = virt_to_page(vdso64_start + i * PAGE_SIZE);
|
|
|
|
pages[vdso_pages] = NULL;
|
|
|
|
vdso_mapping.pages = pages;
|
2008-12-25 12:38:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-01-24 18:51:34 +00:00
|
|
|
arch_initcall(vdso_init);
|