Catching concurrency bugs with KCSAN
The Kernel Concurrency Sanitizer (KCSAN) is a powerful kernel framework for helping catch data races within the Linux kernel (and modules). It was merged into the kernel in the 5.8 series (Aug 2020). It currently works on the x86_64 platform with support for ARM64 being very recent (the 5.17 kernel, March 2022).
What KCSAN does, in a nutshell
KCSAN figures out data races (if you haven't already, please first read this section: What exactly is a data race?) and reports them. In a nutshell, KCSAN treats all aligned writes up to the processor word size as atomic (regardless of whether they're plain or marked accesses). In effect, KCSAN works by checking for unmarked (or plain) reads that race with these writes (that is, any write to the same address where the unmarked read occurred)!
KCSAN is essentially a robot that (with the help of a syzbot instance), continuously scans the kernel's main branches, setting up watchpoints on...