Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arm64: vdso: use SYS_CNTVCTSS_EL0 for gettimeofday

If FEAT_ECV is implemented, the self-synchronized counter CNTVCTSS_EL0 can
be used, removing the need for an ISB.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Andre Przywara <andre.przywara@arm.com>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Link: https://lore.kernel.org/r/20220830104833.34636-4-joey.gouly@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Joey Gouly and committed by
Catalin Marinas
9025cebf 4e3bca8f

+15 -4
+15 -4
arch/arm64/include/asm/vdso/gettimeofday.h
··· 7 7 8 8 #ifndef __ASSEMBLY__ 9 9 10 + #include <asm/alternative.h> 10 11 #include <asm/barrier.h> 11 12 #include <asm/unistd.h> 13 + #include <asm/sysreg.h> 12 14 13 15 #define VDSO_HAS_CLOCK_GETRES 1 14 16 ··· 80 78 return 0; 81 79 82 80 /* 83 - * This isb() is required to prevent that the counter value 81 + * If FEAT_ECV is available, use the self-synchronizing counter. 82 + * Otherwise the isb is required to prevent that the counter value 84 83 * is speculated. 85 - */ 86 - isb(); 87 - asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory"); 84 + */ 85 + asm volatile( 86 + ALTERNATIVE("isb\n" 87 + "mrs %0, cntvct_el0", 88 + "nop\n" 89 + __mrs_s("%0", SYS_CNTVCTSS_EL0), 90 + ARM64_HAS_ECV) 91 + : "=r" (res) 92 + : 93 + : "memory"); 94 + 88 95 arch_counter_enforce_ordering(res); 89 96 90 97 return res;