Commit 371d3f56 authored by Yang Yingliang's avatar Yang Yingliang
Browse files

vdso: do cntvct workaround in the VDSO

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I8LFBU


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

Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent 381c02a7
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -94,6 +94,38 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
	:
	: "memory");

#ifdef CONFIG_ARM_ARCH_TIMER_WORKAROUND_IN_USERSPACE
	if (vd->vdso_fix) {
		u64 new;
		int retries = 50;

		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(
			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--;
		}
	}
#endif
	arch_counter_enforce_ordering(res);

	return res;