mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] netfs: Order the issued_to update after queueing the subrequest
@ 2026-12-05 17:31 Zhenwen Liang
  0 siblings, 0 replies; only message in thread
From: Zhenwen Liang @ 2026-12-05 17:31 UTC (permalink / raw)
  To: David Howells, netfs
  Cc: Paulo Alcantara, linux-fsdevel, Christian Brauner, linux-kernel

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);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-05 17:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05 17:31 [PATCH] netfs: Order the issued_to update after queueing the subrequest Zhenwen Liang

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®