Skip to contentSkip to conversation

KCSAN updates for v5.9

PATCH In review Paul E. McKenney 2 participants 10 messages Jun 23, 2020 – Jun 24, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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(-)
maintainer
#1 lore raw
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_kcsan inline' in test, courtesy of Marco Elver.

Quoted 7 lines

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.

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

#2 lore raw
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_kcsan inline' in test, courtesy of Marco Elver.

Quoted 7 lines

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.

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

maintainer
#3 lore raw
Quoted 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_kcsan inline' in test, courtesy of Marco Elver.

Quoted 7 lines

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.

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

#4 lore raw
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_kcsan inline' in test, courtesy of Marco Elver.

Quoted 7 lines

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.

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

#5 lore raw
In reply to 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 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_kcsan inline' in test, courtesy of Marco Elver.

Quoted 7 lines

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.

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(-)
#6 lore raw

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
index ce4bbd9..8fa0dd6 100644
@@ -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
index 3f3b5bc..3d282d5 100644
@@ -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
index bd4da1a..dd66206 100644
@@ -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
#7 lore raw

PATCH 2/3 kcsan: Simplify compiler flags

In reply to Paul E. McKenney

From: 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
index 092ce58..fea064a 100644
@@ -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
#8 lore raw

PATCH 3/3 kcsan: Disable branch tracing in core runtime

In reply to Paul E. McKenney

From: 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
index fea064a..65ca553 100644
@@ -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
#9 lore raw
In reply to Paul E. McKenney
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_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.

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(-)