Skip to content

Commit 37cbd27

Browse files
willdeacongregkh
authored andcommitted
arm64: vdso: Avoid ISB after reading from cntvct_el0
commit 77ec462 upstream. We can avoid the expensive ISB instruction after reading the counter in the vDSO gettime functions by creating a fake address hazard against a dummy stack read, just like we do inside the kernel. Signed-off-by: Will Deacon <will@kernel.org> Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com> Link: https://lore.kernel.org/r/20210318170738.7756-5-will@kernel.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Chanho Park <chanho61.park@samsung.com>
1 parent 7a2b5bb commit 37cbd27

3 files changed

Lines changed: 20 additions & 26 deletions

File tree

‎arch/arm64/include/asm/arch_timer.h‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,25 +165,6 @@ static inline void arch_timer_set_cntkctl(u32 cntkctl)
165165
isb();
166166
}
167167

168-
/*
169-
* Ensure that reads of the counter are treated the same as memory reads
170-
* for the purposes of ordering by subsequent memory barriers.
171-
*
172-
* This insanity brought to you by speculative system register reads,
173-
* out-of-order memory accesses, sequence locks and Thomas Gleixner.
174-
*
175-
* http://lists.infradead.org/pipermail/linux-arm-kernel/2019-February/631195.html
176-
*/
177-
#define arch_counter_enforce_ordering(val) do { \
178-
u64 tmp, _val = (val); \
179-
\
180-
asm volatile( \
181-
" eor %0, %1, %1\n" \
182-
" add %0, sp, %0\n" \
183-
" ldr xzr, [%0]" \
184-
: "=r" (tmp) : "r" (_val)); \
185-
} while (0)
186-
187168
static __always_inline u64 __arch_counter_get_cntpct_stable(void)
188169
{
189170
u64 cnt;
@@ -224,8 +205,6 @@ static __always_inline u64 __arch_counter_get_cntvct(void)
224205
return cnt;
225206
}
226207

227-
#undef arch_counter_enforce_ordering
228-
229208
static inline int arch_timer_arch_init(void)
230209
{
231210
return 0;

‎arch/arm64/include/asm/barrier.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,25 @@ static inline unsigned long array_index_mask_nospec(unsigned long idx,
7070
return mask;
7171
}
7272

73+
/*
74+
* Ensure that reads of the counter are treated the same as memory reads
75+
* for the purposes of ordering by subsequent memory barriers.
76+
*
77+
* This insanity brought to you by speculative system register reads,
78+
* out-of-order memory accesses, sequence locks and Thomas Gleixner.
79+
*
80+
* http://lists.infradead.org/pipermail/linux-arm-kernel/2019-February/631195.html
81+
*/
82+
#define arch_counter_enforce_ordering(val) do { \
83+
u64 tmp, _val = (val); \
84+
\
85+
asm volatile( \
86+
" eor %0, %1, %1\n" \
87+
" add %0, sp, %0\n" \
88+
" ldr xzr, [%0]" \
89+
: "=r" (tmp) : "r" (_val)); \
90+
} while (0)
91+
7392
#define __smp_mb() dmb(ish)
7493
#define __smp_rmb() dmb(ishld)
7594
#define __smp_wmb() dmb(ishst)

‎arch/arm64/include/asm/vdso/gettimeofday.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode,
8383
*/
8484
isb();
8585
asm volatile("mrs %0, cntvct_el0" : "=r" (res) :: "memory");
86-
/*
87-
* This isb() is required to prevent that the seq lock is
88-
* speculated.#
89-
*/
90-
isb();
86+
arch_counter_enforce_ordering(res);
9187

9288
return res;
9389
}

0 commit comments

Comments
 (0)