From: Yang Yingliang <yangyingliang@huawei.com> hulk inclusion category: feature bugzilla: https://atomgit.com/openeuler/kernel/issues/8301 CVE: NA -------------------------------------------------- If a cntvct workaround is enabled, read CNTVCT_EL0 twice in VDSO to avoid the clock bug. Without this patch on Kunpeng916: ./gettimeofday -E -C 200 -L -S -W -N "gettimeofday" Running: gettimeofday# ./gettimeofday -E -C 200 -L -S -W -N gettimeofday prc thr usecs/call samples errors cnt/samp gettimeofday 1 1 0.31753 198 0 20000 With this patch on Kunpeng916: ./gettimeofday -E -C 200 -L -S -W -N "gettimeofday" Running: gettimeofday# ./gettimeofday -E -C 200 -L -S -W -N gettimeofday prc thr usecs/call samples errors cnt/samp gettimeofday 1 1 0.05244 198 0 20000 This patch was backported from OLK-6.6 partially before, since we already backported 9025cebf12d1 ("arm64: vdso: use SYS_CNTVCTSS_EL0 for gettimeofday"). Now we backport the whole patch. Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Signed-off-by: Xinyu Zheng <zhengxinyu6@huawei.com> --- arch/arm64/include/asm/vdso/gettimeofday.h | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h index b5cf4581ea18..cf5b6db57cc2 100644 --- a/arch/arm64/include/asm/vdso/gettimeofday.h +++ b/arch/arm64/include/asm/vdso/gettimeofday.h @@ -98,10 +98,29 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, u64 new; int retries = 50; - asm volatile("mrs %0, cntvct_el0" : "=r" (new) :: "memory"); + asm volatile( + ALTERNATIVE("mrs %0, cntvct_el0", + __mrs_s("%0", SYS_CNTVCTSS_EL0), + ARM64_HAS_ECV) + : "=r" (new) + : + : "memory"); while (unlikely((new - res) >> vd->vdso_shift) && retries) { - asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory"); - asm volatile("mrs %0, cntvct_el0" : "=r" (new) :: "memory"); + asm volatile( + ALTERNATIVE("mrs %0, cntvct_el0", + __mrs_s("%0", SYS_CNTVCTSS_EL0), + ARM64_HAS_ECV) + : "=r" (res) + : + : "memory"); + + asm volatile( + ALTERNATIVE("mrs %0, cntvct_el0", + __mrs_s("%0", SYS_CNTVCTSS_EL0), + ARM64_HAS_ECV) + : "=r" (new) + : + : "memory"); retries--; } } -- 2.34.1