KCSAN updates for v5.9
Subsystems (5)
cover KCSAN updates for v5.9
Hello!
This series provides KCSAN updates:
1. Annotate a data race in vm_area_dup(), courtesy of Qian Cai.
2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add ASSERT_EXCLUSIVE_ACCESS() to __list_splice_init_rcu().
4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in osq_lock.
6. Prefer '__no_kcsan inline' in test, courtesy of Marco Elver.
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename test.c to selftest.c, courtesy of Marco Elver.
9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
Thanx, Paul
------------------------------------------------------------------------
arch/x86/mm/pat/set_memory.c | 2 include/linux/rculist.h | 2 kernel/fork.c | 8 kernel/kcsan/Makefile | 5 kernel/kcsan/atomic.h | 6 kernel/kcsan/core.c | 9 kernel/kcsan/kcsan-test.c | 1111 ++++++++++++++++++++++++++++++++++++++++++- kernel/kcsan/selftest.c | 1 kernel/locking/osq_lock.c | 6 lib/Kconfig.kcsan | 23 10 files changed, 1161 insertions(+), 12 deletions(-)
Marco Elver
maintainerQuoted 17 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.
Quoted 7 lines
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
Do we want GCC support back for 5.9?
https://lkml.kernel.org/r/[email protected]
I was hoping it could go into 5.9, because it makes a big difference in terms of usability as it provides more compiler choice. The only significant change for GCC support is the addition of the checking of (CC_IS_GCC && (....)).
Thanks,
-- Marco
Quoted 26 lines · Marco Elver
Quoted 17 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.Quoted 7 lines
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
Quoted 8 lines
Do we want GCC support back for 5.9?
https://lkml.kernel.org/r/[email protected]I was hoping it could go into 5.9, because it makes a big difference in terms of usability as it provides more compiler choice. The only significant change for GCC support is the addition of the checking of (
CC_IS_GCC&& (....)).
Very good, I will rebase the following into the KCSAN branch for v5.9:
3e490e3 kcsan: Re-add GCC as a supported compiler 03296de kcsan: Simplify compiler flags d831090 kcsan: Disable branch tracing in core runtime
Please let me know if any other adjustments are needed.
Thanx, Paul
Marco Elver
maintainerQuoted 37 lines · Paul E. McKenney
Quoted 26 lines · Marco Elver
Quoted 17 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.Quoted 7 lines
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
Quoted 8 lines
Do we want GCC support back for 5.9?
https://lkml.kernel.org/r/[email protected]I was hoping it could go into 5.9, because it makes a big difference in terms of usability as it provides more compiler choice. The only significant change for GCC support is the addition of the checking of (
CC_IS_GCC&& (....)).
Quoted 7 lines
Very good, I will rebase the following into the KCSAN branch for v5.9:
3e490e3 kcsan: Re-add GCC as a supported compiler 03296de kcsan: Simplify compiler flags d831090 kcsan: Disable branch tracing in core runtime
Please let me know if any other adjustments are needed.
Looks good to me, thank you!
Thanks,
-- Marco
Quoted 40 lines · Marco Elver
Quoted 39 lines · Paul E. McKenney
Quoted 26 lines · Marco Elver
Quoted 17 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.Quoted 7 lines
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
Quoted 8 lines
Do we want GCC support back for 5.9?
https://lkml.kernel.org/r/[email protected]I was hoping it could go into 5.9, because it makes a big difference in terms of usability as it provides more compiler choice. The only significant change for GCC support is the addition of the checking of (
CC_IS_GCC&& (....)).Very good, I will rebase the following into the KCSAN branch for v5.9:
Quoted 7 lines
Quoted 5 lines
3e490e3 kcsan: Re-add GCC as a supported compiler 03296de kcsan: Simplify compiler flags d831090 kcsan: Disable branch tracing in core runtime
Please let me know if any other adjustments are needed.
Looks good to me, thank you!
And updated on the "dev" branch of -rcu.
Thanx, Paul
Quoted 3 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
And three more, so that GCC can join Clang in the KCSAN fun.
Quoted 12 lines
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.
Quoted 7 lines
7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
10. Add jiffies test to test suite, courtesy of Marco Elver.
11. Re-add GCC as a supported compiler.
12. Simplify compiler flags.
13. Disable branch tracing in core runtime.
Please note that using GCC for KCSAN requires building your own compiler from recent mainline.
Thanx, Paul
------------------------------------------------------------------------
The added three (#11-#13) only:
------------------------------------------------------------------------
Documentation/dev-tools/kcsan.rst | 3 ++- kernel/kcsan/Makefile | 6 +++--- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-)
PATCH 1/3 kcsan: Re-add GCC as a supported compiler
From: Marco Elver <[email protected]>
GCC version 11 recently implemented all requirements to correctly support KCSAN:
1. Correct no_sanitize-attribute inlining behaviour:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=4089df8ef4a63126b0774c39b6638845244c20d2
2. --param=tsan-distinguish-volatile
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ab2789ec507a94f1a75a6534bca51c7b39037ce0
3. --param=tsan-instrument-func-entry-exit
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=06712fc68dc9843d9af7c7ac10047f49d305ad76
Therefore, we can re-enable GCC for KCSAN, and document the new compiler requirements.
--- Documentation/dev-tools/kcsan.rst | 3 ++- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-)
Documentation/dev-tools/kcsan.rst +2 -1
@@ -8,7 +8,8 @@ approach to detect races. KCSAN's primary purpose is to detect `data races`_. Usage ----- -KCSAN requires Clang version 11 or later. +KCSAN is supported by both GCC and Clang. With GCC we require version 11 or +later, and with Clang also require version 11 or later. To enable KCSAN configure the kernel with::
lib/Kconfig.kcsan +2 -1
@@ -4,7 +4,8 @@ config HAVE_ARCH_KCSAN bool config HAVE_KCSAN_COMPILER - def_bool CC_IS_CLANG && $(cc-option,-fsanitize=thread -mllvm -tsan-distinguish-volatile=1) + def_bool (CC_IS_CLANG && $(cc-option,-fsanitize=thread -mllvm -tsan-distinguish-volatile=1)) || \ + (CC_IS_GCC && $(cc-option,-fsanitize=thread --param tsan-distinguish-volatile=1)) help For the list of compilers that support KCSAN, please see <file:Documentation/dev-tools/kcsan.rst>.
scripts/Makefile.kcsan +1 -1
@@ -6,7 +6,7 @@ ifdef CONFIG_KCSAN ifdef CONFIG_CC_IS_CLANG cc-param = -mllvm -$(1) else -cc-param = --param -$(1) +cc-param = --param $(1) endif # Keep most options here optional, to allow enabling more compilers if absence
Signature · 1 line
2.9.5
PATCH 2/3 kcsan: Simplify compiler flags
In reply to Paul E. McKenneyFrom: Marco Elver <[email protected]>
Simplify the set of compiler flags for the runtime by removing cc-option from -fno-stack-protector, because all supported compilers support it. This saves us one compiler invocation during build.
--- kernel/kcsan/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/kcsan/Makefile +2 -2
@@ -7,8 +7,8 @@ CFLAGS_REMOVE_core.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) -CFLAGS_core.o := $(call cc-option,-fno-conserve-stack,) \ - $(call cc-option,-fno-stack-protector,) +CFLAGS_core.o := $(call cc-option,-fno-conserve-stack) \ + -fno-stack-protector obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
Signature · 1 line
2.9.5
PATCH 3/3 kcsan: Disable branch tracing in core runtime
In reply to Paul E. McKenneyFrom: Marco Elver <[email protected]>
Disable branch tracing in core KCSAN runtime if branches are being traced (TRACE_BRANCH_PROFILING). This it to avoid its performance impact, but also avoid recursion in case KCSAN is enabled for the branch tracing runtime.
The latter had already been a problem for KASAN:
https://lore.kernel.org/lkml/CANpmjNOeXmD5E3O50Z3MjkiuCYaYOPyi+1rq=GZvEKwBvLR0Ug@mail.gmail.com/
--- kernel/kcsan/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kcsan/Makefile +1 -1
@@ -8,7 +8,7 @@ CFLAGS_REMOVE_debugfs.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) CFLAGS_core.o := $(call cc-option,-fno-conserve-stack) \ - -fno-stack-protector + -fno-stack-protector -DDISABLE_BRANCH_PROFILING obj-y := core.o debugfs.o report.o obj-$(CONFIG_KCSAN_SELFTEST) += selftest.o
Signature · 1 line
2.9.5
Quoted 25 lines · Paul E. McKenney
Quoted 3 lines · Paul E. McKenney
Hello!
This series provides KCSAN updates:
And three more, so that GCC can join Clang in the KCSAN fun.
Quoted 18 lines
1. Annotate a data race in
vm_area_dup(), courtesy of Qian Cai.2. x86/mm/pat: Mark an intentional data race, courtesy of Qian Cai.
3. Add
ASSERT_EXCLUSIVE_ACCESS()to__list_splice_init_rcu().4. Add test suite, courtesy of Marco Elver.
5. locking/osq_lock: Annotate a data race in
osq_lock.6. Prefer '
__no_kcsaninline' in test, courtesy of Marco Elver.7. Silence -Wmissing-prototypes warning with W=1, courtesy of Qian Cai.
8. Rename
test.ctoselftest.c, courtesy of Marco Elver.9. Remove existing special atomic rules, courtesy of Marco Elver.
Quoted 7 lines
Quoted 1 line
10. Add jiffies test to test suite, courtesy of Marco Elver.
11. Re-add GCC as a supported compiler.
12. Simplify compiler flags.
13. Disable branch tracing in core runtime.
All three of which, I should hasten to add, are courtesy of Marco Elver.
Quoted 2 lines
Please note that using GCC for KCSAN requires building your own compiler from recent mainline.
Thanx, Paul
Quoted 9 lines
------------------------------------------------------------------------
The added three (#11-#13) only:
------------------------------------------------------------------------Documentation/dev-tools/kcsan.rst | 3 ++- kernel/kcsan/Makefile | 6 +++--- lib/Kconfig.kcsan | 3 ++- scripts/Makefile.kcsan | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-)