Skip to contentSkip to conversation

Extend KCSAN to all powerpc

PATCH Applied Christophe Leroy 5 participants 10 messages May 12, 2023 – Jul 3, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Extend KCSAN to all powerpc

This series enables KCSAN on all powerpc.

To do this, a fix is required to KCSAN core.

Once that fix is done, the stubs can also be removed from xtensa.

It would be nice if patch 1 could go in v6.4 as a fix, then patches 2 and 3 could be handled separately in each architecture in next cycle.

Christophe Leroy (2):
kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures
xtensa: Remove 64 bits atomic builtins stubs

Rohan McLure (1):
powerpc/{32,book3e}: kcsan: Extend KCSAN Support

 arch/powerpc/Kconfig          |  2 +-
 arch/xtensa/lib/Makefile      |  2 --
 arch/xtensa/lib/kcsan-stubs.c | 54 -----------------------------------
 kernel/kcsan/core.c           |  2 ++
 4 files changed, 3 insertions(+), 57 deletions(-)
 delete mode 100644 arch/xtensa/lib/kcsan-stubs.c
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/3 kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures

Activating KCSAN on a 32 bits architecture leads to the following link-time failure:

LD .tmp_vmlinux.kallsyms1
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_load':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_load_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_store':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_store_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_exchange':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_add':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_add_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_sub':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_sub_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_and':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_and_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_or':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_or_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_xor':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_xor_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_nand':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_nand_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_strong':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_weak':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_val':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'

32 bits architectures don't have 64 bits atomic builtins. Only include DEFINE_TSAN_ATOMIC_OPS(64) on 64 bits architectures.

Fixes 0f8ad5f2e934 ("kcsan: Add support for atomic builtins")
---
 kernel/kcsan/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/kcsan/core.c +2 -0
index 5a60cc52adc0..8a7baf4e332e 100644
@@ -1270,7 +1270,9 @@ static __always_inline void kcsan_atomic_builtin_memorder(int memorder)
 DEFINE_TSAN_ATOMIC_OPS(8);
 DEFINE_TSAN_ATOMIC_OPS(16);
 DEFINE_TSAN_ATOMIC_OPS(32);
+#ifdef CONFIG_64BIT
 DEFINE_TSAN_ATOMIC_OPS(64);
+#endif
 
 void __tsan_atomic_thread_fence(int memorder);
 void __tsan_atomic_thread_fence(int memorder)
Signature · 1 line
2.40.1
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures

Quoted 30 lines · Christophe Leroy

Activating KCSAN on a 32 bits architecture leads to the following link-time failure:

LD .tmp_vmlinux.kallsyms1
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_load':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_load_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_store':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_store_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_exchange':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_add':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_add_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_sub':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_sub_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_and':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_and_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_or':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_or_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_xor':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_xor_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_nand':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_nand_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_strong':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_weak':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_val':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'

Quoted 6 lines

32 bits architectures don't have 64 bits atomic builtins. Only include DEFINE_TSAN_ATOMIC_OPS(64) on 64 bits architectures.

Fixes 0f8ad5f2e934 ("kcsan: Add support for atomic builtins")

Do you have your own tree to take this through with the other patches?

Quoted 21 lines
---
 kernel/kcsan/core.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/kcsan/core.c +2 -1
index 5a60cc52adc0..8a7baf4e332e 100644
@@ -1270,7 +1270,9 @@ static __always_inline void kcsan_atomic_builtin_memorder(int memorder)
 DEFINE_TSAN_ATOMIC_OPS(8);
 DEFINE_TSAN_ATOMIC_OPS(16);
 DEFINE_TSAN_ATOMIC_OPS(32);
+#ifdef CONFIG_64BIT
 DEFINE_TSAN_ATOMIC_OPS(64);
+#endif
 
 void __tsan_atomic_thread_fence(int memorder);
 void __tsan_atomic_thread_fence(int memorder)
--

2.40.1

#3 lore raw

Re: [PATCH 1/3] kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures

Le 12/05/2023 à 18:09, Marco Elver a écrit :

Quoted 35 lines
Quoted 33 lines · Christophe Leroy

Activating KCSAN on a 32 bits architecture leads to the following link-time failure:

LD .tmp_vmlinux.kallsyms1
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_load':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_load_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_store':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_store_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_exchange':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_add':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_add_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_sub':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_sub_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_and':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_and_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_or':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_or_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_xor':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_xor_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_fetch_nand':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_fetch_nand_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_strong':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_weak':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_compare_exchange_val':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_compare_exchange_8'

32 bits architectures don't have 64 bits atomic builtins. Only include DEFINE_TSAN_ATOMIC_OPS(64) on 64 bits architectures.

Quoted 7 lines
Quoted 3 lines
Fixes 0f8ad5f2e934 ("kcsan: Add support for atomic builtins")

Do you have your own tree to take this through with the other patches?

I don't have my own tree but I guess that it can be taken by Michael for 6.5 via powerpc tree with acks from you and Max.

Michael is that ok for you ?

Christophe

#4 lore raw

Re: [PATCH 1/3] kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures

Quoted 12 lines · Christophe Leroy

Le 12/05/2023 à 18:09, Marco Elver a écrit :

Quoted 11 lines
Quoted 9 lines · Christophe Leroy

Activating KCSAN on a 32 bits architecture leads to the following link-time failure:

LD .tmp_vmlinux.kallsyms1
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_load':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_load_8'
powerpc64-linux-ld: kernel/kcsan/core.o: in function `__tsan_atomic64_store':
kernel/kcsan/core.c:1273: undefined reference to `__atomic_store_8'

...

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

32 bits architectures don't have 64 bits atomic builtins. Only include DEFINE_TSAN_ATOMIC_OPS(64) on 64 bits architectures.

Fixes 0f8ad5f2e934 ("kcsan: Add support for atomic builtins")
Quoted 8 lines
Quoted 3 lines

Do you have your own tree to take this through with the other patches?

I don't have my own tree but I guess that it can be taken by Michael for 6.5 via powerpc tree with acks from you and Max.

Michael is that ok for you ?

Yeah I can take it.

cheers

#5 lore raw

PATCH 2/3 powerpc/{32,book3e}: kcsan: Extend KCSAN Support

In reply to Christophe Leroy

From: Rohan McLure <[email protected]>

Enable HAVE_ARCH_KCSAN on all powerpc platforms, permitting use of the kernel concurrency sanitiser through the CONFIG_KCSAN_* kconfig options.

Boots and passes selftests on 32-bit and 64-bit platforms. See documentation in Documentation/dev-tools/kcsan.rst for more information.

---
 arch/powerpc/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/Kconfig +1 -1
index 539d1f03ff42..2f6af3cb75d6 100644
@@ -211,7 +211,7 @@ config PPC
 	select HAVE_ARCH_KASAN			if PPC_RADIX_MMU
 	select HAVE_ARCH_KASAN			if PPC_BOOK3E_64
 	select HAVE_ARCH_KASAN_VMALLOC		if HAVE_ARCH_KASAN
-	select HAVE_ARCH_KCSAN            	if PPC_BOOK3S_64
+	select HAVE_ARCH_KCSAN
 	select HAVE_ARCH_KFENCE			if ARCH_SUPPORTS_DEBUG_PAGEALLOC
 	select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET
 	select HAVE_ARCH_WITHIN_STACK_FRAMES
Signature · 1 line
2.40.1
#6 lore raw

PATCH 3/3 xtensa: Remove 64 bits atomic builtins stubs

In reply to Christophe Leroy

The stubs were provided by commit 725aea873261 ("xtensa: enable KCSAN") to make linker happy allthought they are not meant to be used at all.

KCSAN core has been fixed to not require them anymore on 32 bits architectures.

Then they can be removed.

---
 arch/xtensa/lib/Makefile      |  2 --
 arch/xtensa/lib/kcsan-stubs.c | 54 -----------------------------------
 2 files changed, 56 deletions(-)
 delete mode 100644 arch/xtensa/lib/kcsan-stubs.c
arch/xtensa/lib/Makefile +0 -2
index 7ecef0519a27..23c22411d1d9 100644
@@ -8,5 +8,3 @@ lib-y	+= memcopy.o memset.o checksum.o \
 	   divsi3.o udivsi3.o modsi3.o umodsi3.o mulsi3.o umulsidi3.o \
 	   usercopy.o strncpy_user.o strnlen_user.o
 lib-$(CONFIG_PCI) += pci-auto.o
-lib-$(CONFIG_KCSAN) += kcsan-stubs.o
-KCSAN_SANITIZE_kcsan-stubs.o := n
arch/xtensa/lib/kcsan-stubs.c deleted +0 -54

54 lines not on this page · raw message

Signature · 1 line
2.40.1
maintainer Acked-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] xtensa: Remove 64 bits atomic builtins stubs

Quoted 7 lines · Christophe Leroy

The stubs were provided by commit 725aea873261 ("xtensa: enable KCSAN") to make linker happy allthought they are not meant to be used at all.

KCSAN core has been fixed to not require them anymore on 32 bits architectures.

Quoted 8 lines

Then they can be removed.

---
 arch/xtensa/lib/Makefile      |  2 --
 arch/xtensa/lib/kcsan-stubs.c | 54 -----------------------------------
 2 files changed, 56 deletions(-)
 delete mode 100644 arch/xtensa/lib/kcsan-stubs.c
Signature · 2 lines
Thanks.
-- Max
maintainer Acked-by on the v1 series
#8 lore raw
In reply to Christophe Leroy
Quoted 10 lines · Christophe Leroy

This series enables KCSAN on all powerpc.

To do this, a fix is required to KCSAN core.

Once that fix is done, the stubs can also be removed from xtensa.

It would be nice if patch 1 could go in v6.4 as a fix, then patches 2 and 3 could be handled separately in each architecture in next cycle.

Quoted 6 lines

Christophe Leroy (2):
kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures
xtensa: Remove 64 bits atomic builtins stubs

Rohan McLure (1):
powerpc/{32,book3e}: kcsan: Extend KCSAN Support

#9 lore raw
In reply to Christophe Leroy
Quoted 10 lines · Christophe Leroy

This series enables KCSAN on all powerpc.

To do this, a fix is required to KCSAN core.

Once that fix is done, the stubs can also be removed from xtensa.

It would be nice if patch 1 could go in v6.4 as a fix, then patches 2 and 3 could be handled separately in each architecture in next cycle.

[...]

Applied to powerpc/next.

[1/3] kcsan: Don't expect 64 bits atomic builtins from 32 bits architectures

      https://git.kernel.org/powerpc/c/353e7300a1db928e427462f2745f9a2cd1625b3d
[2/3] powerpc/{32,book3e}: kcsan: Extend KCSAN Support
      https://git.kernel.org/powerpc/c/95567f46b4d20c047750a5e3029461afcdc67697
[3/3] xtensa: Remove 64 bits atomic builtins stubs
      https://git.kernel.org/powerpc/c/bcea4f7a70dc800e769ef02d8c3bc4df357ed893

cheers