Re: [PATCH v2 31/34] drivers/tty: Enable capability analysis for core files

2025-03-05 Thread Marco Elver
On Wed, 5 Mar 2025 at 10:15, Jiri Slaby wrote: > > On 04. 03. 25, 10:21, Marco Elver wrote: > > Enable capability analysis for drivers/tty/*. > > > > This demonstrates a larger conversion to use Clang's capability > > analysis. The benefit is additional static c

Re: [PATCH v2 01/34] compiler_types: Move lock checking attributes to compiler-capability-analysis.h

2025-03-05 Thread Marco Elver
On Wed, Mar 05, 2025 at 11:36AM +0300, Dan Carpenter wrote: > On Tue, Mar 04, 2025 at 10:21:00AM +0100, Marco Elver wrote: > > +#ifndef _LINUX_COMPILER_CAPABILITY_ANALYSIS_H > > +#define _LINUX_COMPILER_CAPABILITY_ANALYSIS_H > > + > > +#ifdef __CHECKER__ > > + >

Re: [PATCH v2 03/34] compiler-capability-analysis: Add test stub

2025-03-04 Thread Marco Elver
On Wed, 5 Mar 2025 at 00:52, Bart Van Assche wrote: > > On 3/4/25 1:21 AM, Marco Elver wrote: > > +#include > > + > > +/* > > + * Test that helper macros work as expected. > > + */ > > +static void __used test_common_helpers(void) > > +{

Re: [PATCH v2 02/34] compiler-capability-analysis: Add infrastructure for Clang's capability analysis

2025-03-04 Thread Marco Elver
On Tue, 4 Mar 2025 at 16:29, Peter Zijlstra wrote: > > On Tue, Mar 04, 2025 at 10:21:01AM +0100, Marco Elver wrote: > > > +# define __asserts_cap(var) > > __attribute__((assert_capability(var))) > > +# define __asserts_shared_cap(var)

Re: [PATCH v2 06/34] cleanup: Basic compatibility with capability analysis

2025-03-04 Thread Marco Elver
On Tue, 4 Mar 2025 at 13:55, Peter Zijlstra wrote: > > On Tue, Mar 04, 2025 at 10:21:05AM +0100, Marco Elver wrote: > > Due to the scoped cleanup helpers used for lock guards wrapping > > acquire/release around their own constructors/destructors that store > > pointers

Re: [PATCH v2 00/34] Compiler-Based Capability- and Locking-Analysis

2025-03-04 Thread Marco Elver
On Tue, 4 Mar 2025 at 12:21, Peter Zijlstra wrote: > > On Tue, Mar 04, 2025 at 10:20:59AM +0100, Marco Elver wrote: > > > === Initial Uses === > > > > With this initial series, the following synchronization primitives are > > supported: `raw_spinlock_t`,

[PATCH v2 24/34] compiler-capability-analysis: Introduce header suppressions

2025-03-04 Thread Marco Elver
version to version 20+. With this in place, we can start enabling the analysis on more complex subsystems in subsequent changes. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 ++ lib/Kconfig.debug | 4 ++- scripts/Makefile.capability

[PATCH v2 10/34] locking/mutex: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
Add support for Clang's capability analysis for mutex. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/mutex.h | 29 + include/linux/mutex_types.h | 4 +- lib/test_capability-analy

[PATCH v2 23/34] compiler-capability-analysis: Remove __cond_lock() function-like helper

2025-03-04 Thread Marco Elver
Signed-off-by: Marco Elver --- v2: * New patch. --- .../dev-tools/capability-analysis.rst | 2 - Documentation/mm/process_addrs.rst| 6 +- .../net/wireless/intel/iwlwifi/iwl-trans.c| 4 +- .../net/wireless/intel/iwlwifi/iwl-trans.h| 6 +- .../wireless/intel/iwlwifi

[PATCH v2 06/34] cleanup: Basic compatibility with capability analysis

2025-03-04 Thread Marco Elver
ical. [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#scoped-capability Signed-off-by: Marco Elver --- include/linux/cleanup.h | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index ec00e3f7af2b..93a166549ad

[PATCH v2 30/34] printk: Move locking annotation to printk.c

2025-03-04 Thread Marco Elver
obal, move the annotation to printk.c. Capability analysis remains disabled for printk.c. This is needed to enable capability analysis for modules that include . Signed-off-by: Marco Elver --- v2: * New patch. --- include/linux/console.h | 4 ++-- kernel/printk/printk.c | 2 ++ 2 files

[PATCH v2 28/34] stackdepot: Enable capability analysis

2025-03-04 Thread Marco Elver
Enable capability analysis for stackdepot. Signed-off-by: Marco Elver --- v2: * Remove disable/enable_capability_analysis() around headers. --- lib/Makefile | 1 + lib/stackdepot.c | 20 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Makefile b/lib

[PATCH v2 34/34] MAINTAINERS: Add entry for Capability Analysis

2025-03-04 Thread Marco Elver
Add entry for all new files added for Clang's capability analysis. Signed-off-by: Marco Elver Cc: Bart Van Assche --- MAINTAINERS | 11 +++ 1 file changed, 11 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8e0736dc2ee0..cf9bf14f99b9 100644 --- a/MAINTAINERS

[PATCH v2 32/34] security/tomoyo: Enable capability analysis

2025-03-04 Thread Marco Elver
= NULL; For which Tetsuo writes: "Good catch. This should be data_race(), for tomoyo_write_control() might concurrently update head->write_buf from non-NULL to non-NULL with head->io_sem held." Signed-off-by: Marco Elver Cc: Kentaro Takeda Cc: Tetsuo Handa --- v2:

[PATCH v2 31/34] drivers/tty: Enable capability analysis for core files

2025-03-04 Thread Marco Elver
Enable capability analysis for drivers/tty/*. This demonstrates a larger conversion to use Clang's capability analysis. The benefit is additional static checking of locking rules, along with better documentation. Signed-off-by: Marco Elver Cc: Greg Kroah-Hartman Cc: Jiri Slaby --- v2:

[PATCH v2 29/34] rhashtable: Enable capability analysis

2025-03-04 Thread Marco Elver
: Marco Elver --- v2: * Remove disable/enable_capability_analysis() around headers. --- include/linux/rhashtable.h | 14 +++--- lib/Makefile | 2 ++ lib/rhashtable.c | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/linux/rhashtable.h

[PATCH v2 33/34] crypto: Enable capability analysis

2025-03-04 Thread Marco Elver
Enable capability analysis for crypto subsystem. This demonstrates a larger conversion to use Clang's capability analysis. The benefit is additional static checking of locking rules, along with better documentation. Signed-off-by: Marco Elver Cc: Herbert Xu Cc: "David S. Miller&q

[PATCH v2 27/34] kcov: Enable capability analysis

2025-03-04 Thread Marco Elver
Enable capability analysis for the KCOV subsystem. Signed-off-by: Marco Elver --- v2: * Remove disable/enable_capability_analysis() around headers. --- kernel/Makefile | 2 ++ kernel/kcov.c | 36 +--- 2 files changed, 27 insertions(+), 11 deletions(-) diff

[PATCH v2 26/34] kfence: Enable capability analysis

2025-03-04 Thread Marco Elver
Enable capability analysis for the KFENCE subsystem. Notable, kfence_handle_page_fault() required minor restructure, which also fixed a subtle race; arguably that function is more readable now. Signed-off-by: Marco Elver --- v2: * Remove disable/enable_capability_analysis() around headers

[PATCH v2 25/34] compiler: Let data_race() imply disabled capability analysis

2025-03-04 Thread Marco Elver
(..) macro imply capability-unsafety. The data_race() macro already denotes the intent that something subtly unsafe is about to happen, so it should be clear enough as-is. Signed-off-by: Marco Elver --- v2: * New patch. --- include/linux/compiler.h | 2 ++ lib/test_capability-analysis.c | 2

[PATCH v2 20/34] locking/ww_mutex: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
capability analysis makes incorrect use of the API harder. Signed-off-by: Marco Elver --- v2: * New patch. --- .../dev-tools/capability-analysis.rst | 3 +- include/linux/ww_mutex.h | 21 -- lib/test_capability-analysis.c| 65 +++ 3 fil

[PATCH v2 19/34] locking/local_lock: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
Add support for Clang's capability analysis for local_lock_t. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/local_lock.h| 18 include/linux/local_lock_internal.h | 41 ++---

[PATCH v2 22/34] compiler-capability-analysis: Remove Sparse support

2025-03-04 Thread Marco Elver
"Luc Van Oostenryck" Cc: Peter Zijlstra Signed-off-by: Marco Elver --- v2: * New patch. --- Documentation/dev-tools/sparse.rst | 19 --- include/linux/compiler-capability-analysis.h | 56 ++-- include/linux/rcupdate.h | 15 +- 3 file

[PATCH v2 18/34] locking/local_lock: Include missing headers

2025-03-04 Thread Marco Elver
rst use in this function) 33 | l->owner = current; Include missing headers to allow including local_lock.h where the required headers are not otherwise included. Signed-off-by: Marco Elver --- include/linux/local_lock_internal.h | 2 ++ 1 file changed, 2 insertions(+) diff --

[PATCH v2 21/34] debugfs: Make debugfs_cancellation a capability struct

2025-03-04 Thread Marco Elver
o that the compiler can see the cancellation function argument, as well as making struct debugfs_cancellation a real capability to benefit from Clang's capability analysis. Signed-off-by: Marco Elver --- include/linux/debugfs.h | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-

[PATCH v2 16/34] kref: Add capability-analysis annotations

2025-03-04 Thread Marco Elver
Mark functions that conditionally acquire the passed lock. Signed-off-by: Marco Elver --- include/linux/kref.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/kref.h b/include/linux/kref.h index 88e82ab1367c..9bc6abe57572 100644 --- a/include/linux/kref.h +++ b/include/linux

[PATCH v2 17/34] locking/rwsem: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
Add support for Clang's capability analysis for rw_semaphore. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/rwsem.h | 56 +--- lib/test_capability-analysis.c| 64 +

[PATCH v2 15/34] srcu: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
Add support for Clang's capability analysis for SRCU. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/srcu.h | 61 +-- lib/test_capability-analysis.c| 24 3 files change

[PATCH v2 13/34] bit_spinlock: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
tended. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 3 ++- include/linux/bit_spinlock.h | 22 +--- include/linux/list_bl.h | 2 ++ lib/test_capability-analysis.c| 26 +++ 4 fi

[PATCH v2 14/34] rcu: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
which enforces using them to update RCU-protected pointers marked with __rcu_guarded. Signed-off-by: Marco Elver --- v2: * Reword commit message and point out re-entrancy caveat. --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/cleanup.h | 4 + in

[PATCH v2 12/34] bit_spinlock: Include missing

2025-03-04 Thread Marco Elver
allow including bit_spinlock.h where is not otherwise included. Signed-off-by: Marco Elver --- include/linux/bit_spinlock.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h index bbc4730a6505..f1174a2fcc4d 100644 --- a/include/linux/bit_

[PATCH v2 11/34] locking/seqlock: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
Add support for Clang's capability analysis for seqlock_t. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/seqlock.h | 24 +++ include/linux/seqlock_types.h | 5 ++- lib/test_capability-analy

[PATCH v2 09/34] compiler-capability-analysis: Change __cond_acquires to take return value

2025-03-04 Thread Marco Elver
which should be more intuitive. No functional change intended. Signed-off-by: Marco Elver --- v2: * Use symbolic values for __cond_acquires() and __cond_acquires_shared() (suggested by Bart). --- fs/dlm/lock.c| 2 +- include/linux/compiler-capability

[PATCH v2 08/34] locking/rwlock, spinlock: Support Clang's capability analysis

2025-03-04 Thread Marco Elver
arded variables. The test verifies that common patterns do not generate false positives. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 3 +- include/linux/rwlock.h| 25 ++-- include/linux/rwlock_api_smp.h| 29 +++- in

[PATCH v2 07/34] lockdep: Annotate lockdep assertions for capability analysis

2025-03-04 Thread Marco Elver
ample, where not all control-flow paths in a function require a held lock, and therefore marking the function with __must_hold(..) is inappropriate. Signed-off-by: Marco Elver --- include/linux/lockdep.h | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/lock

[PATCH v2 05/34] checkpatch: Warn about capability_unsafe() without comment

2025-03-04 Thread Marco Elver
Warn about applications of capability_unsafe() without a comment, to encourage documenting the reasoning behind why it was deemed safe. Signed-off-by: Marco Elver --- scripts/checkpatch.pl | 8 1 file changed, 8 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl

[PATCH v2 04/34] Documentation: Add documentation for Compiler-Based Capability Analysis

2025-03-04 Thread Marco Elver
Adds documentation in Documentation/dev-tools/capability-analysis.rst, and adds it to the index and cross-references from Sparse's document. Signed-off-by: Marco Elver --- v2: * Remove cross-reference to Sparse, since we plan to remove Sparse support anyway. * Mention __no_capability_ana

[PATCH v2 03/34] compiler-capability-analysis: Add test stub

2025-03-04 Thread Marco Elver
Add a simple test stub where we will add common supported patterns that should not generate false positive of each new supported capability. Signed-off-by: Marco Elver --- lib/Kconfig.debug | 14 ++ lib/Makefile | 3 +++ lib/test_capability-analysis.c

[PATCH v2 02/34] compiler-capability-analysis: Add infrastructure for Clang's capability analysis

2025-03-04 Thread Marco Elver
t changes. A Clang version that supports -Wthread-safety-pointer is recommended, but not required: https://github.com/llvm/llvm-project/commit/de10e44b6fe7 Signed-off-by: Marco Elver --- v2: * New -Wthread-safety feature rename to -Wthread-safety-pointer (was -Wthread-safety-addressof). * Introdu

[PATCH v2 01/34] compiler_types: Move lock checking attributes to compiler-capability-analysis.h

2025-03-04 Thread Marco Elver
towards "capability analysis". No functional change intended. Signed-off-by: Marco Elver --- include/linux/compiler-capability-analysis.h | 32 include/linux/compiler_types.h | 18 ++- 2 files changed, 34 insertions(+), 16 deletions(-) create m

[PATCH v2 00/34] Compiler-Based Capability- and Locking-Analysis

2025-03-04 Thread Marco Elver
ems as additional examples of larger subsystem. Where it was obvious, the __guarded_by attribute was added to lock-guarded variables to improve coverage. * drivers/tty * security/tomoyo * crypto/ RFC v1: https://lore.kernel.org/lkml/20250206181711.1902989-1-el...@google.com

Re: [PATCH RFC 00/24] Compiler-Based Capability- and Locking-Analysis

2025-02-26 Thread Marco Elver
On Thu, 6 Feb 2025 at 19:17, Marco Elver wrote: [...] > Capability analysis is a C language extension, which enables statically > checking that user-definable "capabilities" are acquired and released where > required. An obvious application is lock-safety checking for the

Re: [PATCH RFC 15/24] rcu: Support Clang's capability analysis

2025-02-21 Thread Marco Elver
On Fri, 21 Feb 2025 at 19:52, Peter Zijlstra wrote: > > On Fri, Feb 21, 2025 at 10:08:06AM -0800, Paul E. McKenney wrote: > > > > ... unfortunately even for shared locks, the compiler does not like > > > re-entrancy yet. It's not yet supported, and to fix that I'd have to go > > > and implement th

Re: [PATCH RFC 15/24] rcu: Support Clang's capability analysis

2025-02-21 Thread Marco Elver
On Thu, Feb 20, 2025 at 05:26PM -0800, Paul E. McKenney wrote: [...] > > That's what I've tried with this patch (rcu_read_lock_bh() also > > acquires "RCU", on top of "RCU_BH"). I need to add a re-entrancy test, > > and make sure it doesn't complain about that. At a later stage we > > might also wa

Re: [PATCH RFC 15/24] rcu: Support Clang's capability analysis

2025-02-20 Thread Marco Elver
On Thu, 20 Feb 2025 at 23:36, Paul E. McKenney wrote: [...] > Suppose that one function walks an RCU-protected list, calling some > function from some other subsystem on each element. Suppose that each > element has another RCU protected list. > > It would be good if the two subsystems could just

Re: [PATCH RFC 15/24] rcu: Support Clang's capability analysis

2025-02-20 Thread Marco Elver
On Thu, 20 Feb 2025 at 23:00, Paul E. McKenney wrote: > > On Thu, Feb 06, 2025 at 07:10:09PM +0100, Marco Elver wrote: > > Improve the existing annotations to properly support Clang's capability > > analysis. > > > > The old annotations distinguished

Re: [PATCH RFC 08/24] lockdep: Annotate lockdep assertions for capability analysis

2025-02-11 Thread Marco Elver
On Mon, 10 Feb 2025 at 19:54, Bart Van Assche wrote: > > > On 2/10/25 10:23 AM, Marco Elver wrote: > > If you try to write code where you access a guarded_by variable, but > > the lock is held not in all paths we can write it like this: > > > > struct bar { >

Re: [PATCH RFC 08/24] lockdep: Annotate lockdep assertions for capability analysis

2025-02-10 Thread Marco Elver
On Mon, 10 Feb 2025 at 19:10, Bart Van Assche wrote: > > On 2/6/25 10:10 AM, Marco Elver wrote: > > diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h > > index 67964dc4db95..5cea929b2219 100644 > > --- a/include/linux/lockdep.h > > +++ b/include/linux/lo

Re: [PATCH RFC 02/24] compiler-capability-analysis: Rename __cond_lock() to __cond_acquire()

2025-02-07 Thread Marco Elver
On Fri, 7 Feb 2025 at 10:41, Peter Zijlstra wrote: > > On Fri, Feb 07, 2025 at 10:32:25AM +0100, Marco Elver wrote: > > On Fri, Feb 07, 2025 at 09:28AM +0100, Peter Zijlstra wrote: > > > On Thu, Feb 06, 2025 at 07:09:56PM +0100, Marco Elver wrote: > > > > J

Re: [PATCH RFC 02/24] compiler-capability-analysis: Rename __cond_lock() to __cond_acquire()

2025-02-07 Thread Marco Elver
On Fri, Feb 07, 2025 at 09:28AM +0100, Peter Zijlstra wrote: > On Thu, Feb 06, 2025 at 07:09:56PM +0100, Marco Elver wrote: > > Just like the pairing of attribute __acquires() with a matching > > function-like macro __acquire(), the attribute __cond_acquires() should > > hav

Re: [PATCH RFC 07/24] cleanup: Basic compatibility with capability analysis

2025-02-06 Thread Marco Elver
On Thu, 6 Feb 2025 at 22:29, Bart Van Assche wrote: > > On 2/6/25 10:10 AM, Marco Elver wrote: > > @@ -243,15 +243,18 @@ const volatile void * __must_check_fn(const volatile > > void *val) > > #define DEFINE_CLASS(_name, _type, _exit, _init, _init_args...)

Re: [PATCH RFC 01/24] compiler_types: Move lock checking attributes to compiler-capability-analysis.h

2025-02-06 Thread Marco Elver
On Thu, 6 Feb 2025 at 19:40, Bart Van Assche wrote: > > On 2/6/25 10:09 AM, Marco Elver wrote: > > +/* Sparse context/lock checking support. */ > > +# define __must_hold(x) __attribute__((context(x,1,1))) > > +# define __acquires(x) __at

[PATCH RFC 13/24] bit_spinlock: Include missing

2025-02-06 Thread Marco Elver
allow including bit_spinlock.h where is not otherwise included. Signed-off-by: Marco Elver --- include/linux/bit_spinlock.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/bit_spinlock.h b/include/linux/bit_spinlock.h index bbc4730a6505..f1174a2fcc4d 100644 --- a/include/linux/bit_

[PATCH RFC 21/24] kfence: Enable capability analysis

2025-02-06 Thread Marco Elver
Enable capability analysis for the KFENCE subsystem. Notable, kfence_handle_page_fault() required minor restructure, which also fixed a subtle race; arguably that function is more readable now. Signed-off-by: Marco Elver --- mm/kfence/Makefile | 2 ++ mm/kfence/core.c| 24

[PATCH RFC 24/24] rhashtable: Enable capability analysis

2025-02-06 Thread Marco Elver
: Marco Elver --- include/linux/rhashtable.h | 14 +++--- lib/Makefile | 2 ++ lib/rhashtable.c | 12 +--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h index 8463a128e2f4..c6374691ccc7

[PATCH RFC 23/24] stackdepot: Enable capability analysis

2025-02-06 Thread Marco Elver
Enable capability analysis for stackdepot. Signed-off-by: Marco Elver --- lib/Makefile | 1 + lib/stackdepot.c | 24 ++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 1dbb59175eb0..f40ba93c9a94 100644 --- a/lib

[PATCH RFC 22/24] kcov: Enable capability analysis

2025-02-06 Thread Marco Elver
Enable capability analysis for the KCOV subsystem. Signed-off-by: Marco Elver --- kernel/Makefile | 2 ++ kernel/kcov.c | 40 +--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 87866b037fbe

[PATCH RFC 18/24] locking/rwsem: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
Add support for Clang's capability analysis for rw_semaphore. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/rwsem.h | 56 +--- lib/test_capability-analysis.c| 64 +

[PATCH RFC 20/24] debugfs: Make debugfs_cancellation a capability struct

2025-02-06 Thread Marco Elver
o that the compiler can see the cancellation function argument, as well as making struct debugfs_cancellation a real capability to benefit from Clang's capability analysis. Signed-off-by: Marco Elver --- include/linux/debugfs.h | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-

[PATCH RFC 19/24] locking/local_lock: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
Add support for Clang's capability analysis for local_lock_t. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/local_lock.h| 18 include/linux/local_lock_internal.h | 41 ++---

[PATCH RFC 17/24] kref: Add capability-analysis annotations

2025-02-06 Thread Marco Elver
Mark functions that conditionally acquire the passed lock. Signed-off-by: Marco Elver --- include/linux/kref.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/kref.h b/include/linux/kref.h index 88e82ab1367c..c1bd26936f41 100644 --- a/include/linux/kref.h +++ b/include/linux

[PATCH RFC 16/24] srcu: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
Add support for Clang's capability analysis for SRCU. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/srcu.h | 61 +-- lib/test_capability-analysis.c| 24 3 files change

[PATCH RFC 14/24] bit_spinlock: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
tended. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 3 ++- include/linux/bit_spinlock.h | 22 +--- include/linux/list_bl.h | 2 ++ lib/test_capability-analysis.c| 26 +++ 4 fi

[PATCH RFC 15/24] rcu: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
warn if a pointer is dereferenced without any of the RCU locks held, or updated without the appropriate helpers. The primitives rcu_assign_pointer() and friends are wrapped with capability_unsafe(), which enforces using them to update RCU-protected pointers marked with __rcu_guarded. Signed-off-by: Marco

[PATCH RFC 12/24] locking/seqlock: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
Add support for Clang's capability analysis for seqlock_t. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/seqlock.h | 24 +++ include/linux/seqlock_types.h | 5 ++- lib/test_capability-analy

[PATCH RFC 09/24] locking/rwlock, spinlock: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
arded variables. The test verifies that common patterns do not generate false positives. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 3 +- include/linux/rwlock.h| 25 ++-- include/linux/rwlock_api_smp.h| 29 +++- in

[PATCH RFC 11/24] locking/mutex: Support Clang's capability analysis

2025-02-06 Thread Marco Elver
Add support for Clang's capability analysis for mutex. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 2 +- include/linux/mutex.h | 29 + include/linux/mutex_types.h | 4 +- lib/test_capability-analy

[PATCH RFC 08/24] lockdep: Annotate lockdep assertions for capability analysis

2025-02-06 Thread Marco Elver
ample, where not all control-flow paths in a function require a held lock, and therefore marking the function with __must_hold(..) is inappropriate. Signed-off-by: Marco Elver --- include/linux/lockdep.h | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/lock

[PATCH RFC 10/24] compiler-capability-analysis: Change __cond_acquires to take return value

2025-02-06 Thread Marco Elver
While Sparse is oblivious to the return value of conditional acquire functions, Clang's capability analysis needs to know the return value which indicates successful acquisition. Add the additional argument, and convert existing uses. No functional change intended. Signed-off-by: Marco

[PATCH RFC 06/24] checkpatch: Warn about capability_unsafe() without comment

2025-02-06 Thread Marco Elver
Warn about applications of capability_unsafe() without a comment, to encourage documenting the reasoning behind why it was deemed safe. Signed-off-by: Marco Elver --- scripts/checkpatch.pl | 8 1 file changed, 8 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl

[PATCH RFC 07/24] cleanup: Basic compatibility with capability analysis

2025-02-06 Thread Marco Elver
ical. [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#scoped-capability Signed-off-by: Marco Elver --- include/linux/cleanup.h | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h index ec00e3f7af2b..93a166549ad

[PATCH RFC 05/24] Documentation: Add documentation for Compiler-Based Capability Analysis

2025-02-06 Thread Marco Elver
Adds documentation in Documentation/dev-tools/capability-analysis.rst, and adds it to the index and cross-references from Sparse's document. Signed-off-by: Marco Elver --- .../dev-tools/capability-analysis.rst | 147 ++ Documentation/dev-tools/index.rst

[PATCH RFC 04/24] compiler-capability-analysis: Add test stub

2025-02-06 Thread Marco Elver
Add a simple test stub where we will add common supported patterns that should not generate false positive of each new supported capability. Signed-off-by: Marco Elver --- lib/Kconfig.debug | 14 ++ lib/Makefile | 3 +++ lib/test_capability-analysis.c

[PATCH RFC 03/24] compiler-capability-analysis: Add infrastructure for Clang's capability analysis

2025-02-06 Thread Marco Elver
changes. [ RFC Note: A Clang version that supports -Wthread-safety-addressof is recommended, but not required: https://github.com/llvm/llvm-project/pull/123063 Should this patch series reach non-RFC stage, it is planned to be committed to Clang before. ] Signed-off-by: Marco Elver -

[PATCH RFC 02/24] compiler-capability-analysis: Rename __cond_lock() to __cond_acquire()

2025-02-06 Thread Marco Elver
Just like the pairing of attribute __acquires() with a matching function-like macro __acquire(), the attribute __cond_acquires() should have a matching function-like macro __cond_acquire(). To be consistent, rename __cond_lock() to __cond_acquire(). Signed-off-by: Marco Elver --- drivers/net

[PATCH RFC 01/24] compiler_types: Move lock checking attributes to compiler-capability-analysis.h

2025-02-06 Thread Marco Elver
towards "capability analysis". No functional change intended. Signed-off-by: Marco Elver --- include/linux/compiler-capability-analysis.h | 32 include/linux/compiler_types.h | 18 ++- 2 files changed, 34 insertions(+), 16 deletions(-) create m

[PATCH RFC 00/24] Compiler-Based Capability- and Locking-Analysis

2025-02-06 Thread Marco Elver
ency: https://github.com/llvm/llvm-project/pull/123063 This series is also available at this Git tree: https://git.kernel.org/pub/scm/linux/kernel/git/melver/linux.git/log/?h=cap-analysis Marco Elver (24): compiler_types: Move lock checking attributes to compiler-capability-a

Re: [PATCH v2 2/6] ubsan: Reintroduce signed and unsigned overflow sanitizers

2024-02-02 Thread Marco Elver
On Fri, 2 Feb 2024 at 13:17, Kees Cook wrote: > > On Fri, Feb 02, 2024 at 12:01:55PM +0100, Marco Elver wrote: > > On Fri, 2 Feb 2024 at 11:16, Kees Cook wrote: > > > [...] > > > +config UBSAN_UNSIGNED_WRAP > > > + bool "Perform

Re: [PATCH v2 2/6] ubsan: Reintroduce signed and unsigned overflow sanitizers

2024-02-02 Thread Marco Elver
ithmetic wrap-around. > > Additionally keep these disabled under CONFIG_COMPILE_TEST for now. > > Link: https://github.com/KSPP/linux/issues/26 [1] > Link: https://github.com/KSPP/linux/issues/27 [2] > Link: https://github.com/KSPP/linux/issues/344 [3] > Cc: Justin Stitt > Cc: Miguel