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=1796383043; b=NgaBPAjm4gu6CepYGV+VCLs6cM85Hc9oGwFi93XhekJu9f6s5FXaCd+q6JA2f+hK3iCD ndcHvGdarOCuYTVHr+15uj4MSszraP/g6/bHijvUR921n3/JzbBN88WD3HcD6PIelbjgv eDe+/II8gJgQlTQ/feg7xeNb2c7fsQkbK3WLAirjyNJPUfbGpykbAMhsAmCx3TV3iBmYl cz77by1rZFQ1oZMzmDoO1mBR+prbgBF4XuXiUC8ZSq4qw2NT+yUPv4iRzBHY5GE8040Gj 5VbigVY8ncwjkvMujK9HgXpgsHSLTV/YXUFvPPMxCnYLsCf85Dmf36jrahlsSbk32YQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383043; 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=flcXQJUPzLfBWnLowbOFFfGu0YV0XZftHboprOzN7ZY=; b=VJq2RQhcfkV0TezeZxgBsFqwOda2uu8wGeQFN5exC1nU8vThkyl3GnRe2lBgRDAlKLs7 65xb4pX0g+J8CQ9bcnycvAOtnE5WlumbJoRcw8SlT6dztL0gTifP7+Vu40EP4KRqlzNE5 QftF+graoS6Sa5YkePStwsEUUryk+pP9NjBATrrsmHVF4MxX3SqXXOXTvNu/8c0HtDohK M1JCGucDxHJ4HiGn6TvIcuHLiBVs4AsaEyz3qry1rq8FRi4I6inhXeMThu28xJNrQTFOa RmeV8nO4nLXZb4/SNGTgWv0fKQ3OOnxWU97X4AvK6Mi2NCo5fnrb+MbHEtiXL79NIRA== 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=P6m8qTQ2; 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 595EF606A33B; Fri, 4 Dec 2026 11:17:23 +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=P6m8qTQ2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40B771F00A09; Fri, 4 Dec 2026 11:17:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383042; bh=flcXQJUPzLfBWnLowbOFFfGu0YV0XZftHboprOzN7ZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=P6m8qTQ2ISG3l9u+6W7L1gaCxVGTySVmOo4nJeO0jdjy+plzjqnu1vQEZ37oKWww5 p+mfJ2EFUAQB1/w94feFvZCWQGcWFtTkOeRTLMPkoAC46C5oiBRlEMbC5mzQKfGqQH NDYJXLpQDZTQYdmVgx20nOv/zdLVTjF7f3K5MJ6E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Paulo Alcantara Subject: [PATCH 6.18 700/703] smb: client: let umount -f abort retried reads and writes Date: Fri, 4 Dec 2026 19:09:59 +0900 Message-ID: <20261204100646.467406096@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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 @@ -58,6 +58,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; @@ -69,6 +70,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 @@ -331,6 +331,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. */ @@ -864,6 +873,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 @@ -1494,6 +1494,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 @@ -168,6 +168,8 @@ extern bool backup_cred(struct cifs_sb_i extern bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 eof, 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); extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, int); extern int cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, int flags, --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -46,6 +46,40 @@ static bool cifs_writeback_dying(struct fatal_signal_pending(current); } +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. @@ -59,6 +93,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; @@ -70,6 +105,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)); @@ -139,6 +180,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; @@ -201,6 +246,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; @@ -212,6 +258,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)); @@ -262,6 +312,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; @@ -328,6 +382,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 @@ -4779,9 +4779,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, @@ -4890,9 +4888,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); @@ -5136,9 +5132,7 @@ smb2_writev_callback(struct mid_q_entry /* 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); @@ -5312,9 +5306,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);