KCSAN cleanups and noinstr
Subsystems (5)
cover KCSAN cleanups and noinstr
Hi all,
Here's two KCSAN cleanups and the required noinstr change for x86.
PATCH 1/3 x86, kcsan: Remove __no_kcsan_or_inline usage
Now that KCSAN relies on -tsan-distinguish-volatile we no longer need the annotation for constant_test_bit(). Remove it.
--- arch/x86/include/asm/bitops.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/include/asm/bitops.h +1 -5
@@ -201,12 +201,8 @@ arch_test_and_change_bit(long nr, volati return GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(btc), *addr, c, "Ir", nr); } -static __no_kcsan_or_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) +static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) { -/* -* Because this is a plain access, we need to disable KCSAN here to -* avoid double instrumentation via instrumented bitops. -*/ return ((1UL << (nr & (BITS_PER_LONG -1 ))) & (addr[nr >> _BITOPS_LONG_SHIFT])) !=0 ; }
PATCH 2/3 kcsan: Remove __no_kcsan_or_inline
In reply to Peter ZijlstraThere are no more user of this function attribute, also, with us now actively supporting '__no_kcsan inline' it doesn't make sense to have in any case.
--- Documentation/dev-tools/kcsan.rst | 6 ------ include/linux/compiler_types.h | 5 +---- 2 files changed, 1 insertion(+), 10 deletions(-)
Documentation/dev-tools/kcsan.rst +0 -6
@@ -114,12 +114,6 @@ functions, compilation units, or entire To dynamically limit for which functions to generate reports, see the `DebugFS interface`_ blacklist/whitelist feature. - For ``__always_inline`` functions, replace ``__always_inline`` with - ``__no_kcsan_or_inline`` (which implies ``__always_inline``):: - - static __no_kcsan_or_inline void foo(void) { - ... - * To disable data race detection for a particular compilation unit, add to the ``Makefile``::
include/linux/compiler_types.h +1 -4
@@ -193,10 +193,7 @@ struct ftrace_likely_data {#define __no_kcsan __no_sanitize_thread#ifdef __SANITIZE_THREAD__ -# define __no_kcsan_or_inline __no_kcsan notrace __maybe_unused -# define __no_sanitize_or_inline __no_kcsan_or_inline -#else -# define __no_kcsan_or_inline __always_inline +# define __no_sanitize_or_inline __no_kcsan notrace __maybe_unused#endif #ifndef __no_sanitize_or_inline
PATCH 3/3 x86, kcsan: Add __no_kcsan to noinstr
In reply to Peter ZijlstraThe 'noinstr' function attribute means no-instrumentation, this should very much include *SAN. Because lots of that is broken at present, only include KCSAN for now, as that is limited to clang11, which has sane function attribute behaviour.
--- include/linux/compiler_types.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/compiler_types.h +4 -4
@@ -118,10 +118,6 @@ struct ftrace_likely_data {#define notrace __attribute__((__no_instrument_function__))#endif -/* Section for code which can't be instrumented at all */ -#define noinstr \ - noinline notrace __attribute((__section__(".noinstr.text"))) -/* * it doesn't make sense on ARM (currently the only user of __naked) * to trace naked functions because then mcount is called without
@@ -200,6 +196,10 @@ struct ftrace_likely_data {#define __no_sanitize_or_inline __always_inline#endif +/* Section for code which can't be instrumented at all */ +#define noinstr \ + noinline notrace __attribute((__section__(".noinstr.text"))) __no_kcsan +#endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */
Quoted 4 lines · Peter Zijlstra
Hi all,
Here's two KCSAN cleanups and the required noinstr change for x86.
Thank you!
As promised, here are the patches that would take care of KASAN and UBSAN, rebased on the patches here:
https://lkml.kernel.org/r/[email protected]
Thanks,
-- Marco