[PATCH 09/10] objtool: Drop noinstr hack for KCSAN_WEAK_MEMORY

Nathan Chancellor posted 10 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH 09/10] objtool: Drop noinstr hack for KCSAN_WEAK_MEMORY
Posted by Nathan Chancellor 1 month, 2 weeks ago
Now that the minimum supported version of LLVM for building the kernel
has been bumped to 15.0.0, __no_kcsan will always ensure that the thread
sanitizer functions are not generated, so remove the check for tsan
functions in is_profiling_func() and the always true depends and
unnecessary select lines in KCSAN_WEAK_MEMORY.

Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Marco Elver <elver@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: kasan-dev@googlegroups.com
---
 lib/Kconfig.kcsan     |  6 ------
 tools/objtool/check.c | 10 ----------
 2 files changed, 16 deletions(-)

diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan
index 609ddfc73de5..4ce4b0c0109c 100644
--- a/lib/Kconfig.kcsan
+++ b/lib/Kconfig.kcsan
@@ -185,12 +185,6 @@ config KCSAN_WEAK_MEMORY
 	bool "Enable weak memory modeling to detect missing memory barriers"
 	default y
 	depends on KCSAN_STRICT
-	# We can either let objtool nop __tsan_func_{entry,exit}() and builtin
-	# atomics instrumentation in .noinstr.text, or use a compiler that can
-	# implement __no_kcsan to really remove all instrumentation.
-	depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \
-		   CC_IS_GCC || CLANG_VERSION >= 140000
-	select OBJTOOL if HAVE_NOINSTR_HACK
 	help
 	  Enable support for modeling a subset of weak memory, which allows
 	  detecting a subset of data races due to missing memory barriers.
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index d14f20ef1db1..efa4c060ff4e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2453,16 +2453,6 @@ static bool is_profiling_func(const char *name)
 	if (!strncmp(name, "__sanitizer_cov_", 16))
 		return true;
 
-	/*
-	 * Some compilers currently do not remove __tsan_func_entry/exit nor
-	 * __tsan_atomic_signal_fence (used for barrier instrumentation) with
-	 * the __no_sanitize_thread attribute, remove them. Once the kernel's
-	 * minimum Clang version is 14.0, this can be removed.
-	 */
-	if (!strncmp(name, "__tsan_func_", 12) ||
-	    !strcmp(name, "__tsan_atomic_signal_fence"))
-		return true;
-
 	return false;
 }
 

-- 
2.50.1
Re: [PATCH 09/10] objtool: Drop noinstr hack for KCSAN_WEAK_MEMORY
Posted by Marco Elver 1 month, 2 weeks ago
On Mon, 18 Aug 2025 at 20:58, Nathan Chancellor <nathan@kernel.org> wrote:
>
> Now that the minimum supported version of LLVM for building the kernel
> has been bumped to 15.0.0, __no_kcsan will always ensure that the thread
> sanitizer functions are not generated, so remove the check for tsan
> functions in is_profiling_func() and the always true depends and
> unnecessary select lines in KCSAN_WEAK_MEMORY.
>
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Acked-by: Marco Elver <elver@google.com>

Good riddance.

> ---
> Cc: Josh Poimboeuf <jpoimboe@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Marco Elver <elver@google.com>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: kasan-dev@googlegroups.com
> ---
>  lib/Kconfig.kcsan     |  6 ------
>  tools/objtool/check.c | 10 ----------
>  2 files changed, 16 deletions(-)
>
> diff --git a/lib/Kconfig.kcsan b/lib/Kconfig.kcsan
> index 609ddfc73de5..4ce4b0c0109c 100644
> --- a/lib/Kconfig.kcsan
> +++ b/lib/Kconfig.kcsan
> @@ -185,12 +185,6 @@ config KCSAN_WEAK_MEMORY
>         bool "Enable weak memory modeling to detect missing memory barriers"
>         default y
>         depends on KCSAN_STRICT
> -       # We can either let objtool nop __tsan_func_{entry,exit}() and builtin
> -       # atomics instrumentation in .noinstr.text, or use a compiler that can
> -       # implement __no_kcsan to really remove all instrumentation.
> -       depends on !ARCH_WANTS_NO_INSTR || HAVE_NOINSTR_HACK || \
> -                  CC_IS_GCC || CLANG_VERSION >= 140000
> -       select OBJTOOL if HAVE_NOINSTR_HACK
>         help
>           Enable support for modeling a subset of weak memory, which allows
>           detecting a subset of data races due to missing memory barriers.
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index d14f20ef1db1..efa4c060ff4e 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2453,16 +2453,6 @@ static bool is_profiling_func(const char *name)
>         if (!strncmp(name, "__sanitizer_cov_", 16))
>                 return true;
>
> -       /*
> -        * Some compilers currently do not remove __tsan_func_entry/exit nor
> -        * __tsan_atomic_signal_fence (used for barrier instrumentation) with
> -        * the __no_sanitize_thread attribute, remove them. Once the kernel's
> -        * minimum Clang version is 14.0, this can be removed.
> -        */
> -       if (!strncmp(name, "__tsan_func_", 12) ||
> -           !strcmp(name, "__tsan_atomic_signal_fence"))
> -               return true;
> -
>         return false;
>  }
>
>
> --
> 2.50.1
>
Re: [PATCH 09/10] objtool: Drop noinstr hack for KCSAN_WEAK_MEMORY
Posted by Peter Zijlstra 1 month, 2 weeks ago
On Mon, Aug 18, 2025 at 11:57:25AM -0700, Nathan Chancellor wrote:
> Now that the minimum supported version of LLVM for building the kernel
> has been bumped to 15.0.0, __no_kcsan will always ensure that the thread
> sanitizer functions are not generated, so remove the check for tsan
> functions in is_profiling_func() and the always true depends and
> unnecessary select lines in KCSAN_WEAK_MEMORY.
> 
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>

Acked-by: Peter Zijlstra (Intel) <peterz@infraded.org>