Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=143.255.12.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794071590; b=HJtEV0f8pZdZNalr+gAmLRaZueDraucummtPA7IuWuXoIP7A7jmaNRqR6I2A0g/hBcwJ C9V8peDvIyJbGOECnKENKMmsDIcb444gBEPR88+bDlnW4j2O9CD1UJdDpIP8NkDPhEQLQ jrbE8InhYcFKxzRdTVS7FvtI2bYMM8DoHgkjwcPTkpzskjexzaWvoL0254AlfWg/OLXFV YGUZbyr8PhNT4SuGPPpLwLtoCA4ceOOo5hyLiLwoZNRroYSo+tfT95vUE0fj/rb489jgo Ch3fisZDuzx4TCBWcmpxNGV9IhOG0XWVwdnbatRgDJmXyKcph6i2nYPq2QQBR6aEdIQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794071590; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=lHQnMIa1BPBilg1hVVzdNc6mjRHb1cIB4++UQLG5LpI=; b=GCY0plQZMuuFoACL8bG/jomZvmYmZj7pmeLGTTuQJIutGJgtMkz+fIoIIdfrzhUqousV KgjRjf4n+IcElfy2kKFRbGUBTkIw8Deo2z7pIuN5dTWGTfs6hT3yIgtdkNyvxzDWQ5QIs bsnCf4jjdBMS9cENm/H+TMTFR/hTbjAHfNdyrPhu/FQlMmutWwX0DkDJOhLuegc5ZjpM8 Vpg0MHd+0zaybeDlioiefTrhNkz4mVrJ0Xil1uSlGa2kpWrpVaYYf0JtiFGjN5T1J51l9 Rd3hUzPAtH/UESlweqFjMINSjcis6kTG3TuOMbNxycbdbhExE6JbSxlI24wkiTJC9wQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=manguebit.org; spf=pass smtp.mailfrom=manguebit.org; dkim=pass header.d=manguebit.org header.i=@manguebit.org header.a=rsa-sha256 header.s=dkim header.b=cKcpxS9c; arc=none smtp.remote-ip=143.255.12.172 Received: from mx1.manguebit.org (mx1.manguebit.org [143.255.12.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1B8D606A331; Sat, 7 Nov 2026 17:13:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C1B8D606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manguebit.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manguebit.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manguebit.org header.i=@manguebit.org header.a=rsa-sha256 header.s=dkim header.b=cKcpxS9c DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=manguebit.org; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Content-Type:Reply-To: Content-ID:Content-Description; bh=lHQnMIa1BPBilg1hVVzdNc6mjRHb1cIB4++UQLG5LpI=; b=cKcpxS9c/f+DQHc+7kphyPTBFO 3TEJVm4IMB7j5uYl5KNxHRpOTnYvp3UnP1lSCwTFVv69I3OTsVfA2+Vy1tm0XBFrZxLhh0JVYQM7E ngmxrWdZtni7qBN8Wt9h8eQWRiR9ioaSuyHX2zi5EXkR5l0oE4+IJPWrGrsxysXa78I84W8peum7z TuN6jumJN1pmhmcqoo85gab/mvW8E7kaClSjK0InPAIzLGxRNdWBZ2G2vpSqCoPlbNo/HnkqSOqS5 5Q0FUyg3EkXGTxSj6gn0D0ibX0ig0t/lEzd88maeHiDEFOp2ygVIIQxkjAtR4yl1VBJxk2PgZBRDv IQszqHGA==; Received: from pc by mx1.manguebit.org with local (Exim 4.100.1) id 1xPjyU-000000017fz-2Sz0; Sat, 07 Nov 2026 14:13:07 -0300 From: Paulo Alcantara To: linux-cifs@vger.kernel.org, netfs@lists.linux.dev, David Howells Cc: Namjae Jeon , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Bharath SM , Christian Brauner , stable@vger.kernel.org Subject: [PATCH v9 06/19] smb: client: don't give up writeback on the first replayable error Date: Sat, 7 Nov 2026 14:12:52 -0300 Message-ID: <20261107171305.2847361-7-pc@manguebit.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107171305.2847361-1-pc@manguebit.org> References: <20261107171305.2847361-1-pc@manguebit.org> X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Read and write retries follow the hard and retrans mount options, and mounts are soft with no retrans by default. For writeback this means that a single replayable error, e.g. a reconnect while sending, fails the subrequest and netfs ends writeback with its folios clean: the data is gone, possibly long after write(2) succeeded, with only fsync(2) left to notice. NFS soft mounts, by comparison, wait minutes for a server to answer before failing a request. Keep retrying writeback on replayable errors, with exponential backoff: forever on hard mounts, and on soft mounts for max(3, retrans) echo intervals from the first failure - 3 minutes by default, the time after which a silent server is considered unresponsive. The window applies to each write sent to the server, not to the whole writeback. umount -f or a shutdown still stops it right away. Direct and unbuffered writes, whose callers get the error, keep following the mount options. Fixes: 2c1238a7477a ("cifs: make retry logic in read/write path consistent with other paths") Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org --- fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 21 +++++++++++++++++++++ fs/smb/client/smb2ops.c | 9 +-------- fs/smb/client/smb2proto.h | 9 +++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index fb732c178e76..b6a993cc0245 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1499,6 +1499,7 @@ struct cifs_io_subrequest { bool replay; unsigned int retries; /* number of retries so far */ unsigned int cur_sleep; /* time to sleep before replay */ + unsigned long retry_deadline; struct kvec iov[2]; struct TCP_Server_Info *server; #ifdef CONFIG_CIFS_SMB_DIRECT diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 270858e526f9..e8557c670dc3 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -53,12 +53,33 @@ bool cifs_io_stopped(struct cifs_io_subrequest *subreq) return aborts && rwsem_is_contended(&sb->s_umount); } +static bool cifs_writeback_retry_expired(struct cifs_io_subrequest *subreq, + struct cifs_tcon *tcon) +{ + struct TCP_Server_Info *server = tcon->ses->server; + unsigned long window; + + if (tcon->retry) + return false; + if (!subreq->retry_deadline) { + window = max(3U, server->retrans) * server->echo_interval; + subreq->retry_deadline = (jiffies + window) | 1; + } + return time_after(jiffies, subreq->retry_deadline); +} + bool cifs_io_should_replay(struct cifs_io_subrequest *subreq) { struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink); if (cifs_io_stopped(subreq)) return false; + if (subreq->rreq->origin == NETFS_WRITEBACK) { + if (cifs_writeback_retry_expired(subreq, tcon)) + return false; + smb2_replay_backoff(&subreq->cur_sleep); + return true; + } return smb2_should_replay(tcon, &subreq->retries, &subreq->cur_sleep); } diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index dc55cd512616..457f18ce3245 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -2934,14 +2934,7 @@ bool smb2_should_replay(struct cifs_tcon *tcon, return false; if (tcon->retry || (*pretries)++ < tcon->ses->server->retrans) { - /* Update sleep time for exponential backoff */ - if (!(*pcur_sleep)) - (*pcur_sleep) = 1; - else { - (*pcur_sleep) = ((*pcur_sleep) << 1); - if ((*pcur_sleep) > CIFS_MAX_SLEEP) - (*pcur_sleep) = CIFS_MAX_SLEEP; - } + smb2_replay_backoff(pcur_sleep); return true; } diff --git a/fs/smb/client/smb2proto.h b/fs/smb/client/smb2proto.h index c79e5cb2ce26..b2acff8938f3 100644 --- a/fs/smb/client/smb2proto.h +++ b/fs/smb/client/smb2proto.h @@ -121,6 +121,15 @@ unsigned long smb_rqst_len(struct TCP_Server_Info *server, void smb2_set_next_command(struct cifs_tcon *tcon, struct smb_rqst *rqst); void smb2_set_related(struct smb_rqst *rqst); void smb2_set_replay(struct TCP_Server_Info *server, struct smb_rqst *rqst); + +static inline void smb2_replay_backoff(int *pcur_sleep) +{ + if (!*pcur_sleep) + *pcur_sleep = 1; + else + *pcur_sleep = min(*pcur_sleep << 1, CIFS_MAX_SLEEP); +} + bool smb2_should_replay(struct cifs_tcon *tcon, int *pretries, int *pcur_sleep); -- 2.56.0