Skip to content

Commit 33190b6

Browse files
Qian Caipaulmckrcu
authored andcommitted
locking/osq_lock: Annotate a data race in osq_lock
The prev->next pointer can be accessed concurrently as noticed by KCSAN: write (marked) to 0xffff9d3370dbbe40 of 8 bytes by task 3294 on cpu 107: osq_lock+0x25f/0x350 osq_wait_next at kernel/locking/osq_lock.c:79 (inlined by) osq_lock at kernel/locking/osq_lock.c:185 rwsem_optimistic_spin <snip> read to 0xffff9d3370dbbe40 of 8 bytes by task 3398 on cpu 100: osq_lock+0x196/0x350 osq_lock at kernel/locking/osq_lock.c:157 rwsem_optimistic_spin <snip> Since the write only stores NULL to prev->next and the read tests if prev->next equals to this_cpu_ptr(&osq_node). Even if the value is shattered, the code is still working correctly. Thus, mark it as an intentional data race using the data_race() macro. Signed-off-by: Qian Cai <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 1fe84fd commit 33190b6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/locking/osq_lock.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ bool osq_lock(struct optimistic_spin_queue *lock)
154154
*/
155155

156156
for (;;) {
157-
if (prev->next == node &&
157+
/*
158+
* cpu_relax() below implies a compiler barrier which would
159+
* prevent this comparison being optimized away.
160+
*/
161+
if (data_race(prev->next) == node &&
158162
cmpxchg(&prev->next, node, NULL) == node)
159163
break;
160164

0 commit comments

Comments
 (0)