From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.161.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796491905; b=lAP1KsBm7e03dJfWj4yHWKLgm4ZiQH8E2io7OBMYB1rQLOhqklDh0xCOj5ON/74MhUy5 hhtS4g6YeR2zji3nr92X12oRfaKtPSLjuN27fYA6UjBmIyK8+u8SH1T+25FB/eb5RXBLl RTYBJgG/w4m0FJ0rhV2VwdoqeawFlsDmgwFFXHOWGTgj2CAQpub4ejXe8B3JKva9PgCCZ RAVyI7XKdvBKiQlw1h054NNYYuFS0gnd+XB6KE0Wn3LJYwJNu+Dent+bv3JKznlqulO5P F5J5uVerkRALnGGnw4XEGrRJBdZIp2DHWabvsuvgyuf+fh+DvyG4xn+1SWAjOAWD3kQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796491905; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=1/gevMNaN/4/mzj8OcBdAuLmnCDkOprGqyE3lg4OXhU=; b=ATgVg3pWF8FK6mwZVNhHToXGgFHx7AiAu9V8DEm4E2Oa1kHmUowDI3jeg/2Eg9QiTt4r prHCQZ3eQDkg+OBHAb7LNi02n2gyhjm9ABKa/5WOHJby0v2AroqP797+nZxwmQXiMxBcm rMk3lhdbPinmkYec/96QQb0O37bTHHTinOxRri5zf0xuIlT4KXWuAZueMmXd+kbcYp0Sv sjVt9qfAAbvbqdCuBDeO3SiJG12zd5TCiz3itGURy5zR7OkRSmRySOCOZMImqzQ0OKBe5 Tvh0NS8pZIQdJEu04ZB8HUNO7Xz29TyDzxYT0hmYPutxioLb09t51aF42MUvSknEgFQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=PpQtIzaW; arc=none smtp.remote-ip=209.85.161.71 Received: from mail-oo1-f71.google.com (mail-oo1-f71.google.com [209.85.161.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9E25606A31F for ; Sat, 5 Dec 2026 17:31:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A9E25606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=PpQtIzaW Received: by mail-oo1-f71.google.com with SMTP id 006d021491bc7-6e1fc036608so1422190eaf.0 for ; Sat, 05 Dec 2026 09:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796491903; x=1797096703; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=1/gevMNaN/4/mzj8OcBdAuLmnCDkOprGqyE3lg4OXhU=; b=PpQtIzaWQTCPaxSVnMOqvMSC1mtCPxlTqz7s7CY1/+x7vUcloPlZv2C6c7Et6X+TUf 0uTo3eDj1r9qRHhfdoVbPfOPkaaLus7B8EA9WOf/p1r5bBOTi9O7G1lyjvmfYbqvb3jy /PY4aKVipTAnl+4FEWvBO84cBo8EdpNB4yXXPvRhUGw6c4s1ahymCTSKztD8jWFdSrYw sDV+oCuS8pLr0ahhEjsaxndF7P/THqBq5Mky7Zwjj+flXSSjijzjXdIpebBbz0fz0giY My0H027ZzZbcAYR+LgcCB/lJ8E4UmmE2Et3Lz9zgldN7Af7fKyGdQdLqf7XwumgYifo5 325g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796491903; x=1797096703; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1/gevMNaN/4/mzj8OcBdAuLmnCDkOprGqyE3lg4OXhU=; b=gW96fxNWxhg19yKeRAsN0fZP/+h8zVlA/XUPuZorZWA8P4Us6Bhw/wLibVOj+uhZRJ 28QlCabL1vJ59aD/Kj3b3qL370vJjaWluss2iv56SpGuh3YWfNzD0QuV2QpOCSC4A4gk QfVivXzvLJia6IWPN9xbVirrIul82HSkFaKgijyUR2pX7tD3bgfkbWwN5CL31k1Xix4j fq8W42PDsUHd5tl6Jjyiztlb9APZr4wiDnDa01ozWQEcMW3HKecrT8UsuT/gKL1C0W7l GIxwf197oWcoUvMDLeisB0MKArT3+UBqIoo3QXNu9GGdHqE/pymOfxpcLQ0rJnbypB2R h0gw== X-Forwarded-Encrypted: i=1; AL+hErGNAC8OGhZoe7SiEGM9JBgMZ5jUQg9FTJIsOtHdhaKl3JMd/pfARQn0BVVxMlfQ4h1wtntEvJF1tpQHcH4=@vger.kernel.org X-Gm-Message-State: APuU4Z8GDfwKd4Dte7c7/LgeZw0ArDTnGWSQl3Mpdod86/wv0kEw92bi Yq+KWJrnK9mwlL8ySL4o1rSpjQbN51VHT9+yfA24fchwXRo+qBDk9xbkDW7nK4NPPFf4Jmtyq+q DqNyXhxBWRHieRwOhcsd+KDMMGvOFDg== X-Received: from jabem13.prod.google.com ([2002:a05:6638:4dad:b0:622:9529:ee52]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6820:c7cd:b0:71a:ef4a:8693 with SMTP id 006d021491bc7-71bf20739c1mr3371357eaf.21.1796491903488; Sat, 05 Dec 2026 09:31:43 -0800 (PST) Date: Sat, 5 Dec 2026 17:31:40 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261205173140.231384-1-zhenwenliang@google.com> Subject: [PATCH] netfs: Order the issued_to update after queueing the subrequest From: Zhenwen Liang To: David Howells , netfs@lists.linux.dev Cc: Paulo Alcantara , linux-fsdevel@vger.kernel.org, Christian Brauner , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 --- 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);