From: Qian Cai <cai@lca.pw>
To: peterz@infradead.org, mingo@redhat.com
Cc: will@kernel.org, elver@google.com, linux-kernel@vger.kernel.org,
Qian Cai <cai@lca.pw>
Subject: [PATCH -next] locking/osq_lock: mark an intentional data race
Date: Fri, 31 Jan 2020 09:50:38 -0500 [thread overview]
Message-ID: <20200131145038.2386-1-cai@lca.pw> (raw)
node->next could be accessed concurrently as reported by KCSAN,
BUG: KCSAN: data-race in osq_lock / osq_unlock
write (marked) to 0xffff8bb2f1abbe40 of 8 bytes by task 1138 on cpu 44:
osq_lock+0x149/0x340 kernel/locking/osq_lock.c:143
__mutex_lock+0x277/0xd20 kernel/locking/mutex.c:657
mutex_lock_nested+0x31/0x40
kernfs_iop_getattr+0x58/0x90
vfs_getattr_nosec+0x11a/0x170
vfs_statx_fd+0x54/0x90
__do_sys_newfstat+0x40/0x90
__x64_sys_newfstat+0x3a/0x50
do_syscall_64+0x91/0xb47
entry_SYSCALL_64_after_hwframe+0x49/0xbe
read to 0xffff8bb2f1abbe40 of 8 bytes by task 1150 on cpu 29:
osq_unlock+0xee/0x170 kernel/locking/osq_lock.c:78
__mutex_lock+0xb68/0xd20 kernel/locking/mutex.c:686
mutex_lock_nested+0x31/0x40
kernfs_iop_getattr+0x58/0x90
vfs_getattr_nosec+0x11a/0x170
vfs_statx_fd+0x54/0x90
__do_sys_newfstat+0x40/0x90
__x64_sys_newfstat+0x3a/0x50
do_syscall_64+0x91/0xb47
entry_SYSCALL_64_after_hwframe+0x49/0xbe
This is a false positive. Since even if that load is shattered the code
will function correctly -- it checks for any !0 value, any byte
composite that is !0 is sufficient. Hence, mark it as an intentional
data race using the data_race() macro.
Signed-off-by: Qian Cai <cai@lca.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..009bf18c2226 100644
--- a/kernel/locking/osq_lock.c
+++ b/kernel/locking/osq_lock.c
@@ -75,7 +75,7 @@ osq_wait_next(struct optimistic_spin_queue *lock,
* wait for either @lock to point to us, through its Step-B, or
* wait for a new @node->next from its Step-C.
*/
- if (node->next) {
+ if (data_race(node->next)) {
next = xchg(&node->next, NULL);
if (next)
break;
--
2.21.0 (Apple Git-122.2)
reply other threads:[~2020-01-31 14:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200131145038.2386-1-cai@lca.pw \
--to=cai@lca.pw \
--cc=elver@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).