2019-06-03 13:44:50 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-07-11 09:00:26 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
|
|
|
|
* <benh@kernel.crashing.org>
|
|
|
|
* Copyright (C) 2012 ARM Limited
|
|
|
|
* Copyright (C) 2015 Regents of the University of California
|
|
|
|
*/
|
|
|
|
|
2019-10-18 06:21:28 +08:00
|
|
|
#include <linux/elf.h>
|
2017-07-11 09:00:26 +08:00
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/binfmts.h>
|
|
|
|
#include <linux/err.h>
|
2020-06-09 22:14:48 +08:00
|
|
|
#include <asm/page.h>
|
2021-09-01 10:46:19 +08:00
|
|
|
#include <asm/vdso.h>
|
|
|
|
|
2021-01-02 21:24:34 +08:00
|
|
|
#ifdef CONFIG_GENERIC_TIME_VSYSCALL
|
2020-06-09 22:14:48 +08:00
|
|
|
#include <vdso/datapage.h>
|
|
|
|
#else
|
2021-09-01 10:46:19 +08:00
|
|
|
struct vdso_data {
|
|
|
|
};
|
2020-06-09 22:14:48 +08:00
|
|
|
#endif
|
2017-07-11 09:00:26 +08:00
|
|
|
|
|
|
|
extern char vdso_start[], vdso_end[];
|
|
|
|
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
enum vvar_pages {
|
|
|
|
VVAR_DATA_PAGE_OFFSET,
|
|
|
|
VVAR_NR_PAGES,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
|
|
|
|
|
2021-03-30 02:22:51 +08:00
|
|
|
static unsigned int vdso_pages __ro_after_init;
|
|
|
|
static struct page **vdso_pagelist __ro_after_init;
|
2017-07-11 09:00:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The vDSO data page.
|
|
|
|
*/
|
|
|
|
static union {
|
|
|
|
struct vdso_data data;
|
|
|
|
u8 page[PAGE_SIZE];
|
|
|
|
} vdso_data_store __page_aligned_data;
|
2020-06-09 22:14:48 +08:00
|
|
|
struct vdso_data *vdso_data = &vdso_data_store.data;
|
2017-07-11 09:00:26 +08:00
|
|
|
|
|
|
|
static int __init vdso_init(void)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
|
|
|
|
vdso_pagelist =
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
kcalloc(vdso_pages + VVAR_NR_PAGES, sizeof(struct page *), GFP_KERNEL);
|
2017-07-11 09:00:26 +08:00
|
|
|
if (unlikely(vdso_pagelist == NULL)) {
|
|
|
|
pr_err("vdso: pagelist allocation failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < vdso_pages; i++) {
|
|
|
|
struct page *pg;
|
|
|
|
|
|
|
|
pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
|
|
|
|
vdso_pagelist[i] = pg;
|
|
|
|
}
|
|
|
|
vdso_pagelist[i] = virt_to_page(vdso_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
arch_initcall(vdso_init);
|
|
|
|
|
|
|
|
int arch_setup_additional_pages(struct linux_binprm *bprm,
|
|
|
|
int uses_interp)
|
|
|
|
{
|
|
|
|
struct mm_struct *mm = current->mm;
|
|
|
|
unsigned long vdso_base, vdso_len;
|
|
|
|
int ret;
|
|
|
|
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
|
|
|
|
|
|
|
|
vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT;
|
2017-07-11 09:00:26 +08:00
|
|
|
|
2021-09-01 10:46:21 +08:00
|
|
|
if (mmap_write_lock_killable(mm))
|
|
|
|
return -EINTR;
|
|
|
|
|
2017-07-11 09:00:26 +08:00
|
|
|
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
|
2018-01-22 20:44:02 +08:00
|
|
|
if (IS_ERR_VALUE(vdso_base)) {
|
2017-07-11 09:00:26 +08:00
|
|
|
ret = vdso_base;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
mm->context.vdso = NULL;
|
|
|
|
ret = install_special_mapping(mm, vdso_base, VVAR_SIZE,
|
|
|
|
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
|
|
|
|
if (unlikely(ret))
|
|
|
|
goto end;
|
2017-07-11 09:00:26 +08:00
|
|
|
|
2020-06-09 22:14:49 +08:00
|
|
|
ret =
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
install_special_mapping(mm, vdso_base + VVAR_SIZE,
|
|
|
|
vdso_pages << PAGE_SHIFT,
|
2017-07-11 09:00:26 +08:00
|
|
|
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
|
|
|
|
vdso_pagelist);
|
|
|
|
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
if (unlikely(ret))
|
2020-06-09 22:14:49 +08:00
|
|
|
goto end;
|
2017-07-11 09:00:26 +08:00
|
|
|
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
/*
|
|
|
|
* Put vDSO base into mm struct. We need to do this before calling
|
|
|
|
* install_special_mapping or the perf counter mmap tracking code
|
|
|
|
* will fail to recognise it as a vDSO (since arch_vma_name fails).
|
|
|
|
*/
|
|
|
|
mm->context.vdso = (void *)vdso_base + VVAR_SIZE;
|
2020-06-09 22:14:49 +08:00
|
|
|
|
2017-07-11 09:00:26 +08:00
|
|
|
end:
|
2020-06-09 12:33:25 +08:00
|
|
|
mmap_write_unlock(mm);
|
2017-07-11 09:00:26 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *arch_vma_name(struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
|
|
|
|
return "[vdso]";
|
2020-06-09 22:14:49 +08:00
|
|
|
if (vma->vm_mm && (vma->vm_start ==
|
riscv/vdso: Move vdso data page up front
As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the
same issue exists on riscv, testcase is shown below, make sure that vdso.so is
bigger than page size,
struct timespec tp;
clock_gettime(5, &tp);
printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec);
without this patch, test result : tv_sec: 0, tv_nsec: 0
with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000
Move the vdso data page in front of the VDSO area to fix the issue.
Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions")
Signed-off-by: Tong Tiangen <tongtiangen@huawei.com>
Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
2021-09-01 10:46:20 +08:00
|
|
|
(long)vma->vm_mm->context.vdso - VVAR_SIZE))
|
2020-06-09 22:14:49 +08:00
|
|
|
return "[vdso_data]";
|
2017-07-11 09:00:26 +08:00
|
|
|
return NULL;
|
|
|
|
}
|