]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
compiler-context-analysis: Remove __assume_ctx_lock from initializers
authorMarco Elver <elver@google.com>
Mon, 19 Jan 2026 09:05:56 +0000 (10:05 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 28 Jan 2026 19:45:25 +0000 (20:45 +0100)
Remove __assume_ctx_lock() from lock initializers.

Implicitly asserting an active context during initialization caused
false-positive double-lock errors when acquiring a lock immediately after its
initialization. Moving forward, guarded member initialization must either:

1. Use guard(type_init)(&lock) or scoped_guard(type_init, ...).
2. Use context_unsafe() for simple initialization.

Reported-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/57062131-e79e-42c2-aa0b-8f931cb8cac2@acm.org/
Link: https://patch.msgid.link/20260119094029.1344361-7-elver@google.com
include/linux/local_lock_internal.h
include/linux/mutex.h
include/linux/rwlock.h
include/linux/rwlock_rt.h
include/linux/rwsem.h
include/linux/seqlock.h
include/linux/spinlock.h
include/linux/spinlock_rt.h
include/linux/ww_mutex.h
lib/test_context-analysis.c

index ed2f3fb4c360409a36cb255f6062bba9de2ee201..eff711bf973f546f9f5c925b2f4abf0fa270f8ad 100644 (file)
@@ -87,13 +87,11 @@ do {                                                                \
                              0, LD_WAIT_CONFIG, LD_WAIT_INV,   \
                              LD_LOCK_PERCPU);                  \
        local_lock_debug_init(lock);                            \
-       __assume_ctx_lock(lock);                                \
 } while (0)
 
 #define __local_trylock_init(lock)                             \
 do {                                                           \
        __local_lock_init((local_lock_t *)lock);                \
-       __assume_ctx_lock(lock);                                \
 } while (0)
 
 #define __spinlock_nested_bh_init(lock)                                \
@@ -105,7 +103,6 @@ do {                                                                \
                              0, LD_WAIT_CONFIG, LD_WAIT_INV,   \
                              LD_LOCK_NORMAL);                  \
        local_lock_debug_init(lock);                            \
-       __assume_ctx_lock(lock);                                \
 } while (0)
 
 #define __local_lock_acquire(lock)                                     \
index 6b12009351d2364f1cf469224e166cbbb96d09ec..ecaa0440f6ec48a7c36b852d8e6509514483d2a4 100644 (file)
@@ -62,7 +62,6 @@ do {                                                                  \
        static struct lock_class_key __key;                             \
                                                                        \
        __mutex_init((mutex), #mutex, &__key);                          \
-       __assume_ctx_lock(mutex);                                       \
 } while (0)
 
 /**
index 65a5b55e1bcdc9c8c1510f6f48c4f2dacd3759ba..3390d21c95dd1b0bfff324d486cc526ba092e317 100644 (file)
@@ -22,11 +22,10 @@ do {                                                                \
        static struct lock_class_key __key;                     \
                                                                \
        __rwlock_init((lock), #lock, &__key);                   \
-       __assume_ctx_lock(lock);                                \
 } while (0)
 #else
 # define rwlock_init(lock)                                     \
-       do { *(lock) = __RW_LOCK_UNLOCKED(lock); __assume_ctx_lock(lock); } while (0)
+       do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0)
 #endif
 
 #ifdef CONFIG_DEBUG_SPINLOCK
index 37b387dcab21bbd02c45f07d11ec6b2ad34c91f4..5353abbfdc0bfe5811d7affb783f4aa2f4d45f6e 100644 (file)
@@ -22,7 +22,6 @@ do {                                                  \
                                                        \
        init_rwbase_rt(&(rwl)->rwbase);                 \
        __rt_rwlock_init(rwl, #rwl, &__key);            \
-       __assume_ctx_lock(rwl);                         \
 } while (0)
 
 extern void rt_read_lock(rwlock_t *rwlock)     __acquires_shared(rwlock);
index ea1bbdb57a4778b40459d9abe9e833c9932ee061..9bf1d93d3d7ba35df0e8c80d80293578e3fcd305 100644 (file)
@@ -121,7 +121,6 @@ do {                                                                \
        static struct lock_class_key __key;                     \
                                                                \
        __init_rwsem((sem), #sem, &__key);                      \
-       __assume_ctx_lock(sem);                                 \
 } while (0)
 
 /*
@@ -175,7 +174,6 @@ do {                                                                \
        static struct lock_class_key __key;                     \
                                                                \
        __init_rwsem((sem), #sem, &__key);                      \
-       __assume_ctx_lock(sem);                                 \
 } while (0)
 
 static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem)
index 077c8d5b2afd49aa98b93a00e0e1412a3bfdfd3d..5a40252b833486315ca72ddd31d38cd27b11883e 100644 (file)
@@ -817,7 +817,6 @@ static __always_inline void write_seqcount_latch_end(seqcount_latch_t *s)
        do {                                                            \
                spin_lock_init(&(sl)->lock);                            \
                seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock);   \
-               __assume_ctx_lock(sl);                                  \
        } while (0)
 
 /**
index 7b11991c742a8d3c408966e072b4e490015f9c59..e1e2f144af9b41dfca5dca8affb5321e024be94a 100644 (file)
@@ -106,12 +106,11 @@ do {                                                                      \
        static struct lock_class_key __key;                             \
                                                                        \
        __raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN);      \
-       __assume_ctx_lock(lock);                                        \
 } while (0)
 
 #else
 # define raw_spin_lock_init(lock)                              \
-       do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); __assume_ctx_lock(lock); } while (0)
+       do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); } while (0)
 #endif
 
 #define raw_spin_is_locked(lock)       arch_spin_is_locked(&(lock)->raw_lock)
@@ -324,7 +323,6 @@ do {                                                                \
                                                                \
        __raw_spin_lock_init(spinlock_check(lock),              \
                             #lock, &__key, LD_WAIT_CONFIG);    \
-       __assume_ctx_lock(lock);                                \
 } while (0)
 
 #else
@@ -333,7 +331,6 @@ do {                                                                \
 do {                                           \
        spinlock_check(_lock);                  \
        *(_lock) = __SPIN_LOCK_UNLOCKED(_lock); \
-       __assume_ctx_lock(_lock);               \
 } while (0)
 
 #endif
index 0a585768358f13f51674fe9dbe14517963eda74b..373618a4243c1c8297db13b4bb9238f7b8868ff9 100644 (file)
@@ -20,7 +20,6 @@ static inline void __rt_spin_lock_init(spinlock_t *lock, const char *name,
 do {                                                           \
        rt_mutex_base_init(&(slock)->lock);                     \
        __rt_spin_lock_init(slock, name, key, percpu);          \
-       __assume_ctx_lock(slock);                               \
 } while (0)
 
 #define _spin_lock_init(slock, percpu)                         \
index 58e959ee10e9075994e9b695d11c1ab4210e0ab3..c47d4b9b88b30b399bfb6805e11d7fd72c1e0dde 100644 (file)
@@ -107,7 +107,6 @@ context_lock_struct(ww_acquire_ctx) {
  */
 static inline void ww_mutex_init(struct ww_mutex *lock,
                                 struct ww_class *ww_class)
-       __assumes_ctx_lock(lock)
 {
        ww_mutex_base_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key);
        lock->ctx = NULL;
index 0f05943d957fa644183b5823d4b3dca8e4373d19..140efa8a97636ef3fc81903eb88ae04cda0dccc9 100644 (file)
@@ -542,12 +542,6 @@ struct test_ww_mutex_data {
        int counter __guarded_by(&mtx);
 };
 
-static void __used test_ww_mutex_init(struct test_ww_mutex_data *d)
-{
-       ww_mutex_init(&d->mtx, &ww_class);
-       d->counter = 0;
-}
-
 static void __used test_ww_mutex_lock_noctx(struct test_ww_mutex_data *d)
 {
        if (!ww_mutex_lock(&d->mtx, NULL)) {