Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Siddharth Chintamaneni <sidchintamaneni@gmail.com>,
	Adam Kim <adamkim@microsoft.com>,
	Paulo Alcantara <pc@manguebit.org>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.12.y] smb: client: fix busy dentry on unmount from persistent handle reopen
Date: Fri,  4 Dec 2026 00:37:42 -0500	[thread overview]
Message-ID: <20261204053722.2814757-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120200-frantic-defective-e379@gregkh>

From: Siddharth Chintamaneni <sidchintamaneni@gmail.com>

[ Upstream commit 340ca61e9d31c31403013dc9190550d615844828 ]

During unmount, cifs_kill_sb() waits on cifs_sb->outstanding_rreq for
in-flight netfs I/O requests and oplock breaks to complete before
flushing serverclose_wq and fileinfo_put_wq.

While cifs_kill_sb() is waiting on outstanding_rreq, any cifsFileInfo
referenced by an in-flight request (req->cfile) remains on
tcon->openFileList. On a mount using persistent handles, if a reconnect
runs on cifsiod_wq during this window, smb2_reconnect_server() calls
cifs_reopen_persistent_handles(), which walks tcon->openFileList and
takes a new reference on open_file via cifsFileInfo_get() to reopen the
handle over the network:

  Thread 1 (umount)      Thread 2 (cifsiod_wq)    Thread 3 (workers)
  -----------------      ---------------------    ------------------
  cifs_kill_sb()
  wait(outstanding_rreq)
    [blocks: rreq == 1]
                         smb2_reconnect_server()
                         cifs_reopen_persistent_handles()
                           finds open_file on list
                           cifsFileInfo_get(open_file)
                           [cfile->count: 1 -> 2]
                           cifs_reopen_file()
                                                  cifs_free_request()
                                                    cifsFileInfo_put()
                                                    [cfile->count: 2 -> 1]
                                                    dec(outstanding_rreq)
    [wakes: rreq == 0]
  flush(serverclose_wq)
  flush(fileinfo_put_wq)
  kill_anon_super(sb)
    -> generic_shutdown_super()
       BUG: Dentry still in use (1)
       VFS: Busy inodes after unmount!

Fix this by incrementing cifs_sb->outstanding_rreq when
cifs_reopen_persistent_handles() takes a reference on open_file and
decrementing it after cifsFileInfo_put(open_file), so wait_var_event()
in cifs_kill_sb() waits for any in-progress persistent handle reopen to
finish and queue its final put before draining fileinfo_put_wq.

Fixes: 340cea84f691 ("cifs: open files should not hold ref on superblock")
Cc: stable@vger.kernel.org
Reported-by: Adam Kim <adamkim@microsoft.com>
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
Signed-off-by: Paulo Alcantara <pc@manguebit.org>
[ sashal: Adapted to the older cifs_reopen_persistent_handles() (void return, no retry/rc handling) and used CIFS_SB(open_file->dentry->d_sb) instead of CIFS_SB(open_file->dentry). ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/smb/client/file.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index 5c24f05d53fd0..732553cfdce39 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -1470,6 +1470,7 @@ void
 cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
 {
 	struct cifsFileInfo *open_file, *tmp;
+	struct cifs_sb_info *cifs_sb;
 	LIST_HEAD(tmp_list);
 
 	if (!tcon->use_persistent || !tcon->need_reopen_files)
@@ -1484,16 +1485,21 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon)
 	list_for_each_entry(open_file, &tcon->openFileList, tlist) {
 		if (!open_file->invalidHandle)
 			continue;
+		cifs_sb = CIFS_SB(open_file->dentry->d_sb);
 		cifsFileInfo_get(open_file);
+		atomic_inc(&cifs_sb->outstanding_rreq);
 		list_add_tail(&open_file->rlist, &tmp_list);
 	}
 	spin_unlock(&tcon->open_file_lock);
 
 	list_for_each_entry_safe(open_file, tmp, &tmp_list, rlist) {
+		cifs_sb = CIFS_SB(open_file->dentry->d_sb);
 		if (cifs_reopen_file(open_file, false /* do not flush */))
 			tcon->need_reopen_files = true;
 		list_del_init(&open_file->rlist);
 		cifsFileInfo_put(open_file);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
 	}
 }
 
-- 
2.53.0


      reply	other threads:[~2026-12-04  5:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:56 FAILED: patch "[PATCH] smb: client: fix busy dentry on unmount from persistent" failed to apply to 6.12-stable tree gregkh
2026-12-04  5:37 ` Sasha Levin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204053722.2814757-1-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=adamkim@microsoft.com \
    --cc=pc@manguebit.org \
    --cc=sidchintamaneni@gmail.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox