riscv: introduce vDSO common flow
Subsystems (2)
v2 cover riscv: introduce vDSO common flow
Even if RISC-V has supported the vDSO feature, the latency of the functions for obtaining the system time is still expensive. It is because these functions still trigger a corresponding system call in the process, which slows down the response time. If we want to remove the system call to reduce the latency, the kernel should have the ability to output the system clock information to userspace. This patch introduces the vDSO common flow to enable the kernel to achieve the above feature and uses "rdtime" instruction to obtain the current time in the user space. Under this condition, the latency cost by the ecall from U-mode to S-mode can be eliminated. After applying this patch, the latency of gettimeofday() measured on the HiFive unleashed board can be reduced by %61.
change since v1:
1. Modify the permission of vdso_data to read-only
Vincent Chen (2):
riscv: use vDSO common flow to reduce the latency of the time-related
functions
riscv: set the permission of vdso_data to read-only
arch/riscv/Kconfig | 3 ++ arch/riscv/include/asm/clocksource.h | 7 +++ arch/riscv/include/asm/processor.h | 12 +---- arch/riscv/include/asm/vdso.h | 3 -- arch/riscv/include/asm/vdso/clocksource.h | 8 +++ arch/riscv/include/asm/vdso/gettimeofday.h | 79 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/vdso/processor.h | 19 +++++++ arch/riscv/include/asm/vdso/vsyscall.h | 27 ++++++++++ arch/riscv/kernel/vdso.c | 21 ++++++-- arch/riscv/kernel/vdso/Makefile | 12 +++-- arch/riscv/kernel/vdso/clock_getres.S | 18 ------- arch/riscv/kernel/vdso/clock_gettime.S | 18 ------- arch/riscv/kernel/vdso/gettimeofday.S | 18 ------- arch/riscv/kernel/vdso/vdso.lds.S | 2 + arch/riscv/kernel/vdso/vgettimeofday.c | 25 ++++++++++ drivers/clocksource/timer-riscv.c | 1 + 16 files changed, 199 insertions(+), 74 deletions(-) create mode 100644 arch/riscv/include/asm/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/gettimeofday.h create mode 100644 arch/riscv/include/asm/vdso/processor.h create mode 100644 arch/riscv/include/asm/vdso/vsyscall.h delete mode 100644 arch/riscv/kernel/vdso/clock_getres.S delete mode 100644 arch/riscv/kernel/vdso/clock_gettime.S delete mode 100644 arch/riscv/kernel/vdso/gettimeofday.S create mode 100644 arch/riscv/kernel/vdso/vgettimeofday.c
Signature · 1 line
2.7.4
PATCH v2 1/2 riscv: use vDSO common flow to reduce the latency of the time-related functions
Even if RISC-V has supported the vDSO feature, the latency of the functions for obtaining the system time is still expensive. It is because these functions still trigger a corresponding system call in the process, which slows down the response time. If we want to remove the system call to reduce the latency, the kernel should have the ability to output the system clock information to userspace. This patch introduces the vDSO common flow to enable the kernel to achieve the above feature and uses "rdtime" instruction to obtain the current time in the user space. Under this condition, the latency cost by the ecall from U-mode to S-mode can be eliminated. After applying this patch, the latency of gettimeofday() measured on the HiFive unleashed board can be reduced by %61.
--- arch/riscv/Kconfig | 3 ++ arch/riscv/include/asm/clocksource.h | 7 +++ arch/riscv/include/asm/processor.h | 12 +---- arch/riscv/include/asm/vdso.h | 3 -- arch/riscv/include/asm/vdso/clocksource.h | 8 +++ arch/riscv/include/asm/vdso/gettimeofday.h | 79 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/vdso/processor.h | 19 +++++++ arch/riscv/include/asm/vdso/vsyscall.h | 27 ++++++++++ arch/riscv/kernel/vdso.c | 5 +- arch/riscv/kernel/vdso/Makefile | 12 +++-- arch/riscv/kernel/vdso/clock_getres.S | 18 ------- arch/riscv/kernel/vdso/clock_gettime.S | 18 ------- arch/riscv/kernel/vdso/gettimeofday.S | 18 ------- arch/riscv/kernel/vdso/vdso.lds.S | 2 + arch/riscv/kernel/vdso/vgettimeofday.c | 25 ++++++++++ drivers/clocksource/timer-riscv.c | 1 + 16 files changed, 185 insertions(+), 72 deletions(-) create mode 100644 arch/riscv/include/asm/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/gettimeofday.h create mode 100644 arch/riscv/include/asm/vdso/processor.h create mode 100644 arch/riscv/include/asm/vdso/vsyscall.h delete mode 100644 arch/riscv/kernel/vdso/clock_getres.S delete mode 100644 arch/riscv/kernel/vdso/clock_gettime.S delete mode 100644 arch/riscv/kernel/vdso/gettimeofday.S create mode 100644 arch/riscv/kernel/vdso/vgettimeofday.c
arch/riscv/Kconfig +3 -0
@@ -68,6 +68,9 @@ config RISCV select ARCH_HAS_GCOV_PROFILE_ALL select HAVE_COPY_THREAD_TLS select HAVE_ARCH_KASAN if MMU && 64BIT + select HAVE_GENERIC_VDSO + select GENERIC_TIME_VSYSCALL + select GENERIC_GETTIMEOFDAY config ARCH_MMAP_RND_BITS_MIN default 18 if 64BIT
arch/riscv/include/asm/clocksource.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_CLOCKSOURCE_H +#define _ASM_CLOCKSOURCE_H + +#include <asm/vdso/clocksource.h> + +#endif
arch/riscv/include/asm/processor.h +2 -10
@@ -8,6 +8,8 @@#include <linux/const.h> +#include <vdso/processor.h> +#include <asm/ptrace.h> /*
@@ -58,16 +60,6 @@ static inline void release_thread(struct task_struct *dead_task)extern unsigned long get_wchan (struct task_struct *p); -static inline void cpu_relax (void ) -{ -#ifdef __riscv_muldiv -int dummy; -/* In lieu of a halt instruction, induce a long-latency stall. */ - __asm__ __volatile__ ("div %0, %0, zero" :"=r" (dummy)); -#endif -barrier (); -} -static inline void wait_for_interrupt (void ) { __asm__ __volatile__ ("wfi" );
arch/riscv/include/asm/vdso.h +0 -3
@@ -10,9 +10,6 @@#include <linux/types.h> -struct vdso_data { -}; -/* * 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
arch/riscv/include/asm/vdso/clocksource.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSOCLOCKSOURCE_H +#define __ASM_VDSOCLOCKSOURCE_H + +#define VDSO_ARCH_CLOCKMODES \ + VDSO_CLOCKMODE_ARCHTIMER + +#endif
arch/riscv/include/asm/vdso/gettimeofday.h new file +79 -0
79 lines not on this page · raw message
arch/riscv/include/asm/vdso/processor.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_VDSO_PROCESSOR_H +#define __ASM_VDSO_PROCESSOR_H + +#ifndef __ASSEMBLY__ + +static inline void cpu_relax (void ) +{ +#ifdef __riscv_muldiv +int dummy; +/* In lieu of a halt instruction, induce a long-latency stall. */ + __asm__ __volatile__ ("div %0, %0, zero" :"=r" (dummy)); +#endif +barrier (); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_VDSO_PROCESSOR_H */
arch/riscv/include/asm/vdso/vsyscall.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_VSYSCALL_H +#define __ASM_VDSO_VSYSCALL_H + +#ifndef __ASSEMBLY__ + +#include <linux/timekeeper_internal.h> +#include <vdso/datapage.h> + +extern struct vdso_data *vdso_data; + +/* +* Update the vDSO data page to keep in sync with kernel timekeeping. +*/ +static __always_inline struct vdso_data *__riscv_get_k_vdso_data(void) +{ +return vdso_data; +} + +#define __arch_get_k_vdso_data __riscv_get_k_vdso_data + +/* The asm-generic header needs to be included after the definitions above */ +#include <asm-generic/vdso/vsyscall.h> + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_VDSO_VSYSCALL_H */
arch/riscv/kernel/vdso.c +3 -2
@@ -11,8 +11,9 @@#include <linux/slab.h> #include <linux/binfmts.h> #include <linux/err.h> +#include <asm/page.h> +#include <vdso/datapage.h> -#include <asm/vdso.h> extern char vdso_start[], vdso_end[];
@@ -26,7 +27,7 @@ static union {struct vdso_data data;u8 page[PAGE_SIZE ]; }vdso_data_store __page_aligned_data; -static struct vdso_data *vdso_data = &vdso_data_store.data; +struct vdso_data *vdso_data = &vdso_data_store.data;static int __init vdso_init (void ) {
arch/riscv/kernel/vdso/Makefile +9 -3
@@ -1,12 +1,14 @@ # SPDX-License-Identifier: GPL-2.0-only # Copied from arch/tile/kernel/vdso/Makefile +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before +# the inclusion of generic Makefile. +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT +include $(srctree)/lib/vdso/Makefile # Symbols present in the vdso vdso-syms = rt_sigreturn ifdef CONFIG_64BIT -vdso-syms += gettimeofday -vdso-syms += clock_gettime -vdso-syms += clock_getres +vdso-syms += vgettimeofday endif vdso-syms += getcpu vdso-syms += flush_icache
@@ -14,6 +16,10 @@ vdso-syms += flush_icache # Files to link into the vdso obj-vdso = $(patsubst %, %.o, $(vdso-syms)) +ifneq ($(c-gettimeofday-y),) + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) +endif + # Build rules targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
arch/riscv/kernel/vdso/clock_getres.S deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_clock_getres(clockid_t clock_id, struct timespec *res); */ -ENTRY(__vdso_clock_getres) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_clock_getres - ecall - ret - .cfi_endproc -ENDPROC(__vdso_clock_getres)
arch/riscv/kernel/vdso/clock_gettime.S deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_clock_gettime(clockid_t clock_id, struct timespec *tp); */ -ENTRY(__vdso_clock_gettime) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_clock_gettime - ecall - ret - .cfi_endproc -ENDPROC(__vdso_clock_gettime)
arch/riscv/kernel/vdso/gettimeofday.S deleted +0 -18
@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); */ -ENTRY(__vdso_gettimeofday) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_gettimeofday - ecall - ret - .cfi_endproc -ENDPROC(__vdso_gettimeofday)
arch/riscv/kernel/vdso/vdso.lds.S +2 -0
@@ -2,11 +2,13 @@ /* * Copyright (C) 2012 Regents of the University of California */ +#include <asm/page.h> OUTPUT_ARCH(riscv) SECTIONS { + PROVIDE(_vdso_data = . + PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :text
arch/riscv/kernel/vdso/vgettimeofday.c new file +25 -0
@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copied from arch/arm64/kernel/vdso/vgettimeofday.c +* +* Copyright (C) 2018 ARM Ltd. +* Copyright (C) 2020 SiFive +*/ + +#include <linux/time.h> +#include <linux/types.h> + +int __vdso_clock_gettime (clockid_t clock,struct __kernel_timespec *ts) +{ +return __cvdso_clock_gettime (clock, ts); +} + +int __vdso_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +{ +return __cvdso_gettimeofday (tv, tz); +} + +int __vdso_clock_getres (clockid_t clock_id,struct __kernel_timespec *res) +{ +return __cvdso_clock_getres (clock_id, res); +}
drivers/clocksource/timer-riscv.c +1 -0
@@ -67,6 +67,7 @@ static struct clocksource riscv_clocksource = { .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, .read = riscv_clocksource_rdtime, + .vdso_clock_mode = VDSO_CLOCKMODE_ARCHTIMER, };static int riscv_timer_starting_cpu (unsigned int cpu)
Signature · 1 line
2.7.4
Re: [PATCH v2 1/2] riscv: use vDSO common flow to reduce the latency of the time-related functions
Quoted 13 lines · Vincent Chen
Even if RISC-V has supported the vDSO feature, the latency of the functions for obtaining the system time is still expensive. It is because these functions still trigger a corresponding system call in the process, which slows down the response time. If we want to remove the system call to reduce the latency, the kernel should have the ability to output the system clock information to userspace. This patch introduces the vDSO common flow to enable the kernel to achieve the above feature and uses "rdtime" instruction to obtain the current time in the user space. Under this condition, the latency cost by the ecall from U-mode to S-mode can be eliminated. After applying this patch, the latency of
gettimeofday()measured on the HiFive unleashed board can be reduced by %61.
Quoted 1 line
Signed-off-by Vincent Chen <[email protected]>
Sorry, I forgot to add "Reviewed-by: Atish Patra <[email protected]>" here.
Quoted 449 lines
--- arch/riscv/Kconfig | 3 ++ arch/riscv/include/asm/clocksource.h | 7 +++ arch/riscv/include/asm/processor.h | 12 +---- arch/riscv/include/asm/vdso.h | 3 -- arch/riscv/include/asm/vdso/clocksource.h | 8 +++ arch/riscv/include/asm/vdso/gettimeofday.h | 79 ++++++++++++++++++++++++++++++ arch/riscv/include/asm/vdso/processor.h | 19 +++++++ arch/riscv/include/asm/vdso/vsyscall.h | 27 ++++++++++ arch/riscv/kernel/vdso.c | 5 +- arch/riscv/kernel/vdso/Makefile | 12 +++-- arch/riscv/kernel/vdso/clock_getres.S | 18 ------- arch/riscv/kernel/vdso/clock_gettime.S | 18 ------- arch/riscv/kernel/vdso/gettimeofday.S | 18 ------- arch/riscv/kernel/vdso/vdso.lds.S | 2 + arch/riscv/kernel/vdso/vgettimeofday.c | 25 ++++++++++ drivers/clocksource/timer-riscv.c | 1 + 16 files changed, 185 insertions(+), 72 deletions(-) create mode 100644 arch/riscv/include/asm/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/clocksource.h create mode 100644 arch/riscv/include/asm/vdso/gettimeofday.h create mode 100644 arch/riscv/include/asm/vdso/processor.h create mode 100644 arch/riscv/include/asm/vdso/vsyscall.h delete mode 100644 arch/riscv/kernel/vdso/clock_getres.S delete mode 100644 arch/riscv/kernel/vdso/clock_gettime.S delete mode 100644 arch/riscv/kernel/vdso/gettimeofday.S create mode 100644 arch/riscv/kernel/vdso/vgettimeofday.carch/riscv/Kconfig +3
-0@@ -68,6 +68,9 @@ config RISCV select ARCH_HAS_GCOV_PROFILE_ALL select HAVE_COPY_THREAD_TLS select HAVE_ARCH_KASAN if MMU && 64BIT + select HAVE_GENERIC_VDSO + select GENERIC_TIME_VSYSCALL + select GENERIC_GETTIMEOFDAY config ARCH_MMAP_RND_BITS_MIN default 18 if 64BITarch/riscv/include/asm/clocksource.h new file +7
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_CLOCKSOURCE_H +#define _ASM_CLOCKSOURCE_H + +#include <asm/vdso/clocksource.h> + +#endif arch/riscv/include/asm/processor.h +2
-10@@ -8,6 +8,8 @@#include <linux/const.h> +#include <vdso/processor.h> +#include <asm/ptrace.h> /* @@ -58,16 +60,6 @@ static inline void release_thread(struct task_struct *dead_task)extern unsigned long get_wchan (struct task_struct *p); -static inline void cpu_relax (void ) -{ -#ifdef __riscv_muldiv -int dummy; -/* In lieu of a halt instruction, induce a long-latency stall. */ - __asm__ __volatile__ ("div %0, %0, zero" :"=r" (dummy)); -#endif -barrier (); -} -static inline void wait_for_interrupt (void ) { __asm__ __volatile__ ("wfi" );arch/riscv/include/asm/vdso.h +0
-3@@ -10,9 +10,6 @@#include <linux/types.h> -struct vdso_data { -}; -/* * 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 arch/riscv/include/asm/vdso/clocksource.h new file +8
-0@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSOCLOCKSOURCE_H +#define __ASM_VDSOCLOCKSOURCE_H + +#define VDSO_ARCH_CLOCKMODES \ + VDSO_CLOCKMODE_ARCHTIMER + +#endif arch/riscv/include/asm/vdso/gettimeofday.h new file +79
-0@@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_GETTIMEOFDAY_H +#define __ASM_VDSO_GETTIMEOFDAY_H + +#ifndef __ASSEMBLY__ + +#include <asm/unistd.h> +#include <asm/csr.h> +#include <uapi/linux/time.h> + +#define VDSO_HAS_CLOCK_GETRES 1 + +static __always_inline +int gettimeofday_fallback(struct __kernel_old_timeval *_tv, +struct timezone *_tz) +{ + register struct __kernel_old_timeval *tv asm("a0") = _tv; + register struct timezone *tz asm("a1") = _tz; + registerlong ret asm("a0" ); + register long nr asm("a7") = __NR_gettimeofday; + + asmvolatile ("ecall\n" + :"=r" (ret) + :"r" (tv),"r" (tz),"r" (nr) + :"memory" ); + +return ret; +} + +static __always_inline +long clock_gettime_fallback (clockid_t _clkid,struct __kernel_timespec *_ts) +{ + register clockid_t clkid asm("a0") = _clkid; + register struct __kernel_timespec *ts asm("a1") = _ts; + registerlong ret asm("a0" ); + register long nr asm("a7") = __NR_clock_gettime; + + asmvolatile ("ecall\n" + :"=r" (ret) + :"r" (clkid),"r" (ts),"r" (nr) + :"memory" ); + +return ret; +} + +static __always_inline +int clock_getres_fallback(clockid_t _clkid, struct __kernel_timespec *_ts) +{ + register clockid_t clkid asm("a0") = _clkid; + register struct __kernel_timespec *ts asm("a1") = _ts; + registerlong ret asm("a0" ); + register long nr asm("a7") = __NR_clock_getres; + + asmvolatile ("ecall\n" + :"=r" (ret) + :"r" (clkid),"r" (ts),"r" (nr) + :"memory" ); + +return ret; +} + +static __always_inline u64 __arch_get_hw_counter(s32 clock_mode) +{ +/* +* The purpose of csr_read(CSR_TIME) is to trap the system into +* M-mode to obtain the value of CSR_TIME. Hence, unlike other +* architecture, no fence instructions surround the csr_read() +*/ +return csr_read (CSR_TIME ); +} + +static __always_inline const struct vdso_data *__arch_get_vdso_data(void) +{ +return _vdso_data; +} + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_VDSO_GETTIMEOFDAY_H */ arch/riscv/include/asm/vdso/processor.h new file +19
-0@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_VDSO_PROCESSOR_H +#define __ASM_VDSO_PROCESSOR_H + +#ifndef __ASSEMBLY__ + +static inline void cpu_relax (void ) +{ +#ifdef __riscv_muldiv +int dummy; +/* In lieu of a halt instruction, induce a long-latency stall. */ + __asm__ __volatile__ ("div %0, %0, zero" :"=r" (dummy)); +#endif +barrier (); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_VDSO_PROCESSOR_H */ arch/riscv/include/asm/vdso/vsyscall.h new file +27
-0@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_VSYSCALL_H +#define __ASM_VDSO_VSYSCALL_H + +#ifndef __ASSEMBLY__ + +#include <linux/timekeeper_internal.h> +#include <vdso/datapage.h> + +extern struct vdso_data *vdso_data; + +/* +* Update the vDSO data page to keep in sync with kernel timekeeping. +*/ +static __always_inline struct vdso_data *__riscv_get_k_vdso_data(void) +{ +return vdso_data; +} + +#define __arch_get_k_vdso_data __riscv_get_k_vdso_data + +/* The asm-generic header needs to be included after the definitions above */ +#include <asm-generic/vdso/vsyscall.h> + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_VDSO_VSYSCALL_H */ arch/riscv/kernel/vdso.c +3
-2@@ -11,8 +11,9 @@#include <linux/slab.h> #include <linux/binfmts.h> #include <linux/err.h> +#include <asm/page.h> +#include <vdso/datapage.h> -#include <asm/vdso.h> extern char vdso_start[], vdso_end[];@@ -26,7 +27,7 @@ static union {struct vdso_data data;u8 page[PAGE_SIZE ]; }vdso_data_store __page_aligned_data; -static struct vdso_data *vdso_data = &vdso_data_store.data; +struct vdso_data *vdso_data = &vdso_data_store.data;static int __init vdso_init (void ) {arch/riscv/kernel/vdso/Makefile +9
-3@@ -1,12 +1,14 @@ # SPDX-License-Identifier: GPL-2.0-only # Copied from arch/tile/kernel/vdso/Makefile +# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before +# the inclusion of generic Makefile. +ARCH_REL_TYPE_ABS := R_RISCV_32|R_RISCV_64|R_RISCV_JUMP_SLOT +include $(srctree)/lib/vdso/Makefile # Symbols present in the vdso vdso-syms = rt_sigreturn ifdef CONFIG_64BIT -vdso-syms += gettimeofday -vdso-syms += clock_gettime -vdso-syms += clock_getres +vdso-syms += vgettimeofday endif vdso-syms += getcpu vdso-syms += flush_icache@@ -14,6 +16,10 @@ vdso-syms += flush_icache # Files to link into the vdso obj-vdso = $(patsubst %, %.o, $(vdso-syms)) +ifneq ($(c-gettimeofday-y),) + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) +endif + # Build rules targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds vdso-dummy.o obj-vdso := $(addprefix $(obj)/, $(obj-vdso))arch/riscv/kernel/vdso/clock_getres.S deleted +0
-18@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_clock_getres(clockid_t clock_id, struct timespec *res); */ -ENTRY(__vdso_clock_getres) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_clock_getres - ecall - ret - .cfi_endproc -ENDPROC(__vdso_clock_getres)arch/riscv/kernel/vdso/clock_gettime.S deleted +0
-18@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_clock_gettime(clockid_t clock_id, struct timespec *tp); */ -ENTRY(__vdso_clock_gettime) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_clock_gettime - ecall - ret - .cfi_endproc -ENDPROC(__vdso_clock_gettime)arch/riscv/kernel/vdso/gettimeofday.S deleted +0
-18@@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2017 SiFive - */ - -#include <linux/linkage.h> -#include <asm/unistd.h> - - .text -/* int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); */ -ENTRY(__vdso_gettimeofday) - .cfi_startproc - /* For now, just do the syscall. */ - li a7, __NR_gettimeofday - ecall - ret - .cfi_endproc -ENDPROC(__vdso_gettimeofday)arch/riscv/kernel/vdso/vdso.lds.S +2
-0@@ -2,11 +2,13 @@ /* * Copyright (C) 2012 Regents of the University of California */ +#include <asm/page.h> OUTPUT_ARCH(riscv) SECTIONS { + PROVIDE(_vdso_data = . + PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :textarch/riscv/kernel/vdso/vgettimeofday.c new file +25
-0@@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copied from arch/arm64/kernel/vdso/vgettimeofday.c +* +* Copyright (C) 2018 ARM Ltd. +* Copyright (C) 2020 SiFive +*/ + +#include <linux/time.h> +#include <linux/types.h> + +int __vdso_clock_gettime (clockid_t clock,struct __kernel_timespec *ts) +{ +return __cvdso_clock_gettime (clock, ts); +} + +int __vdso_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +{ +return __cvdso_gettimeofday (tv, tz); +} + +int __vdso_clock_getres (clockid_t clock_id,struct __kernel_timespec *res) +{ +return __cvdso_clock_getres (clock_id, res); +}drivers/clocksource/timer-riscv.c +1
-1@@ -67,6 +67,7 @@ static struct clocksource riscv_clocksource = { .mask = CLOCKSOURCE_MASK(64), .flags = CLOCK_SOURCE_IS_CONTINUOUS, .read = riscv_clocksource_rdtime, + .vdso_clock_mode = VDSO_CLOCKMODE_ARCHTIMER, };static int riscv_timer_starting_cpu (unsigned int cpu) --2.7.4
PATCH v2 2/2 riscv: set the permission of vdso_data to read-only
In reply to Vincent ChenThe original vdso_data page is empty, so the permission of the vdso_data page can be the same with the vdso text page. After introducing the vDSO common flow, the vdso_data is not empty and the permission should be changed to read-only.
--- arch/riscv/kernel/vdso.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
arch/riscv/kernel/vdso.c +14 -2
@@ -76,13 +76,22 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,*/ mm->context.vdso = (void *)vdso_base; - ret =install_special_mapping (mm, vdso_base, vdso_len, + 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)) +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:up_write (&mm->mmap_sem);return ret;
@@ -92,5 +101,8 @@ 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]" ; +if (vma->vm_mm && (vma->vm_start == + (long )vma->vm_mm->context.vdso +PAGE_SIZE )) +return "[vdso_data]" ;return NULL ; }
Signature · 1 line
2.7.4