[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200211040651.1993-1-cai@lca.pw>
Date: Mon, 10 Feb 2020 23:06:51 -0500
From: Qian Cai <cai@....pw>
To: peterz@...radead.org, mingo@...hat.com
Cc: will@...nel.org, elver@...gle.com, linux-kernel@...r.kernel.org,
Qian Cai <cai@....pw>
Subject: [PATCH -next] locking/osq_lock: annotate a data race in osq_lock
prev->next could 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 <cai@....pw>
---
kernel/locking/osq_lock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c
index 1f7734949ac8..3c44ddbc11ce 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -154,7 +154,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
*/
for (;;) {
- if (prev->next == node &&
+ if (data_race(prev->next == node) &&
cmpxchg(&prev->next, node, NULL) == node)
break;
--
2.21.0 (Apple Git-122.2)
Powered by blists - more mailing lists