Skip to content

Commit b682b70

Browse files
melverPeter Zijlstra
authored andcommitted
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
1 parent 4153943 commit b682b70

10 files changed

Lines changed: 2 additions & 22 deletions

File tree

include/linux/local_lock_internal.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,11 @@ do { \
8787
0, LD_WAIT_CONFIG, LD_WAIT_INV, \
8888
LD_LOCK_PERCPU); \
8989
local_lock_debug_init(lock); \
90-
__assume_ctx_lock(lock); \
9190
} while (0)
9291

9392
#define __local_trylock_init(lock) \
9493
do { \
9594
__local_lock_init((local_lock_t *)lock); \
96-
__assume_ctx_lock(lock); \
9795
} while (0)
9896

9997
#define __spinlock_nested_bh_init(lock) \
@@ -105,7 +103,6 @@ do { \
105103
0, LD_WAIT_CONFIG, LD_WAIT_INV, \
106104
LD_LOCK_NORMAL); \
107105
local_lock_debug_init(lock); \
108-
__assume_ctx_lock(lock); \
109106
} while (0)
110107

111108
#define __local_lock_acquire(lock) \

include/linux/mutex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ do { \
6262
static struct lock_class_key __key; \
6363
\
6464
__mutex_init((mutex), #mutex, &__key); \
65-
__assume_ctx_lock(mutex); \
6665
} while (0)
6766

6867
/**

include/linux/rwlock.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ do { \
2222
static struct lock_class_key __key; \
2323
\
2424
__rwlock_init((lock), #lock, &__key); \
25-
__assume_ctx_lock(lock); \
2625
} while (0)
2726
#else
2827
# 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)
3029
#endif
3130

3231
#ifdef CONFIG_DEBUG_SPINLOCK

include/linux/rwlock_rt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ do { \
2222
\
2323
init_rwbase_rt(&(rwl)->rwbase); \
2424
__rt_rwlock_init(rwl, #rwl, &__key); \
25-
__assume_ctx_lock(rwl); \
2625
} while (0)
2726

2827
extern void rt_read_lock(rwlock_t *rwlock) __acquires_shared(rwlock);

include/linux/rwsem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ do { \
121121
static struct lock_class_key __key; \
122122
\
123123
__init_rwsem((sem), #sem, &__key); \
124-
__assume_ctx_lock(sem); \
125124
} while (0)
126125

127126
/*
@@ -175,7 +174,6 @@ do { \
175174
static struct lock_class_key __key; \
176175
\
177176
__init_rwsem((sem), #sem, &__key); \
178-
__assume_ctx_lock(sem); \
179177
} while (0)
180178

181179
static __always_inline int rwsem_is_locked(const struct rw_semaphore *sem)

include/linux/seqlock.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ static __always_inline void write_seqcount_latch_end(seqcount_latch_t *s)
817817
do { \
818818
spin_lock_init(&(sl)->lock); \
819819
seqcount_spinlock_init(&(sl)->seqcount, &(sl)->lock); \
820-
__assume_ctx_lock(sl); \
821820
} while (0)
822821

823822
/**

include/linux/spinlock.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,11 @@ do { \
106106
static struct lock_class_key __key; \
107107
\
108108
__raw_spin_lock_init((lock), #lock, &__key, LD_WAIT_SPIN); \
109-
__assume_ctx_lock(lock); \
110109
} while (0)
111110

112111
#else
113112
# 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)
115114
#endif
116115

117116
#define raw_spin_is_locked(lock) arch_spin_is_locked(&(lock)->raw_lock)
@@ -324,7 +323,6 @@ do { \
324323
\
325324
__raw_spin_lock_init(spinlock_check(lock), \
326325
#lock, &__key, LD_WAIT_CONFIG); \
327-
__assume_ctx_lock(lock); \
328326
} while (0)
329327

330328
#else
@@ -333,7 +331,6 @@ do { \
333331
do { \
334332
spinlock_check(_lock); \
335333
*(_lock) = __SPIN_LOCK_UNLOCKED(_lock); \
336-
__assume_ctx_lock(_lock); \
337334
} while (0)
338335

339336
#endif

include/linux/spinlock_rt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ static inline void __rt_spin_lock_init(spinlock_t *lock, const char *name,
2020
do { \
2121
rt_mutex_base_init(&(slock)->lock); \
2222
__rt_spin_lock_init(slock, name, key, percpu); \
23-
__assume_ctx_lock(slock); \
2423
} while (0)
2524

2625
#define _spin_lock_init(slock, percpu) \

include/linux/ww_mutex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ context_lock_struct(ww_acquire_ctx) {
107107
*/
108108
static inline void ww_mutex_init(struct ww_mutex *lock,
109109
struct ww_class *ww_class)
110-
__assumes_ctx_lock(lock)
111110
{
112111
ww_mutex_base_init(&lock->base, ww_class->mutex_name, &ww_class->mutex_key);
113112
lock->ctx = NULL;

lib/test_context-analysis.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,6 @@ struct test_ww_mutex_data {
542542
int counter __guarded_by(&mtx);
543543
};
544544

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-
551545
static void __used test_ww_mutex_lock_noctx(struct test_ww_mutex_data *d)
552546
{
553547
if (!ww_mutex_lock(&d->mtx, NULL)) {

0 commit comments

Comments
 (0)