[PATCH] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'

Nathan Chancellor posted 1 patch 3 months, 2 weeks ago
lib/Kconfig.kmsan | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
Posted by Nathan Chancellor 3 months, 2 weeks ago
Commit 5ff8c11775c7 ("KMSAN: Remove tautological checks") changed
CONFIG_HAVE_KMSAN_COMPILER from a dynamic check for
'-fsanitize=kernel-memory' to just being true for CONFIG_CC_IS_CLANG.
This missed the fact that not all architectures supported
'-fsanitize=kernel-memory' at the same time. For example, SystemZ / s390
gained support for KMSAN in clang-18 [1], so builds with clang-15
through clang-17 can select KMSAN but they error with:

  clang-16: error: unsupported option '-fsanitize=kernel-memory' for target 's390x-unknown-linux-gnu'

Restore the cc-option check for '-fsanitize=kernel-memory' to make sure
the compiler target properly supports '-fsanitize=kernel-memory'. The
check for '-msan-disable-checks=1' does not need to be restored because
all supported clang versions for building the kernel support it.

Fixes: 5ff8c11775c7 ("KMSAN: Remove tautological checks")
Link: https://github.com/llvm/llvm-project/commit/a3e56a8792ffaf3a3d3538736e1042b8db45ab89 [1]
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202510220236.AVuXXCYy-lkp@intel.com/
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
I plan to take this via kbuild-fixes for 6.18-rc3 or -rc4.
---
 lib/Kconfig.kmsan | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Kconfig.kmsan b/lib/Kconfig.kmsan
index 7251b6b59e69..cae1ddcc18e1 100644
--- a/lib/Kconfig.kmsan
+++ b/lib/Kconfig.kmsan
@@ -3,7 +3,7 @@ config HAVE_ARCH_KMSAN
 	bool
 
 config HAVE_KMSAN_COMPILER
-	def_bool CC_IS_CLANG
+	def_bool $(cc-option,-fsanitize=kernel-memory)
 
 config KMSAN
 	bool "KMSAN: detector of uninitialized values use"

---
base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
change-id: 20251023-fix-kmsan-check-s390-clang-190d37bbcff3

Best regards,
--  
Nathan Chancellor <nathan@kernel.org>
Re: [PATCH] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
Posted by Nathan Chancellor 3 months, 2 weeks ago
On Thu, 23 Oct 2025 21:01:29 +0200, Nathan Chancellor wrote:
> Commit 5ff8c11775c7 ("KMSAN: Remove tautological checks") changed
> CONFIG_HAVE_KMSAN_COMPILER from a dynamic check for
> '-fsanitize=kernel-memory' to just being true for CONFIG_CC_IS_CLANG.
> This missed the fact that not all architectures supported
> '-fsanitize=kernel-memory' at the same time. For example, SystemZ / s390
> gained support for KMSAN in clang-18 [1], so builds with clang-15
> through clang-17 can select KMSAN but they error with:
> 
> [...]

Applied, thanks!

[1/1] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
      https://git.kernel.org/kbuild/c/a16758f0142ab

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>
Re: [PATCH] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
Posted by Nathan Chancellor 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 11:54:35PM +0100, Nathan Chancellor wrote:
> On Thu, 23 Oct 2025 21:01:29 +0200, Nathan Chancellor wrote:
> > Commit 5ff8c11775c7 ("KMSAN: Remove tautological checks") changed
> > CONFIG_HAVE_KMSAN_COMPILER from a dynamic check for
> > '-fsanitize=kernel-memory' to just being true for CONFIG_CC_IS_CLANG.
> > This missed the fact that not all architectures supported
> > '-fsanitize=kernel-memory' at the same time. For example, SystemZ / s390
> > gained support for KMSAN in clang-18 [1], so builds with clang-15
> > through clang-17 can select KMSAN but they error with:
> > 
> > [...]
> 
> Applied, thanks!
> 
> [1/1] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
>       https://git.kernel.org/kbuild/c/a16758f0142ab

Whoops, sent the applied message for the wrong change... This is going
to be in kbuild-fixes as https://git.kernel.org/kbuild/c/3423b2866797c
for -next testing but I will adjust it for any tags I receive in the
next few days.

Cheers,
Nathan
Re: [PATCH] KMSAN: Restore dynamic check for '-fsanitize=kernel-memory'
Posted by Nicolas Schier 3 months, 2 weeks ago
On Thu, Oct 23, 2025 at 09:01:29PM +0200, Nathan Chancellor wrote:
> Commit 5ff8c11775c7 ("KMSAN: Remove tautological checks") changed
> CONFIG_HAVE_KMSAN_COMPILER from a dynamic check for
> '-fsanitize=kernel-memory' to just being true for CONFIG_CC_IS_CLANG.
> This missed the fact that not all architectures supported
> '-fsanitize=kernel-memory' at the same time. For example, SystemZ / s390
> gained support for KMSAN in clang-18 [1], so builds with clang-15
> through clang-17 can select KMSAN but they error with:
> 
>   clang-16: error: unsupported option '-fsanitize=kernel-memory' for target 's390x-unknown-linux-gnu'
> 
> Restore the cc-option check for '-fsanitize=kernel-memory' to make sure
> the compiler target properly supports '-fsanitize=kernel-memory'. The
> check for '-msan-disable-checks=1' does not need to be restored because
> all supported clang versions for building the kernel support it.
> 
> Fixes: 5ff8c11775c7 ("KMSAN: Remove tautological checks")
> Link: https://github.com/llvm/llvm-project/commit/a3e56a8792ffaf3a3d3538736e1042b8db45ab89 [1]
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/r/202510220236.AVuXXCYy-lkp@intel.com/
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> I plan to take this via kbuild-fixes for 6.18-rc3 or -rc4.
> ---
>  lib/Kconfig.kmsan | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/Kconfig.kmsan b/lib/Kconfig.kmsan
> index 7251b6b59e69..cae1ddcc18e1 100644
> --- a/lib/Kconfig.kmsan
> +++ b/lib/Kconfig.kmsan
> @@ -3,7 +3,7 @@ config HAVE_ARCH_KMSAN
>  	bool
>  
>  config HAVE_KMSAN_COMPILER
> -	def_bool CC_IS_CLANG
> +	def_bool $(cc-option,-fsanitize=kernel-memory)
>  
>  config KMSAN
>  	bool "KMSAN: detector of uninitialized values use"
> 
> ---
> base-commit: 211ddde0823f1442e4ad052a2f30f050145ccada
> change-id: 20251023-fix-kmsan-check-s390-clang-190d37bbcff3
> 
> Best regards,
> --  
> Nathan Chancellor <nathan@kernel.org>
> 

Thanks!

Acked-by: Nicolas Schier <nsc@kernel.org>


-- 
Nicolas