Add Kernel Concurrency Sanitizer (KCSAN)
Subsystems (19)
Marco Elver
maintainerv4 cover Add Kernel Concurrency Sanitizer (KCSAN)
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.com
The current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsan
We want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/
Race conditions vs. data races
------------------------------
Race conditions are logic bugs, where unexpected interleaving of racing concurrent operations result in an erroneous state.
Data races on the other hand are defined at the *memory model/language level*. Many data races are also harmful race conditions, which a tool like KCSAN reports! However, not all data races are race conditions and vice-versa. KCSAN's intent is to report data races according to the LKMM. A data race detector can only work at the memory model/language level.
Deeper analysis, to find high-level race conditions only, requires conveying the intended kernel logic to a tool. This requires (1) the developer writing a specification or model of their code, and then (2) the tool verifying that the implementation matches. This has been done for small bits of code using model checkers and other formal methods, but does not scale to the level of what can be covered with a dynamic analysis based data race detector such as KCSAN.
For reasons outlined in [1, 2], data races can be much more subtle, but can cause no less harm than high-level race conditions.
Changelog
---------
v4:
* Major changes:
- Optimizations resulting in performance improvement of 33% (on microbenchmark).
- Deal with nested interrupts for atomic_next.
- Simplify report.c (removing double-locking as well), in preparation for KCSAN_REPORT_VALUE_CHANGE_ONLY.
- Add patch to introduce "data_race(expr)" macro.
- Introduce KCSAN_REPORT_VALUE_CHANGE_ONLY option for further filtering of data
races: if a conflicting write was observed via a watchpoint, only report the data race if a value change was observed as well. The option will be enabled by default on syzbot. (rcu-functions will be excluded from this filter at request of Paul McKenney.) Context:
http://lkml.kernel.org/r/CANpmjNOepvb6+zJmDePxj21n2rctM4Sp4rJ66x_J-L1UmNK54A@mail.gmail.com
v3: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Add microbenchmark.
- Add instruction watchpoint skip randomization.
- Refactor API and core runtime fast-path and slow-path. Compared to the previous version, with a default config and benchmarked using the added microbenchmark, this version is 3.8x faster.
- Make __tsan_unaligned __alias of generic accesses.
- Rename kcsan_{begin,end}_atomic -> kcsan_{nestable,flat}_atomic_{begin,end}
- For filter list in debugfs.c use kmalloc+krealloc instead of kvmalloc.
- Split Documentation into separate patch.
v2: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Replace kcsan_check_access(.., {true, false}) with kcsan_check_{read,write}.
- Change atomic-instrumented.h to use __atomic_check_{read,write}.
- Use common struct kcsan_ctx in task_struct and for per-CPU interrupt contexts.
v1: http://lkml.kernel.org/r/[email protected]
Marco Elver (10):
kcsan: Add Kernel Concurrency Sanitizer infrastructure include/linux/compiler.h: Introduce data_race(expr) macro
kcsan: Add Documentation entry in dev-tools objtool, kcsan: Add KCSAN runtime functions to whitelist build, kcsan: Add KCSAN build exceptions
seqlock, kcsan: Add annotations for KCSAN
seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier asm-generic, kcsan: Add KCSAN instrumentation for bitops locking/atomics, kcsan: Add KCSAN instrumentation x86, kcsan: Enable KCSAN for x86
Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/kcsan.rst | 256 +++++++++ MAINTAINERS | 11 + Makefile | 3 +- arch/x86/Kconfig | 1 + arch/x86/boot/Makefile | 2 + arch/x86/boot/compressed/Makefile | 2 + arch/x86/entry/vdso/Makefile | 3 + arch/x86/include/asm/bitops.h | 6 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/cpu/Makefile | 3 + arch/x86/lib/Makefile | 4 + arch/x86/mm/Makefile | 4 + arch/x86/purgatory/Makefile | 2 + arch/x86/realmode/Makefile | 3 + arch/x86/realmode/rm/Makefile | 3 + drivers/firmware/efi/libstub/Makefile | 2 + include/asm-generic/atomic-instrumented.h | 393 +++++++------- include/asm-generic/bitops-instrumented.h | 18 + include/linux/compiler-clang.h | 9 + include/linux/compiler-gcc.h | 7 + include/linux/compiler.h | 57 +- include/linux/kcsan-checks.h | 97 ++++ include/linux/kcsan.h | 115 ++++ include/linux/sched.h | 4 + include/linux/seqlock.h | 51 +- init/init_task.c | 8 + init/main.c | 2 + kernel/Makefile | 6 + kernel/kcsan/Makefile | 11 + kernel/kcsan/atomic.h | 27 + kernel/kcsan/core.c | 626 ++++++++++++++++++++++ kernel/kcsan/debugfs.c | 275 ++++++++++ kernel/kcsan/encoding.h | 94 ++++ kernel/kcsan/kcsan.h | 108 ++++ kernel/kcsan/report.c | 320 +++++++++++ kernel/kcsan/test.c | 121 +++++ kernel/sched/Makefile | 6 + lib/Kconfig.debug | 2 + lib/Kconfig.kcsan | 118 ++++ lib/Makefile | 3 + mm/Makefile | 8 + scripts/Makefile.kcsan | 6 + scripts/Makefile.lib | 10 + scripts/atomic/gen-atomic-instrumented.sh | 17 +- tools/objtool/check.c | 18 + 46 files changed, 2641 insertions(+), 206 deletions(-) create mode 100644 Documentation/dev-tools/kcsan.rst create mode 100644 include/linux/kcsan-checks.h create mode 100644 include/linux/kcsan.h create mode 100644 kernel/kcsan/Makefile create mode 100644 kernel/kcsan/atomic.h create mode 100644 kernel/kcsan/core.c create mode 100644 kernel/kcsan/debugfs.c create mode 100644 kernel/kcsan/encoding.h create mode 100644 kernel/kcsan/kcsan.h create mode 100644 kernel/kcsan/report.c create mode 100644 kernel/kcsan/test.c create mode 100644 lib/Kconfig.kcsan create mode 100644 scripts/Makefile.kcsan
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 1/10 kcsan: Add Kernel Concurrency Sanitizer infrastructure
Kernel Concurrency Sanitizer (KCSAN) is a dynamic data-race detector for kernel space. KCSAN is a sampling watchpoint-based data-race detector. See the included Documentation/dev-tools/kcsan.rst for more details.
This patch adds basic infrastructure, but does not yet enable KCSAN for any architecture.
---
v4:
* Performance optimizations:
- Avoid modulo in SLOT_IDX in fast-path: introduce SLOT_IDX_FAST.
- Further fast-path optimizations by moving more code into slow-path. => 33% faster compared to v3 (using microbenchmark).
* compiler.h: Fix __no_sanitize_thread for GCC 4.9 in regular build.
* Deal with nested interrupts for atomic_next.
* Sort headers that were not sorted in new files.
* Add more comments.
* Simplify report.c (removing double-locking as well), in preparation for KCSAN_REPORT_VALUE_CHANGE_ONLY.
* Introduce KCSAN_REPORT_VALUE_CHANGE_ONLY option for further filtering of data
races: if a conflicting write was observed via a watchpoint, only report the data race if a value change was observed as well. The option will be enabled by default on syzbot. (rcu-functions will be excluded from this filter at request of Paul McKenney.) Context:
http://lkml.kernel.org/r/CANpmjNOepvb6+zJmDePxj21n2rctM4Sp4rJ66x_J-L1UmNK54A@mail.gmail.com
v3:
* Move Documentation to separate patch.
* Default init_task 'disable_count' to 0, since kcsan_enabled is sufficient.
* Fix CFLAGS for compilers that do not support all options.
* lib/Kconfig.kcsan:
- Clarify preference of config option over boot param in comment.
- Add ref to Documentation
- Remove unnecessary "KCSAN:"
* include/linux/compiler.h: Remove (const void*) casts
* include/linux/kcsan.h:
- Reword atomic nestable and flat region comment, and clarify that they are independent.
- Rename atomic_region -> atomic_nest_count.
- Rename atomic_region_flat -> in_flat_atomic.
- Rename kcsan_{begin,end}_atomic -> kcsan_{nestable,flat}_atomic_{begin,end}
* kernel/kcsan/kcsan.h:
- Capitalize enums.
- Make KCSAN_NUM_WATCHPOINTS configurable -> lib/Kconfig.kcsan.
* Make kcsan_is_atomic inlinable by turning atomic.c into atomic.h.
* kernel/kcsan/core.c (merged with previous kcsan.c):
- Make __tsan_unaligned __alias of generic accesses.
- user_access_save/restore() usage comment.
- Add instruction watchpoint skip randomization.
- Refactor API and core runtime fast-path and slow-path; check_access is now the single entry point for checking an access. Compared to the previous version, with a default config and benchmarked using the microbenchmark, this version is 3.8x faster.
* kernel/kcsan/test.c: Add more comments where appropriate.
* kernel/kcsan/report.c:
- get_thread_desc should just return "interrupt" for any interrupt.
- increase NUM_STACK_ENTRIES to 64.
* kernel/kcsan/debugfs.c
- More appropriate error codes.
- Use kmalloc+krealloc instead of kvmalloc.
- Handle kmalloc failures.
- Add debugfs based microbenchmark.
* Use '{ }' on same line where appropriate.
* Prefer IS_ENABLED instead of #ifdef.
* Use common spelling: "data-race" -> "data race"
* Other typos.
v2:
* Elaborate comment about instrumentation calls emitted by compilers.
* Replace kcsan_check_access(.., {true, false}) with kcsan_check_{read,write} for improved readability.
* Change bug title of race of unknown origin to just say "data-race in".
* Refine "Key Properties" in kcsan.rst, and mention observed slow-down.
* Add comment about safety of find_watchpoint without user_access_save.
* Remove unnecessary preempt_disable/enable and elaborate on comment why we want to disable interrupts and preemptions.
* Use common struct kcsan_ctx in task_struct and for per-CPU interrupt contexts [Suggested by Mark Rutland].
--- MAINTAINERS | 11 + Makefile | 3 +- include/linux/compiler-clang.h | 9 + include/linux/compiler-gcc.h | 7 + include/linux/compiler.h | 37 +- include/linux/kcsan-checks.h | 97 +++++ include/linux/kcsan.h | 115 ++++++ include/linux/sched.h | 4 + init/init_task.c | 8 + init/main.c | 2 + kernel/Makefile | 1 + kernel/kcsan/Makefile | 11 + kernel/kcsan/atomic.h | 27 ++ kernel/kcsan/core.c | 626 +++++++++++++++++++++++++++++++++ kernel/kcsan/debugfs.c | 275 +++++++++++++++ kernel/kcsan/encoding.h | 94 +++++ kernel/kcsan/kcsan.h | 108 ++++++ kernel/kcsan/report.c | 320 +++++++++++++++++ kernel/kcsan/test.c | 121 +++++++ lib/Kconfig.debug | 2 + lib/Kconfig.kcsan | 118 +++++++ lib/Makefile | 3 + scripts/Makefile.kcsan | 6 + scripts/Makefile.lib | 10 + 24 files changed, 2006 insertions(+), 9 deletions(-) create mode 100644 include/linux/kcsan-checks.h create mode 100644 include/linux/kcsan.h create mode 100644 kernel/kcsan/Makefile create mode 100644 kernel/kcsan/atomic.h create mode 100644 kernel/kcsan/core.c create mode 100644 kernel/kcsan/debugfs.c create mode 100644 kernel/kcsan/encoding.h create mode 100644 kernel/kcsan/kcsan.h create mode 100644 kernel/kcsan/report.c create mode 100644 kernel/kcsan/test.c create mode 100644 lib/Kconfig.kcsan create mode 100644 scripts/Makefile.kcsan
MAINTAINERS +11 -0
@@ -8848,6 +8848,17 @@ F: Documentation/kbuild/kconfig* F: scripts/kconfig/ F: scripts/Kconfig.include +KCSAN +M: Marco Elver <[email protected]> +R: Dmitry Vyukov <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/dev-tools/kcsan.rst +F: include/linux/kcsan*.h +F: kernel/kcsan/ +F: lib/Kconfig.kcsan +F: scripts/Makefile.kcsan + KDUMP M: Dave Young <[email protected]> M: Baoquan He <[email protected]>
Makefile +2 -1
@@ -478,7 +478,7 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE -export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN +export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN CFLAGS_KCSAN export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
@@ -900,6 +900,7 @@ endif include scripts/Makefile.kasan include scripts/Makefile.extrawarn include scripts/Makefile.ubsan +include scripts/Makefile.kcsan # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments KBUILD_CPPFLAGS += $(KCPPFLAGS)
include/linux/compiler-clang.h +9 -0
@@ -24,6 +24,15 @@#define __no_sanitize_address#endif +#if __has_feature (thread_sanitizer) +/* emulate gcc's __SANITIZE_THREAD__ flag */ +#define __SANITIZE_THREAD__ +#define __no_sanitize_thread \ + __attribute__((no_sanitize("thread"))) +#else +#define __no_sanitize_thread +#endif +/* * Not all versions of clang implement the the type-generic versions * of the builtin overflow checkers. Fortunately, clang implements
include/linux/compiler-gcc.h +7 -0
@@ -145,6 +145,13 @@#define __no_sanitize_address#endif +#if defined(__SANITIZE_THREAD__) &&__has_attribute (__no_sanitize_thread__) +#define __no_sanitize_thread \ + __attribute__((__noinline__)) __attribute__((no_sanitize_thread)) +#else +#define __no_sanitize_thread +#endif +#if GCC_VERSION >=50100 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1#endif
include/linux/compiler.h +29 -8
@@ -178,6 +178,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,#endif #include <uapi/linux/types.h> +#include <linux/kcsan-checks.h> #define __READ_ONCE_SIZE \ ({ \
@@ -193,12 +194,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, } \ }) -static __always_inline -void __read_once_size(const volatile void *p, void *res, int size) -{ - __READ_ONCE_SIZE; -} -#ifdef CONFIG_KASAN /* * We can't declare function 'inline' because __no_sanitize_address confilcts
@@ -207,18 +202,44 @@ void __read_once_size(const volatile void *p, void *res, int size)* '__maybe_unused' allows us to avoid defined-but-not-used warnings. */ # define __no_kasan_or_inline __no_sanitize_address notrace __maybe_unused +# define __no_sanitize_or_inline __no_kasan_or_inline#else # define __no_kasan_or_inline __always_inline#endif -static __no_kasan_or_inline +#ifdef __SANITIZE_THREAD__ +/* +* Rely on __SANITIZE_THREAD__ instead of CONFIG_KCSAN, to avoid not inlining in +* compilation units where instrumentation is disabled. +*/ +# define __no_kcsan_or_inline __no_sanitize_thread notrace __maybe_unused +# define __no_sanitize_or_inline __no_kcsan_or_inline +#else +# define __no_kcsan_or_inline __always_inline +#endif + +#ifndef __no_sanitize_or_inline +#define __no_sanitize_or_inline __always_inline +#endif + +static __no_kcsan_or_inline +void __read_once_size(const volatile void *p, void *res, int size) +{ +kcsan_check_atomic_read (p, size); + __READ_ONCE_SIZE; +} + +static __no_sanitize_or_inline void __read_once_size_nocheck(const volatile void *p, void *res, int size) { __READ_ONCE_SIZE; } -static __always_inline void __write_once_size(volatile void *p, void *res, int size) +static __no_kcsan_or_inline +void __write_once_size(volatile void *p, void *res, int size) { +kcsan_check_atomic_write (p, size); +switch (size) {case 1 : *(volatile __u8 *)p = *(__u8 *)res;break ;case 2 : *(volatile __u16 *)p = *(__u16 *)res;break ;
include/linux/kcsan-checks.h new file +97 -0
97 lines not on this page · raw message
include/linux/kcsan.h new file +115 -0
115 lines not on this page · raw message
include/linux/sched.h +4 -0
@@ -31,6 +31,7 @@#include <linux/task_io_accounting.h> #include <linux/posix-timers.h> #include <linux/rseq.h> +#include <linux/kcsan.h> /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context ;
@@ -1172,6 +1173,9 @@ struct task_struct {#ifdef CONFIG_KASAN unsigned int kasan_depth;#endif +#ifdef CONFIG_KCSAN +struct kcsan_ctx kcsan_ctx; +#endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER /* Index of current stored address in ret_stack: */
init/init_task.c +8 -0
@@ -161,6 +161,14 @@ struct task_struct init_task#ifdef CONFIG_KASAN .kasan_depth = 1,#endif +#ifdef CONFIG_KCSAN + .kcsan_ctx = { + .disable_count = 0, + .atomic_next = 0, + .atomic_nest_count = 0, + .in_flat_atomic = false, + }, +#endif #ifdef CONFIG_TRACE_IRQFLAGS .softirqs_enabled = 1,#endif
init/main.c +2 -0
@@ -93,6 +93,7 @@#include <linux/rodata_test.h> #include <linux/jump_label.h> #include <linux/mem_encrypt.h> +#include <linux/kcsan.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -779,6 +780,7 @@ asmlinkage __visible void __init start_kernel(void)acpi_subsystem_init ();arch_post_acpi_subsys_init ();sfi_init_late (); +kcsan_init ();/* Do the rest non-__init'ed, we're now alive */ arch_call_rest_init ();
kernel/Makefile +1 -0
@@ -102,6 +102,7 @@ obj-$(CONFIG_TRACEPOINTS) += trace/ obj-$(CONFIG_IRQ_WORK) += irq_work.o obj-$(CONFIG_CPU_PM) += cpu_pm.o obj-$(CONFIG_BPF) += bpf/ +obj-$(CONFIG_KCSAN) += kcsan/ obj-$(CONFIG_PERF_EVENTS) += events/
kernel/kcsan/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +KCSAN_SANITIZE := n +KCOV_INSTRUMENT := n + +CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) + +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ + $(call cc-option,-fno-stack-protector,) + +obj-y := core.o debugfs.o report.o +obj-$(CONFIG_KCSAN_SELFTEST) += test.o
kernel/kcsan/atomic.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _KERNEL_KCSAN_ATOMIC_H +#define _KERNEL_KCSAN_ATOMIC_H + +#include <linux/jiffies.h> + +/* +* Helper that returns true if access to ptr should be considered as an atomic +* access, even though it is not explicitly atomic. +* +* List all volatile globals that have been observed in races, to suppress +* data race reports between accesses to these variables. +* +* For now, we assume that volatile accesses of globals are as strong as atomic +* accesses (READ_ONCE, WRITE_ONCE cast to volatile). The situation is still not +* entirely clear, as on some architectures (Alpha) READ_ONCE/WRITE_ONCE do more +* than cast to volatile. Eventually, we hope to be able to remove this +* function. +*/ +static inline bool kcsan_is_atomic (const volatile void *ptr) +{ +/* only jiffies for now */ +return ptr == &jiffies; +} + +#endif /* _KERNEL_KCSAN_ATOMIC_H */
kernel/kcsan/core.c new file +626 -0
626 lines not on this page · raw message
kernel/kcsan/debugfs.c new file +275 -0
275 lines not on this page · raw message
kernel/kcsan/encoding.h new file +94 -0
94 lines not on this page · raw message
kernel/kcsan/kcsan.h new file +108 -0
108 lines not on this page · raw message
kernel/kcsan/report.c new file +320 -0
320 lines not on this page · raw message
kernel/kcsan/test.c new file +121 -0
121 lines not on this page · raw message
lib/Kconfig.debug +2 -0
@@ -2086,6 +2086,8 @@ source "lib/Kconfig.kgdb" source "lib/Kconfig.ubsan" +source "lib/Kconfig.kcsan" + config ARCH_HAS_DEVMEM_IS_ALLOWED bool
lib/Kconfig.kcsan new file +118 -0
118 lines not on this page · raw message
lib/Makefile +3 -0
@@ -24,6 +24,9 @@ KASAN_SANITIZE_string.o := n CFLAGS_string.o := $(call cc-option, -fno-stack-protector) endif +# Used by KCSAN while enabled, avoid recursion. +KCSAN_SANITIZE_random32.o := n + lib-y := ctype.o string.o vsprintf.o cmdline.o \ rbtree.o radix-tree.o timerqueue.o xarray.o \ idr.o extable.o \
scripts/Makefile.kcsan new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +ifdef CONFIG_KCSAN + +CFLAGS_KCSAN := -fsanitize=thread + +endif # CONFIG_KCSAN
scripts/Makefile.lib +10 -0
@@ -152,6 +152,16 @@ _c_flags += $(if $(patsubst n%,, \ $(CFLAGS_KCOV)) endif +# +# Enable KCSAN flags except some files or directories we don't want to check +# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE) +# +ifeq ($(CONFIG_KCSAN),y) +_c_flags += $(if $(patsubst n%,, \ + $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \ + $(CFLAGS_KCSAN)) +endif + # $(srctree)/$(src) for including checkin headers from generated source files # $(objtree)/$(obj) for including generated headers from checkin source files ifeq ($(KBUILD_EXTMOD),)
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
lib/Kconfig.kcsan line 8
Quoted 3 lines · Marco Elver' via kasan-dev
lib/Kconfig.kcsan new file +3
-0+menuconfig KCSAN + bool "KCSAN: watchpoint-based dynamic data race detector" + depends on HAVE_ARCH_KCSAN && !KASAN && STACKTRACE
"!KASAN" makes me sorrow. What's problem of those two?
Quoted 6 lines
lib/Kconfig.kcsan new file +6
-0+ default n + help + Kernel Concurrency Sanitizer is a dynamic data race detector, which + uses a watchpoint-based sampling approach to detect races. See + <file:Documentation/dev-tools/kcsan.rst> for more details. +
Marco Elver
maintainerRe: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 8 lines · Qian Cai
lib/Kconfig.kcsan line 8
Quoted 3 lines · Marco Elver' via kasan-dev
lib/Kconfig.kcsan new file +3
-0+menuconfig KCSAN + bool "KCSAN: watchpoint-based dynamic data race detector" + depends on HAVE_ARCH_KCSAN && !KASAN && STACKTRACE"!KASAN" makes me sorrow. What's problem of those two?
Both of them instrument memory accesses, and gcc doesn't let us combine '-fsanitize={kernel-,}address' and '-fsanitize=thread'.
Quoted 1 line
cc1: error: ‘-fsanitize=address’ and ‘-fsanitize=kernel-address’ are incompatible with ‘-fsanitize=thread’
In principle, it may be possible:
- either by updating the compiler, which we want to avoid because we'd have to convince gcc and clang to do this; I can see this being infeasible because the compiler needs to become aware (somehow propagate in the IR) of what is ASAN inline-instrumentation and what is TSAN instrumentation and not emit recursive instrumentation.
- or somehow merging the instrumentation, but, IMHO this is probably a really bad idea for various other reasons (complexity, performance, stability, etc.).
Regardless of approach, my guess is that the complexity outweighs any benefits this may provide in the end. Not only would a hypothetical kernel that combines these be extremely slow, it'd also diminish the practical value because testing and finding bugs would also be impaired due to performance.
Thanks,
-- Marco
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 9 lines · Marco Elver
Regardless of approach, my guess is that the complexity outweighs any benefits this may provide in the end. Not only would a hypothetical kernel that combines these be extremely slow, it'd also diminish the practical value because testing and finding bugs would also be impaired due to performance.
On the other hand, it is valuable for distros to be able to select both for the debug kernel variant. Performance is usually not a major concern over there and could be migrated by other means like selecting powerful systems etc.
Marco Elver
maintainerRe: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 5 lines · Qian Cai
Quoted 5 lines · Marco Elver
Quoted 7 lines
Quoted 5 lines
Regardless of approach, my guess is that the complexity outweighs any benefits this may provide in the end. Not only would a hypothetical kernel that combines these be extremely slow, it'd also diminish the practical value because testing and finding bugs would also be impaired due to performance.
On the other hand, it is valuable for distros to be able to select both for the debug kernel variant. Performance is usually not a major concern over there and could be migrated by other means like selecting powerful systems etc.
Fair enough. However, right now none of gcc nor clang would support this. It is something to revisit in future, but is certainly not something that can trivially be resolved.
Thanks,
-- Marco
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
In reply to Marco ElverQuoted 39 lines · Marco Elver' via kasan-dev
kernel/kcsan/core.c new file +36
-0+static noinline void kcsan_setup_watchpoint(const volatile void *ptr, +size_t size,bool is_write) +{ +atomic_long_t *watchpoint; +union { +u8 _1; +u16 _2; +u32 _4; +u64 _8; + } expect_value; +bool value_change = false; +unsigned long ua_flags =user_access_save (); +unsigned long irq_flags; + +/* +* Always reset kcsan_skip counter in slow-path to avoid underflow; see +* should_watch(). +*/ +reset_kcsan_skip (); + +if (!kcsan_is_enabled ()) + goto out; + +if (!check_encodable ((unsigned long )ptr, size)) { +kcsan_counter_inc (KCSAN_COUNTER_UNENCODABLE_ACCESSES ); + goto out; + } + +/* +* Disable interrupts & preemptions to avoid another thread on the same +* CPU accessing memory locations for the set up watchpoint; this is to +* avoid reporting races to e.g. CPU-local data. +* +* An alternative would be adding the source CPU to the watchpoint +* encoding, and checking that watchpoint-CPU != this-CPU. There are +* several problems with this:
kernel/kcsan/core.c line 344
Quoted 10 lines
kernel/kcsan/core.c new file +10
-0+* 1. we should avoid stealing more bits from the watchpoint encoding +* as it would affect accuracy, as well as increase performance +* overhead in the fast-path; +* 2. if we are preempted, but there *is* a genuine data race, we +* would *not* report it -- since this is the common case (vs. +* CPU-local data accesses), it makes more sense (from a data race +* detection point of view) to simply disable preemptions to ensure +* as many tasks as possible run on other CPUs. +*/ +local_irq_save (irq_flags);
Enabling KCSAN will now generate a warning during boot here.
Config (need to deselect KASAN and select KCSAN):
https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
[ 13.358813][ T0] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch [ 13.361606][ T0] Speculative Store Bypass: Vulnerable [ 13.363254][ T0] TAA: Vulnerable: Clear CPU buffers attempted, no microcode [ 13.366836][ T0] MDS: Vulnerable: Clear CPU buffers attempted, no microcode [ 13.369877][ T0] debug: unmapping init [mem 0xffffffff8dd83000-0xffffffff8dd87fff] [ 13.415028][ T1] ------------[ cut here ]------------ [ 13.416814][ T1] DEBUG_LOCKS_WARN_ON(!current->hardirqs_enabled) [ 13.416814][ T1] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:4406 check_flags.part.26+0x102/0x240 [ 13.416814][ T1] Modules linked in: [ 13.416814][ T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc2-next-20191220+ #4 [ 13.416814][ T1] Hardware name: HP ProLiant DL580 Gen9/ProLiant DL580 Gen9, BIOS U17 07/21/2016 [ 13.416814][ T1] RIP: 0010:check_flags.part.26+0x102/0x240 [ 13.416814][ T1] Code: bc 8d e8 51 a1 15 00 44 8b 05 2a a0 46 01 45 85 c0 0f 85 57 76 00 00 48 c7 c6 5d fa 7b 8d 48 c7 c7 b1 54 7b 8d e8 10 91 f5 ff <0f> 0b e9 3d 76 00 00 65 48 8b 3c 25 40 7f 01 00 e8 89 f0 ff ff e8 [ 13.416814][ T1] RSP: 0000:ffff9d3206287ce8 EFLAGS: 00010082 [ 13.416814][ T1] RAX: 0000000000000000 RBX: ffff8e5b8541e040 RCX: 0000000000000000 [ 13.416814][ T1] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 [ 13.416814][ T1] RBP: ffff9d3206287cf0 R08: 0000000000000000 R09: 0000ffff8dbcc254 [ 13.416814][ T1] R10: 0000ffffffffffff R11: 0000ffff8dbcc257 R12: 0000000000000235 [ 13.416814][ T1] R13: 0000000000000000 R14: 0000000000000246 R15: 000000000000001b [ 13.416814][ T1] FS: 0000000000000000(0000) GS:ffff8e61e3200000(0000) knlGS:0000000000000000 [ 13.416814][ T1] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 13.416814][ T1] CR2: ffff8e79f07ff000 CR3: 0000001284c0e001 CR4: 00000000003606f0 [ 13.416814][ T1] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 13.416814][ T1] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 13.416814][ T1] Call Trace: [ 13.416814][ T1] lock_is_held_type+0x66/0x160 [ 13.416814][ T1] ___might_sleep+0xc1/0x1d0 [ 13.416814][ T1] __might_sleep+0x5b/0xa0 [ 13.416814][ T1] slab_pre_alloc_hook+0x7b/0xa0 [ 13.416814][ T1] __kmalloc_node+0x60/0x300 [ 13.416814 T1] ? alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] ? topology_phys_to_logical_die+0x7e/0x180 [ 13.416814][ T1] alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] zalloc_cpumask_var+0x2a/0x40 [ 13.416814][ T1] native_smp_prepare_cpus+0x246/0x425 [ 13.416814][ T1] kernel_init_freeable+0x1b8/0x496 [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] kernel_init+0x18/0x17f [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] ret_from_fork+0x3a/0x50 [ 13.416814][ T1] irq event stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 13.416814][ T1] ---[ end trace 7d1df66da055aa92 ]--- [ 13.416814][ T1] possible reason: unannotated irqs-on. [ 13.416814][ent stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0
The other issue is that the system is unable to boot due to endless of those messages.
[ 17.976814][ T578] Reported by Kernel Concurrency Sanitizer on: [ 17.976814][ T578] CPU: 12 PID: 578 Comm: pgdatinit1 Tainted: G W 5.5.0-rc2-next-20191220+ #4 [ 17.976814][ T578] Hardware name: HP ProLiant DL580 Gen9/ProLiant DL580 Gen9, BIOS U17 07/21/2016 [ 17.976814][ T578] ================================================================== [ 17.976814][ T578] ================================================================== [ 17.976814][ T578] BUG: KCSAN: data-race in __change_page_attr / __change_page_attr [ 17.976814][ T578] [ 17.976814][ T578] write to 0xffffffff8dda0de0 of 8 bytes by task 577 on cpu 2: [ 17.976814][ T578] __change_page_attr+0xef7/0x16a0 [ 17.976814][ T578] __change_page_attr_set_clr+0xec/0x4f0 [ 17.97681pages_np+0xcc/0x100 [ 17.976814][ T578] __kernel_map_pages+0xd6/0xdb [ 17.976814][ T578] __free_pages_ok+0x1a8/0x730 [ 17.976814][ T578] __free_pages+0x51/0x90 [ 17.976814][ T578] __free_pages_core+0x1c7/0x2c0 [ 17.976814][ T578] deferred_free_range+0x59/0x8f [ 17.976814][ T578] deferred_init_maxorder+0x1d6/0x21d [ 17.976814][ T578] deferred_init_memmap+0x14a/0x1c1 [ 17.976814][ T578] kthread+0x1e0/0x200 [ 17.976814][ T578] ret_from_fork+0x3a/0x50 [ 17.976814][ T578] [ 17.976814][ T578] read to 0xffffffff8dda0de0 of 8 bytes by task 578 on cpu 12: [ 17.976814][ T578] __change_page_attr+0xed1/0x16a0 [ 17.976814][ T578] __change_page_attr_set_clr+0xec/0x4f0 [ 17.976814][ T578] __set_pages_np+0xcc/0x100 [ 17.976814][ T578] __kernel_map_pages+0xd6/0xdb [ 17.976814][ T578] __free_pages_ok+0x1a8/0x730 [ 17.976814][ T578] __free_pages+0x51/0x90 [ 17.976814][ T578] __free_pages_core+0x1c7/0x2c0 [ 17.976814][ T578] deferred_free_range+0x59/0x8f [ 17.976814][ T578] deferred_init_maxorder+0x1aa/0x21d [ 17.976814][ T578] deferred_init_memmap+0x14a/0x1c1 [ 17.976814][ T578] kthread+0x1e0/0x200 [ 17.976814][ T578] ret_from_fork+0x3a/0x50
# ./scripts/faddr2line vmlinux __change_page_attr+0xef7/0x16a0 __change_page_attr+0xef7/0x16a0: static_protections at arch/x86/mm/pat/set_memory.c:528 (inlined by) __change_page_attr at arch/x86/mm/pat/set_memory.c:1516
# ./scripts/faddr2line vmlinux __change_page_attr+0xed1/0x16a0 __change_page_attr+0xed1/0x16a0: cpa_inc_4k_install at arch/x86/mm/pat/set_memory.c:131 (inlined by) __change_page_attr at arch/x86/mm/pat/set_memory.c:1514
Quoted 12 lines
kernel/kcsan/core.c new file +12
-0+ + watchpoint =insert_watchpoint ((unsigned long )ptr, size, is_write); +if (watchpoint ==NULL ) { +/* +* Out of capacity: the size of `watchpoints`, and the frequency +* with which `should_watch()` returns true should be tweaked so +* that this case happens very rarely. +*/ +kcsan_counter_inc (KCSAN_COUNTER_NO_CAPACITY ); + goto out_unlock; + } +
Marco Elver
maintainerRe: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 53 lines · Qian Cai
Quoted 40 lines · Marco Elver' via kasan-dev
kernel/kcsan/core.c new file +36
-0+static noinline void kcsan_setup_watchpoint(const volatile void *ptr, +size_t size,bool is_write) +{ +atomic_long_t *watchpoint; +union { +u8 _1; +u16 _2; +u32 _4; +u64 _8; + } expect_value; +bool value_change = false; +unsigned long ua_flags =user_access_save (); +unsigned long irq_flags; + +/* +* Always reset kcsan_skip counter in slow-path to avoid underflow; see +* should_watch(). +*/ +reset_kcsan_skip (); + +if (!kcsan_is_enabled ()) + goto out; + +if (!check_encodable ((unsigned long )ptr, size)) { +kcsan_counter_inc (KCSAN_COUNTER_UNENCODABLE_ACCESSES ); + goto out; + } + +/* +* Disable interrupts & preemptions to avoid another thread on the same +* CPU accessing memory locations for the set up watchpoint; this is to +* avoid reporting races to e.g. CPU-local data. +* +* An alternative would be adding the source CPU to the watchpoint +* encoding, and checking that watchpoint-CPU != this-CPU. There are +* several problems with this: kernel/kcsan/core.c line 344
Quoted 10 lines
kernel/kcsan/core.c new file +10
-0+* 1. we should avoid stealing more bits from the watchpoint encoding +* as it would affect accuracy, as well as increase performance +* overhead in the fast-path; +* 2. if we are preempted, but there *is* a genuine data race, we +* would *not* report it -- since this is the common case (vs. +* CPU-local data accesses), it makes more sense (from a data race +* detection point of view) to simply disable preemptions to ensure +* as many tasks as possible run on other CPUs. +*/ +local_irq_save (irq_flags);Enabling KCSAN will now generate a warning during boot here.
Quoted 3 lines
Config (need to deselect KASAN and select KCSAN):
https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
Thanks, I'll look into KCSAN + lockdep compatibility. It's probably missing some KCSAN_SANITIZE := n in some Makefile.
Quoted 54 lines
[ 13.358813][ T0] Spectre V2 : Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch [ 13.361606][ T0] Speculative Store Bypass: Vulnerable [ 13.363254][ T0] TAA: Vulnerable: Clear CPU buffers attempted, no microcode [ 13.366836][ T0] MDS: Vulnerable: Clear CPU buffers attempted, no microcode [ 13.369877][ T0] debug: unmapping init [mem 0xffffffff8dd83000-0xffffffff8dd87fff] [ 13.415028][ T1] ------------[ cut here ]------------ [ 13.416814][ T1] DEBUG_LOCKS_WARN_ON(!current->hardirqs_enabled) [ 13.416814][ T1] WARNING: CPU: 0 PID: 1 at kernel/locking/lockdep.c:4406 check_flags.part.26+0x102/0x240 [ 13.416814][ T1] Modules linked in: [ 13.416814][ T1] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc2-next-20191220+ #4 [ 13.416814][ T1] Hardware name: HP ProLiant DL580 Gen9/ProLiant DL580 Gen9, BIOS U17 07/21/2016 [ 13.416814][ T1] RIP: 0010:check_flags.part.26+0x102/0x240 [ 13.416814][ T1] Code: bc 8d e8 51 a1 15 00 44 8b 05 2a a0 46 01 45 85 c0 0f 85 57 76 00 00 48 c7 c6 5d fa 7b 8d 48 c7 c7 b1 54 7b 8d e8 10 91 f5 ff <0f> 0b e9 3d 76 00 00 65 48 8b 3c 25 40 7f 01 00 e8 89 f0 ff ff e8 [ 13.416814][ T1] RSP: 0000:ffff9d3206287ce8 EFLAGS: 00010082 [ 13.416814][ T1] RAX: 0000000000000000 RBX: ffff8e5b8541e040 RCX: 0000000000000000 [ 13.416814][ T1] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 [ 13.416814][ T1] RBP: ffff9d3206287cf0 R08: 0000000000000000 R09: 0000ffff8dbcc254 [ 13.416814][ T1] R10: 0000ffffffffffff R11: 0000ffff8dbcc257 R12: 0000000000000235 [ 13.416814][ T1] R13: 0000000000000000 R14: 0000000000000246 R15: 000000000000001b [ 13.416814][ T1] FS: 0000000000000000(0000) GS:ffff8e61e3200000(0000) knlGS:0000000000000000 [ 13.416814][ T1] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 13.416814][ T1] CR2: ffff8e79f07ff000 CR3: 0000001284c0e001 CR4: 00000000003606f0 [ 13.416814][ T1] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 13.416814][ T1] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 [ 13.416814][ T1] Call Trace: [ 13.416814][ T1] lock_is_held_type+0x66/0x160 [ 13.416814][ T1] ___might_sleep+0xc1/0x1d0 [ 13.416814][ T1] __might_sleep+0x5b/0xa0 [ 13.416814][ T1] slab_pre_alloc_hook+0x7b/0xa0 [ 13.416814][ T1] __kmalloc_node+0x60/0x300 [ 13.416814 T1] ? alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] ? topology_phys_to_logical_die+0x7e/0x180 [ 13.416814][ T1] alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] zalloc_cpumask_var+0x2a/0x40 [ 13.416814][ T1] native_smp_prepare_cpus+0x246/0x425 [ 13.416814][ T1] kernel_init_freeable+0x1b8/0x496 [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] kernel_init+0x18/0x17f [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] ret_from_fork+0x3a/0x50 [ 13.416814][ T1] irq event stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 13.416814][ T1] ---[ end trace 7d1df66da055aa92 ]--- [ 13.416814][ T1] possible reason: unannotated irqs-on. [ 13.416814][ent stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0
Quoted 1 line
The other issue is that the system is unable to boot due to endless of those messages.
Apart from fixing the data races, I can add a feature to KCSAN to limit reporting too often (will send patch).
Quoted 40 lines
[ 17.976814][ T578] Reported by Kernel Concurrency Sanitizer on: [ 17.976814][ T578] CPU: 12 PID: 578 Comm: pgdatinit1 Tainted: G W 5.5.0-rc2-next-20191220+ #4 [ 17.976814][ T578] Hardware name: HP ProLiant DL580 Gen9/ProLiant DL580 Gen9, BIOS U17 07/21/2016 [ 17.976814][ T578] ================================================================== [ 17.976814][ T578] ================================================================== [ 17.976814][ T578] BUG: KCSAN: data-race in __change_page_attr / __change_page_attr [ 17.976814][ T578] [ 17.976814][ T578] write to 0xffffffff8dda0de0 of 8 bytes by task 577 on cpu 2: [ 17.976814][ T578] __change_page_attr+0xef7/0x16a0 [ 17.976814][ T578] __change_page_attr_set_clr+0xec/0x4f0 [ 17.97681pages_np+0xcc/0x100 [ 17.976814][ T578] __kernel_map_pages+0xd6/0xdb [ 17.976814][ T578] __free_pages_ok+0x1a8/0x730 [ 17.976814][ T578] __free_pages+0x51/0x90 [ 17.976814][ T578] __free_pages_core+0x1c7/0x2c0 [ 17.976814][ T578] deferred_free_range+0x59/0x8f [ 17.976814][ T578] deferred_init_maxorder+0x1d6/0x21d [ 17.976814][ T578] deferred_init_memmap+0x14a/0x1c1 [ 17.976814][ T578] kthread+0x1e0/0x200 [ 17.976814][ T578] ret_from_fork+0x3a/0x50 [ 17.976814][ T578] [ 17.976814][ T578] read to 0xffffffff8dda0de0 of 8 bytes by task 578 on cpu 12: [ 17.976814][ T578] __change_page_attr+0xed1/0x16a0 [ 17.976814][ T578] __change_page_attr_set_clr+0xec/0x4f0 [ 17.976814][ T578] __set_pages_np+0xcc/0x100 [ 17.976814][ T578] __kernel_map_pages+0xd6/0xdb [ 17.976814][ T578] __free_pages_ok+0x1a8/0x730 [ 17.976814][ T578] __free_pages+0x51/0x90 [ 17.976814][ T578] __free_pages_core+0x1c7/0x2c0 [ 17.976814][ T578] deferred_free_range+0x59/0x8f [ 17.976814][ T578] deferred_init_maxorder+0x1aa/0x21d [ 17.976814][ T578] deferred_init_memmap+0x14a/0x1c1 [ 17.976814][ T578] kthread+0x1e0/0x200 [ 17.976814][ T578] ret_from_fork+0x3a/0x50# ./scripts/faddr2line vmlinux __change_page_attr+0xef7/0x16a0 __change_page_attr+0xef7/0x16a0: static_protections at arch/x86/mm/pat/set_memory.c:528 (inlined by) __change_page_attr at arch/x86/mm/pat/set_memory.c:1516
Quoted 4 lines
# ./scripts/faddr2line vmlinux __change_page_attr+0xed1/0x16a0 __change_page_attr+0xed1/0x16a0: cpa_inc_4k_install at arch/x86/mm/pat/set_memory.c:131 (inlined by) __change_page_attr at arch/x86/mm/pat/set_memory.c:1514
Thanks,
-- Marco
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 6 lines · Marco Elver
Thanks, I'll look into KCSAN + lockdep compatibility. It's probably missing some
KCSAN_SANITIZE:= n in someMakefile.
Can I have a update on fixing this? It looks like more of a problem that kcsan_setup_watchpoint() will disable IRQs and then dive into the page allocator where it would complain because it might sleep.
BTW, I saw Paul sent a pull request for 5.6 but it is ugly to have everybody could trigger a deadlock (sleep function called in atomic context) like this during boot once this hits the mainline not to mention about only recently it is possible to test this feature (thanks to warning ratelimit) with the existing debugging options because it was unable to boot due to the brokenness with debug_pagealloc as mentioned in this thread, so this does sounds like it needs more soak time for the mainline to me.
0000000000000400
[ 13.416814][ T1] Call Trace: [ 13.416814][ T1] lock_is_held_type+0x66/0x160 [ 13.416814][ T1] ___might_sleep+0xc1/0x1d0 [ 13.416814][ T1] __might_sleep+0x5b/0xa0 [ 13.416814][ T1] slab_pre_alloc_hook+0x7b/0xa0 [ 13.416814][ T1] __kmalloc_node+0x60/0x300 [ 13.416814 T1] ? alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] ? topology_phys_to_logical_die+0x7e/0x180 [ 13.416814][ T1] alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] zalloc_cpumask_var+0x2a/0x40 [ 13.416814][ T1] native_smp_prepare_cpus+0x246/0x425 [ 13.416814][ T1] kernel_init_freeable+0x1b8/0x496 [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] kernel_init+0x18/0x17f [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] ret_from_fork+0x3a/0x50 [ 13.416814][ T1] irq event stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 13.416814][ T1] ---[ end trace 7d1df66da055aa92 ]--- [ 13.416814][ T1] possible reason: unannotated irqs-on. [ 13.416814][ent stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0
Marco Elver
maintainerRe: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 9 lines · Qian Cai
Quoted 7 lines · Marco Elver
Thanks, I'll look into KCSAN + lockdep compatibility. It's probably missing some
KCSAN_SANITIZE:= n in someMakefile.Can I have a update on fixing this? It looks like more of a problem that
kcsan_setup_watchpoint()will disable IRQs and then dive into the page allocator where it would complain because it might sleep.
KCSAN does *not* keep IRQs disabled (we have a clear irqsave / restore pair kcsan_setup_watchpoint).
If you look closer at the warning you sent in this thread, the warning is not generated because IRQs are off when it wants to sleep, but rather because IRQs are enabled but IRQ tracing state is inconsistent:
"DEBUG_LOCKS_WARN_ON(!current->hardirqs_enabled)" in lockdep checks that if IRQs are enabled, the trace state matches. These are only checked with LOCKDEP_DEBUG and TRACE_IRQFLAGS.
In other words, IRQ trace flags got corrupted somewhere. AFAIK, this problem here is only relevant with TRACE_IRQFLAGS -- again, it is clear that IRQs are enabled but the IRQ tracing logic somehow ended up corrupting hardirqs_enabled (TRACE_IRQFLAGS).
I believe this patch will take care of this issue:
http://lkml.kernel.org/r/[email protected]
Thanks,
-- Marco
Quoted 31 lines
BTW, I saw Paul sent a pull request for 5.6 but it is ugly to have everybody could trigger a deadlock (sleep function called in atomic context) like this during boot once this hits the mainline not to mention about only recently it is possible to test this feature (thanks to warning ratelimit) with the existing debugging options because it was unable to boot due to the brokenness with
debug_pageallocas mentioned in this thread, so this does sounds like it needs more soak time for the mainline to me.0000000000000400
[ 13.416814][ T1] Call Trace: [ 13.416814][ T1] lock_is_held_type+0x66/0x160 [ 13.416814][ T1] ___might_sleep+0xc1/0x1d0 [ 13.416814][ T1] __might_sleep+0x5b/0xa0 [ 13.416814][ T1] slab_pre_alloc_hook+0x7b/0xa0 [ 13.416814][ T1] __kmalloc_node+0x60/0x300 [ 13.416814 T1] ? alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] ? topology_phys_to_logical_die+0x7e/0x180 [ 13.416814][ T1] alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] zalloc_cpumask_var+0x2a/0x40 [ 13.416814][ T1] native_smp_prepare_cpus+0x246/0x425 [ 13.416814][ T1] kernel_init_freeable+0x1b8/0x496 [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] kernel_init+0x18/0x17f [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] ret_from_fork+0x3a/0x50 [ 13.416814][ T1] irq event stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 13.416814][ T1] ---[ end trace 7d1df66da055aa92 ]--- [ 13.416814][ T1] possible reason: unannotated irqs-on. [ 13.416814][ent stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
In reply to Qian CaiQuoted 10 lines · Qian Cai
Quoted 6 lines · Marco Elver
Thanks, I'll look into KCSAN + lockdep compatibility. It's probably missing some
KCSAN_SANITIZE:= n in someMakefile.Can I have a update on fixing this? It looks like more of a problem that
kcsan_setup_watchpoint()will disable IRQs and then dive into the page allocator where it would complain because it might sleep.BTW, I saw Paul sent a pull request for 5.6 but it is ugly to have everybody could trigger a deadlock (sleep function called in atomic context) like this during boot once this hits the mainline not to mention about only recently it is possible to test this feature (thanks to warning ratelimit) with the existing debugging options because it was unable to boot due to the brokenness with
debug_pageallocas mentioned in this thread, so this does sounds like it needs more soak time for the mainline to me.
Just so I understand... Does this problem happen even in CONFIG_KCSAN=n kernels?
I have been running extensive CONFIG_KSCAN=y rcutorture tests for quite awhile now, so even if this only happens for CONFIG_KSCAN=y, it is not like it affects everyone.
Yes, it should be fixed, and Marco does have a patch on the way.
Thanx, Paul
Quoted 29 lines
0000000000000400
[ 13.416814][ T1] Call Trace: [ 13.416814][ T1] lock_is_held_type+0x66/0x160 [ 13.416814][ T1] ___might_sleep+0xc1/0x1d0 [ 13.416814][ T1] __might_sleep+0x5b/0xa0 [ 13.416814][ T1] slab_pre_alloc_hook+0x7b/0xa0 [ 13.416814][ T1] __kmalloc_node+0x60/0x300 [ 13.416814 T1] ? alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] ? topology_phys_to_logical_die+0x7e/0x180 [ 13.416814][ T1] alloc_cpumask_var_node+0x44/0x70 [ 13.416814][ T1] zalloc_cpumask_var+0x2a/0x40 [ 13.416814][ T1] native_smp_prepare_cpus+0x246/0x425 [ 13.416814][ T1] kernel_init_freeable+0x1b8/0x496 [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] kernel_init+0x18/0x17f [ 13.416814][ T1] ? rest_init+0x381/0x381 [ 13.416814][ T1] ret_from_fork+0x3a/0x50 [ 13.416814][ T1] irq event stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0 [ 13.416814][ T1] ---[ end trace 7d1df66da055aa92 ]--- [ 13.416814][ T1] possible reason: unannotated irqs-on. [ 13.416814][ent stamp: 910 [ 13.416814][ T1] hardirqs last enabled at (909): [<ffffffff8d1240f3>] _raw_write_unlock_irqrestore+0x53/0x57 [ 13.416814][ T1] hardirqs last disabled at (910): [<ffffffff8c8bba76>] kcsan_setup_watchpoint+0x96/0x460 [ 13.416814][ T1] softirqs last enabled at (0): [<ffffffff8c6b697a>] copy_process+0x11fa/0x34f0 [ 13.416814][ T1] softirqs last disabled at (0): [<0000000000000000>] 0x0
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 6 lines · Paul E. McKenney
Just so I understand... Does this problem happen even in
CONFIG_KCSAN=nkernels?
No.
Quoted 6 lines
I have been running extensive
CONFIG_KSCAN=yrcutorture tests for quite awhile now, so even if this only happens forCONFIG_KSCAN=y, it is not like it affects everyone.Yes, it should be fixed, and Marco does have a patch on the way.
The concern is really about setting KSCAN=y in a distro debug kernel where it has other debug options. I’ll try to dig into more of those issues in the next few days.
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 8 lines · Qian Cai
Quoted 6 lines · Paul E. McKenney
Just so I understand... Does this problem happen even in
CONFIG_KCSAN=nkernels?No.
Whew!!! ;-)
Quoted 7 lines
Quoted 5 lines
I have been running extensive
CONFIG_KSCAN=yrcutorture tests for quite awhile now, so even if this only happens forCONFIG_KSCAN=y, it is not like it affects everyone.Yes, it should be fixed, and Marco does have a patch on the way.
The concern is really about setting KSCAN=y in a distro debug kernel where it has other debug options. I’ll try to dig into more of those issues in the next few days.
Understood. But there are likely to be other issues with KCSAN, given how new it is. Yes, yes, I certainly would like to believe that the patches we currently know about will make KCSAN perfect for distros, I have way too much grey hair (and too little hair as well!) to really beleive that.
As an alternative, once the patches needed for your tests to pass reach mainline, you could announce that KCSAN was ready to be enabled in distros.
Though I confess that I don't know how that works. Is there a separate testing kernel binary provided by the distros in question?
Thanx, Paul
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 10 lines · Paul E. McKenney
As an alternative, once the patches needed for your tests to pass reach mainline, you could announce that KCSAN was ready to be enabled in distros.
Though I confess that I don't know how that works. Is there a separate testing kernel binary provided by the distros in question?
I don’t think I have powers to announce that. Once the feature hit the mainline, distro people could start to use in the debug kernel variant, and it is a shame to only find out it is broken. Anyway, I’ll try to edge out those corner cases. Stay tuned.
Re: [PATCH v4 01/10] kcsan: Add Kernel Concurrency Sanitizer infrastructure
Quoted 4 lines · Qian Cai
Quoted 4 lines · Paul E. McKenney
Quoted 8 lines
Quoted 6 lines
As an alternative, once the patches needed for your tests to pass reach mainline, you could announce that KCSAN was ready to be enabled in distros.
Though I confess that I don't know how that works. Is there a separate testing kernel binary provided by the distros in question?
I don’t think I have powers to announce that. Once the feature hit the mainline, distro people could start to use in the debug kernel variant, and it is a shame to only find out it is broken. Anyway, I’ll try to edge out those corner cases. Stay tuned.
Very good, thank you!
And you do have the power to announce. But just like most of the rest of use, myself included, you won't always have the power to make people actually pay attention to what you say. ;-)
Thanx, Paul
Marco Elver
maintainerPATCH v4 2/10 include/linux/compiler.h: Introduce data_race(expr) macro
In reply to Marco ElverThis introduces the data_race(expr) macro, which can be used to annotate expressions for purposes of (1) documenting, and (2) giving tooling such as KCSAN information about which data races are deemed "safe".
More context:
http://lkml.kernel.org/r/CAHk-=wg5CkOEF8DTez1Qu0XTEFw_oHhxN98bDnFqbY7HL5AB2g@mail.gmail.com
---
v4:
* Introduce this patch to KCSAN series.
--- include/linux/compiler.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/linux/compiler.h +20 -0
@@ -310,6 +310,26 @@ unsigned long read_word_at_a_time(const void *addr) __u.__val; \ }) +#include <linux/kcsan.h> + +/* +* data_race: macro to document that accesses in an expression may conflict with +* other concurrent accesses resulting in data races, but the resulting +* behaviour is deemed safe regardless. +* +* This macro *does not* affect normal code generation, but is a hint to tooling +* that data races here should be ignored. +*/ +#define data_race (expr) \ + ({ \ + typeof(({ expr; })) __val; \ + kcsan_nestable_atomic_begin(); \ + __val = ({ expr; }); \ + kcsan_nestable_atomic_end(); \ + __val; \ + }) +#else +#endif /* __KERNEL__ */ /*
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 3/10 kcsan: Add Documentation entry in dev-tools
In reply to Marco Elver---
v4:
* Update to performance numbers after optimizations: no measurable change with default, and minor improvement when no watchpoints are set up.
* Add section on race conditions vs. data races.
* Add section on selective analysis.
v3:
* Split Documentation into separate patch.
* Fix typos.
* Accuracy: refer to unsoundness/completeness.
* Update with new slow-down after optimizations.
* Add Alternatives Considered section and move KTSAN mentions there.
--- Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/kcsan.rst | 256 ++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 Documentation/dev-tools/kcsan.rst
Documentation/dev-tools/index.rst +1 -0
@@ -21,6 +21,7 @@ whole; patches welcome! kasan ubsan kmemleak + kcsan gdb-kernel-debugging kgdb kselftest
Documentation/dev-tools/kcsan.rst new file +256 -0
256 lines not on this page · raw message
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 4/10 objtool, kcsan: Add KCSAN runtime functions to whitelist
In reply to Marco ElverThis patch adds KCSAN runtime functions to the objtool whitelist.
---
v3:
* Add missing instrumentation functions.
* Use new function names of refactored core runtime.
--- tools/objtool/check.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
tools/objtool/check.c +18 -0
@@ -466,6 +466,24 @@ static const char *uaccess_safe_builtin[] = {"__asan_report_store4_noabort" ,"__asan_report_store8_noabort" ,"__asan_report_store16_noabort" , +/* KCSAN */ +"kcsan_found_watchpoint" , +"kcsan_setup_watchpoint" , +/* KCSAN/TSAN */ +"__tsan_func_entry" , +"__tsan_func_exit" , +"__tsan_read_range" , +"__tsan_write_range" , +"__tsan_read1" , +"__tsan_read2" , +"__tsan_read4" , +"__tsan_read8" , +"__tsan_read16" , +"__tsan_write1" , +"__tsan_write2" , +"__tsan_write4" , +"__tsan_write8" , +"__tsan_write16" ,/* KCOV */ "write_comp_data" , "__sanitizer_cov_trace_pc",
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 5/10 build, kcsan: Add KCSAN build exceptions
In reply to Marco ElverThis blacklists several compilation units from KCSAN. See the respective inline comments for the reasoning.
---
v3:
* Moved EFI stub build exception hunk from x86-specific patch, since it's not x86-specific.
* Spelling "data-race" -> "data race".
--- drivers/firmware/efi/libstub/Makefile | 2 ++ kernel/Makefile | 5 +++++ kernel/sched/Makefile | 6 ++++++ mm/Makefile | 8 ++++++++ 4 files changed, 21 insertions(+)
drivers/firmware/efi/libstub/Makefile +2 -0
@@ -31,7 +31,9 @@ KBUILD_CFLAGS := $(cflags-y) -DDISABLE_BRANCH_PROFILING \ -D__DISABLE_EXPORTS GCOV_PROFILE := n +# Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n +KCSAN_SANITIZE := n UBSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y
kernel/Makefile +5 -0
@@ -23,6 +23,9 @@ endif # Prevents flicker of uninteresting __do_softirq()/__local_bh_disable_ip() # in coverage traces. KCOV_INSTRUMENT_softirq.o := n +# Avoid KCSAN instrumentation in softirq ("No shared variables, all the data +# are CPU local" => assume no data races), to reduce overhead in interrupts. +KCSAN_SANITIZE_softirq.o = n # These are called from save_stack_trace() on slub debug path, # and produce insane amounts of uninteresting coverage. KCOV_INSTRUMENT_module.o := n
@@ -30,6 +33,7 @@ KCOV_INSTRUMENT_extable.o := n # Don't self-instrument. KCOV_INSTRUMENT_kcov.o := n KASAN_SANITIZE_kcov.o := n +KCSAN_SANITIZE_kcov.o := n CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector) # cond_syscall is currently not LTO compatible
@@ -118,6 +122,7 @@ obj-$(CONFIG_RSEQ) += rseq.o obj-$(CONFIG_GCC_PLUGIN_STACKLEAK) += stackleak.o KASAN_SANITIZE_stackleak.o := n +KCSAN_SANITIZE_stackleak.o := n KCOV_INSTRUMENT_stackleak.o := n $(obj)/configs.o: $(obj)/config_data.gz
kernel/sched/Makefile +6 -0
@@ -7,6 +7,12 @@ endif # that is not a function of syscall inputs. E.g. involuntary context switches. KCOV_INSTRUMENT := n +# There are numerous races here, however, most of them due to plain accesses. +# This would make it even harder for syzbot to find reproducers, because these +# bugs trigger without specific input. Disable by default, but should re-enable +# eventually. +KCSAN_SANITIZE := n + ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y) # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is # needed for x86 only. Why this used to be enabled for all architectures is beyond
mm/Makefile +8 -0
@@ -7,6 +7,14 @@ KASAN_SANITIZE_slab_common.o := n KASAN_SANITIZE_slab.o := n KASAN_SANITIZE_slub.o := n +# These produce frequent data race reports: most of them are due to races on +# the same word but accesses to different bits of that word. Re-enable KCSAN +# for these when we have more consensus on what to do about them. +KCSAN_SANITIZE_slab_common.o := n +KCSAN_SANITIZE_slab.o := n +KCSAN_SANITIZE_slub.o := n +KCSAN_SANITIZE_page_alloc.o := n + # These files are disabled because they produce non-interesting and/or # flaky coverage that is not a function of syscall inputs. E.g. slab is out of # free pages, or a task is migrated between nodes.
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 6/10 seqlock, kcsan: Add annotations for KCSAN
In reply to Marco ElverSince seqlocks in the Linux kernel do not require the use of marked atomic accesses in critical sections, we teach KCSAN to assume such accesses are atomic. KCSAN currently also pretends that writes to sequence are atomic, although currently plain writes are used (their corresponding reads are READ_ONCE).
Further, to avoid false positives in the absence of clear ending of a seqlock reader critical section (only when using the raw interface), KCSAN assumes a fixed number of accesses after start of a seqlock critical section are atomic.
=== Commentary on design around absence of clear begin/end markings === Seqlock usage via seqlock_t follows a predictable usage pattern, where clear critical section begin/end is enforced. With subtle special cases for readers needing to be flat atomic regions, e.g. because usage such as in:
- fs/namespace.c:__legitimize_mnt - unbalanced read_seqretry
- fs/dcache.c:d_walk - unbalanced need_seqretry
But, anything directly accessing seqcount_t seems to be unpredictable. Filtering for usage of read_seqcount_retry not following 'do { .. } while (read_seqcount_retry(..));':
$ git grep 'read_seqcount_retry' | grep -Ev 'while \(|seqlock.h|Doc|\* ' => about 1/3 of the total read_seqcount_retry usage.
Just looking at fs/namei.c, we conclude that it is non-trivial to prescribe and migrate to an interface that would force clear begin/end seqlock markings for critical sections.
As such, we concluded that the best design currently, is to simply ensure that KCSAN works well with the existing code.
---
v3:
* Remove comment from raw_seqcount_barrier that should have been in next patch.
* Renamed kcsan_{nestable,flat}_atomic_{begin,end}
* Elaborate why clear begin/end cannot be enforced easily.
--- include/linux/seqlock.h | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-)
include/linux/seqlock.h +38 -2
@@ -37,8 +37,24 @@#include <linux/preempt.h> #include <linux/lockdep.h> #include <linux/compiler.h> +#include <linux/kcsan.h> #include <asm/processor.h> +/* +* The seqlock interface does not prescribe a precise sequence of read +* begin/retry/end. For readers, typically there is a call to +* read_seqcount_begin() and read_seqcount_retry(), however, there are more +* esoteric cases which do not follow this pattern. +* +* As a consequence, we take the following best-effort approach for raw usage +* via seqcount_t under KCSAN: upon beginning a seq-reader critical section, +* pessimistically mark then next KCSAN_SEQLOCK_REGION_MAX memory accesses as +* atomics; if there is a matching read_seqcount_retry() call, no following +* memory operations are considered atomic. Usage of seqlocks via seqlock_t +* interface is not affected. +*/ +#define KCSAN_SEQLOCK_REGION_MAX 1000 +/* * Version using sequence counter only. * This can be used when code has its own mutex protecting the
@@ -115,6 +131,7 @@ static inline unsigned __read_seqcount_begin(const seqcount_t *s)cpu_relax (); goto repeat; } +kcsan_atomic_next (KCSAN_SEQLOCK_REGION_MAX );return ret; }
@@ -131,6 +148,7 @@ static inline unsigned raw_read_seqcount(const seqcount_t *s) {unsigned ret =READ_ONCE (s->sequence);smp_rmb (); +kcsan_atomic_next (KCSAN_SEQLOCK_REGION_MAX );return ret; }
@@ -183,6 +201,7 @@ static inline unsigned raw_seqcount_begin(const seqcount_t *s) {unsigned ret =READ_ONCE (s->sequence);smp_rmb (); +kcsan_atomic_next (KCSAN_SEQLOCK_REGION_MAX );return ret & ~1 ; }
@@ -202,7 +221,8 @@ static inline unsigned raw_seqcount_begin(const seqcount_t *s)*/ static inline int __read_seqcount_retry (const seqcount_t *s,unsigned start) { -return unlikely (s->sequence != start); +kcsan_atomic_next (0 ); +return unlikely (READ_ONCE (s->sequence) != start); }/**
@@ -225,6 +245,7 @@ static inline int read_seqcount_retry(const seqcount_t *s, unsigned start)static inline void raw_write_seqcount_begin (seqcount_t *s) { +kcsan_nestable_atomic_begin (); s->sequence++;smp_wmb (); }
@@ -233,6 +254,7 @@ static inline void raw_write_seqcount_end(seqcount_t *s) {smp_wmb (); s->sequence++; +kcsan_nestable_atomic_end (); }/**
@@ -271,9 +293,11 @@ static inline void raw_write_seqcount_end(seqcount_t *s)*/ static inline void raw_write_seqcount_barrier (seqcount_t *s) { +kcsan_nestable_atomic_begin (); s->sequence++;smp_wmb (); s->sequence++; +kcsan_nestable_atomic_end (); }static inline int raw_read_seqcount_latch (seqcount_t *s)
@@ -398,7 +422,9 @@ static inline void write_seqcount_end(seqcount_t *s)static inline void write_seqcount_invalidate (seqcount_t *s) {smp_wmb (); +kcsan_nestable_atomic_begin (); s->sequence+=2 ; +kcsan_nestable_atomic_end (); } typedef struct {
@@ -430,11 +456,21 @@ typedef struct {*/ static inline unsigned read_seqbegin (const seqlock_t *sl) { -return read_seqcount_begin (&sl->seqcount); +unsigned ret =read_seqcount_begin (&sl->seqcount); + +kcsan_atomic_next (0 );/* non-raw usage, assume closing read_seqretry */ +kcsan_flat_atomic_begin (); +return ret; }static inline unsigned read_seqretry (const seqlock_t *sl,unsigned start) { +/* +* Assume not nested: read_seqretry may be called multiple times when +* completing read critical section. +*/ +kcsan_flat_atomic_end (); +return read_seqcount_retry (&sl->seqcount, start); }
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 7/10 seqlock: Require WRITE_ONCE surrounding raw_seqcount_barrier
In reply to Marco ElverThis patch proposes to require marked atomic accesses surrounding raw_write_seqcount_barrier. We reason that otherwise there is no way to guarantee propagation nor atomicity of writes before/after the barrier [1]. For example, consider the compiler tears stores either before or after the barrier; in this case, readers may observe a partial value, and because readers are unaware that writes are going on (writes are not in a seq-writer critical section), will complete the seq-reader critical section while having observed some partial state.
[1] https://lwn.net/Articles/793253/
This came up when designing and implementing KCSAN, because KCSAN would flag these accesses as data-races. After careful analysis, our reasoning as above led us to conclude that the best thing to do is to propose an amendment to the raw_seqcount_barrier usage.
---
v3:
* Add missing comment that was in preceding seqlock patch.
--- include/linux/seqlock.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
include/linux/seqlock.h +9 -2
@@ -265,6 +265,13 @@ static inline void raw_write_seqcount_end(seqcount_t *s)* usual consistency guarantee. It is one wmb cheaper, because we can * collapse the two back-to-back wmb()s. * +* Note that, writes surrounding the barrier should be declared atomic (e.g. +* via WRITE_ONCE): a) to ensure the writes become visible to other threads +* atomically, avoiding compiler optimizations; b) to document which writes are +* meant to propagate to the reader critical section. This is necessary because +* neither writes before and after the barrier are enclosed in a seq-writer +* critical section that would ensure readers are aware of ongoing writes. +* * seqcount_t seq; * bool X = true, Y = false; *
@@ -284,11 +291,11 @@ static inline void raw_write_seqcount_end(seqcount_t *s)* * void write(void) * { -* Y = true; +* WRITE_ONCE(Y, true); * * raw_write_seqcount_barrier(seq); * -* X = false; +* WRITE_ONCE(X, false); * } */ static inline void raw_write_seqcount_barrier (seqcount_t *s)
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 8/10 asm-generic, kcsan: Add KCSAN instrumentation for bitops
In reply to Marco ElverAdd explicit KCSAN checks for bitops.
---
v2:
* Use kcsan_check{,_atomic}_{read,write} instead of kcsan_check_{access,atomic}.
--- include/asm-generic/bitops-instrumented.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/asm-generic/bitops-instrumented.h +18 -0
@@ -12,6 +12,7 @@#define _ASM_GENERIC_BITOPS_INSTRUMENTED_H#include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> /** * set_bit - Atomically set a bit in memory
@@ -26,6 +27,7 @@static inline void set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_set_bit (nr, addr); }
@@ -41,6 +43,7 @@ static inline void set_bit(long nr, volatile unsigned long *addr)static inline void __set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___set_bit (nr, addr); }
@@ -54,6 +57,7 @@ static inline void __set_bit(long nr, volatile unsigned long *addr)static inline void clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_clear_bit (nr, addr); }
@@ -69,6 +73,7 @@ static inline void clear_bit(long nr, volatile unsigned long *addr)static inline void __clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___clear_bit (nr, addr); }
@@ -82,6 +87,7 @@ static inline void __clear_bit(long nr, volatile unsigned long *addr)static inline void clear_bit_unlock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_clear_bit_unlock (nr, addr); }
@@ -97,6 +103,7 @@ static inline void clear_bit_unlock(long nr, volatile unsigned long *addr)static inline void __clear_bit_unlock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___clear_bit_unlock (nr, addr); }
@@ -113,6 +120,7 @@ static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr)static inline void change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_change_bit (nr, addr); }
@@ -128,6 +136,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)static inline void __change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___change_bit (nr, addr); }
@@ -141,6 +150,7 @@ static inline void __change_bit(long nr, volatile unsigned long *addr)static inline bool test_and_set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_set_bit (nr, addr); }
@@ -155,6 +165,7 @@ static inline bool test_and_set_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_set_bit (nr, addr); }
@@ -170,6 +181,7 @@ static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr)static inline bool test_and_set_bit_lock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_set_bit_lock (nr, addr); }
@@ -183,6 +195,7 @@ static inline bool test_and_set_bit_lock(long nr, volatile unsigned long *addr)static inline bool test_and_clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_clear_bit (nr, addr); }
@@ -197,6 +210,7 @@ static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_clear_bit (nr, addr); }
@@ -210,6 +224,7 @@ static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr)static inline bool test_and_change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_change_bit (nr, addr); }
@@ -224,6 +239,7 @@ static inline bool test_and_change_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_change_bit (nr, addr); }
@@ -235,6 +251,7 @@ static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr)static inline bool test_bit (long nr,const volatile unsigned long *addr) {kasan_check_read (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_read (addr +BIT_WORD (nr),sizeof (long ));return arch_test_bit (nr, addr); }
@@ -254,6 +271,7 @@ static inline bool clear_bit_unlock_is_negative_byte(long nr, volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_clear_bit_unlock_is_negative_byte (nr, addr); }/* Let everybody know we have it. */
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerRe: [PATCH v4 08/10] asm-generic, kcsan: Add KCSAN instrumentation for bitops
---
Tentative version of the bitops patch that applies with the new instrumented bitops infrastructure currently in linux-next. (Note that that test_bit() is an atomic bitop, but is currently in the wrong header.)
Otherwise there is no functional change compared to v4 that applies to mainline.
--- include/asm-generic/bitops/instrumented-atomic.h | 7 +++++++ include/asm-generic/bitops/instrumented-lock.h | 5 +++++ include/asm-generic/bitops/instrumented-non-atomic.h | 8 ++++++++ 3 files changed, 20 insertions(+)
include/asm-generic/bitops/instrumented-atomic.h +7 -0
@@ -12,6 +12,7 @@#define _ASM_GENERIC_BITOPS_INSTRUMENTED_ATOMIC_H#include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> /** * set_bit - Atomically set a bit in memory
@@ -26,6 +27,7 @@static inline void set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_set_bit (nr, addr); }
@@ -39,6 +41,7 @@ static inline void set_bit(long nr, volatile unsigned long *addr)static inline void clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_clear_bit (nr, addr); }
@@ -55,6 +58,7 @@ static inline void clear_bit(long nr, volatile unsigned long *addr)static inline void change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_change_bit (nr, addr); }
@@ -68,6 +72,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)static inline bool test_and_set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_set_bit (nr, addr); }
@@ -81,6 +86,7 @@ static inline bool test_and_set_bit(long nr, volatile unsigned long *addr)static inline bool test_and_clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_clear_bit (nr, addr); }
@@ -94,6 +100,7 @@ static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr)static inline bool test_and_change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_change_bit (nr, addr); }
include/asm-generic/bitops/instrumented-lock.h +5 -0
@@ -12,6 +12,7 @@#define _ASM_GENERIC_BITOPS_INSTRUMENTED_LOCK_H#include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> /** * clear_bit_unlock - Clear a bit in memory, for unlock
@@ -23,6 +24,7 @@static inline void clear_bit_unlock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));arch_clear_bit_unlock (nr, addr); }
@@ -38,6 +40,7 @@ static inline void clear_bit_unlock(long nr, volatile unsigned long *addr)static inline void __clear_bit_unlock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___clear_bit_unlock (nr, addr); }
@@ -53,6 +56,7 @@ static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr)static inline bool test_and_set_bit_lock (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_test_and_set_bit_lock (nr, addr); }
@@ -72,6 +76,7 @@ static inline bool clear_bit_unlock_is_negative_byte(long nr, volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_write (addr +BIT_WORD (nr),sizeof (long ));return arch_clear_bit_unlock_is_negative_byte (nr, addr); }/* Let everybody know we have it. */
include/asm-generic/bitops/instrumented-non-atomic.h +8 -0
@@ -12,6 +12,7 @@#define _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H#include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> /** * __set_bit - Set a bit in memory
@@ -25,6 +26,7 @@static inline void __set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___set_bit (nr, addr); }
@@ -40,6 +42,7 @@ static inline void __set_bit(long nr, volatile unsigned long *addr)static inline void __clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___clear_bit (nr, addr); }
@@ -55,6 +58,7 @@ static inline void __clear_bit(long nr, volatile unsigned long *addr)static inline void __change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));arch___change_bit (nr, addr); }
@@ -69,6 +73,7 @@ static inline void __change_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_set_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_set_bit (nr, addr); }
@@ -83,6 +88,7 @@ static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_clear_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_clear_bit (nr, addr); }
@@ -97,6 +103,7 @@ static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr)static inline bool __test_and_change_bit (long nr,volatile unsigned long *addr) {kasan_check_write (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_write (addr +BIT_WORD (nr),sizeof (long ));return arch___test_and_change_bit (nr, addr); }
@@ -108,6 +115,7 @@ static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr)static inline bool test_bit (long nr,const volatile unsigned long *addr) {kasan_check_read (addr +BIT_WORD (nr),sizeof (long )); +kcsan_check_atomic_read (addr +BIT_WORD (nr),sizeof (long ));return arch_test_bit (nr, addr); }
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
Marco Elver
maintainerPATCH v4 9/10 locking/atomics, kcsan: Add KCSAN instrumentation
In reply to Marco ElverThis adds KCSAN instrumentation to atomic-instrumented.h.
---
v2:
* Use kcsan_check{,_atomic}_{read,write} instead of kcsan_check_{access,atomic}.
* Introduce __atomic_check_{read,write} [Suggested by Mark Rutland].
--- include/asm-generic/atomic-instrumented.h | 393 +++++++++++----------- scripts/atomic/gen-atomic-instrumented.sh | 17 +- 2 files changed, 218 insertions(+), 192 deletions(-)
include/asm-generic/atomic-instrumented.h +203 -190
@@ -19,11 +19,24 @@#include <linux/build_bug.h> #include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> + +static inline void __atomic_check_read (const volatile void *v,size_t size) +{ +kasan_check_read (v, size); +kcsan_check_atomic_read (v, size); +} + +static inline void __atomic_check_write (const volatile void *v,size_t size) +{ +kasan_check_write (v, size); +kcsan_check_atomic_write (v, size); +}static inline int atomic_read (const atomic_t *v) { -kasan_check_read (v,sizeof (*v)); +__atomic_check_read (v,sizeof (*v));return arch_atomic_read (v); }#define atomic_read atomic_read
@@ -32,7 +45,7 @@ atomic_read(const atomic_t *v)static inline int atomic_read_acquire (const atomic_t *v) { -kasan_check_read (v,sizeof (*v)); +__atomic_check_read (v,sizeof (*v));return arch_atomic_read_acquire (v); }#define atomic_read_acquire atomic_read_acquire
@@ -41,7 +54,7 @@ atomic_read_acquire(const atomic_t *v)static inline void atomic_set (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_set (v, i); }#define atomic_set atomic_set
@@ -50,7 +63,7 @@ atomic_set(atomic_t *v, int i)static inline void atomic_set_release (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_set_release (v, i); }#define atomic_set_release atomic_set_release
@@ -59,7 +72,7 @@ atomic_set_release(atomic_t *v, int i)static inline void atomic_add (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_add (i, v); }#define atomic_add atomic_add
@@ -68,7 +81,7 @@ atomic_add(int i, atomic_t *v)static inline int atomic_add_return (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_return (i, v); }#define atomic_add_return atomic_add_return
@@ -78,7 +91,7 @@ atomic_add_return(int i, atomic_t *v)static inline int atomic_add_return_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_return_acquire (i, v); }#define atomic_add_return_acquire atomic_add_return_acquire
@@ -88,7 +101,7 @@ atomic_add_return_acquire(int i, atomic_t *v)static inline int atomic_add_return_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_return_release (i, v); }#define atomic_add_return_release atomic_add_return_release
@@ -98,7 +111,7 @@ atomic_add_return_release(int i, atomic_t *v)static inline int atomic_add_return_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_return_relaxed (i, v); }#define atomic_add_return_relaxed atomic_add_return_relaxed
@@ -108,7 +121,7 @@ atomic_add_return_relaxed(int i, atomic_t *v)static inline int atomic_fetch_add (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_add (i, v); }#define atomic_fetch_add atomic_fetch_add
@@ -118,7 +131,7 @@ atomic_fetch_add(int i, atomic_t *v)static inline int atomic_fetch_add_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_add_acquire (i, v); }#define atomic_fetch_add_acquire atomic_fetch_add_acquire
@@ -128,7 +141,7 @@ atomic_fetch_add_acquire(int i, atomic_t *v)static inline int atomic_fetch_add_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_add_release (i, v); }#define atomic_fetch_add_release atomic_fetch_add_release
@@ -138,7 +151,7 @@ atomic_fetch_add_release(int i, atomic_t *v)static inline int atomic_fetch_add_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_add_relaxed (i, v); }#define atomic_fetch_add_relaxed atomic_fetch_add_relaxed
@@ -147,7 +160,7 @@ atomic_fetch_add_relaxed(int i, atomic_t *v)static inline void atomic_sub (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_sub (i, v); }#define atomic_sub atomic_sub
@@ -156,7 +169,7 @@ atomic_sub(int i, atomic_t *v)static inline int atomic_sub_return (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_sub_return (i, v); }#define atomic_sub_return atomic_sub_return
@@ -166,7 +179,7 @@ atomic_sub_return(int i, atomic_t *v)static inline int atomic_sub_return_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_sub_return_acquire (i, v); }#define atomic_sub_return_acquire atomic_sub_return_acquire
@@ -176,7 +189,7 @@ atomic_sub_return_acquire(int i, atomic_t *v)static inline int atomic_sub_return_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_sub_return_release (i, v); }#define atomic_sub_return_release atomic_sub_return_release
@@ -186,7 +199,7 @@ atomic_sub_return_release(int i, atomic_t *v)static inline int atomic_sub_return_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_sub_return_relaxed (i, v); }#define atomic_sub_return_relaxed atomic_sub_return_relaxed
@@ -196,7 +209,7 @@ atomic_sub_return_relaxed(int i, atomic_t *v)static inline int atomic_fetch_sub (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_sub (i, v); }#define atomic_fetch_sub atomic_fetch_sub
@@ -206,7 +219,7 @@ atomic_fetch_sub(int i, atomic_t *v)static inline int atomic_fetch_sub_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_sub_acquire (i, v); }#define atomic_fetch_sub_acquire atomic_fetch_sub_acquire
@@ -216,7 +229,7 @@ atomic_fetch_sub_acquire(int i, atomic_t *v)static inline int atomic_fetch_sub_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_sub_release (i, v); }#define atomic_fetch_sub_release atomic_fetch_sub_release
@@ -226,7 +239,7 @@ atomic_fetch_sub_release(int i, atomic_t *v)static inline int atomic_fetch_sub_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_sub_relaxed (i, v); }#define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed
@@ -236,7 +249,7 @@ atomic_fetch_sub_relaxed(int i, atomic_t *v)static inline void atomic_inc (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_inc (v); }#define atomic_inc atomic_inc
@@ -246,7 +259,7 @@ atomic_inc(atomic_t *v)static inline int atomic_inc_return (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_return (v); }#define atomic_inc_return atomic_inc_return
@@ -256,7 +269,7 @@ atomic_inc_return(atomic_t *v)static inline int atomic_inc_return_acquire (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_return_acquire (v); }#define atomic_inc_return_acquire atomic_inc_return_acquire
@@ -266,7 +279,7 @@ atomic_inc_return_acquire(atomic_t *v)static inline int atomic_inc_return_release (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_return_release (v); }#define atomic_inc_return_release atomic_inc_return_release
@@ -276,7 +289,7 @@ atomic_inc_return_release(atomic_t *v)static inline int atomic_inc_return_relaxed (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_return_relaxed (v); }#define atomic_inc_return_relaxed atomic_inc_return_relaxed
@@ -286,7 +299,7 @@ atomic_inc_return_relaxed(atomic_t *v)static inline int atomic_fetch_inc (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_inc (v); }#define atomic_fetch_inc atomic_fetch_inc
@@ -296,7 +309,7 @@ atomic_fetch_inc(atomic_t *v)static inline int atomic_fetch_inc_acquire (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_inc_acquire (v); }#define atomic_fetch_inc_acquire atomic_fetch_inc_acquire
@@ -306,7 +319,7 @@ atomic_fetch_inc_acquire(atomic_t *v)static inline int atomic_fetch_inc_release (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_inc_release (v); }#define atomic_fetch_inc_release atomic_fetch_inc_release
@@ -316,7 +329,7 @@ atomic_fetch_inc_release(atomic_t *v)static inline int atomic_fetch_inc_relaxed (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_inc_relaxed (v); }#define atomic_fetch_inc_relaxed atomic_fetch_inc_relaxed
@@ -326,7 +339,7 @@ atomic_fetch_inc_relaxed(atomic_t *v)static inline void atomic_dec (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_dec (v); }#define atomic_dec atomic_dec
@@ -336,7 +349,7 @@ atomic_dec(atomic_t *v)static inline int atomic_dec_return (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_return (v); }#define atomic_dec_return atomic_dec_return
@@ -346,7 +359,7 @@ atomic_dec_return(atomic_t *v)static inline int atomic_dec_return_acquire (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_return_acquire (v); }#define atomic_dec_return_acquire atomic_dec_return_acquire
@@ -356,7 +369,7 @@ atomic_dec_return_acquire(atomic_t *v)static inline int atomic_dec_return_release (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_return_release (v); }#define atomic_dec_return_release atomic_dec_return_release
@@ -366,7 +379,7 @@ atomic_dec_return_release(atomic_t *v)static inline int atomic_dec_return_relaxed (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_return_relaxed (v); }#define atomic_dec_return_relaxed atomic_dec_return_relaxed
@@ -376,7 +389,7 @@ atomic_dec_return_relaxed(atomic_t *v)static inline int atomic_fetch_dec (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_dec (v); }#define atomic_fetch_dec atomic_fetch_dec
@@ -386,7 +399,7 @@ atomic_fetch_dec(atomic_t *v)static inline int atomic_fetch_dec_acquire (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_dec_acquire (v); }#define atomic_fetch_dec_acquire atomic_fetch_dec_acquire
@@ -396,7 +409,7 @@ atomic_fetch_dec_acquire(atomic_t *v)static inline int atomic_fetch_dec_release (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_dec_release (v); }#define atomic_fetch_dec_release atomic_fetch_dec_release
@@ -406,7 +419,7 @@ atomic_fetch_dec_release(atomic_t *v)static inline int atomic_fetch_dec_relaxed (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_dec_relaxed (v); }#define atomic_fetch_dec_relaxed atomic_fetch_dec_relaxed
@@ -415,7 +428,7 @@ atomic_fetch_dec_relaxed(atomic_t *v)static inline void atomic_and (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_and (i, v); }#define atomic_and atomic_and
@@ -424,7 +437,7 @@ atomic_and(int i, atomic_t *v)static inline int atomic_fetch_and (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_and (i, v); }#define atomic_fetch_and atomic_fetch_and
@@ -434,7 +447,7 @@ atomic_fetch_and(int i, atomic_t *v)static inline int atomic_fetch_and_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_and_acquire (i, v); }#define atomic_fetch_and_acquire atomic_fetch_and_acquire
@@ -444,7 +457,7 @@ atomic_fetch_and_acquire(int i, atomic_t *v)static inline int atomic_fetch_and_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_and_release (i, v); }#define atomic_fetch_and_release atomic_fetch_and_release
@@ -454,7 +467,7 @@ atomic_fetch_and_release(int i, atomic_t *v)static inline int atomic_fetch_and_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_and_relaxed (i, v); }#define atomic_fetch_and_relaxed atomic_fetch_and_relaxed
@@ -464,7 +477,7 @@ atomic_fetch_and_relaxed(int i, atomic_t *v)static inline void atomic_andnot (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_andnot (i, v); }#define atomic_andnot atomic_andnot
@@ -474,7 +487,7 @@ atomic_andnot(int i, atomic_t *v)static inline int atomic_fetch_andnot (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_andnot (i, v); }#define atomic_fetch_andnot atomic_fetch_andnot
@@ -484,7 +497,7 @@ atomic_fetch_andnot(int i, atomic_t *v)static inline int atomic_fetch_andnot_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_andnot_acquire (i, v); }#define atomic_fetch_andnot_acquire atomic_fetch_andnot_acquire
@@ -494,7 +507,7 @@ atomic_fetch_andnot_acquire(int i, atomic_t *v)static inline int atomic_fetch_andnot_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_andnot_release (i, v); }#define atomic_fetch_andnot_release atomic_fetch_andnot_release
@@ -504,7 +517,7 @@ atomic_fetch_andnot_release(int i, atomic_t *v)static inline int atomic_fetch_andnot_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_andnot_relaxed (i, v); }#define atomic_fetch_andnot_relaxed atomic_fetch_andnot_relaxed
@@ -513,7 +526,7 @@ atomic_fetch_andnot_relaxed(int i, atomic_t *v)static inline void atomic_or (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_or (i, v); }#define atomic_or atomic_or
@@ -522,7 +535,7 @@ atomic_or(int i, atomic_t *v)static inline int atomic_fetch_or (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_or (i, v); }#define atomic_fetch_or atomic_fetch_or
@@ -532,7 +545,7 @@ atomic_fetch_or(int i, atomic_t *v)static inline int atomic_fetch_or_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_or_acquire (i, v); }#define atomic_fetch_or_acquire atomic_fetch_or_acquire
@@ -542,7 +555,7 @@ atomic_fetch_or_acquire(int i, atomic_t *v)static inline int atomic_fetch_or_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_or_release (i, v); }#define atomic_fetch_or_release atomic_fetch_or_release
@@ -552,7 +565,7 @@ atomic_fetch_or_release(int i, atomic_t *v)static inline int atomic_fetch_or_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_or_relaxed (i, v); }#define atomic_fetch_or_relaxed atomic_fetch_or_relaxed
@@ -561,7 +574,7 @@ atomic_fetch_or_relaxed(int i, atomic_t *v)static inline void atomic_xor (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic_xor (i, v); }#define atomic_xor atomic_xor
@@ -570,7 +583,7 @@ atomic_xor(int i, atomic_t *v)static inline int atomic_fetch_xor (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_xor (i, v); }#define atomic_fetch_xor atomic_fetch_xor
@@ -580,7 +593,7 @@ atomic_fetch_xor(int i, atomic_t *v)static inline int atomic_fetch_xor_acquire (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_xor_acquire (i, v); }#define atomic_fetch_xor_acquire atomic_fetch_xor_acquire
@@ -590,7 +603,7 @@ atomic_fetch_xor_acquire(int i, atomic_t *v)static inline int atomic_fetch_xor_release (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_xor_release (i, v); }#define atomic_fetch_xor_release atomic_fetch_xor_release
@@ -600,7 +613,7 @@ atomic_fetch_xor_release(int i, atomic_t *v)static inline int atomic_fetch_xor_relaxed (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_xor_relaxed (i, v); }#define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed
@@ -610,7 +623,7 @@ atomic_fetch_xor_relaxed(int i, atomic_t *v)static inline int atomic_xchg (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_xchg (v, i); }#define atomic_xchg atomic_xchg
@@ -620,7 +633,7 @@ atomic_xchg(atomic_t *v, int i)static inline int atomic_xchg_acquire (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_xchg_acquire (v, i); }#define atomic_xchg_acquire atomic_xchg_acquire
@@ -630,7 +643,7 @@ atomic_xchg_acquire(atomic_t *v, int i)static inline int atomic_xchg_release (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_xchg_release (v, i); }#define atomic_xchg_release atomic_xchg_release
@@ -640,7 +653,7 @@ atomic_xchg_release(atomic_t *v, int i)static inline int atomic_xchg_relaxed (atomic_t *v,int i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_xchg_relaxed (v, i); }#define atomic_xchg_relaxed atomic_xchg_relaxed
@@ -650,7 +663,7 @@ atomic_xchg_relaxed(atomic_t *v, int i)static inline int atomic_cmpxchg (atomic_t *v,int old,int new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_cmpxchg (v, old, new); }#define atomic_cmpxchg atomic_cmpxchg
@@ -660,7 +673,7 @@ atomic_cmpxchg(atomic_t *v, int old, int new)static inline int atomic_cmpxchg_acquire (atomic_t *v,int old,int new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_cmpxchg_acquire (v, old, new); }#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire
@@ -670,7 +683,7 @@ atomic_cmpxchg_acquire(atomic_t *v, int old, int new)static inline int atomic_cmpxchg_release (atomic_t *v,int old,int new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_cmpxchg_release (v, old, new); }#define atomic_cmpxchg_release atomic_cmpxchg_release
@@ -680,7 +693,7 @@ atomic_cmpxchg_release(atomic_t *v, int old, int new)static inline int atomic_cmpxchg_relaxed (atomic_t *v,int old,int new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_cmpxchg_relaxed (v, old, new); }#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed
@@ -690,8 +703,8 @@ atomic_cmpxchg_relaxed(atomic_t *v, int old, int new)static inline bool atomic_try_cmpxchg (atomic_t *v,int *old,int new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic_try_cmpxchg (v, old, new); }#define atomic_try_cmpxchg atomic_try_cmpxchg
@@ -701,8 +714,8 @@ atomic_try_cmpxchg(atomic_t *v, int *old, int new)static inline bool atomic_try_cmpxchg_acquire (atomic_t *v,int *old,int new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic_try_cmpxchg_acquire (v, old, new); }#define atomic_try_cmpxchg_acquire atomic_try_cmpxchg_acquire
@@ -712,8 +725,8 @@ atomic_try_cmpxchg_acquire(atomic_t *v, int *old, int new)static inline bool atomic_try_cmpxchg_release (atomic_t *v,int *old,int new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic_try_cmpxchg_release (v, old, new); }#define atomic_try_cmpxchg_release atomic_try_cmpxchg_release
@@ -723,8 +736,8 @@ atomic_try_cmpxchg_release(atomic_t *v, int *old, int new)static inline bool atomic_try_cmpxchg_relaxed (atomic_t *v,int *old,int new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic_try_cmpxchg_relaxed (v, old, new); }#define atomic_try_cmpxchg_relaxed atomic_try_cmpxchg_relaxed
@@ -734,7 +747,7 @@ atomic_try_cmpxchg_relaxed(atomic_t *v, int *old, int new)static inline bool atomic_sub_and_test (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_sub_and_test (i, v); }#define atomic_sub_and_test atomic_sub_and_test
@@ -744,7 +757,7 @@ atomic_sub_and_test(int i, atomic_t *v)static inline bool atomic_dec_and_test (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_and_test (v); }#define atomic_dec_and_test atomic_dec_and_test
@@ -754,7 +767,7 @@ atomic_dec_and_test(atomic_t *v)static inline bool atomic_inc_and_test (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_and_test (v); }#define atomic_inc_and_test atomic_inc_and_test
@@ -764,7 +777,7 @@ atomic_inc_and_test(atomic_t *v)static inline bool atomic_add_negative (int i,atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_negative (i, v); }#define atomic_add_negative atomic_add_negative
@@ -774,7 +787,7 @@ atomic_add_negative(int i, atomic_t *v)static inline int atomic_fetch_add_unless (atomic_t *v,int a,int u) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_fetch_add_unless (v, a, u); }#define atomic_fetch_add_unless atomic_fetch_add_unless
@@ -784,7 +797,7 @@ atomic_fetch_add_unless(atomic_t *v, int a, int u)static inline bool atomic_add_unless (atomic_t *v,int a,int u) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_add_unless (v, a, u); }#define atomic_add_unless atomic_add_unless
@@ -794,7 +807,7 @@ atomic_add_unless(atomic_t *v, int a, int u)static inline bool atomic_inc_not_zero (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_not_zero (v); }#define atomic_inc_not_zero atomic_inc_not_zero
@@ -804,7 +817,7 @@ atomic_inc_not_zero(atomic_t *v)static inline bool atomic_inc_unless_negative (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_inc_unless_negative (v); }#define atomic_inc_unless_negative atomic_inc_unless_negative
@@ -814,7 +827,7 @@ atomic_inc_unless_negative(atomic_t *v)static inline bool atomic_dec_unless_positive (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_unless_positive (v); }#define atomic_dec_unless_positive atomic_dec_unless_positive
@@ -824,7 +837,7 @@ atomic_dec_unless_positive(atomic_t *v)static inline int atomic_dec_if_positive (atomic_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic_dec_if_positive (v); }#define atomic_dec_if_positive atomic_dec_if_positive
@@ -833,7 +846,7 @@ atomic_dec_if_positive(atomic_t *v)static inline s64 atomic64_read (const atomic64_t *v) { -kasan_check_read (v,sizeof (*v)); +__atomic_check_read (v,sizeof (*v));return arch_atomic64_read (v); }#define atomic64_read atomic64_read
@@ -842,7 +855,7 @@ atomic64_read(const atomic64_t *v)static inline s64 atomic64_read_acquire (const atomic64_t *v) { -kasan_check_read (v,sizeof (*v)); +__atomic_check_read (v,sizeof (*v));return arch_atomic64_read_acquire (v); }#define atomic64_read_acquire atomic64_read_acquire
@@ -851,7 +864,7 @@ atomic64_read_acquire(const atomic64_t *v)static inline void atomic64_set (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_set (v, i); }#define atomic64_set atomic64_set
@@ -860,7 +873,7 @@ atomic64_set(atomic64_t *v, s64 i)static inline void atomic64_set_release (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_set_release (v, i); }#define atomic64_set_release atomic64_set_release
@@ -869,7 +882,7 @@ atomic64_set_release(atomic64_t *v, s64 i)static inline void atomic64_add (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_add (i, v); }#define atomic64_add atomic64_add
@@ -878,7 +891,7 @@ atomic64_add(s64 i, atomic64_t *v)static inline s64 atomic64_add_return (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_return (i, v); }#define atomic64_add_return atomic64_add_return
@@ -888,7 +901,7 @@ atomic64_add_return(s64 i, atomic64_t *v)static inline s64 atomic64_add_return_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_return_acquire (i, v); }#define atomic64_add_return_acquire atomic64_add_return_acquire
@@ -898,7 +911,7 @@ atomic64_add_return_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_add_return_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_return_release (i, v); }#define atomic64_add_return_release atomic64_add_return_release
@@ -908,7 +921,7 @@ atomic64_add_return_release(s64 i, atomic64_t *v)static inline s64 atomic64_add_return_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_return_relaxed (i, v); }#define atomic64_add_return_relaxed atomic64_add_return_relaxed
@@ -918,7 +931,7 @@ atomic64_add_return_relaxed(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_add (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_add (i, v); }#define atomic64_fetch_add atomic64_fetch_add
@@ -928,7 +941,7 @@ atomic64_fetch_add(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_add_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_add_acquire (i, v); }#define atomic64_fetch_add_acquire atomic64_fetch_add_acquire
@@ -938,7 +951,7 @@ atomic64_fetch_add_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_add_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_add_release (i, v); }#define atomic64_fetch_add_release atomic64_fetch_add_release
@@ -948,7 +961,7 @@ atomic64_fetch_add_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_add_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_add_relaxed (i, v); }#define atomic64_fetch_add_relaxed atomic64_fetch_add_relaxed
@@ -957,7 +970,7 @@ atomic64_fetch_add_relaxed(s64 i, atomic64_t *v)static inline void atomic64_sub (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_sub (i, v); }#define atomic64_sub atomic64_sub
@@ -966,7 +979,7 @@ atomic64_sub(s64 i, atomic64_t *v)static inline s64 atomic64_sub_return (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_sub_return (i, v); }#define atomic64_sub_return atomic64_sub_return
@@ -976,7 +989,7 @@ atomic64_sub_return(s64 i, atomic64_t *v)static inline s64 atomic64_sub_return_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_sub_return_acquire (i, v); }#define atomic64_sub_return_acquire atomic64_sub_return_acquire
@@ -986,7 +999,7 @@ atomic64_sub_return_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_sub_return_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_sub_return_release (i, v); }#define atomic64_sub_return_release atomic64_sub_return_release
@@ -996,7 +1009,7 @@ atomic64_sub_return_release(s64 i, atomic64_t *v)static inline s64 atomic64_sub_return_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_sub_return_relaxed (i, v); }#define atomic64_sub_return_relaxed atomic64_sub_return_relaxed
@@ -1006,7 +1019,7 @@ atomic64_sub_return_relaxed(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_sub (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_sub (i, v); }#define atomic64_fetch_sub atomic64_fetch_sub
@@ -1016,7 +1029,7 @@ atomic64_fetch_sub(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_sub_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_sub_acquire (i, v); }#define atomic64_fetch_sub_acquire atomic64_fetch_sub_acquire
@@ -1026,7 +1039,7 @@ atomic64_fetch_sub_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_sub_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_sub_release (i, v); }#define atomic64_fetch_sub_release atomic64_fetch_sub_release
@@ -1036,7 +1049,7 @@ atomic64_fetch_sub_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_sub_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_sub_relaxed (i, v); }#define atomic64_fetch_sub_relaxed atomic64_fetch_sub_relaxed
@@ -1046,7 +1059,7 @@ atomic64_fetch_sub_relaxed(s64 i, atomic64_t *v)static inline void atomic64_inc (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_inc (v); }#define atomic64_inc atomic64_inc
@@ -1056,7 +1069,7 @@ atomic64_inc(atomic64_t *v)static inline s64 atomic64_inc_return (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_return (v); }#define atomic64_inc_return atomic64_inc_return
@@ -1066,7 +1079,7 @@ atomic64_inc_return(atomic64_t *v)static inline s64 atomic64_inc_return_acquire (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_return_acquire (v); }#define atomic64_inc_return_acquire atomic64_inc_return_acquire
@@ -1076,7 +1089,7 @@ atomic64_inc_return_acquire(atomic64_t *v)static inline s64 atomic64_inc_return_release (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_return_release (v); }#define atomic64_inc_return_release atomic64_inc_return_release
@@ -1086,7 +1099,7 @@ atomic64_inc_return_release(atomic64_t *v)static inline s64 atomic64_inc_return_relaxed (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_return_relaxed (v); }#define atomic64_inc_return_relaxed atomic64_inc_return_relaxed
@@ -1096,7 +1109,7 @@ atomic64_inc_return_relaxed(atomic64_t *v)static inline s64 atomic64_fetch_inc (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_inc (v); }#define atomic64_fetch_inc atomic64_fetch_inc
@@ -1106,7 +1119,7 @@ atomic64_fetch_inc(atomic64_t *v)static inline s64 atomic64_fetch_inc_acquire (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_inc_acquire (v); }#define atomic64_fetch_inc_acquire atomic64_fetch_inc_acquire
@@ -1116,7 +1129,7 @@ atomic64_fetch_inc_acquire(atomic64_t *v)static inline s64 atomic64_fetch_inc_release (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_inc_release (v); }#define atomic64_fetch_inc_release atomic64_fetch_inc_release
@@ -1126,7 +1139,7 @@ atomic64_fetch_inc_release(atomic64_t *v)static inline s64 atomic64_fetch_inc_relaxed (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_inc_relaxed (v); }#define atomic64_fetch_inc_relaxed atomic64_fetch_inc_relaxed
@@ -1136,7 +1149,7 @@ atomic64_fetch_inc_relaxed(atomic64_t *v)static inline void atomic64_dec (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_dec (v); }#define atomic64_dec atomic64_dec
@@ -1146,7 +1159,7 @@ atomic64_dec(atomic64_t *v)static inline s64 atomic64_dec_return (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_return (v); }#define atomic64_dec_return atomic64_dec_return
@@ -1156,7 +1169,7 @@ atomic64_dec_return(atomic64_t *v)static inline s64 atomic64_dec_return_acquire (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_return_acquire (v); }#define atomic64_dec_return_acquire atomic64_dec_return_acquire
@@ -1166,7 +1179,7 @@ atomic64_dec_return_acquire(atomic64_t *v)static inline s64 atomic64_dec_return_release (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_return_release (v); }#define atomic64_dec_return_release atomic64_dec_return_release
@@ -1176,7 +1189,7 @@ atomic64_dec_return_release(atomic64_t *v)static inline s64 atomic64_dec_return_relaxed (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_return_relaxed (v); }#define atomic64_dec_return_relaxed atomic64_dec_return_relaxed
@@ -1186,7 +1199,7 @@ atomic64_dec_return_relaxed(atomic64_t *v)static inline s64 atomic64_fetch_dec (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_dec (v); }#define atomic64_fetch_dec atomic64_fetch_dec
@@ -1196,7 +1209,7 @@ atomic64_fetch_dec(atomic64_t *v)static inline s64 atomic64_fetch_dec_acquire (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_dec_acquire (v); }#define atomic64_fetch_dec_acquire atomic64_fetch_dec_acquire
@@ -1206,7 +1219,7 @@ atomic64_fetch_dec_acquire(atomic64_t *v)static inline s64 atomic64_fetch_dec_release (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_dec_release (v); }#define atomic64_fetch_dec_release atomic64_fetch_dec_release
@@ -1216,7 +1229,7 @@ atomic64_fetch_dec_release(atomic64_t *v)static inline s64 atomic64_fetch_dec_relaxed (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_dec_relaxed (v); }#define atomic64_fetch_dec_relaxed atomic64_fetch_dec_relaxed
@@ -1225,7 +1238,7 @@ atomic64_fetch_dec_relaxed(atomic64_t *v)static inline void atomic64_and (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_and (i, v); }#define atomic64_and atomic64_and
@@ -1234,7 +1247,7 @@ atomic64_and(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_and (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_and (i, v); }#define atomic64_fetch_and atomic64_fetch_and
@@ -1244,7 +1257,7 @@ atomic64_fetch_and(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_and_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_and_acquire (i, v); }#define atomic64_fetch_and_acquire atomic64_fetch_and_acquire
@@ -1254,7 +1267,7 @@ atomic64_fetch_and_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_and_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_and_release (i, v); }#define atomic64_fetch_and_release atomic64_fetch_and_release
@@ -1264,7 +1277,7 @@ atomic64_fetch_and_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_and_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_and_relaxed (i, v); }#define atomic64_fetch_and_relaxed atomic64_fetch_and_relaxed
@@ -1274,7 +1287,7 @@ atomic64_fetch_and_relaxed(s64 i, atomic64_t *v)static inline void atomic64_andnot (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_andnot (i, v); }#define atomic64_andnot atomic64_andnot
@@ -1284,7 +1297,7 @@ atomic64_andnot(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_andnot (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_andnot (i, v); }#define atomic64_fetch_andnot atomic64_fetch_andnot
@@ -1294,7 +1307,7 @@ atomic64_fetch_andnot(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_andnot_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_andnot_acquire (i, v); }#define atomic64_fetch_andnot_acquire atomic64_fetch_andnot_acquire
@@ -1304,7 +1317,7 @@ atomic64_fetch_andnot_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_andnot_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_andnot_release (i, v); }#define atomic64_fetch_andnot_release atomic64_fetch_andnot_release
@@ -1314,7 +1327,7 @@ atomic64_fetch_andnot_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_andnot_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_andnot_relaxed (i, v); }#define atomic64_fetch_andnot_relaxed atomic64_fetch_andnot_relaxed
@@ -1323,7 +1336,7 @@ atomic64_fetch_andnot_relaxed(s64 i, atomic64_t *v)static inline void atomic64_or (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_or (i, v); }#define atomic64_or atomic64_or
@@ -1332,7 +1345,7 @@ atomic64_or(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_or (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_or (i, v); }#define atomic64_fetch_or atomic64_fetch_or
@@ -1342,7 +1355,7 @@ atomic64_fetch_or(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_or_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_or_acquire (i, v); }#define atomic64_fetch_or_acquire atomic64_fetch_or_acquire
@@ -1352,7 +1365,7 @@ atomic64_fetch_or_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_or_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_or_release (i, v); }#define atomic64_fetch_or_release atomic64_fetch_or_release
@@ -1362,7 +1375,7 @@ atomic64_fetch_or_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_or_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_or_relaxed (i, v); }#define atomic64_fetch_or_relaxed atomic64_fetch_or_relaxed
@@ -1371,7 +1384,7 @@ atomic64_fetch_or_relaxed(s64 i, atomic64_t *v)static inline void atomic64_xor (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));arch_atomic64_xor (i, v); }#define atomic64_xor atomic64_xor
@@ -1380,7 +1393,7 @@ atomic64_xor(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_xor (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_xor (i, v); }#define atomic64_fetch_xor atomic64_fetch_xor
@@ -1390,7 +1403,7 @@ atomic64_fetch_xor(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_xor_acquire (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_xor_acquire (i, v); }#define atomic64_fetch_xor_acquire atomic64_fetch_xor_acquire
@@ -1400,7 +1413,7 @@ atomic64_fetch_xor_acquire(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_xor_release (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_xor_release (i, v); }#define atomic64_fetch_xor_release atomic64_fetch_xor_release
@@ -1410,7 +1423,7 @@ atomic64_fetch_xor_release(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_xor_relaxed (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_xor_relaxed (i, v); }#define atomic64_fetch_xor_relaxed atomic64_fetch_xor_relaxed
@@ -1420,7 +1433,7 @@ atomic64_fetch_xor_relaxed(s64 i, atomic64_t *v)static inline s64 atomic64_xchg (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_xchg (v, i); }#define atomic64_xchg atomic64_xchg
@@ -1430,7 +1443,7 @@ atomic64_xchg(atomic64_t *v, s64 i)static inline s64 atomic64_xchg_acquire (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_xchg_acquire (v, i); }#define atomic64_xchg_acquire atomic64_xchg_acquire
@@ -1440,7 +1453,7 @@ atomic64_xchg_acquire(atomic64_t *v, s64 i)static inline s64 atomic64_xchg_release (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_xchg_release (v, i); }#define atomic64_xchg_release atomic64_xchg_release
@@ -1450,7 +1463,7 @@ atomic64_xchg_release(atomic64_t *v, s64 i)static inline s64 atomic64_xchg_relaxed (atomic64_t *v,s64 i) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_xchg_relaxed (v, i); }#define atomic64_xchg_relaxed atomic64_xchg_relaxed
@@ -1460,7 +1473,7 @@ atomic64_xchg_relaxed(atomic64_t *v, s64 i)static inline s64 atomic64_cmpxchg (atomic64_t *v,s64 old,s64 new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_cmpxchg (v, old, new); }#define atomic64_cmpxchg atomic64_cmpxchg
@@ -1470,7 +1483,7 @@ atomic64_cmpxchg(atomic64_t *v, s64 old, s64 new)static inline s64 atomic64_cmpxchg_acquire (atomic64_t *v,s64 old,s64 new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_cmpxchg_acquire (v, old, new); }#define atomic64_cmpxchg_acquire atomic64_cmpxchg_acquire
@@ -1480,7 +1493,7 @@ atomic64_cmpxchg_acquire(atomic64_t *v, s64 old, s64 new)static inline s64 atomic64_cmpxchg_release (atomic64_t *v,s64 old,s64 new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_cmpxchg_release (v, old, new); }#define atomic64_cmpxchg_release atomic64_cmpxchg_release
@@ -1490,7 +1503,7 @@ atomic64_cmpxchg_release(atomic64_t *v, s64 old, s64 new)static inline s64 atomic64_cmpxchg_relaxed (atomic64_t *v,s64 old,s64 new) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_cmpxchg_relaxed (v, old, new); }#define atomic64_cmpxchg_relaxed atomic64_cmpxchg_relaxed
@@ -1500,8 +1513,8 @@ atomic64_cmpxchg_relaxed(atomic64_t *v, s64 old, s64 new)static inline bool atomic64_try_cmpxchg (atomic64_t *v,s64 *old,s64 new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic64_try_cmpxchg (v, old, new); }#define atomic64_try_cmpxchg atomic64_try_cmpxchg
@@ -1511,8 +1524,8 @@ atomic64_try_cmpxchg(atomic64_t *v, s64 *old, s64 new)static inline bool atomic64_try_cmpxchg_acquire (atomic64_t *v,s64 *old,s64 new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic64_try_cmpxchg_acquire (v, old, new); }#define atomic64_try_cmpxchg_acquire atomic64_try_cmpxchg_acquire
@@ -1522,8 +1535,8 @@ atomic64_try_cmpxchg_acquire(atomic64_t *v, s64 *old, s64 new)static inline bool atomic64_try_cmpxchg_release (atomic64_t *v,s64 *old,s64 new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic64_try_cmpxchg_release (v, old, new); }#define atomic64_try_cmpxchg_release atomic64_try_cmpxchg_release
@@ -1533,8 +1546,8 @@ atomic64_try_cmpxchg_release(atomic64_t *v, s64 *old, s64 new)static inline bool atomic64_try_cmpxchg_relaxed (atomic64_t *v,s64 *old,s64 new) { -kasan_check_write (v,sizeof (*v)); -kasan_check_write (old,sizeof (*old)); +__atomic_check_write (v,sizeof (*v)); +__atomic_check_write (old,sizeof (*old));return arch_atomic64_try_cmpxchg_relaxed (v, old, new); }#define atomic64_try_cmpxchg_relaxed atomic64_try_cmpxchg_relaxed
@@ -1544,7 +1557,7 @@ atomic64_try_cmpxchg_relaxed(atomic64_t *v, s64 *old, s64 new)static inline bool atomic64_sub_and_test (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_sub_and_test (i, v); }#define atomic64_sub_and_test atomic64_sub_and_test
@@ -1554,7 +1567,7 @@ atomic64_sub_and_test(s64 i, atomic64_t *v)static inline bool atomic64_dec_and_test (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_and_test (v); }#define atomic64_dec_and_test atomic64_dec_and_test
@@ -1564,7 +1577,7 @@ atomic64_dec_and_test(atomic64_t *v)static inline bool atomic64_inc_and_test (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_and_test (v); }#define atomic64_inc_and_test atomic64_inc_and_test
@@ -1574,7 +1587,7 @@ atomic64_inc_and_test(atomic64_t *v)static inline bool atomic64_add_negative (s64 i,atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_negative (i, v); }#define atomic64_add_negative atomic64_add_negative
@@ -1584,7 +1597,7 @@ atomic64_add_negative(s64 i, atomic64_t *v)static inline s64 atomic64_fetch_add_unless (atomic64_t *v,s64 a,s64 u) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_fetch_add_unless (v, a, u); }#define atomic64_fetch_add_unless atomic64_fetch_add_unless
@@ -1594,7 +1607,7 @@ atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u)static inline bool atomic64_add_unless (atomic64_t *v,s64 a,s64 u) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_add_unless (v, a, u); }#define atomic64_add_unless atomic64_add_unless
@@ -1604,7 +1617,7 @@ atomic64_add_unless(atomic64_t *v, s64 a, s64 u)static inline bool atomic64_inc_not_zero (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_not_zero (v); }#define atomic64_inc_not_zero atomic64_inc_not_zero
@@ -1614,7 +1627,7 @@ atomic64_inc_not_zero(atomic64_t *v)static inline bool atomic64_inc_unless_negative (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_inc_unless_negative (v); }#define atomic64_inc_unless_negative atomic64_inc_unless_negative
@@ -1624,7 +1637,7 @@ atomic64_inc_unless_negative(atomic64_t *v)static inline bool atomic64_dec_unless_positive (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_unless_positive (v); }#define atomic64_dec_unless_positive atomic64_dec_unless_positive
@@ -1634,7 +1647,7 @@ atomic64_dec_unless_positive(atomic64_t *v)static inline s64 atomic64_dec_if_positive (atomic64_t *v) { -kasan_check_write (v,sizeof (*v)); +__atomic_check_write (v,sizeof (*v));return arch_atomic64_dec_if_positive (v); }#define atomic64_dec_if_positive atomic64_dec_if_positive
@@ -1644,7 +1657,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define xchg (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_xchg(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1653,7 +1666,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define xchg_acquire (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_xchg_acquire(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1662,7 +1675,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define xchg_release (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_xchg_release(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1671,7 +1684,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define xchg_relaxed (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_xchg_relaxed(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1680,7 +1693,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1689,7 +1702,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg_acquire (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg_acquire(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1698,7 +1711,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg_release (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg_release(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1707,7 +1720,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg_relaxed (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg_relaxed(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1716,7 +1729,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg64 (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg64(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1725,7 +1738,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg64_acquire (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg64_acquire(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1734,7 +1747,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg64_release (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg64_release(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1743,7 +1756,7 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg64_relaxed (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg64_relaxed(__ai_ptr, __VA_ARGS__); \ })#endif
@@ -1751,28 +1764,28 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg_local (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg_local(__ai_ptr, __VA_ARGS__); \ })#define cmpxchg64_local (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_cmpxchg64_local(__ai_ptr, __VA_ARGS__); \ })#define sync_cmpxchg (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, sizeof(*__ai_ptr)); \ arch_sync_cmpxchg(__ai_ptr, __VA_ARGS__); \ })#define cmpxchg_double (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ arch_cmpxchg_double(__ai_ptr, __VA_ARGS__); \ })
@@ -1780,9 +1793,9 @@ atomic64_dec_if_positive(atomic64_t *v)#define cmpxchg_double_local (ptr, ...) \ ({ \ typeof(ptr) __ai_ptr = (ptr); \ - kasan_check_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ + __atomic_check_write(__ai_ptr, 2 * sizeof(*__ai_ptr)); \ arch_cmpxchg_double_local(__ai_ptr, __VA_ARGS__); \ })#endif /* _ASM_GENERIC_ATOMIC_INSTRUMENTED_H */ -// b29b625d5de9280f680e42c7be859b55b15e5f6a +// beea41c2a0f2c69e4958ed71bf26f59740fa4b12
scripts/atomic/gen-atomic-instrumented.sh +15 -2
@@ -20,7 +20,7 @@ gen_param_check() # We don't write to constant parameters [ ${type#c} != ${type} ] && rw="read" - printf "\tkasan_check_${rw}(${name}, sizeof(*${name}));\n" + printf "\t__atomic_check_${rw}(${name}, sizeof(*${name}));\n" } #gen_param_check(arg...)
@@ -107,7 +107,7 @@ cat <<EOF #define ${xchg}(ptr, ...) \\ ({ \\ typeof(ptr) __ai_ptr = (ptr); \\ - kasan_check_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\ + __atomic_check_write(__ai_ptr, ${mult}sizeof(*__ai_ptr)); \\ arch_${xchg}(__ai_ptr, __VA_ARGS__); \\ }) EOF
@@ -148,6 +148,19 @@ cat << EOF #include <linux/build_bug.h> #include <linux/kasan-checks.h> +#include <linux/kcsan-checks.h> + +static inline void __atomic_check_read(const volatile void *v, size_t size) +{ + kasan_check_read(v, size); + kcsan_check_atomic_read(v, size); +} + +static inline void __atomic_check_write(const volatile void *v, size_t size) +{ + kasan_check_write(v, size); + kcsan_check_atomic_write(v, size); +} EOF
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerPATCH v4 10/10 x86, kcsan: Enable KCSAN for x86
In reply to Marco ElverThis patch enables KCSAN for x86, with updates to build rules to not use KCSAN for several incompatible compilation units.
---
v4:
* Fix code generation with clang (KCSAN_SANITIZE := n for affected compilation units).
v3:
* Moved EFI stub build exception hunk to generic build exception patch, since it's not x86-specific.
v2:
* Document build exceptions where no previous above comment explained why we cannot instrument.
--- arch/x86/Kconfig | 1 + arch/x86/boot/Makefile | 2 ++ arch/x86/boot/compressed/Makefile | 2 ++ arch/x86/entry/vdso/Makefile | 3 +++ arch/x86/include/asm/bitops.h | 6 +++++- arch/x86/kernel/Makefile | 4 ++++ arch/x86/kernel/cpu/Makefile | 3 +++ arch/x86/lib/Makefile | 4 ++++ arch/x86/mm/Makefile | 4 ++++ arch/x86/purgatory/Makefile | 2 ++ arch/x86/realmode/Makefile | 3 +++ arch/x86/realmode/rm/Makefile | 3 +++ 12 files changed, 36 insertions(+), 1 deletion(-)
arch/x86/Kconfig +1 -0
@@ -226,6 +226,7 @@ config X86 select VIRT_TO_BUS select X86_FEATURE_NAMES if PROC_FS select PROC_PID_ARCH_STATUS if PROC_FS + select HAVE_ARCH_KCSAN if X86_64 config INSTRUCTION_DECODER def_bool y
arch/x86/boot/Makefile +2 -0
@@ -9,7 +9,9 @@ # Changed by many, many contributors over the years. # +# Sanitizer runtimes are unavailable and cannot be linked for early boot code. KASAN_SANITIZE := n +KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Kernel does not boot with kcov instrumentation here.
arch/x86/boot/compressed/Makefile +2 -0
@@ -17,7 +17,9 @@ # (see scripts/Makefile.lib size_append) # compressed vmlinux.bin.all + u32 size of vmlinux.bin.all +# Sanitizer runtimes are unavailable and cannot be linked for early boot code. KASAN_SANITIZE := n +KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
arch/x86/entry/vdso/Makefile +3 -0
@@ -10,8 +10,11 @@ ARCH_REL_TYPE_ABS += R_386_GLOB_DAT|R_386_JMP_SLOT|R_386_RELATIVE include $(srctree)/lib/vdso/Makefile KBUILD_CFLAGS += $(DISABLE_LTO) + +# Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n UBSAN_SANITIZE := n +KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
arch/x86/include/asm/bitops.h +5 -1
@@ -201,8 +201,12 @@ arch_test_and_change_bit(long nr, volatile unsigned long *addr) return GEN_BINARY_RMWcc(LOCK_PREFIX __ASM_SIZE(btc), *addr, c, "Ir", nr); } -static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) +static __no_kcsan_or_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) { +/* +* Because this is a plain access, we need to disable KCSAN here to +* avoid double instrumentation via instrumented bitops. +*/ return ((1UL << (nr & (BITS_PER_LONG -1 ))) & (addr[nr >> _BITOPS_LONG_SHIFT])) !=0 ; }
arch/x86/kernel/Makefile +4 -0
@@ -28,6 +28,10 @@ KASAN_SANITIZE_dumpstack_$(BITS).o := n KASAN_SANITIZE_stacktrace.o := n KASAN_SANITIZE_paravirt.o := n +# With some compiler versions the generated code results in boot hangs, caused +# by several compilation units. To be safe, disable all instrumentation. +KCSAN_SANITIZE := n + OBJECT_FILES_NON_STANDARD_relocate_kernel_$(BITS).o := y OBJECT_FILES_NON_STANDARD_test_nx.o := y OBJECT_FILES_NON_STANDARD_paravirt_patch.o := y
arch/x86/kernel/cpu/Makefile +3 -0
@@ -13,6 +13,9 @@ endif KCOV_INSTRUMENT_common.o := n KCOV_INSTRUMENT_perf_event.o := n +# As above, instrumenting secondary CPU boot code causes boot hangs. +KCSAN_SANITIZE_common.o := n + # Make sure load_percpu_segment has no stackprotector nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_common.o := $(nostackp)
arch/x86/lib/Makefile +4 -0
@@ -6,10 +6,14 @@ # Produces uninteresting flaky coverage. KCOV_INSTRUMENT_delay.o := n +# KCSAN uses udelay for introducing watchpoint delay; avoid recursion. +KCSAN_SANITIZE_delay.o := n + # Early boot use of cmdline; don't instrument it ifdef CONFIG_AMD_MEM_ENCRYPT KCOV_INSTRUMENT_cmdline.o := n KASAN_SANITIZE_cmdline.o := n +KCSAN_SANITIZE_cmdline.o := n ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_cmdline.o = -pg
arch/x86/mm/Makefile +4 -0
@@ -7,6 +7,10 @@ KCOV_INSTRUMENT_mem_encrypt_identity.o := n KASAN_SANITIZE_mem_encrypt.o := n KASAN_SANITIZE_mem_encrypt_identity.o := n +# Disable KCSAN entirely, because otherwise we get warnings that some functions +# reference __initdata sections. +KCSAN_SANITIZE := n + ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_mem_encrypt.o = -pg CFLAGS_REMOVE_mem_encrypt_identity.o = -pg
arch/x86/purgatory/Makefile +2 -0
@@ -17,7 +17,9 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib targets += purgatory.ro +# Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n +KCSAN_SANITIZE := n KCOV_INSTRUMENT := n # These are adjustments to the compiler flags used for objects that
arch/x86/realmode/Makefile +3 -0
@@ -6,7 +6,10 @@ # for more details. # # + +# Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n +KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y subdir- := rm
arch/x86/realmode/rm/Makefile +3 -0
@@ -6,7 +6,10 @@ # for more details. # # + +# Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE := n +KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
Signature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Quoted 15 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsan
Quoted 6 lines
We want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/
I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Thanx, Paul
Quoted 141 lines
Race conditions vs. data races
------------------------------Race conditions are logic bugs, where unexpected interleaving of racing concurrent operations result in an erroneous state.
Data races on the other hand are defined at the *memory model/language level*. Many data races are also harmful race conditions, which a tool like KCSAN reports! However, not all data races are race conditions and vice-versa. KCSAN's intent is to report data races according to the LKMM. A data race detector can only work at the memory model/language level.
Deeper analysis, to find high-level race conditions only, requires conveying the intended kernel logic to a tool. This requires (1) the developer writing a specification or model of their code, and then (2) the tool verifying that the implementation matches. This has been done for small bits of code using model checkers and other formal methods, but does not scale to the level of what can be covered with a dynamic analysis based data race detector such as KCSAN.
For reasons outlined in [1, 2], data races can be much more subtle, but can cause no less harm than high-level race conditions.
Changelog
---------
v4:
* Major changes:
- Optimizations resulting in performance improvement of 33% (on microbenchmark).
- Deal with nested interrupts foratomic_next.
- Simplifyreport.c(removing double-locking as well), in preparation forKCSAN_REPORT_VALUE_CHANGE_ONLY.
- Add patch to introduce "data_race(expr)" macro.
- IntroduceKCSAN_REPORT_VALUE_CHANGE_ONLYoption for further filtering of data
races: if a conflicting write was observed via a watchpoint, only report the data race if a value change was observed as well. The option will be enabled by default on syzbot. (rcu-functions will be excluded from this filter at request of Paul McKenney.) Context:http://lkml.kernel.org/r/CANpmjNOepvb6+zJmDePxj21n2rctM4Sp4rJ66x_J-L1UmNK54A@mail.gmail.comv3: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Add microbenchmark.
- Add instruction watchpoint skip randomization.
- Refactor API and core runtime fast-path and slow-path. Compared to the previous version, with a default config and benchmarked using the added microbenchmark, this version is 3.8x faster.
- Make__tsan_unaligned__aliasof generic accesses.
- Rename kcsan_{begin,end}_atomic -> kcsan_{nestable,flat}_atomic_{begin,end}
- For filter list indebugfs.cuse kmalloc+krealloc instead of kvmalloc.
- Split Documentation into separate patch.v2: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Replacekcsan_check_access(.., {true, false})with kcsan_check_{read,write}.
- Changeatomic-instrumented.hto use __atomic_check_{read,write}.
- Use common structkcsan_ctxintask_structand for per-CPU interrupt contexts.v1: http://lkml.kernel.org/r/[email protected]
Marco Elver (10):
kcsan: Add Kernel Concurrency Sanitizer infrastructureinclude/linux/compiler.h: Introducedata_race(expr)macro
kcsan: Add Documentation entry in dev-tools objtool, kcsan: Add KCSAN runtime functions to whitelist build, kcsan: Add KCSAN build exceptions
seqlock, kcsan: Add annotations for KCSAN
seqlock: RequireWRITE_ONCEsurroundingraw_seqcount_barrierasm-generic, kcsan: Add KCSAN instrumentation for bitops locking/atomics, kcsan: Add KCSAN instrumentation x86, kcsan: Enable KCSAN for x86Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/kcsan.rst | 256 +++++++++ MAINTAINERS | 11 + Makefile | 3 +- arch/x86/Kconfig | 1 + arch/x86/boot/Makefile | 2 + arch/x86/boot/compressed/Makefile | 2 + arch/x86/entry/vdso/Makefile | 3 + arch/x86/include/asm/bitops.h | 6 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/cpu/Makefile | 3 + arch/x86/lib/Makefile | 4 + arch/x86/mm/Makefile | 4 + arch/x86/purgatory/Makefile | 2 + arch/x86/realmode/Makefile | 3 + arch/x86/realmode/rm/Makefile | 3 + drivers/firmware/efi/libstub/Makefile | 2 + include/asm-generic/atomic-instrumented.h | 393 +++++++------- include/asm-generic/bitops-instrumented.h | 18 + include/linux/compiler-clang.h | 9 + include/linux/compiler-gcc.h | 7 + include/linux/compiler.h | 57 +- include/linux/kcsan-checks.h | 97 ++++ include/linux/kcsan.h | 115 ++++ include/linux/sched.h | 4 + include/linux/seqlock.h | 51 +- init/init_task.c | 8 + init/main.c | 2 + kernel/Makefile | 6 + kernel/kcsan/Makefile | 11 + kernel/kcsan/atomic.h | 27 + kernel/kcsan/core.c | 626 ++++++++++++++++++++++ kernel/kcsan/debugfs.c | 275 ++++++++++ kernel/kcsan/encoding.h | 94 ++++ kernel/kcsan/kcsan.h | 108 ++++ kernel/kcsan/report.c | 320 +++++++++++ kernel/kcsan/test.c | 121 +++++ kernel/sched/Makefile | 6 + lib/Kconfig.debug | 2 + lib/Kconfig.kcsan | 118 ++++ lib/Makefile | 3 + mm/Makefile | 8 + scripts/Makefile.kcsan | 6 + scripts/Makefile.lib | 10 + scripts/atomic/gen-atomic-instrumented.sh | 17 +- tools/objtool/check.c | 18 + 46 files changed, 2641 insertions(+), 206 deletions(-) create mode 100644 Documentation/dev-tools/kcsan.rst create mode 100644 include/linux/kcsan-checks.h create mode 100644 include/linux/kcsan.h create mode 100644 kernel/kcsan/Makefile create mode 100644 kernel/kcsan/atomic.h create mode 100644 kernel/kcsan/core.c create mode 100644 kernel/kcsan/debugfs.c create mode 100644 kernel/kcsan/encoding.h create mode 100644 kernel/kcsan/kcsan.h create mode 100644 kernel/kcsan/report.c create mode 100644 kernel/kcsan/test.c create mode 100644 lib/Kconfig.kcsan create mode 100644 scripts/Makefile.kcsanSignature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerQuoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
- There is a change in lib/Kconfig.debug and moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
- bitops-instrumented.h was removed and split into 3 files, and needs re-inserting the instrumentation into the right places.
Otherwise there are no issues. Let me know what you recommend.
Thanks,
-- Marco
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
Thanx, Paul
Marco Elver
maintainerQuoted 42 lines · Paul E. McKenney
Quoted 40 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.
Quoted 8 lines
Quoted 1 line
Otherwise there are no issues. Let me know what you recommend.
Sounds good!
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use the data_race macro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.
Thanks,
-- Marco
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (047ca266cfab "asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..
Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.
My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf --syncconfig Kconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)
Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that CONFIG_RCU_EXPERT exists.)
But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Fair enough?
Thanx, Paul
Marco Elver
maintainerQuoted 96 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)
Quoted 6 lines
But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
Thanks,
-- Marco
Quoted 102 lines · Marco Elver
Quoted 101 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Quoted 8 lines
Quoted 1 line
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
That sounds advisable for an attempt to hit this coming merge window.
So just to make sure I understand, I drop 8/10 and keep the rest during a rebase to 5.4-rc7, correct?
Thanx, Paul
Marco Elver
maintainerQuoted 113 lines · Paul E. McKenney
Quoted 102 lines · Marco Elver
Quoted 101 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Quoted 8 lines
Quoted 1 line
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
Quoted 4 lines
That sounds advisable for an attempt to hit this coming merge window.
So just to make sure I understand, I drop 8/10 and keep the rest during a rebase to 5.4-rc7, correct?
Yes, that's right.
Many thanks,
-- Marco
Quoted 114 lines · Marco Elver
Quoted 113 lines · Paul E. McKenney
Quoted 110 lines · Marco Elver
Quoted 96 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)Quoted 6 lines
But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
Quoted 6 lines
Quoted 4 lines
That sounds advisable for an attempt to hit this coming merge window.
So just to make sure I understand, I drop 8/10 and keep the rest during a rebase to 5.4-rc7, correct?
Yes, that's right.
Very good, I just now pushed a "kcsan" branch on -rcu, and am running rcutorture, first without KCSAN enabled and then with it turned on. If all that works out, I set my -next branch to that point and see what -next testing and kbuild test robot think about it. If all goes well, an RFC pull request.
Look OK?
Thanx, Paul
Marco Elver
maintainerQuoted 123 lines · Paul E. McKenney
Quoted 114 lines · Marco Elver
Quoted 113 lines · Paul E. McKenney
Quoted 110 lines · Marco Elver
Quoted 96 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)Quoted 6 lines
But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
Quoted 6 lines
Quoted 4 lines
That sounds advisable for an attempt to hit this coming merge window.
So just to make sure I understand, I drop 8/10 and keep the rest during a rebase to 5.4-rc7, correct?
Yes, that's right.
Quoted 7 lines
Very good, I just now pushed a "kcsan" branch on -rcu, and am running rcutorture, first without KCSAN enabled and then with it turned on. If all that works out, I set my -next branch to that point and see what -next testing and kbuild test robot think about it. If all goes well, an RFC pull request.
Look OK?
Looks good to me, many thanks!
-- Marco
Quoted 130 lines · Marco Elver
Quoted 129 lines · Paul E. McKenney
Quoted 114 lines · Marco Elver
Quoted 113 lines · Paul E. McKenney
Quoted 110 lines · Marco Elver
Quoted 96 lines · Paul E. McKenney
Quoted 47 lines · Marco Elver
Quoted 46 lines · Paul E. McKenney
Quoted 35 lines · Marco Elver
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Marco Elver
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
Quoted 5 lines
Quoted 2 lines
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/I queued this and ran a quick rcutorture on it, which completed successfully with quite a few reports.
Great. Many thanks for queuing this in -rcu. And regarding merge window you mentioned, we're fine with your assumption to targeting the next (v5.6) merge window.
I've just had a look at linux-next to check what a future rebase requires:
Quoted 6 lines
- There is a change in
lib/Kconfig.debugand moving KCSAN to the "Generic Kernel Debugging Instruments" section seems appropriate.
-bitops-instrumented.hwas removed and split into 3 files, and needs re-inserting the instrumentation into the right places.Otherwise there are no issues. Let me know what you recommend.
Sounds good!
Quoted 8 lines
Quoted 4 lines
I will be rebasing onto v5.5-rc1 shortly after it comes out. My usual approach is to fix any conflicts during that rebasing operation. Does that make sense, or would you prefer to send me a rebased stack at that point? Either way is fine for me.
That's fine with me, thanks! To avoid too much additional churn on your end, I just replied to the bitops patch with a version that will apply with the change to bitops-instrumented infrastructure.
My first thought was to replace 8/10 of the previous version of your patch in -rcu (
047ca266cfab"asm-generic, kcsan: Add KCSAN instrumentation for bitops"), but this does not apply. So I am guessing that I instead do this substitution when a rebase onto -rc1..Except...
Quoted 7 lines
Also considering the merge window, we had a discussion and there are some arguments for targeting the v5.5 merge window:
- we'd unblock ARM and POWER ports;
- we'd unblock people wanting to use thedata_racemacro;
- we'd unblock syzbot just tracking upstream;
Unless there are strong reasons to not target v5.5, I leave it to you if you think it's appropriate.My normal process is to send the pull request shortly after -rc5 comes out, but you do call out some benefits of getting it in sooner, so...
What I will do is to rebase your series onto (say) -rc7, test it, and see about an RFC pull request.
One possible complication is the new 8/10 patch. But maybe it will apply against -rc7?
Another possible complication is this:
scripts/kconfig/conf--syncconfigKconfig
*
* Restart config...
*
*
* KCSAN: watchpoint-based dynamic data race detector
*
KCSAN: watchpoint-based dynamic data race detector (KCSAN) [N/y/?] (NEW)Might be OK in this case because it is quite obvious what it is doing. (Avoiding pain from this is the reason that
CONFIG_RCU_EXPERTexists.)Quoted 6 lines
But I will just mention this in the pull request.
If there is a -rc8, there is of course a higher probability of making it into the next merge window.
Fair enough?
Totally fine with that, sounds like a good plan, thanks!
If it helps, in theory we can also drop and delay the bitops instrumentation patch until the new bitops instrumentation infrastructure is in 5.5-rc1. There won't be any false positives if this is missing, we might just miss a few data races until we have it.
Quoted 6 lines
Quoted 4 lines
That sounds advisable for an attempt to hit this coming merge window.
So just to make sure I understand, I drop 8/10 and keep the rest during a rebase to 5.4-rc7, correct?
Yes, that's right.
Very good, I just now pushed a "kcsan" branch on -rcu, and am running rcutorture, first without KCSAN enabled and then with it turned on. If all that works out, I set my -next branch to that point and see what -next testing and kbuild test robot think about it. If all goes well, an RFC pull request.
Quoted 3 lines
Quoted 1 line
Look OK?
Looks good to me, many thanks!
And I did get one failure on the KCSAN=n run for the TREE03 scenario, but it does not appear to be your fault. Looks like a race between a swait_queue_head swake_up_one() invocation and one of the CPU hotplug operations done late in system shutdown. I have included the splat below for your amusement.
Starting the KCSAN=y runs now.
Thanx, Paul
------------------------------------------------------------------------
[ 601.009355] reboot: Power down [ 601.010447] ------------[ cut here ]------------ [ 601.011020] sched: Unexpected reschedule of offline CPU#1! [ 601.011639] WARNING: CPU: 7 PID: 0 at arch/x86/kernel/apic/ipi.c:67 native_smp_send_reschedule+0x2f/0x40 [ 601.012692] Modules linked in: [ 601.013037] CPU: 7 PID: 0 Comm: swapper/7 Not tainted 5.4.0-rc7+ #1497 [ 601.013755] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.10.2-1ubuntu1 04/01/2014 [ 601.014708] RIP: 0010:native_smp_send_reschedule+0x2f/0x40 [ 601.015312] Code: 05 f6 62 5d 01 73 15 48 8b 05 cd ba 28 01 be fd 00 00 00 48 8b 40 30 e9 bf b0 db 00 89 fe 48 c7 c7 d0 df 5e a7 e8 01 20 02 00 <0f> 0b c3 0f 1f 40 00 66 2e 0f 1f 84 00 00 00 00 00 48 8b 05 99 ba [ 601.017357] RSP: 0018:ffffa1afc020cee0 EFLAGS: 00010086 [ 601.017942] RAX: 0000000000000000 RBX: ffff8d5c1ed24a54 RCX: 0000000000000005 [ 601.018716] RDX: 0000000080000005 RSI: 0000000000000082 RDI: 00000000ffffffff [ 601.019500] RBP: 0000000000000000 R08: 0000000000000cd5 R09: 000000000000003d [ 601.020283] R10: ffff8d5c1f067f80 R11: 20666f20656c7564 R12: 0000000000000001 [ 601.021074] R13: 0000000000027f40 R14: 0000000000000087 R15: ffff8d5c1ed23f00 [ 601.021851] FS: 0000000000000000(0000) GS:ffff8d5c1f1c0000(0000) knlGS:0000000000000000 [ 601.022731] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 601.023360] CR2: 00000000ffffffff CR3: 000000001120a000 CR4: 00000000000006e0 [ 601.024140] Call Trace: [ 601.024437] <IRQ> [ 601.024671] try_to_wake_up+0x2b3/0x650 [ 601.025103] swake_up_locked.part.6+0xe/0x30 [ 601.025579] swake_up_one+0x22/0x30 [ 601.025968] rcu_try_advance_all_cbs+0x71/0x80 [ 601.026459] rcu_cleanup_after_idle+0x28/0x40 [ 601.026941] rcu_irq_enter+0xfb/0x130 [ 601.027347] irq_enter+0x5/0x50 [ 601.027704] smp_reboot_interrupt+0x1a/0xb0 [ 601.028175] ? smp_apic_timer_interrupt+0xa1/0x180 [ 601.028711] reboot_interrupt+0xf/0x20 [ 601.029134] </IRQ> [ 601.029374] RIP: 0010:default_idle+0x1e/0x170 [ 601.029853] Code: 90 90 90 90 90 90 90 90 90 90 90 90 41 55 41 54 55 53 e8 c5 c5 91 ff 0f 1f 44 00 00 e9 07 00 00 00 0f 00 2d e6 b4 54 00 fb f4 <e8> ad c5 91 ff 89 c5 0f 1f 44 00 00 5b 5d 41 5c 41 5d c3 65 8b 05 [ 601.031884] RSP: 0018:ffffa1afc00afec0 EFLAGS: 00000202 ORIG_RAX: ffffffffffffff07 [ 601.032716] RAX: 0000000000000007 RBX: 0000000000000007 RCX: 0000000000000007 [ 601.033498] RDX: 0000000000000001 RSI: 0000000000000087 RDI: ffffffffa769a760 [ 601.034280] RBP: ffffffffa7a1c160 R08: 0000009a8e03a656 R09: 0000000000000001 [ 601.035062] R10: 0000000000000400 R11: 00000000000001d8 R12: 0000000000000000 [ 601.035842] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 [ 601.036632] do_idle+0x1a6/0x240 [ 601.036996] cpu_startup_entry+0x14/0x20 [ 601.037433] start_secondary+0x150/0x180 [ 601.037869] secondary_startup_64+0xa4/0xb0 [ 601.038339] ---[ end trace e4c21199f3882c03 ]--- [ 601.038991] acpi_power_off called
Quoted 6 lines · Marco Elver' via kasan-dev
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
Just booting x86 systems because kcsan_setup_watchpoint() disabled hard irqs?
[ 8.926145][ T0] ------------[ cut here ]------------
[ 8.927850][ T0] DEBUG_LOCKS_WARN_ON(!current->hardirqs_enabled) [ 80] WARNING: CPU: 0 PID: 0 at kernel/locking/lockdep.c:4406 check_flags.part.26+0x102/0x240
[ 8.933072][ T0] Modules linked in:
[ 8.933072][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.4.0-rc8-next- 20191119+ #2
[ 8.933072][ T0] Hardware name: HP ProLiant XL420 Gen9/ProLiant XL420 Gen9, BIOS U19 12/27/2015
[ 8.933072][ T0] RIP: 0010:check_flags.part.26+0x102/0x240
[ 8.933072][ T0] Code: 7b a2 e8 51 6d 15 00 44 8b 05 fa df 45 01 45 85 c0 0f 85 27 76 00 00 48 c7 c6 02 d6 3b a2 48 c7 c7 79 36 3b a2 e8 2f 9f f5 ff <0f> e9 0d 76 00 00 65 48 8b 3c 25 40 3f 01 00 e8 89 f0 ff ff e8
[ 8.933072][ T0] RSP: 0000:ffffffffa2603860 EFLAGS: 00010086 [ 8.933072][ T0] RAX: 0000000000000000 RBX: ffffffffa2617b40 RCX:
0000000000000000
[ 8.933072][ T0] RDX: 0000000000000000 RSI: 0000000000000001 RDI:
0000000000000000
[ 8.933072][ T0] RBP: ffffffffa2603868 R08: 0000000000000000 R09:0000ffffa27bcad4
[ 8.933072][ T0] R10: 0000ffffffffffff R11: 0000ffffa27bcad7 R12:
0000000000000168
[ 8.933072][ T0] R13: 0000000000092cc0 R14: 0000000000000246 R15:ffffffffa1664c89
[ 8.933072][ T0] FS: 0000000000000000(0000) GS:ffff8987f3000000(0000) knlGS:0000000000000000
[ 8.933072][ T0] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8.933072][ T0] CR2: ffff898bfc9ff000 CR3: 000000033dc0e001 CR4:00000000001606f0
[ 8.933072][ T0] Call Trace:
[ 8.933072][ T0] lock_is_held_type+0x66/0x13072][ T0] ?
rcu_is_watching+0x79/0xa0 [ 8.933072][ T0] ? create_object+0x69/0x690 [ 8.933072][ T0] rcu_read_lock_sched_held+0x7f/0xa0 [ 8.933072][ T0] kmem_cache_alloc+0x3b2/0x420 [ 8.933072][ T0] ? create_object+0x69/0x690 [ 8.933072][ T0] create_object+0x69/0x690 [ 8.933072][ T0] ? find_next_bit+0x7b/0xa0 [ 8.933072][ T0] kmemleak_alloc_percpu+0xde/0x170 [ 8.933072][ T0] pcpu_alloc+0x683/0xc90 [ 8.933072][ T0] __alloc_percpu+0x2d/0x40 [ 8.933072][ T0] alloc_vfsmnt+0xd1/0x380 [ 8.933072][ T0] vfs_create_mount+0x7f/0x2e0 [ 8.933072][ T0] ? proc_get_tree+0x4d/0x60 [ 8.933072][ T0] fc_mount+0x6d/0x80 [ 8.933072][ T0] pid_ns_prepare_proc+0x133/0x190 [ 8.933072][ T0] alloc_pid+0x5c3/0x600 [ 8.933072][ T0] copy_process+0x1ca3/0x3480 [ 8.933072][ T0] ? __lock_acquire+0x739/0x25d0 [ 8.933072][ T0] _do_fork+0xaa/0x9c0 [ 8.933072][ T0] ? rcu_blocking_is_gp+0x83/0xb0 [ 8.933072][ T0] ? synchronize_rcu_expedited+0x80/0x6c0 [ 8.933072][ T0] ? rcu_blocking_is_gp+0x83/0xb0 [ 8.933072][ T0] ? rest_init+0x381/0x381 [ 8.933072][ T0] kernel_thread+0xb0/0xe0 [ 8.933072][ T0] ? rest_init+0x381/0x381 [ 8.933072][ T0] rest_init+0x31/0x381 [ 8.933072][ st_init+0x17/0x29 [ 8.933072][ T0] start_kernel+0x6ac/0x6d0 [ 8.933072][ T0] x86_64_start_reservations+0x24/0x26 [ 8.933072][ T0] x86_64_start_kernel+0xef/0xf6 [ 8.933072][ T0] secondary_startup_64+0xb6/0xc0
[ 8.933072][ T0] irq event stamp: 75594
[ 8.933072][ T0] hardirqs last enabled at (75593): [<ffffffffa1203d52>] trace_hardirqs_on_thunk+0x1a/0x1c
[ 8.933072][ T0] hardirqs last disabled at (75594): [<ffffffffa14b4f96>] kcsan_setup_watchpoint+0x96/0x200
[ 8.933072][ T0] softirqs last enabled at (75592): [<ffffffffa200034c>] __do_softirq+0x34c/0x57c
[ 8.933072][ T0] softirqs last disabled at (75585): [<ffffffffa12c6fb2>] irq_exit+0xa2/0xc0
[ 8.933072][ T0] ---[ end trace f4a667495da45c20 ]---
[ 8.933072][ T0] possible reason: unannotated irqs-on.
[ 8.933072][ T0] irq event stamp: 75594
[ 8.933072][ T0] hardirqs last enabled at (75593): [<ffffffffa1203d52>] trace_hardirqs_on_thunk+0x1a/0x1c
[ 8.933072][ T0] hardirqs last disabled at (75594): [<ffffffffa14b4f96>] kcsan_setup_watchpoint+0x96/0x200
[ 8.933072][ T0] softirqs last enabled at (75592): [<ffffffffa200034c>] __do_softirq+0x34c/0x57c
[ 8.933072][ T0] softirqs last disabled at (75585): [<ffffffffa12c6fb2>] irq_exit+0xa2/0xc0
Quoted 157 lines
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/Race conditions vs. data races
------------------------------Race conditions are logic bugs, where unexpected interleaving of racing concurrent operations result in an erroneous state.
Data races on the other hand are defined at the *memory model/language level*. Many data races are also harmful race conditions, which a tool like KCSAN reports! However, not all data races are race conditions and vice-versa. KCSAN's intent is to report data races according to the LKMM. A data race detector can only work at the memory model/language level.
Deeper analysis, to find high-level race conditions only, requires conveying the intended kernel logic to a tool. This requires (1) the developer writing a specification or model of their code, and then (2) the tool verifying that the implementation matches. This has been done for small bits of code using model checkers and other formal methods, but does not scale to the level of what can be covered with a dynamic analysis based data race detector such as KCSAN.
For reasons outlined in [1, 2], data races can be much more subtle, but can cause no less harm than high-level race conditions.
Changelog
---------
v4:
* Major changes:
- Optimizations resulting in performance improvement of 33% (on microbenchmark).
- Deal with nested interrupts foratomic_next.
- Simplifyreport.c(removing double-locking as well), in preparation forKCSAN_REPORT_VALUE_CHANGE_ONLY.
- Add patch to introduce "data_race(expr)" macro.
- IntroduceKCSAN_REPORT_VALUE_CHANGE_ONLYoption for further filtering of data
races: if a conflicting write was observed via a watchpoint, only report the data race if a value change was observed as well. The option will be enabled by default on syzbot. (rcu-functions will be excluded from this filter at request of Paul McKenney.) Context:http://lkml.kernel.org/r/CANpmjNOepvb6+zJmDePxj21n2rctM4Sp4rJ66x_J-L1UmNK54A@mail.gmail.comv3: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Add microbenchmark.
- Add instruction watchpoint skip randomization.
- Refactor API and core runtime fast-path and slow-path. Compared to the previous version, with a default config and benchmarked using the added microbenchmark, this version is 3.8x faster.
- Make__tsan_unaligned__aliasof generic accesses.
- Rename kcsan_{begin,end}_atomic -> kcsan_{nestable,flat}_atomic_{begin,end}
- For filter list indebugfs.cuse kmalloc+krealloc instead of kvmalloc.
- Split Documentation into separate patch.v2: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Replacekcsan_check_access(.., {true, false})with kcsan_check_{read,write}.
- Changeatomic-instrumented.hto use __atomic_check_{read,write}.
- Use common structkcsan_ctxintask_structand for per-CPU interrupt contexts.v1: http://lkml.kernel.org/r/[email protected]
Marco Elver (10):
kcsan: Add Kernel Concurrency Sanitizer infrastructureinclude/linux/compiler.h: Introducedata_race(expr)macro
kcsan: Add Documentation entry in dev-tools objtool, kcsan: Add KCSAN runtime functions to whitelist build, kcsan: Add KCSAN build exceptions
seqlock, kcsan: Add annotations for KCSAN
seqlock: RequireWRITE_ONCEsurroundingraw_seqcount_barrierasm-generic, kcsan: Add KCSAN instrumentation for bitops locking/atomics, kcsan: Add KCSAN instrumentation x86, kcsan: Enable KCSAN for x86Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/kcsan.rst | 256 +++++++++ MAINTAINERS | 11 + Makefile | 3 +- arch/x86/Kconfig | 1 + arch/x86/boot/Makefile | 2 + arch/x86/boot/compressed/Makefile | 2 + arch/x86/entry/vdso/Makefile | 3 + arch/x86/include/asm/bitops.h | 6 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/cpu/Makefile | 3 + arch/x86/lib/Makefile | 4 + arch/x86/mm/Makefile | 4 + arch/x86/purgatory/Makefile | 2 + arch/x86/realmode/Makefile | 3 + arch/x86/realmode/rm/Makefile | 3 + drivers/firmware/efi/libstub/Makefile | 2 + include/asm-generic/atomic-instrumented.h | 393 +++++++------- include/asm-generic/bitops-instrumented.h | 18 + include/linux/compiler-clang.h | 9 + include/linux/compiler-gcc.h | 7 + include/linux/compiler.h | 57 +- include/linux/kcsan-checks.h | 97 ++++ include/linux/kcsan.h | 115 ++++ include/linux/sched.h | 4 + include/linux/seqlock.h | 51 +- init/init_task.c | 8 + init/main.c | 2 + kernel/Makefile | 6 + kernel/kcsan/Makefile | 11 + kernel/kcsan/atomic.h | 27 + kernel/kcsan/core.c | 626 ++++++++++++++++++++++ kernel/kcsan/debugfs.c | 275 ++++++++++ kernel/kcsan/encoding.h | 94 ++++ kernel/kcsan/kcsan.h | 108 ++++ kernel/kcsan/report.c | 320 +++++++++++ kernel/kcsan/test.c | 121 +++++ kernel/sched/Makefile | 6 + lib/Kconfig.debug | 2 + lib/Kconfig.kcsan | 118 ++++ lib/Makefile | 3 + mm/Makefile | 8 + scripts/Makefile.kcsan | 6 + scripts/Makefile.lib | 10 + scripts/atomic/gen-atomic-instrumented.sh | 17 +- tools/objtool/check.c | 18 + 46 files changed, 2641 insertions(+), 206 deletions(-) create mode 100644 Documentation/dev-tools/kcsan.rst create mode 100644 include/linux/kcsan-checks.h create mode 100644 include/linux/kcsan.h create mode 100644 kernel/kcsan/Makefile create mode 100644 kernel/kcsan/atomic.h create mode 100644 kernel/kcsan/core.c create mode 100644 kernel/kcsan/debugfs.c create mode 100644 kernel/kcsan/encoding.h create mode 100644 kernel/kcsan/kcsan.h create mode 100644 kernel/kcsan/report.c create mode 100644 kernel/kcsan/test.c create mode 100644 lib/Kconfig.kcsan create mode 100644 scripts/Makefile.kcsanSignature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Quoted 6 lines · Marco Elver' via kasan-dev
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
This does not allow the system to boot. Just hang forever at the end.
https://cailca.github.io/files/dmesg.txt
the config (dselect KASAN and select KCSAN with default options):
https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
Quoted 157 lines
To gather early feedback, we announced KCSAN back in September, and have integrated the feedback where possible:
http://lkml.kernel.org/r/CANpmjNPJ_bHjfLZCAPV23AXFfiPiyXXqqu72n6TgWzb2Gnu1eA@mail.gmail.comThe current list of known upstream fixes for data races found by KCSAN can be found here:
https://github.com/google/ktsan/wiki/KCSAN#upstream-fixes-of-data-races-found-by-kcsanWe want to point out and acknowledge the work surrounding the LKMM, including several articles that motivate why data races are dangerous [1, 2], justifying a data race detector such as KCSAN.
[1] https://lwn.net/Articles/793253/
[2] https://lwn.net/Articles/799218/Race conditions vs. data races
------------------------------Race conditions are logic bugs, where unexpected interleaving of racing concurrent operations result in an erroneous state.
Data races on the other hand are defined at the *memory model/language level*. Many data races are also harmful race conditions, which a tool like KCSAN reports! However, not all data races are race conditions and vice-versa. KCSAN's intent is to report data races according to the LKMM. A data race detector can only work at the memory model/language level.
Deeper analysis, to find high-level race conditions only, requires conveying the intended kernel logic to a tool. This requires (1) the developer writing a specification or model of their code, and then (2) the tool verifying that the implementation matches. This has been done for small bits of code using model checkers and other formal methods, but does not scale to the level of what can be covered with a dynamic analysis based data race detector such as KCSAN.
For reasons outlined in [1, 2], data races can be much more subtle, but can cause no less harm than high-level race conditions.
Changelog
---------
v4:
* Major changes:
- Optimizations resulting in performance improvement of 33% (on microbenchmark).
- Deal with nested interrupts foratomic_next.
- Simplifyreport.c(removing double-locking as well), in preparation forKCSAN_REPORT_VALUE_CHANGE_ONLY.
- Add patch to introduce "data_race(expr)" macro.
- IntroduceKCSAN_REPORT_VALUE_CHANGE_ONLYoption for further filtering of data
races: if a conflicting write was observed via a watchpoint, only report the data race if a value change was observed as well. The option will be enabled by default on syzbot. (rcu-functions will be excluded from this filter at request of Paul McKenney.) Context:http://lkml.kernel.org/r/CANpmjNOepvb6+zJmDePxj21n2rctM4Sp4rJ66x_J-L1UmNK54A@mail.gmail.comv3: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Add microbenchmark.
- Add instruction watchpoint skip randomization.
- Refactor API and core runtime fast-path and slow-path. Compared to the previous version, with a default config and benchmarked using the added microbenchmark, this version is 3.8x faster.
- Make__tsan_unaligned__aliasof generic accesses.
- Rename kcsan_{begin,end}_atomic -> kcsan_{nestable,flat}_atomic_{begin,end}
- For filter list indebugfs.cuse kmalloc+krealloc instead of kvmalloc.
- Split Documentation into separate patch.v2: http://lkml.kernel.org/r/[email protected]
* Major changes:
- Replacekcsan_check_access(.., {true, false})with kcsan_check_{read,write}.
- Changeatomic-instrumented.hto use __atomic_check_{read,write}.
- Use common structkcsan_ctxintask_structand for per-CPU interrupt contexts.v1: http://lkml.kernel.org/r/[email protected]
Marco Elver (10):
kcsan: Add Kernel Concurrency Sanitizer infrastructureinclude/linux/compiler.h: Introducedata_race(expr)macro
kcsan: Add Documentation entry in dev-tools objtool, kcsan: Add KCSAN runtime functions to whitelist build, kcsan: Add KCSAN build exceptions
seqlock, kcsan: Add annotations for KCSAN
seqlock: RequireWRITE_ONCEsurroundingraw_seqcount_barrierasm-generic, kcsan: Add KCSAN instrumentation for bitops locking/atomics, kcsan: Add KCSAN instrumentation x86, kcsan: Enable KCSAN for x86Documentation/dev-tools/index.rst | 1 + Documentation/dev-tools/kcsan.rst | 256 +++++++++ MAINTAINERS | 11 + Makefile | 3 +- arch/x86/Kconfig | 1 + arch/x86/boot/Makefile | 2 + arch/x86/boot/compressed/Makefile | 2 + arch/x86/entry/vdso/Makefile | 3 + arch/x86/include/asm/bitops.h | 6 +- arch/x86/kernel/Makefile | 4 + arch/x86/kernel/cpu/Makefile | 3 + arch/x86/lib/Makefile | 4 + arch/x86/mm/Makefile | 4 + arch/x86/purgatory/Makefile | 2 + arch/x86/realmode/Makefile | 3 + arch/x86/realmode/rm/Makefile | 3 + drivers/firmware/efi/libstub/Makefile | 2 + include/asm-generic/atomic-instrumented.h | 393 +++++++------- include/asm-generic/bitops-instrumented.h | 18 + include/linux/compiler-clang.h | 9 + include/linux/compiler-gcc.h | 7 + include/linux/compiler.h | 57 +- include/linux/kcsan-checks.h | 97 ++++ include/linux/kcsan.h | 115 ++++ include/linux/sched.h | 4 + include/linux/seqlock.h | 51 +- init/init_task.c | 8 + init/main.c | 2 + kernel/Makefile | 6 + kernel/kcsan/Makefile | 11 + kernel/kcsan/atomic.h | 27 + kernel/kcsan/core.c | 626 ++++++++++++++++++++++ kernel/kcsan/debugfs.c | 275 ++++++++++ kernel/kcsan/encoding.h | 94 ++++ kernel/kcsan/kcsan.h | 108 ++++ kernel/kcsan/report.c | 320 +++++++++++ kernel/kcsan/test.c | 121 +++++ kernel/sched/Makefile | 6 + lib/Kconfig.debug | 2 + lib/Kconfig.kcsan | 118 ++++ lib/Makefile | 3 + mm/Makefile | 8 + scripts/Makefile.kcsan | 6 + scripts/Makefile.lib | 10 + scripts/atomic/gen-atomic-instrumented.sh | 17 +- tools/objtool/check.c | 18 + 46 files changed, 2641 insertions(+), 206 deletions(-) create mode 100644 Documentation/dev-tools/kcsan.rst create mode 100644 include/linux/kcsan-checks.h create mode 100644 include/linux/kcsan.h create mode 100644 kernel/kcsan/Makefile create mode 100644 kernel/kcsan/atomic.h create mode 100644 kernel/kcsan/core.c create mode 100644 kernel/kcsan/debugfs.c create mode 100644 kernel/kcsan/encoding.h create mode 100644 kernel/kcsan/kcsan.h create mode 100644 kernel/kcsan/report.c create mode 100644 kernel/kcsan/test.c create mode 100644 lib/Kconfig.kcsan create mode 100644 scripts/Makefile.kcsanSignature · 1 line
2.24.0.rc1.363.gb1bccd3e3d-goog
Marco Elver
maintainerQuoted 9 lines · Qian Cai
Quoted 6 lines · Marco Elver' via kasan-dev
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
Quoted 7 lines
This does not allow the system to boot. Just hang forever at the end.
https://cailca.github.io/files/dmesg.txt
the config (dselect KASAN and select KCSAN with default options):
https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
Thanks! That config enables lots of other debug code. I could reproduce the hang. It's related to CONFIG_PROVE_LOCKING etc.
The problem is definitely not the fact that kcsan_setup_watchpoint disables interrupts (tested by removing that code). Although lockdep still complains here, and looking at the code in kcsan/core.c, I just can't see how local_irq_restore cannot be called before returning (in the stacktrace you provided, there is no kcsan function), and interrupts should always be re-enabled. (Interrupts are only disabled during delay in kcsan_setup_watchpoint.)
What I also notice is that this happens when the console starts getting spammed with data-race reports (presumably because some extra debug code has lots of data races according to KCSAN).
My guess is that some of the extra debug logic enabled in that config is incompatible with KCSAN. However, so far I cannot tell where exactly the problem is. For now the work-around would be not using KCSAN with these extra debug options. I will investigate more, but nothing obviously wrong stands out..
Many thanks,
-- Marco
Marco Elver
maintainerQuoted 33 lines · Marco Elver
Quoted 9 lines · Qian Cai
Quoted 6 lines · Marco Elver' via kasan-dev
This is the patch-series for the Kernel Concurrency Sanitizer (KCSAN). KCSAN is a sampling watchpoint-based *data race detector*. More details are included in **Documentation/dev-tools/kcsan.rst**. This patch-series only enables KCSAN for x86, but we expect adding support for other architectures is relatively straightforward (we are aware of experimental ARM64 and POWER support).
Quoted 7 lines
This does not allow the system to boot. Just hang forever at the end.
https://cailca.github.io/files/dmesg.txt
the config (dselect KASAN and select KCSAN with default options):
https://raw.githubusercontent.com/cailca/linux-mm/master/x86.config
Thanks! That config enables lots of other debug code. I could reproduce the hang. It's related to
CONFIG_PROVE_LOCKINGetc.The problem is definitely not the fact that
kcsan_setup_watchpointdisables interrupts (tested by removing that code). Although lockdep still complains here, and looking at the code inkcsan/core.c, I just can't see howlocal_irq_restorecannot be called before returning (in the stacktrace you provided, there is no kcsan function), and interrupts should always be re-enabled. (Interrupts are only disabled during delay inkcsan_setup_watchpoint.)What I also notice is that this happens when the console starts getting spammed with data-race reports (presumably because some extra debug code has lots of data races according to KCSAN).
Quoted 5 lines
My guess is that some of the extra debug logic enabled in that config is incompatible with KCSAN. However, so far I cannot tell where exactly the problem is. For now the work-around would be not using KCSAN with these extra debug options. I will investigate more, but nothing obviously wrong stands out..
It seems that due to spinlock_debug.c containing data races, the console gets spammed with reports. However, it's also possible to encounter deadlock, e.g. printk lock -> spinlock_debug -> KCSAN detects data race -> kcsan_print_report() -> printk lock -> deadlock.
So the best thing is to fix the data races in spinlock_debug. I will send a patch separately for you to test.
The issue that lockdep still reports inconsistency in IRQ flags tracing I cannot yet say what the problem is. It seems that lockdep IRQ flags tracing may have an issue with KCSAN for numerous reasons: let's say lockdep and IRQ flags tracing code is instrumented, which then calls into KCSAN, which disables/enables interrupts, but due to tracing calls back into lockdep code. In other words, there may be some recursion which corrupts hardirqs_enabled.
Thanks,
-- Marco