From: Ignacio Encinas <ignacio@iencinas.com>
To: linux-kernel-mentees@lists.linux.dev, skhan@linuxfoundation.org,
Eric Van Hensbergen <ericvh@kernel.org>,
Latchesar Ionkov <lucho@ionkov.net>,
Dominique Martinet <asmadeus@codewreck.org>,
Christian Schoenebeck <linux_oss@crudebyte.com>
Cc: Sishuai Gong <sishuai.system@gmail.com>,
Marco Elver <elver@google.com>,
v9fs@lists.linux.dev, linux-kernel@vger.kernel.org,
syzbot+d69a7cc8c683c2cb7506@syzkaller.appspotmail.com,
syzbot+483d6c9b9231ea7e1851@syzkaller.appspotmail.com,
Ignacio Encinas <ignacio@iencinas.com>
Subject: [PATCH v2] 9p/trans_fd: mark concurrent read and writes to p9_conn->err
Date: Thu, 13 Mar 2025 19:08:19 +0100 [thread overview]
Message-ID: <20250313-p9_conn_err_benign_data_race-v2-1-0bb9f45f6bb2@iencinas.com> (raw)
Writes for the error value of a connection are spinlock-protected inside
p9_conn_cancel, but lockless reads are present elsewhere to avoid
performing unnecessary work after an error has been met.
Mark the write and lockless reads to make KCSAN happy. Mark the write as
exclusive following the recommendation in "Lock-Protected Writes with
Lockless Reads" in tools/memory-model/Documentation/access-marking.txt
while we are at it.
Reported-by: syzbot+d69a7cc8c683c2cb7506@syzkaller.appspotmail.com
Reported-by: syzbot+483d6c9b9231ea7e1851@syzkaller.appspotmail.com
Signed-off-by: Ignacio Encinas <ignacio@iencinas.com>
---
Changes in v2:
Drop unnecessary READ_ONCE in p9_fd_request (that I added in v1)
-@@ net/9p/trans_fd.c: static int p9_fd_request(struct p9_client *client, struct p9_req_t *req)
-
- spin_lock(&m->req_lock);
-
-- if (m->err < 0) {
-+ if (READ_ONCE(m->err) < 0) {
- spin_unlock(&m->req_lock);
- return m->err;
- }
- Link to v1: https://lore.kernel.org/r/20250308-p9_conn_err_benign_data_race-v1-1-729e57d5832b@iencinas.com
---
net/9p/trans_fd.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
index 196060dc6138af10e99ad04a76ee36a11f770c65..758eaeddf32b480e0a88914da66f923f7021e608 100644
--- a/net/9p/trans_fd.c
+++ b/net/9p/trans_fd.c
@@ -196,7 +196,8 @@ static void p9_conn_cancel(struct p9_conn *m, int err)
return;
}
- m->err = err;
+ WRITE_ONCE(m->err, err);
+ ASSERT_EXCLUSIVE_WRITER(m->err);
list_for_each_entry_safe(req, rtmp, &m->req_list, req_list) {
list_move(&req->req_list, &cancel_list);
@@ -283,7 +284,7 @@ static void p9_read_work(struct work_struct *work)
m = container_of(work, struct p9_conn, rq);
- if (m->err < 0)
+ if (READ_ONCE(m->err) < 0)
return;
p9_debug(P9_DEBUG_TRANS, "start mux %p pos %zd\n", m, m->rc.offset);
@@ -450,7 +451,7 @@ static void p9_write_work(struct work_struct *work)
m = container_of(work, struct p9_conn, wq);
- if (m->err < 0) {
+ if (READ_ONCE(m->err) < 0) {
clear_bit(Wworksched, &m->wsched);
return;
}
@@ -622,7 +623,7 @@ static void p9_poll_mux(struct p9_conn *m)
__poll_t n;
int err = -ECONNRESET;
- if (m->err < 0)
+ if (READ_ONCE(m->err) < 0)
return;
n = p9_fd_poll(m->client, NULL, &err);
---
base-commit: 2a520073e74fbb956b5564818fc5529dcc7e9f0e
change-id: 20250308-p9_conn_err_benign_data_race-2758fe8bbed0
Best regards,
--
Ignacio Encinas <ignacio@iencinas.com>
next reply other threads:[~2025-03-13 18:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 18:08 Ignacio Encinas [this message]
2025-03-16 21:24 ` Dominique Martinet
2025-03-17 17:01 ` Ignacio Encinas Rubio
2025-03-18 21:21 ` Ignacio Encinas Rubio
2025-03-18 21:42 ` Dominique Martinet
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=20250313-p9_conn_err_benign_data_race-v2-1-0bb9f45f6bb2@iencinas.com \
--to=ignacio@iencinas.com \
--cc=asmadeus@codewreck.org \
--cc=elver@google.com \
--cc=ericvh@kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=sishuai.system@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=syzbot+483d6c9b9231ea7e1851@syzkaller.appspotmail.com \
--cc=syzbot+d69a7cc8c683c2cb7506@syzkaller.appspotmail.com \
--cc=v9fs@lists.linux.dev \
/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
all inboxes | Powered by JetHome®