diff options
Diffstat (limited to 'include/linux/compiler.h')
| -rw-r--r-- | include/linux/compiler.h | 16 | 
1 files changed, 11 insertions, 5 deletions
| diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 8c252e073bd8..2594553bb30b 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -194,16 +194,22 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,   * This data_race() macro is useful for situations in which data races   * should be forgiven.  One example is diagnostic code that accesses   * shared variables but is not a part of the core synchronization design. + * For example, if accesses to a given variable are protected by a lock, + * except for diagnostic code, then the accesses under the lock should + * be plain C-language accesses and those in the diagnostic code should + * use data_race().  This way, KCSAN will complain if buggy lockless + * accesses to that variable are introduced, even if the buggy accesses + * are protected by READ_ONCE() or WRITE_ONCE().   *   * This macro *does not* affect normal code generation, but is a hint - * to tooling that data races here are to be ignored. + * to tooling that data races here are to be ignored.  If the access must + * be atomic *and* KCSAN should ignore the access, use both data_race() + * and READ_ONCE(), for example, data_race(READ_ONCE(x)).   */  #define data_race(expr)							\  ({									\ -	__unqual_scalar_typeof(({ expr; })) __v = ({			\ -		__kcsan_disable_current();				\ -		expr;							\ -	});								\ +	__kcsan_disable_current();					\ +	__auto_type __v = (expr);					\  	__kcsan_enable_current();					\  	__v;								\  }) |