The meat and potatoes of 'READ_ONCE()' is defined by the '__READ_ONCE_SIZE()' macro, which uses volatile casts in an attempt to avoid tearing of byte, halfword, word and double-word accesses. Allow this to be overridden by the architecture code in the case that things like memory barriers are also required. Signed-off-by: Will Deacon <will@xxxxxxxxxx> --- include/asm-generic/rwonce.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/include/asm-generic/rwonce.h b/include/asm-generic/rwonce.h index abf326634ecd..2c2ac0948c94 100644 --- a/include/asm-generic/rwonce.h +++ b/include/asm-generic/rwonce.h @@ -33,13 +33,29 @@ #include <asm/barrier.h> +#ifndef __read_once_size_1 +#define __read_once_size_1(p) (*(volatile __u8 *)(p)) +#endif + +#ifndef __read_once_size_2 +#define __read_once_size_2(p) (*(volatile __u16 *)(p)) +#endif + +#ifndef __read_once_size_4 +#define __read_once_size_4(p) (*(volatile __u32 *)(p)) +#endif + +#ifndef __read_once_size_8 +#define __read_once_size_8(p) (*(volatile __u64 *)(p)) +#endif + #define __READ_ONCE_SIZE \ ({ \ switch (size) { \ - case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \ - case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \ - case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \ - case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ + case 1: *(__u8 *)res = __read_once_size_1(p); break; \ + case 2: *(__u16 *)res = __read_once_size_2(p); break; \ + case 4: *(__u32 *)res = __read_once_size_4(p); break; \ + case 8: *(__u64 *)res = __read_once_size_8(p); break; \ default: \ barrier(); \ __builtin_memcpy((void *)res, (const void *)p, size); \ @@ -59,6 +75,10 @@ void __read_once_size_nocheck(const volatile void *p, void *res, int size) __READ_ONCE_SIZE; } +#undef __read_once_size_1 +#undef __read_once_size_2 +#undef __read_once_size_4 +#undef __read_once_size_8 #undef __READ_ONCE_SIZE static __always_inline void __write_once_size(volatile void *p, void *res, int size) -- 2.24.0.rc1.363.gb1bccd3e3d-goog