Re: [PATCH] READ_ONCE, WRITE_ONCE, kcsan: Perform checks in __*_ONCE variants

From: Peter Zijlstra
Date: Tue May 12 2020 - 15:09:18 EST


On Tue, May 12, 2020 at 08:38:39PM +0200, Marco Elver wrote:
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index 741c93c62ecf..e902ca5de811 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -224,13 +224,16 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
> * atomicity or dependency ordering guarantees. Note that this may result
> * in tears!
> */
> -#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> +#define __READ_ONCE(x) \
> +({ \
> + kcsan_check_atomic_read(&(x), sizeof(x)); \
> + data_race((*(const volatile __unqual_scalar_typeof(x) *)&(x))); \
> +})

NAK

This will actively insert instrumentation into __READ_ONCE() and I need
it to not have any.