Skip to content

Commit 80d7476

Browse files
melverpaulmckrcu
authored andcommitted
kcsan: Turn barrier instrumentation into macros
Some architectures use barriers in 'extern inline' functions, from which we should not refer to static inline functions. For example, building Alpha with gcc and W=1 shows: ./include/asm-generic/barrier.h:70:30: warning: 'kcsan_rmb' is static but used in inline function 'pmd_offset' which is not static 70 | #define smp_rmb() do { kcsan_rmb(); __smp_rmb(); } while (0) | ^~~~~~~~~ ./arch/alpha/include/asm/pgtable.h:293:9: note: in expansion of macro 'smp_rmb' 293 | smp_rmb(); /* see above */ | ^~~~~~~ Which seems to warn about 6.7.4#3 of the C standard: "An inline definition of a function with external linkage shall not contain a definition of a modifiable object with static or thread storage duration, and shall not contain a reference to an identifier with internal linkage." Fix it by turning barrier instrumentation into macros, which matches definitions in <asm/barrier.h>. Perhaps we can revert this change in future, when there are no more 'extern inline' users left. Link: https://lkml.kernel.org/r/202112041334.X44uWZXf-lkp@intel.com Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
1 parent a70d36e commit 80d7476

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

include/linux/kcsan-checks.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,28 +241,30 @@ static inline void __kcsan_disable_current(void) { }
241241
* disabled with the __no_kcsan function attribute.
242242
*
243243
* Also see definition of __tsan_atomic_signal_fence() in kernel/kcsan/core.c.
244+
*
245+
* These are all macros, like <asm/barrier.h>, since some architectures use them
246+
* in non-static inline functions.
244247
*/
245248
#define __KCSAN_BARRIER_TO_SIGNAL_FENCE(name) \
246-
static __always_inline void kcsan_##name(void) \
247-
{ \
249+
do { \
248250
barrier(); \
249251
__atomic_signal_fence(__KCSAN_BARRIER_TO_SIGNAL_FENCE_##name); \
250252
barrier(); \
251-
}
252-
__KCSAN_BARRIER_TO_SIGNAL_FENCE(mb)
253-
__KCSAN_BARRIER_TO_SIGNAL_FENCE(wmb)
254-
__KCSAN_BARRIER_TO_SIGNAL_FENCE(rmb)
255-
__KCSAN_BARRIER_TO_SIGNAL_FENCE(release)
253+
} while (0)
254+
#define kcsan_mb() __KCSAN_BARRIER_TO_SIGNAL_FENCE(mb)
255+
#define kcsan_wmb() __KCSAN_BARRIER_TO_SIGNAL_FENCE(wmb)
256+
#define kcsan_rmb() __KCSAN_BARRIER_TO_SIGNAL_FENCE(rmb)
257+
#define kcsan_release() __KCSAN_BARRIER_TO_SIGNAL_FENCE(release)
256258
#elif defined(CONFIG_KCSAN_WEAK_MEMORY) && defined(__KCSAN_INSTRUMENT_BARRIERS__)
257259
#define kcsan_mb __kcsan_mb
258260
#define kcsan_wmb __kcsan_wmb
259261
#define kcsan_rmb __kcsan_rmb
260262
#define kcsan_release __kcsan_release
261263
#else /* CONFIG_KCSAN_WEAK_MEMORY && ... */
262-
static inline void kcsan_mb(void) { }
263-
static inline void kcsan_wmb(void) { }
264-
static inline void kcsan_rmb(void) { }
265-
static inline void kcsan_release(void) { }
264+
#define kcsan_mb() do { } while (0)
265+
#define kcsan_wmb() do { } while (0)
266+
#define kcsan_rmb() do { } while (0)
267+
#define kcsan_release() do { } while (0)
266268
#endif /* CONFIG_KCSAN_WEAK_MEMORY && ... */
267269

268270
/**

0 commit comments

Comments
 (0)