From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795620350; b=YW3SEEos+kWE8476rboaF56Innqyh9CAAydkNExrTfzYsOjWbqf27tMFPYUZ1Qp9Otoh Bi399Zd9yZ9Dt3snHxbwSoNVjUhHgwyhCLhS++HElyrBVfS/cgUCxKu9afRVGyP9hOJk6 mjNJKS5N4PN612Roh5DoCuz1P+BabQ4r7mfwVw37ftR5e/hsnqcIRjXcWlv4x0R1ts2ZX 3mm9F3d108KfOADrRpZ6Lu1cQ9swOTb9Epxu91J5RvHkTzLyrKwC0ZJQ39Rly/z3mRL2S 4pkZjLwsSKzyknc+RGmtMbt+FFD2cfMKhcUwzPSb/OnFF4nGubm2HArE3OOSflmSxNg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795620350; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=WsItJJGk0pqLg4b1N2q5LCywc6PrDLTc84oFbntxgrE=; b=cSbfGCSMybJ2z07JJPbRxgRW8WoYpWa85DPX6WiNDmx1EUQraj4ZRvSJ6eFp97HXwKSq beLYJvmTs/NGd6x2kTfMF0+5DS4aUjjVr5Mh0AEtgbx9rbqmseqxr2wyby1OpLjpjH2Ao 1CgiDF5FJ6Fk3LuFXMGAum9i01vYo7W2KgnGbdVnUXqv6WkQWtarWuxGyV+U/z0PgEF/F TbDABPeAeNJJS1HVVI1rHlnDBZ1NGMc1UA/7awRITcqBeWuKH/knELJnTYR+CZFmCraQt PtFQ7o+if2sa27vyWc4q7YjRJpCT6Qtqlg91sVONsZ4tJFGFH0f8mOBtpq+IVIM+lgA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0SdkSuNJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1BCA606A31E; Wed, 25 Nov 2026 15:25:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=0SdkSuNJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE4C41F000CA; Wed, 25 Nov 2026 15:25:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795620350; bh=WsItJJGk0pqLg4b1N2q5LCywc6PrDLTc84oFbntxgrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0SdkSuNJTG6aLMhDZK8uzklxnwRTjv4UPfOugOFQYimPpa6VTTAcmgLkEW1L5RE1t fZW9SPGx9yR6ulli4UIyA8o3xBnIvJAJFKwnpuykMLI4+04M0+BAC0OOe+0QJNLLW2 uajsU38cQ5ra9bHHHElwnrqkmHS1at6zBOTVxmXo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Paulo Alcantara Subject: [PATCH 7.3 0843/1005] smb: client: let umount -f abort retried reads and writes Date: Wed, 25 Nov 2026 15:36:21 +0100 Message-ID: <20261125143841.461561536@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paulo Alcantara commit adeb82ac455582eac1894d1ca1b0aba110a65cc3 upstream. umount -f only wakes up tasks waiting on the server's queues. Reads and writes being retried - forever on hard mounts - keep going, so with the server gone the unmount still hangs in sync_filesystem() waiting for their writeback. NFS kills outstanding RPCs on umount -f instead. Count umount -f attempts per superblock and have each read and write request remember the count it started with. Fail with -EIO, rather than retry, reissue, issue or wait for credits, any subrequest of a request that predates a umount -f once it is a retry or the server or share is disconnected; a kworker doing writeback can't be signalled out of the credit wait otherwise. First attempts on a connected server still go ahead, and requests started later aren't aborted (but see below), so I/O on a healthy server keeps working if the unmount then fails with -EBUSY or only detaches one of several mounts. retry_count is not bumped yet when netfs_retry_write_stream() calls prepare_write() for the first retry, so don't rely on it alone to tell a reissue from a first attempt: treat a subrequest as a retry when it already carries an xid (it has been prepared before) in prepare_write()/prepare_read(), or when its replay flag is set in cifs_io_aborted(), and abort it when the mount is going away even if the connection still looks healthy. Requests created after umount -f - writeback kicked off by the background flusher, an oplock break or sync_filesystem() during the final teardown - snapshot the already bumped count and would otherwise retry forever on a hard mount, hanging cifs_kill_sb(). Once a superblock that saw a umount -f reaches cifs_kill_sb() the mount is going away for good, so flag it and stop retrying I/O on it too; one that never saw a umount -f still flushes as before. A sync(2) or syncfs() waiting under s_umount for writeback started after umount -f would still keep the unmount from reaching cifs_kill_sb(), so also stop retrying such I/O while s_umount is contended. After a failed umount -f, that also stops reads and writes retrying while a remount, freeze or new mount of the same superblock waits on s_umount. Fixes: 2c1238a7477a ("cifs: make retry logic in read/write path consistent with other paths") Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/cifs_fs_sb.h | 2 + fs/smb/client/cifsfs.c | 10 ++++++++ fs/smb/client/cifsglob.h | 1 fs/smb/client/cifsproto.h | 2 + fs/smb/client/file.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ fs/smb/client/smb2pdu.c | 16 +++---------- 6 files changed, 74 insertions(+), 12 deletions(-) --- a/fs/smb/client/cifs_fs_sb.h +++ b/fs/smb/client/cifs_fs_sb.h @@ -57,6 +57,7 @@ struct cifs_sb_info { atomic_t active; atomic_t mnt_cifs_flags; atomic_t outstanding_rreq; /* nr of rreqs not yet fully deinitialized */ + atomic_t umount_aborts; /* nr of umount -f attempts */ struct delayed_work prune_tlinks; struct rcu_head rcu; @@ -68,6 +69,7 @@ struct cifs_sb_info { * (cifs_autodisable_serverino) in order to match new mounts. */ bool mnt_cifs_serverino_autodisabled; + bool exiting; /* umount -f committed: stop retries */ /* * Available once the mount has completed. */ --- a/fs/smb/client/cifsfs.c +++ b/fs/smb/client/cifsfs.c @@ -300,6 +300,15 @@ static void cifs_kill_sb(struct super_bl struct cifs_sb_info *cifs_sb = CIFS_SB(sb); /* + * Reaching here after a umount -f means the mount is going away for + * good, so stop retrying I/O that can no longer complete (e.g. + * writeback to a server that is gone) rather than looping forever on + * a hard mount and hanging the teardown below. + */ + if (atomic_read(&cifs_sb->umount_aborts)) + WRITE_ONCE(cifs_sb->exiting, true); + + /* * We need to release all dentries for the cached directories * and close all deferred file handles before we kill the sb. */ @@ -838,6 +847,7 @@ static void cifs_umount_begin(struct sup if (cifs_sb == NULL) return; + atomic_inc(&cifs_sb->umount_aborts); tcon = cifs_sb_master_tcon(cifs_sb); spin_lock(&cifs_tcp_ses_lock); --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1486,6 +1486,7 @@ struct cifs_io_request { struct netfs_io_request rreq; struct cifsFileInfo *cfile; pid_t pid; + int umount_aborts; }; /* asynchronous read support */ --- a/fs/smb/client/cifsproto.h +++ b/fs/smb/client/cifsproto.h @@ -137,6 +137,8 @@ bool is_size_safe_to_change(struct cifsI bool from_readdir); void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t result); +bool cifs_io_stopped(struct cifs_io_subrequest *subreq); +bool cifs_io_should_replay(struct cifs_io_subrequest *subreq); struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode, int flags); int __cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -39,6 +39,40 @@ static int cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush); +bool cifs_io_stopped(struct cifs_io_subrequest *subreq) +{ + struct super_block *sb = subreq->rreq->inode->i_sb; + struct cifs_sb_info *cifs_sb = CIFS_SB(sb); + int aborts; + + if (cifs_forced_shutdown(cifs_sb) || READ_ONCE(cifs_sb->exiting)) + return true; + aborts = atomic_read(&cifs_sb->umount_aborts); + if (aborts != subreq->req->umount_aborts) + return true; + return aborts && rwsem_is_contended(&sb->s_umount); +} + +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; + return smb2_should_replay(tcon, &subreq->retries, &subreq->cur_sleep); +} + +static bool cifs_io_aborted(struct cifs_io_subrequest *subreq) +{ + struct cifs_tcon *tcon = tlink_tcon(subreq->req->cfile->tlink); + + if (!cifs_io_stopped(subreq)) + return false; + return subreq->subreq.retry_count || subreq->replay || + READ_ONCE(subreq->server->tcpStatus) == CifsNeedReconnect || + tcon->need_reconnect; +} + /* * Prepare a subrequest to upload to the server. We need to allocate credits * so that we know the maximum amount of data that we can include in it. @@ -52,6 +86,7 @@ static void cifs_prepare_write(struct ne struct TCP_Server_Info *server; struct cifsFileInfo *open_file = req->cfile; struct cifs_sb_info *cifs_sb = CIFS_SB(wdata->rreq->inode->i_sb); + bool reprepared = wdata->have_xid; size_t wsize = req->rreq.wsize; int rc; @@ -63,6 +98,12 @@ static void cifs_prepare_write(struct ne server = cifs_pick_channel(tlink_tcon(open_file->tlink)->ses); wdata->server = server; + if (cifs_io_aborted(wdata) || + (reprepared && cifs_io_stopped(wdata))) { + subreq->error = -EIO; + return netfs_prepare_write_failed(subreq); + } + if (cifs_sb->ctx->wsize == 0) cifs_negotiate_wsize(server, cifs_sb->ctx, tlink_tcon(req->cfile->tlink)); @@ -126,6 +167,10 @@ static void __cifs_issue_write(struct ne goto fail; } + rc = -EIO; + if (cifs_io_aborted(wdata)) + goto fail; + rc = adjust_credits(wdata->server, wdata, cifs_trace_rw_credits_issue_write_adjust); if (rc) goto fail; @@ -181,6 +226,7 @@ static int cifs_prepare_read(struct netf struct cifs_io_request *req = container_of(subreq->rreq, struct cifs_io_request, rreq); struct TCP_Server_Info *server; struct cifs_sb_info *cifs_sb = CIFS_SB(rreq->inode->i_sb); + bool reprepared = rdata->have_xid; size_t size; int rc = 0; @@ -192,6 +238,10 @@ static int cifs_prepare_read(struct netf server = cifs_pick_channel(tlink_tcon(req->cfile->tlink)->ses); rdata->server = server; + if (cifs_io_aborted(rdata) || + (reprepared && cifs_io_stopped(rdata))) + return -EIO; + if (cifs_sb->ctx->rsize == 0) cifs_negotiate_rsize(server, cifs_sb->ctx, tlink_tcon(req->cfile->tlink)); @@ -242,6 +292,10 @@ static void cifs_issue_read(struct netfs __func__, rreq->debug_id, subreq->debug_index, rreq->mapping, subreq->transferred, subreq->len); + rc = -EIO; + if (cifs_io_aborted(rdata)) + goto failed; + rc = adjust_credits(server, rdata, cifs_trace_rw_credits_issue_read_adjust); if (rc) goto failed; @@ -300,6 +354,7 @@ static int cifs_init_request(struct netf rreq->rsize = cifs_sb->ctx->rsize; rreq->wsize = cifs_sb->ctx->wsize; req->pid = current->tgid; // Ummm... This may be a workqueue + req->umount_aborts = atomic_read(&cifs_sb->umount_aborts); if (file) { open_file = file->private_data; --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -4850,9 +4850,7 @@ do_retry: /* see if we need to retry */ if (is_replayable_error(rdata->result) && - smb2_should_replay(tcon, - &rdata->retries, - &rdata->cur_sleep)) + cifs_io_should_replay(rdata)) rdata->replay = true; trace_smb3_rw_credits(rreq_debug_id, subreq_debug_index, rdata->credits.value, @@ -4961,9 +4959,7 @@ async_readv_out: out: /* if the send error is retryable, let netfs know about it */ if (is_replayable_error(rc) && - smb2_should_replay(tcon, - &rdata->retries, - &rdata->cur_sleep)) { + cifs_io_should_replay(rdata)) { rdata->replay = true; trace_netfs_sreq(&rdata->subreq, netfs_sreq_trace_io_retry_needed); __set_bit(NETFS_SREQ_NEED_RETRY, &rdata->subreq.flags); @@ -5200,9 +5196,7 @@ smb2_writev_callback(struct TCP_Server_I /* see if we need to retry */ if (is_replayable_error(wdata->result) && - smb2_should_replay(tcon, - &wdata->retries, - &wdata->cur_sleep)) + cifs_io_should_replay(wdata)) wdata->replay = true; cifs_write_subrequest_terminated(wdata, result ?: written); @@ -5374,9 +5368,7 @@ async_writev_out: out: /* if the send error is retryable, let netfs know about it */ if (is_replayable_error(rc) && - smb2_should_replay(tcon, - &wdata->retries, - &wdata->cur_sleep)) { + cifs_io_should_replay(wdata)) { wdata->replay = true; trace_netfs_sreq(&wdata->subreq, netfs_sreq_trace_io_retry_needed); __set_bit(NETFS_SREQ_NEED_RETRY, &wdata->subreq.flags);