mbox series

[v3,0/5] powerpc: Add KCSAN support

Message ID 20230206021801.105268-1-rmclure@linux.ibm.com (mailing list archive)
Headers show
Series powerpc: Add KCSAN support | expand

Message

Rohan McLure Feb. 6, 2023, 2:17 a.m. UTC
Add Kernel Concurrency Sanitiser support for PPC64. Doing so involves
exclusion of a number of compilation units from instrumentation, as was
done with KASAN.

KCSAN uses watchpoints on memory accesses to enforce the semantics of
the Linux kernel memory model, notifying the user of observed data races
which have not been declared to be intended in source through the
data_race() macro, in order to remove false positives.

A number of such race conditions are identified. This patch series
provides support for the instrumentation, with bug fixes as well as
removal of false positives to be issued in future patches.

v3: Restrict support to PPC64 as kcsan code expects support for
__atomic* builtins for 64-bit atomic types.

v2: Implement __smp_mb() in terms of __mb() to avoid multiple calls to
kcsan_mb().
Link: https://lore.kernel.org/linuxppc-dev/20230201043438.1301212-4-rmclure@linux.ibm.com/

v1: https://lore.kernel.org/linuxppc-dev/20230131234859.1275125-1-rmclure@linux.ibm.com/

Rohan McLure (5):
  powerpc: kcsan: Add exclusions from instrumentation
  powerpc: kcsan: Exclude udelay to prevent recursive instrumentation
  powerpc: kcsan: Memory barriers semantics
  powerpc: kcsan: Prevent recursive instrumentation with IRQ
    save/restores
  powerpc: kcsan: Add KCSAN Support

 arch/powerpc/Kconfig               |  1 +
 arch/powerpc/include/asm/barrier.h | 12 ++++++------
 arch/powerpc/kernel/Makefile       | 10 ++++++++++
 arch/powerpc/kernel/irq_64.c       |  6 +++---
 arch/powerpc/kernel/time.c         |  4 ++--
 arch/powerpc/kernel/trace/Makefile |  1 +
 arch/powerpc/kernel/vdso/Makefile  |  1 +
 arch/powerpc/lib/Makefile          |  2 ++
 arch/powerpc/purgatory/Makefile    |  1 +
 arch/powerpc/xmon/Makefile         |  1 +
 10 files changed, 28 insertions(+), 11 deletions(-)

Comments

Christophe Leroy Feb. 6, 2023, 8:12 a.m. UTC | #1
Le 06/02/2023 à 03:17, Rohan McLure a écrit :
> Add Kernel Concurrency Sanitiser support for PPC64. Doing so involves
> exclusion of a number of compilation units from instrumentation, as was
> done with KASAN.
> 
> KCSAN uses watchpoints on memory accesses to enforce the semantics of
> the Linux kernel memory model, notifying the user of observed data races
> which have not been declared to be intended in source through the
> data_race() macro, in order to remove false positives.
> 
> A number of such race conditions are identified. This patch series
> provides support for the instrumentation, with bug fixes as well as
> removal of false positives to be issued in future patches.
> 
> v3: Restrict support to PPC64 as kcsan code expects support for
> __atomic* builtins for 64-bit atomic types.

I see no reason to drop support for PPC32.

See commit 725aea873261 ("xtensa: enable KCSAN")
xtensa is a 32 bits architecture, they have implemented stubs for 64-bit 
atomics.

Maybe those stubs should be made generic by moving them into 
kernel/kcsan/ and building them for all 32 bit architectures.

Christophe


> 
> v2: Implement __smp_mb() in terms of __mb() to avoid multiple calls to
> kcsan_mb().
> Link: https://lore.kernel.org/linuxppc-dev/20230201043438.1301212-4-rmclure@linux.ibm.com/
> 
> v1: https://lore.kernel.org/linuxppc-dev/20230131234859.1275125-1-rmclure@linux.ibm.com/
> 
> Rohan McLure (5):
>    powerpc: kcsan: Add exclusions from instrumentation
>    powerpc: kcsan: Exclude udelay to prevent recursive instrumentation
>    powerpc: kcsan: Memory barriers semantics
>    powerpc: kcsan: Prevent recursive instrumentation with IRQ
>      save/restores
>    powerpc: kcsan: Add KCSAN Support
> 
>   arch/powerpc/Kconfig               |  1 +
>   arch/powerpc/include/asm/barrier.h | 12 ++++++------
>   arch/powerpc/kernel/Makefile       | 10 ++++++++++
>   arch/powerpc/kernel/irq_64.c       |  6 +++---
>   arch/powerpc/kernel/time.c         |  4 ++--
>   arch/powerpc/kernel/trace/Makefile |  1 +
>   arch/powerpc/kernel/vdso/Makefile  |  1 +
>   arch/powerpc/lib/Makefile          |  2 ++
>   arch/powerpc/purgatory/Makefile    |  1 +
>   arch/powerpc/xmon/Makefile         |  1 +
>   10 files changed, 28 insertions(+), 11 deletions(-)
>
Michael Ellerman Feb. 15, 2023, 12:41 p.m. UTC | #2
On Mon, 6 Feb 2023 13:17:56 +1100, Rohan McLure wrote:
> Add Kernel Concurrency Sanitiser support for PPC64. Doing so involves
> exclusion of a number of compilation units from instrumentation, as was
> done with KASAN.
> 
> KCSAN uses watchpoints on memory accesses to enforce the semantics of
> the Linux kernel memory model, notifying the user of observed data races
> which have not been declared to be intended in source through the
> data_race() macro, in order to remove false positives.
> 
> [...]

Applied to powerpc/next.

[1/5] powerpc: kcsan: Add exclusions from instrumentation
      https://git.kernel.org/powerpc/c/2fb857bc9f9e106439017ed323f522cc785395bb
[2/5] powerpc: kcsan: Exclude udelay to prevent recursive instrumentation
      https://git.kernel.org/powerpc/c/2a7ce82dc46c591c9244057d89a6591c9639b9b9
[3/5] powerpc: kcsan: Memory barriers semantics
      https://git.kernel.org/powerpc/c/b6e259297a6bffb882d55715284bb5219eefda42
[4/5] powerpc: kcsan: Prevent recursive instrumentation with IRQ save/restores
      https://git.kernel.org/powerpc/c/4f8e09106f6e457c6e9a4ce597fa9ae2bda032c3
[5/5] powerpc: kcsan: Add KCSAN Support
      https://git.kernel.org/powerpc/c/6f0926c00565a91f3bd7ca1aa05db307daed5e0f

cheers