riscv/vdso: Move vdso data page up front
As commit601255ae3c
("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:ad5d1122b8
("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>
This commit is contained in:
parent
bb4a23c994
commit
78a743cd82
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef CONFIG_MMU
|
#ifdef CONFIG_MMU
|
||||||
|
|
||||||
|
#define __VVAR_PAGES 1
|
||||||
|
|
||||||
#ifndef __ASSEMBLY__
|
#ifndef __ASSEMBLY__
|
||||||
#include <generated/vdso-offsets.h>
|
#include <generated/vdso-offsets.h>
|
||||||
|
|
||||||
|
@ -23,6 +23,13 @@ struct vdso_data {
|
|||||||
|
|
||||||
extern char vdso_start[], vdso_end[];
|
extern char vdso_start[], vdso_end[];
|
||||||
|
|
||||||
|
enum vvar_pages {
|
||||||
|
VVAR_DATA_PAGE_OFFSET,
|
||||||
|
VVAR_NR_PAGES,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT)
|
||||||
|
|
||||||
static unsigned int vdso_pages __ro_after_init;
|
static unsigned int vdso_pages __ro_after_init;
|
||||||
static struct page **vdso_pagelist __ro_after_init;
|
static struct page **vdso_pagelist __ro_after_init;
|
||||||
|
|
||||||
@ -41,7 +48,7 @@ static int __init vdso_init(void)
|
|||||||
|
|
||||||
vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
|
vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
|
||||||
vdso_pagelist =
|
vdso_pagelist =
|
||||||
kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL);
|
kcalloc(vdso_pages + VVAR_NR_PAGES, sizeof(struct page *), GFP_KERNEL);
|
||||||
if (unlikely(vdso_pagelist == NULL)) {
|
if (unlikely(vdso_pagelist == NULL)) {
|
||||||
pr_err("vdso: pagelist allocation failed\n");
|
pr_err("vdso: pagelist allocation failed\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -66,7 +73,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
|
|||||||
unsigned long vdso_base, vdso_len;
|
unsigned long vdso_base, vdso_len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
|
BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES);
|
||||||
|
|
||||||
|
vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT;
|
||||||
|
|
||||||
mmap_write_lock(mm);
|
mmap_write_lock(mm);
|
||||||
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
|
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
|
||||||
@ -75,29 +84,28 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ret =
|
||||||
|
install_special_mapping(mm, vdso_base + VVAR_SIZE,
|
||||||
|
vdso_pages << PAGE_SHIFT,
|
||||||
|
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
|
||||||
|
vdso_pagelist);
|
||||||
|
|
||||||
|
if (unlikely(ret))
|
||||||
|
goto end;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put vDSO base into mm struct. We need to do this before calling
|
* Put vDSO base into mm struct. We need to do this before calling
|
||||||
* install_special_mapping or the perf counter mmap tracking code
|
* install_special_mapping or the perf counter mmap tracking code
|
||||||
* will fail to recognise it as a vDSO (since arch_vma_name fails).
|
* will fail to recognise it as a vDSO (since arch_vma_name fails).
|
||||||
*/
|
*/
|
||||||
mm->context.vdso = (void *)vdso_base;
|
mm->context.vdso = (void *)vdso_base + VVAR_SIZE;
|
||||||
|
|
||||||
ret =
|
|
||||||
install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT,
|
|
||||||
(VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
|
|
||||||
vdso_pagelist);
|
|
||||||
|
|
||||||
if (unlikely(ret)) {
|
|
||||||
mm->context.vdso = NULL;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
vdso_base += (vdso_pages << PAGE_SHIFT);
|
|
||||||
ret = install_special_mapping(mm, vdso_base, PAGE_SIZE,
|
|
||||||
(VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]);
|
|
||||||
|
|
||||||
if (unlikely(ret))
|
|
||||||
mm->context.vdso = NULL;
|
|
||||||
end:
|
end:
|
||||||
mmap_write_unlock(mm);
|
mmap_write_unlock(mm);
|
||||||
return ret;
|
return ret;
|
||||||
@ -108,7 +116,7 @@ const char *arch_vma_name(struct vm_area_struct *vma)
|
|||||||
if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
|
if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso))
|
||||||
return "[vdso]";
|
return "[vdso]";
|
||||||
if (vma->vm_mm && (vma->vm_start ==
|
if (vma->vm_mm && (vma->vm_start ==
|
||||||
(long)vma->vm_mm->context.vdso + PAGE_SIZE))
|
(long)vma->vm_mm->context.vdso - VVAR_SIZE))
|
||||||
return "[vdso_data]";
|
return "[vdso_data]";
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
* Copyright (C) 2012 Regents of the University of California
|
* Copyright (C) 2012 Regents of the University of California
|
||||||
*/
|
*/
|
||||||
#include <asm/page.h>
|
#include <asm/page.h>
|
||||||
|
#include <asm/vdso.h>
|
||||||
|
|
||||||
OUTPUT_ARCH(riscv)
|
OUTPUT_ARCH(riscv)
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
PROVIDE(_vdso_data = . + PAGE_SIZE);
|
PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE);
|
||||||
. = SIZEOF_HEADERS;
|
. = SIZEOF_HEADERS;
|
||||||
|
|
||||||
.hash : { *(.hash) } :text
|
.hash : { *(.hash) } :text
|
||||||
|
Loading…
Reference in New Issue
Block a user