[PATCH v1 2/2] smb: client: fix busy dentry on unmount from cancelled deferred close
From: Siddharth Chintamaneni
Date: Tue Nov 17 2026 - 19:25:46 EST
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@xxxxxxxxx>
---
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