mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
To: Paulo Alcantara <pc@manguebit.org>
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
	Allen Pais <apais@microsoft.com>,
	Rachel Menge <rachelmenge@linux.microsoft.com>,
	Hardik Garg <hargar@linux.microsoft.com>,
	Siddharth Chintamaneni <sidchintamaneni@gmail.com>,
	Gillian Laming <glaming@microsoft.com>,
	linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 2/2] smb: client: fix busy dentry on unmount from cancelled deferred close
Date: Wed, 18 Nov 2026 00:25:29 +0000	[thread overview]
Message-ID: <20261118002529.250616-3-sidchintamaneni@gmail.com> (raw)
In-Reply-To: <20261118002529.250616-1-sidchintamaneni@gmail.com>

When cifs_close_deferred_file(), cifs_close_all_deferred_files(), or
cifs_close_deferred_file_under_dentry() cancels a pending deferred close
via cancel_delayed_work(&cfile->deferred), the cifsFileInfo is moved to
a thread-local stack list (file_head) before open_file_lock is dropped
and _cifsFileInfo_put() is called outside the lock.

Because tcon->openFileList is shared across superblocks using the same
tree connection, a concurrent operation or unmount on a sibling mount
sharing the tcon can cancel a deferred close work item belonging to a
superblock that is concurrently unmounting. Once cancel_delayed_work()
removes the work from deferredclose_wq, cifs_kill_sb() observes neither
a pending delayed work item on deferredclose_wq nor a non-zero
outstanding_rreq counter, and proceeds to kill_anon_super() before
_cifsFileInfo_put() drops cfile->dentry:

  Thread 1 (umount sb1)            Thread 2 (sibling mount / rename)
  ---------------------            ---------------------------------
                                   cifs_close_all_deferred_files(tcon)
                                     spin_lock(&tcon->open_file_lock)
                                     cancel_delayed_work(&cfile->deferred)
                                     list_add_tail(..., &file_head)
                                     spin_unlock(&tcon->open_file_lock)
  cifs_kill_sb(sb1)
    cifs_close_all_deferred_files_sb()
      [delayed_work_pending == false]
    flush(cifsoplockd_wq)
    flush(deferredclose_wq)
    wait(outstanding_rreq == 0)
    flush(serverclose_wq)
    flush(fileinfo_put_wq)
    kill_anon_super(sb1)
      -> generic_shutdown_super()
         BUG: Dentry still in use (1)
         VFS: Busy inodes after unmount!
                                     _cifsFileInfo_put(cfile, true, false)
                                       dput(cfile->dentry) [too late]

Fix this by incrementing cifs_sb->outstanding_rreq while still holding
open_file_lock whenever cancel_delayed_work(&cfile->deferred) succeeds,
and decrementing it (waking any waiter in cifs_kill_sb()) after
_cifsFileInfo_put() completes.

Fixes: 5efdd9122eff ("smb3: allow deferred close timeout to be configurable")
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
 fs/smb/client/misc.c | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/fs/smb/client/misc.c b/fs/smb/client/misc.c
index 72a986bfaefc4..5072efd0ea568 100644
--- a/fs/smb/client/misc.c
+++ b/fs/smb/client/misc.c
@@ -502,15 +502,19 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)
 {
 	struct cifsFileInfo *cfile = NULL, *failed_cfile = NULL;
 	struct file_list *tmp_list, *tmp_next_list;
+	struct cifs_sb_info *cifs_sb;
 	LIST_HEAD(file_head);
 
 	if (cifs_inode == NULL)
 		return;
 
+	cifs_sb = CIFS_SB(cifs_inode->netfs.inode.i_sb);
+
 	spin_lock(&cifs_inode->open_file_lock);
 	list_for_each_entry(cfile, &cifs_inode->openFileList, flist) {
 		if (delayed_work_pending(&cfile->deferred)) {
 			if (cancel_delayed_work(&cfile->deferred)) {
+				atomic_inc(&cifs_sb->outstanding_rreq);
 				spin_lock(&cifs_inode->deferred_lock);
 				cifs_del_deferred_close(cfile);
 				spin_unlock(&cifs_inode->deferred_lock);
@@ -528,11 +532,16 @@ cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode)
 	}
 	spin_unlock(&cifs_inode->open_file_lock);
 
-	if (failed_cfile)
+	if (failed_cfile) {
 		_cifsFileInfo_put(failed_cfile, false, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
+	}
 
 	list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) {
 		_cifsFileInfo_put(tmp_list->cfile, false, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
@@ -543,12 +552,15 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
 {
 	struct cifsFileInfo *cfile, *failed_cfile = NULL;
 	struct file_list *tmp_list, *tmp_next_list;
+	struct cifs_sb_info *cifs_sb;
 	LIST_HEAD(file_head);
 
 	spin_lock(&tcon->open_file_lock);
 	list_for_each_entry(cfile, &tcon->openFileList, tlist) {
 		if (delayed_work_pending(&cfile->deferred)) {
 			if (cancel_delayed_work(&cfile->deferred)) {
+				cifs_sb = CIFS_SB(d_inode(cfile->dentry)->i_sb);
+				atomic_inc(&cifs_sb->outstanding_rreq);
 				spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 				cifs_del_deferred_close(cfile);
 				spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
@@ -566,11 +578,18 @@ cifs_close_all_deferred_files(struct cifs_tcon *tcon)
 	}
 	spin_unlock(&tcon->open_file_lock);
 
-	if (failed_cfile)
+	if (failed_cfile) {
+		cifs_sb = CIFS_SB(d_inode(failed_cfile->dentry)->i_sb);
 		_cifsFileInfo_put(failed_cfile, true, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
+	}
 
 	list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) {
+		cifs_sb = CIFS_SB(d_inode(tmp_list->cfile->dentry)->i_sb);
 		_cifsFileInfo_put(tmp_list->cfile, true, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
@@ -618,6 +637,7 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
 {
 	struct file_list *tmp_list, *tmp_next_list;
 	struct cifsFileInfo *cfile, *failed_cfile = NULL;
+	struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
 	LIST_HEAD(file_head);
 
 	spin_lock(&tcon->open_file_lock);
@@ -625,6 +645,7 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
 		if ((cfile->dentry == dentry) &&
 		    delayed_work_pending(&cfile->deferred) &&
 		    cancel_delayed_work(&cfile->deferred)) {
+			atomic_inc(&cifs_sb->outstanding_rreq);
 			spin_lock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
 			cifs_del_deferred_close(cfile);
 			spin_unlock(&CIFS_I(d_inode(cfile->dentry))->deferred_lock);
@@ -640,11 +661,16 @@ void cifs_close_deferred_file_under_dentry(struct cifs_tcon *tcon,
 	}
 	spin_unlock(&tcon->open_file_lock);
 
-	if (failed_cfile)
+	if (failed_cfile) {
 		_cifsFileInfo_put(failed_cfile, true, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
+	}
 
 	list_for_each_entry_safe(tmp_list, tmp_next_list, &file_head, list) {
 		_cifsFileInfo_put(tmp_list->cfile, true, false);
+		if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+			wake_up_var(&cifs_sb->outstanding_rreq);
 		list_del(&tmp_list->list);
 		kfree(tmp_list);
 	}
-- 
2.43.0


      parent reply	other threads:[~2026-11-18  0:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18  0:25 [PATCH v1 0/2] smb: client: fix cached-dir and deferred-close unmount races Siddharth Chintamaneni
2026-11-18  0:25 ` [PATCH v1 1/2] smb: client: drop dentries for dying cached dirs during unmount Siddharth Chintamaneni
2026-11-18  0:25 ` Siddharth Chintamaneni [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=20261118002529.250616-3-sidchintamaneni@gmail.com \
    --to=sidchintamaneni@gmail.com \
    --cc=apais@microsoft.com \
    --cc=bharathsm@microsoft.com \
    --cc=glaming@microsoft.com \
    --cc=hargar@linux.microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=rachelmenge@linux.microsoft.com \
    --cc=ronniesahlberg@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    /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

all inboxes | Powered by JetHome®