riscv: Fix two vdso issue
v2 cover riscv: Fix two vdso issue
v2->v1:
Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if CONFIG_GENERIC_TIME_VSYSCALL=n.
1) Refactor the asm/vdso.h to avoid vdso.lds syntax error.
2) Move vdso data page up front and introduce enum vvar_pages, To pave the way for the subsequent support of TIME_NS, the support of TIME_NS will be issued in the later patch.
3) In arch_setup_additional_pages(), make Wait for the lock in the killable mode and return with EINTR if the task got killed while waiting.
Tong Tiangen (3):
riscv/vdso: Refactor asm/vdso.h
riscv/vdso: Move vdso data page up front
riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for
write killable
arch/riscv/include/asm/syscall.h | 1 + arch/riscv/include/asm/vdso.h | 10 ++---- arch/riscv/kernel/syscall_table.c | 1 - arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------ arch/riscv/kernel/vdso/vdso.lds.S | 3 +- 5 files changed, 39 insertions(+), 29 deletions(-)
Signature · 1 line
2.18.0.huawei.25
PATCH v2 1/3 riscv/vdso: Refactor asm/vdso.h
The asm/vdso.h will be included in vdso.lds.S in the next patch, the following cleanup is needed to avoid syntax error:
1.the declaration of sys_riscv_flush_icache() is moved into asm/syscall.h. 2.the definition of struct vdso_data is moved into kernel/vdso.c. 2.the definition of VDSO_SYMBOL is placed under "#ifndef __ASSEMBLY__".
Also remove the redundant linux/types.h include.
--- arch/riscv/include/asm/syscall.h | 1 + arch/riscv/include/asm/vdso.h | 10 ++-------- arch/riscv/kernel/syscall_table.c | 1 - arch/riscv/kernel/vdso.c | 5 ++++- 4 files changed, 7 insertions(+), 10 deletions(-)
arch/riscv/include/asm/syscall.h +1 -0
@@ -82,4 +82,5 @@ static inline int syscall_get_arch(struct task_struct *task) #endif } +asmlinkage long sys_riscv_flush_icache (uintptr_t ,uintptr_t ,uintptr_t );#endif /* _ASM_RISCV_SYSCALL_H */
arch/riscv/include/asm/vdso.h +2 -8
@@ -8,13 +8,7 @@#ifndef _ASM_RISCV_VDSO_H#define _ASM_RISCV_VDSO_H -#include <linux/types.h> - -#ifndef CONFIG_GENERIC_TIME_VSYSCALL -struct vdso_data { -}; -#endif - +#ifndef __ASSEMBLY__/* * The VDSO symbols are mapped into Linux so we can just use regular symbol * addressing to get their offsets in userspace. The symbols are mapped at an
@@ -29,6 +23,6 @@ struct vdso_data { (void __user *)((unsigned long)(base) + __vdso_##name); \ }) -asmlinkage long sys_riscv_flush_icache (uintptr_t ,uintptr_t ,uintptr_t ); +#endif #endif /* _ASM_RISCV_VDSO_H */
arch/riscv/kernel/syscall_table.c +0 -1
@@ -7,7 +7,6 @@#include <linux/linkage.h> #include <linux/syscalls.h> #include <asm-generic/syscalls.h> -#include <asm/vdso.h> #include <asm/syscall.h> #undef __SYSCALL
arch/riscv/kernel/vdso.c +4 -1
@@ -12,10 +12,13 @@#include <linux/binfmts.h> #include <linux/err.h> #include <asm/page.h> +#include <asm/vdso.h> +#ifdef CONFIG_GENERIC_TIME_VSYSCALL #include <vdso/datapage.h> #else -#include <asm/vdso.h> +struct vdso_data { +};#endif extern char vdso_start[], vdso_end[];
Signature · 1 line
2.18.0.huawei.25
PATCH v2 2/3 riscv/vdso: Move vdso data page up front
In reply to Tong TiangenAs 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.
--- arch/riscv/include/asm/vdso.h | 2 ++ arch/riscv/kernel/vdso.c | 44 ++++++++++++++++++------------- arch/riscv/kernel/vdso/vdso.lds.S | 3 ++- 3 files changed, 30 insertions(+), 19 deletions(-)
arch/riscv/include/asm/vdso.h +2 -0
@@ -8,6 +8,8 @@#ifndef _ASM_RISCV_VDSO_H#define _ASM_RISCV_VDSO_H +#define __VVAR_PAGES 1 +#ifndef __ASSEMBLY__/* * The VDSO symbols are mapped into Linux so we can just use regular symbol
arch/riscv/kernel/vdso.c +26 -18
82 lines not on this page · raw message
arch/riscv/kernel/vdso/vdso.lds.S +2 -1
@@ -3,12 +3,13 @@ * Copyright (C) 2012 Regents of the University of California */ #include <asm/page.h> +#include <asm/vdso.h> OUTPUT_ARCH(riscv) SECTIONS { - PROVIDE(_vdso_data = . + PAGE_SIZE); + PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
Signature · 1 line
2.18.0.huawei.25
PATCH v2 3/3 riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for write killable
In reply to Tong Tiangenriscv architectures relying on mmap_sem for write in their arch_setup_additional_pages. If the waiting task gets killed by the oom killer it would block oom_reaper from asynchronous address space reclaim and reduce the chances of timely OOM resolving. Wait for the lock in the killable mode and return with EINTR if the task got killed while waiting.
--- arch/riscv/kernel/vdso.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/riscv/kernel/vdso.c +3 -1
@@ -77,7 +77,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, vdso_len = (vdso_pages +VVAR_NR_PAGES ) <<PAGE_SHIFT ; -mmap_write_lock (mm); +if (mmap_write_lock_killable (mm)) +return -EINTR ; + vdso_base =get_unmapped_area (NULL ,0 , vdso_len,0 ,0 );if (IS_ERR_VALUE (vdso_base)) { ret = vdso_base;
Signature · 1 line
2.18.0.huawei.25
Quoted 3 lines · Tong Tiangen
v2->v1:
Add patch "Refactorasm/vdso.h" to avoidvdso.ldssyntax error ifCONFIG_GENERIC_TIME_VSYSCALL=n.
This is better than v1.
Quoted 4 lines
1) Refactor the
asm/vdso.hto avoidvdso.ldssyntax error.2) Move vdso data page up front
Move vdso data page before code page could save the problem which the .text
section could be bigger than PAGE_SIZE.
Quoted 3 lines
and introduce enum
vvar_pages, To pave the
way for the subsequent support ofTIME_NS, the support ofTIME_NSwill be issued in the later patch.
This makes it easier to introduce new features TIME_NS.
Quoted 3 lines
3) In
arch_setup_additional_pages(), make Wait for the lock in the killable mode and return with EINTR if the task got killed while waiting.
For series,
Quoted 13 lines
Tong Tiangen (3):
riscv/vdso: Refactorasm/vdso.h
riscv/vdso: Move vdso data page up front
riscv/vdso: makearch_setup_additional_pageswait formmap_semfor
write killablearch/riscv/include/asm/syscall.h | 1 + arch/riscv/include/asm/vdso.h | 10 ++---- arch/riscv/kernel/syscall_table.c | 1 - arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------ arch/riscv/kernel/vdso/vdso.lds.S | 3 +- 5 files changed, 39 insertions(+), 29 deletions(-)