Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler-context-analysis: Remove __assume_ctx_lock from initializers

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

authored by

Marco Elver and committed by
Peter Zijlstra
b682b70d 41539433

+2 -22
-3
include/linux/local_lock_internal.h
··· 87 87 0, LD_WAIT_CONFIG, LD_WAIT_INV, \ 88 88 LD_LOCK_PERCPU); \ 89 89 local_lock_debug_init(lock); \ 90 - __assume_ctx_lock(lock); \ 91 90 } while (0) 92 91 93 92 #define __local_trylock_init(lock) \ 94 93 do { \ 95 94 __local_lock_init((local_lock_t *)lock); \ 96 - __assume_ctx_lock(lock); \ 97 95 } while (0) 98 96 99 97 #define __spinlock_nested_bh_init(lock) \ ··· 103 105 0, LD_WAIT_CONFIG, LD_WAIT_INV, \ 104 106 LD_LOCK_NORMAL); \ 105 107 local_lock_debug_init(lock); \ 106 - __assume_ctx_lock(lock); \ 107 108 } while (0) 108 109 109 110 #define __local_lock_acquire(lock) \
-1
include/linux/mutex.h
··· 62 62 static struct lock_class_key __key; \ 63 63 \ 64 64 __mutex_init((mutex), #mutex, &__key); \ 65 - __assume_ctx_lock(mutex); \ 66 65 } while (0) 67 66 68 67 /**
+1 -2
include/linux/rwlock.h
··· 22 22 static struct lock_class_key __key; \ 23 23 \ 24 24 __rwlock_init((lock), #lock, &__key); \ 25 - __assume_ctx_lock(lock); \ 26 25 } while (0) 27 26 #else 28 27 # define rwlock_init(lock) \ 29 - do { *(lock) = __RW_LOCK_UNLOCKED(lock); __assume_ctx_lock(lock); } while (0) 28 + do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0) 30 29 #endif 31 30 32 31 #ifdef CONFIG_DEBUG_SPINLOCK
-1
include/linux/rwlock_rt.h
··· 22 22 \ 23 23 init_rwbase_rt(&(rwl)->rwbase); \ 24 24 __rt_rwlock_init(rwl, #rwl, &__key); \ 25 - __assume_ctx_lock(rwl); \ 26 25 } while (0) 27 26 28 27 extern void rt_read_lock(rwlock_t *rwlock) __acquires_shared(rwlock);
-2
include/linux/rwsem.h
··· 121 121 static struct lock_class_key __key; \ 122 122 \ 123 123 __init_rwsem((sem), #sem, &__key); \ 124 - __assume_ctx_lock(sem); \ 125 124 } while (0) 126 125 127 126 /* ··· 174 175 static struct lock_class_key __key; \ 175 176 \ 176 177 __init_rwsem((sem), #sem, &__key); \ 177 - __assume_ctx_lock(sem); \ 178 178 } while (0) 179 179 180 180 static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem)
-1
include/linux/seqlock.h
··· 817 817 do { \ 818 818 spin_lock_init(&(sl)->lock); \ 819 819 seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock); \ 820 - __assume_ctx_lock(sl); \ 821 820 } while (0) 822 821 823 822 /**
+1 -4
include/linux/spinlock.h
··· 106 106 static struct lock_class_key __key; \ 107 107 \ 108 108 __raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN); \ 109 - __assume_ctx_lock(lock); \ 110 109 } while (0) 111 110 112 111 #else 113 112 # define raw_spin_lock_init(lock) \ 114 - do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); __assume_ctx_lock(lock); } while (0) 113 + do { *(lock) = __RAW_SPIN_LOCK_UNLOCKED(lock); } while (0) 115 114 #endif 116 115 117 116 #define raw_spin_is_locked(lock) arch_spin_is_locked(&(lock)->raw_lock) ··· 323 324 \ 324 325 __raw_spin_lock_init(spinlock_check(lock), \ 325 326 #lock, &__key, LD_WAIT_CONFIG); \ 326 - __assume_ctx_lock(lock); \ 327 327 } while (0) 328 328 329 329 #else ··· 331 333 do { \ 332 334 spinlock_check(_lock); \ 333 335 *(_lock) = __SPIN_LOCK_UNLOCKED(_lock); \ 334 - __assume_ctx_lock(_lock); \ 335 336 } while (0) 336 337 337 338 #endif
-1
include/linux/spinlock_rt.h
··· 20 20 do { \ 21 21 rt_mutex_base_init(&(slock)->lock); \ 22 22 __rt_spin_lock_init(slock, name, key, percpu); \ 23 - __assume_ctx_lock(slock); \ 24 23 } while (0) 25 24 26 25 #define _spin_lock_init(slock, percpu) \
-1
include/linux/ww_mutex.h
··· 107 107 */ 108 108 static inline void ww_mutex_init(struct ww_mutex *lock, 109 109 struct ww_class *ww_class) 110 - __assumes_ctx_lock(lock) 111 110 { 112 111 ww_mutex_base_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key); 113 112 lock->ctx = NULL;
-6
lib/test_context-analysis.c
··· 542 542 int counter __guarded_by(&mtx); 543 543 }; 544 544 545 - static void __used test_ww_mutex_init(struct test_ww_mutex_data *d) 546 - { 547 - ww_mutex_init(&d->mtx, &ww_class); 548 - d->counter = 0; 549 - } 550 - 551 545 static void __used test_ww_mutex_lock_noctx(struct test_ww_mutex_data *d) 552 546 { 553 547 if (!ww_mutex_lock(&d->mtx, NULL)) {