kcsan: Move kcsan_{disable,enable}_current() to kcsan-checks.h
Subsystems (2)
Marco Elver
maintainerPATCH 1/2 kcsan: Move kcsan_{disable,enable}_current() to kcsan-checks.h
Both affect access checks, and should therefore be in kcsan-checks.h. This is in preparation to use these in compiler.h.
--- include/linux/kcsan-checks.h | 16 ++++++++++++++++ include/linux/kcsan.h | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-)
include/linux/kcsan-checks.h +16 -0
@@ -36,6 +36,20 @@*/ void __kcsan_check_access (const volatile void *ptr,size_t size,int type); +/** +* kcsan_disable_current - disable KCSAN for the current context +* +* Supports nesting. +*/ +void kcsan_disable_current (void ); + +/** +* kcsan_enable_current - re-enable KCSAN for the current context +* +* Supports nesting. +*/ +void kcsan_enable_current (void ); +/** * kcsan_nestable_atomic_begin - begin nestable atomic region *
@@ -133,6 +147,8 @@ void kcsan_end_scoped_access(struct kcsan_scoped_access *sa);static inline void __kcsan_check_access (const volatile void *ptr,size_t size,int type) { } +static inline void kcsan_disable_current (void ) { } +static inline void kcsan_enable_current (void ) { }static inline void kcsan_nestable_atomic_begin (void ) { }static inline void kcsan_nestable_atomic_end (void ) { }static inline void kcsan_flat_atomic_begin (void ) { }
include/linux/kcsan.h +0 -16
@@ -50,25 +50,9 @@ struct kcsan_ctx {*/ void kcsan_init (void ); -/** -* kcsan_disable_current - disable KCSAN for the current context -* -* Supports nesting. -*/ -void kcsan_disable_current (void ); - -/** -* kcsan_enable_current - re-enable KCSAN for the current context -* -* Supports nesting. -*/ -void kcsan_enable_current (void ); -#else /* CONFIG_KCSAN */ static inline void kcsan_init (void ) { } -static inline void kcsan_disable_current (void ) { } -static inline void kcsan_enable_current (void ) { }#endif /* CONFIG_KCSAN */
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Marco Elver
maintainerPATCH 2/2 kcsan: Change data_race() to no longer require marking racing accesses
Thus far, accesses marked with data_race() would still require the racing access to be marked in some way (be it with READ_ONCE(), WRITE_ONCE(), or data_race() itself), as otherwise KCSAN would still report a data race. This requirement, however, seems to be unintuitive, and some valid use-cases demand *not* marking other accesses, as it might hide more serious bugs (e.g. diagnostic reads).
Therefore, this commit changes data_race() to no longer require marking racing accesses (although it's still recommended if possible).
The alternative would have been introducing another variant of data_race(), however, since usage of data_race() already needs to be carefully reasoned about, distinguishing between these cases likely adds more complexity in the wrong place.
--- include/linux/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/compiler.h +2 -2
@@ -326,9 +326,9 @@ unsigned long read_word_at_a_time(const void *addr)#define data_race (expr) \ ({ \ typeof(({ expr; })) __val; \ - kcsan_nestable_atomic_begin(); \ + kcsan_disable_current(); \ __val = ({ expr; }); \ - kcsan_nestable_atomic_end(); \ + kcsan_enable_current(); \ __val; \ })#else
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Re: [PATCH 2/2] kcsan: Change data_race() to no longer require marking racing accesses
Quoted 7 lines · Marco Elver
Thus far, accesses marked with
data_race()would still require the racing access to be marked in some way (be it withREAD_ONCE(),WRITE_ONCE(), ordata_race()itself), as otherwise KCSAN would still report a data race. This requirement, however, seems to be unintuitive, and some valid use-cases demand *not* marking other accesses, as it might hide more serious bugs (e.g. diagnostic reads).
Quoted 7 lines
Therefore, this commit changes
data_race()to no longer require marking racing accesses (although it's still recommended if possible).The alternative would have been introducing another variant of
data_race(), however, since usage ofdata_race()already needs to be carefully reasoned about, distinguishing between these cases likely adds more complexity in the wrong place.
Just a thought, but perhaps worth extending scripts/checkpatch.pl to check for use of data_race() without a comment? We already have that for memory barriers, so should be easy enough to extend with any luck.
Quoted 15 lines
Signed-off-by Marco Elver <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Will Deacon <[email protected]>Cc Qian Cai <[email protected]>--- include/linux/compiler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/compiler.h +0
-0@@ -326,9 +326,9 @@ unsigned long read_word_at_a_time(const void *addr)#define data_race (expr) \
include/linux/compiler.h unsigned long read_word_at_a_time(const void *addr) · line 334
Quoted 10 lines
include/linux/compiler.h +2
-2({ \ typeof(({ expr; })) __val; \ -kcsan_nestable_atomic_begin (); \ +kcsan_disable_current (); \ __val = ({ expr; }); \ -kcsan_nestable_atomic_end (); \ +kcsan_enable_current (); \ __val; \ }) #else
Will
Quoted 4 lines · Marco Elver
Both affect access checks, and should therefore be in
kcsan-checks.h. This is in preparation to use these incompiler.h.Signed-off-by Marco Elver <[email protected]>
The two of these do indeed make data_race() act more like one would expect, thank you! I have queued them for further testing and review.
Thanx, Paul
Quoted 72 lines
--- include/linux/kcsan-checks.h | 16 ++++++++++++++++ include/linux/kcsan.h | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-)include/linux/kcsan-checks.h +16
-0@@ -36,6 +36,20 @@*/ void __kcsan_check_access (const volatile void *ptr,size_t size,int type); +/** +* kcsan_disable_current - disable KCSAN for the current context +* +* Supports nesting. +*/ +void kcsan_disable_current (void ); + +/** +* kcsan_enable_current - re-enable KCSAN for the current context +* +* Supports nesting. +*/ +void kcsan_enable_current (void ); +/** * kcsan_nestable_atomic_begin - begin nestable atomic region * @@ -133,6 +147,8 @@ void kcsan_end_scoped_access(struct kcsan_scoped_access *sa);static inline void __kcsan_check_access (const volatile void *ptr,size_t size,int type) { } +static inline void kcsan_disable_current (void ) { } +static inline void kcsan_enable_current (void ) { }static inline void kcsan_nestable_atomic_begin (void ) { }static inline void kcsan_nestable_atomic_end (void ) { }static inline void kcsan_flat_atomic_begin (void ) { }include/linux/kcsan.h +0
-16@@ -50,25 +50,9 @@ struct kcsan_ctx {*/ void kcsan_init (void ); -/** -* kcsan_disable_current - disable KCSAN for the current context -* -* Supports nesting. -*/ -void kcsan_disable_current (void ); - -/** -* kcsan_enable_current - re-enable KCSAN for the current context -* -* Supports nesting. -*/ -void kcsan_enable_current (void ); -#else /* CONFIG_KCSAN */ static inline void kcsan_init (void ) { } -static inline void kcsan_disable_current (void ) { } -static inline void kcsan_enable_current (void ) { }#endif /* CONFIG_KCSAN */ Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Quoted 8 lines · Marco Elver
Both affect access checks, and should therefore be in
kcsan-checks.h. This is in preparation to use these incompiler.h.Signed-off-by Marco Elver <[email protected]>--- include/linux/kcsan-checks.h | 16 ++++++++++++++++ include/linux/kcsan.h | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-)
Will
Paul E. McKenney
AppliedQuoted 11 lines · Will Deacon
Quoted 8 lines · Marco Elver
Both affect access checks, and should therefore be in
kcsan-checks.h. This is in preparation to use these incompiler.h.Signed-off-by Marco Elver <[email protected]>--- include/linux/kcsan-checks.h | 16 ++++++++++++++++ include/linux/kcsan.h | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-)Acked-by Will Deacon <[email protected]>
Applied both acks, thank you!
Thanx, Paul