[PATCH 0/3] Extend KCSAN to all powerpc

0 views
Skip to first unread message

Christophe Leroy

unread,
May 12, 2023, 11:31:30 AM5/12/23
to Marco Elver, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, Christophe Leroy, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
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

--
2.40.1

Christophe Leroy

unread,
May 12, 2023, 11:31:38 AM5/12/23
to Marco Elver, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, Christophe Leroy, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
From: Rohan McLure <rmc...@linux.ibm.com>

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.

Signed-off-by: Rohan McLure <rmc...@linux.ibm.com>
Signed-off-by: Christophe Leroy <christop...@csgroup.eu>
---
arch/powerpc/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 539d1f03ff42..2f6af3cb75d6 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
--
2.40.1

Christophe Leroy

unread,
May 12, 2023, 11:31:38 AM5/12/23
to Marco Elver, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, Christophe Leroy, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
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")
Suggested-by: Marco Elver <el...@google.com>
Signed-off-by: Christophe Leroy <christop...@csgroup.eu>
---
kernel/kcsan/core.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c
index 5a60cc52adc0..8a7baf4e332e 100644
--- a/kernel/kcsan/core.c
+++ b/kernel/kcsan/core.c
@@ -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

Christophe Leroy

unread,
May 12, 2023, 11:31:40 AM5/12/23
to Marco Elver, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, Christophe Leroy, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
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.

Signed-off-by: Christophe Leroy <christop...@csgroup.eu>
---
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

diff --git a/arch/xtensa/lib/Makefile b/arch/xtensa/lib/Makefile
index 7ecef0519a27..23c22411d1d9 100644
--- a/arch/xtensa/lib/Makefile
+++ b/arch/xtensa/lib/Makefile
@@ -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
diff --git a/arch/xtensa/lib/kcsan-stubs.c b/arch/xtensa/lib/kcsan-stubs.c
deleted file mode 100644
index 2b08faa62b86..000000000000
--- a/arch/xtensa/lib/kcsan-stubs.c
+++ /dev/null
@@ -1,54 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-#include <linux/bug.h>
-#include <linux/types.h>
-
-void __atomic_store_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_load_8(const volatile void *p, int i)
-{
- BUG();
-}
-
-u64 __atomic_exchange_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-bool __atomic_compare_exchange_8(volatile void *p1, void *p2, u64 v, bool b, int i1, int i2)
-{
- BUG();
-}
-
-u64 __atomic_fetch_add_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_fetch_sub_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_fetch_and_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_fetch_or_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_fetch_xor_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
-
-u64 __atomic_fetch_nand_8(volatile void *p, u64 v, int i)
-{
- BUG();
-}
--
2.40.1

Marco Elver

unread,
May 12, 2023, 12:10:26 PM5/12/23
to Christophe Leroy, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
Reviewed-by: Marco Elver <el...@google.com>

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

Marco Elver

unread,
May 12, 2023, 12:23:12 PM5/12/23
to Christophe Leroy, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, Max Filippov, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
On Fri, 12 May 2023 at 17:31, Christophe Leroy
<christop...@csgroup.eu> wrote:
>
> 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

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

Max Filippov

unread,
May 12, 2023, 12:38:35 PM5/12/23
to Christophe Leroy, Marco Elver, Dmitry Vyukov, Paul E. McKenney, Michael Ellerman, Nicholas Piggin, Chris Zankel, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
On Fri, May 12, 2023 at 8:31 AM Christophe Leroy
<christop...@csgroup.eu> wrote:
>
> 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.
>
> Signed-off-by: Christophe Leroy <christop...@csgroup.eu>
> ---
> 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

Acked-by: Max Filippov <jcmv...@gmail.com>

--
Thanks.
-- Max

Christophe Leroy

unread,
May 12, 2023, 2:39:14 PM5/12/23
to Marco Elver, Michael Ellerman, Dmitry Vyukov, Paul E. McKenney, Nicholas Piggin, Chris Zankel, Max Filippov, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
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

Michael Ellerman

unread,
Jun 9, 2023, 8:55:59 AM6/9/23
to Christophe Leroy, Marco Elver, Dmitry Vyukov, Paul E. McKenney, Nicholas Piggin, Chris Zankel, Max Filippov, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
Christophe Leroy <christop...@csgroup.eu> writes:
> Le 12/05/2023 à 18:09, Marco Elver a écrit :
>> On Fri, 12 May 2023 at 17:31, Christophe Leroy
>> <christop...@csgroup.eu> wrote:
>>>
>>> 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'
...
>>>
>>> 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")
>>> Suggested-by: Marco Elver <el...@google.com>
>>> Signed-off-by: Christophe Leroy <christop...@csgroup.eu>
>>
>> Reviewed-by: Marco Elver <el...@google.com>
>>
>> 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

Michael Ellerman

unread,
Jul 3, 2023, 1:34:36 AM7/3/23
to Marco Elver, Dmitry Vyukov, Paul E. McKenney, Nicholas Piggin, Chris Zankel, Max Filippov, Christophe Leroy, linux-...@vger.kernel.org, linuxp...@lists.ozlabs.org, kasa...@googlegroups.com, Rohan McLure
On Fri, 12 May 2023 17:31:16 +0200, Christophe Leroy wrote:
> 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
Reply all
Reply to author
Forward
0 new messages