From: Zhenwen Liang <zhenwenliang@google.com>
To: David Howells <dhowells@redhat.com>, netfs@lists.linux.dev
Cc: Paulo Alcantara <pc@manguebit.org>,
linux-fsdevel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] netfs: Order the issued_to update after queueing the subrequest
Date: Sat, 5 Dec 2026 17:31:40 +0000 [thread overview]
Message-ID: <20261205173140.231384-1-zhenwenliang@google.com> (raw)
netfs_prepare_write() queues a new subrequest with a release store and
then drops wreq->lock, and the issuer then advances wreq->issued_to with
a plain atomic64_set(). netfs_collect_write_results() reads issued_to
before the subrequest list, so on arm64 it can see the new issued_to but
an empty list, jump collected_to past the in-flight subrequest and end
writeback on its folios too early. Not reproduced. x86 and POWER are not
affected (TSO, and the lwsync in the unlock orders the two stores).
Use atomic64_set_release() for the issued_to updates and
atomic64_read_acquire() in the collector, as David Howells' unmerged
bvecq series already does.
The problem was found, and this patch prepared, with the help of a
formal analysis tool we are developing that uses AI assistance; I have
reviewed the analysis and the patch.
Link: https://lore.kernel.org/r/20261008102253.1003776-7-dhowells@redhat.com/
Fixes: 288ace2f57c9 ("netfs: New writeback implementation")
Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
---
David, would you rather carry this ordering yourself as a separate fix
(so that it can go to stable), or take this patch?
In linux-next, 6703bfa120ef removes netfs_write_folio_single(), so the
last two write_issue.c hunks drop there.
Compile-tested only (arm64, W=1).
fs/netfs/write_collect.c | 3 ++-
fs/netfs/write_issue.c | 8 ++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/netfs/write_collect.c b/fs/netfs/write_collect.c
index 6e8ea53..efad395 100644
--- a/fs/netfs/write_collect.c
+++ b/fs/netfs/write_collect.c
@@ -230,7 +230,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
trace_netfs_rreq(wreq, netfs_rreq_trace_collect);
reassess_streams:
- issued_to = atomic64_read(&wreq->issued_to);
+ /* Order reading the issued_to point before reading the queue it refers to. */
+ issued_to = atomic64_read_acquire(&wreq->issued_to);
smp_rmb();
collected_to = ULLONG_MAX;
if (wreq->origin == NETFS_WRITEBACK ||
diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c
index f233641..f00f1f4 100644
--- a/fs/netfs/write_issue.c
+++ b/fs/netfs/write_issue.c
@@ -505,7 +505,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
iter_off = stream->submit_off;
}
- atomic64_set(&wreq->issued_to, fpos + stream->submit_off);
+ atomic64_set_release(&wreq->issued_to, fpos + stream->submit_off);
stream->submit_extendable_to = fsize - stream->submit_off;
part = netfs_advance_write(wreq, stream, fpos + stream->submit_off,
stream->submit_len, to_eof);
@@ -520,7 +520,7 @@ static int netfs_write_folio(struct netfs_io_request *wreq,
if (fsize > iter_off)
rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
+ atomic64_set_release(&wreq->issued_to, fpos + fsize);
if (!debug)
kdebug("R=%x: No submit", wreq->debug_id);
@@ -721,7 +721,7 @@ static int netfs_write_folio_single(struct netfs_io_request *wreq,
iter_off = stream->submit_off;
}
- atomic64_set(&wreq->issued_to, fpos + stream->submit_off);
+ atomic64_set_release(&wreq->issued_to, fpos + stream->submit_off);
stream->submit_extendable_to = fsize - stream->submit_off;
part = netfs_advance_write(wreq, stream, fpos + stream->submit_off,
stream->submit_len, to_eof);
@@ -737,7 +737,7 @@ static int netfs_write_folio_single(struct netfs_io_request *wreq,
wreq->buffer.iter.iov_offset = 0;
if (fsize > iter_off)
rolling_buffer_advance(&wreq->buffer, fsize - iter_off);
- atomic64_set(&wreq->issued_to, fpos + fsize);
+ atomic64_set_release(&wreq->issued_to, fpos + fsize);
if (!no_debug)
kdebug("R=%x: No submit", wreq->debug_id);
reply other threads:[~2026-12-05 17:31 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=20261205173140.231384-1-zhenwenliang@google.com \
--to=zhenwenliang@google.com \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.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
all inboxes | Powered by JetHome®