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 1/2] smb: client: drop dentries for dying cached dirs during unmount
Date: Wed, 18 Nov 2026 00:25:28 +0000 [thread overview]
Message-ID: <20261118002529.250616-2-sidchintamaneni@gmail.com> (raw)
In-Reply-To: <20261118002529.250616-1-sidchintamaneni@gmail.com>
During unmount, cifs_kill_sb() calls close_all_cached_dirs() to release
all cached directory dentries and flush cfid_put_wq before calling
kill_anon_super(). Two races allow a cached_fid's dentry reference to
outlive close_all_cached_dirs() and trigger a busy-dentry panic in
generic_shutdown_super():
1. When invalidate_all_cached_dirs() or
cifs_mark_open_handles_for_deleted_file() runs concurrently, it moves
cached_fid entries from cfids->entries onto cfids->dying under
cfids->cfid_list_lock, then drops cfid_list_lock before laundromat_work
runs on cfid_put_wq. If close_all_cached_dirs() runs in that window, it
only walks cfids->entries (missing cfids->dying) and flushes cfid_put_wq
before laundromat_work is queued, leaving cfid->dentry held:
Thread 1 (umount) Thread 2 (reconnect / open_dirs)
----------------- --------------------------------
invalidate_all_cached_dirs()
spin_lock(&cfid_list_lock)
list_move(&cfid->entry, &cfids->dying)
spin_unlock(&cfid_list_lock)
cifs_kill_sb()
close_all_cached_dirs()
spin_lock(&cfid_list_lock)
walks cfids->entries (empty)
spin_unlock(&cfid_list_lock)
flush_workqueue(cfid_put_wq)
kill_anon_super(sb)
-> generic_shutdown_super()
BUG: Dentry still in use (1)
VFS: Busy inodes after unmount!
mod_delayed_work(cfid_put_wq,
&cfids->laundromat_work, 0)
dput(cfid->dentry) [too late]
2. When two mounts share a cifs_tcon and drop_cached_dir_by_name() (for
example via rmdir on the sibling mount) drops the final reference in
close_cached_dir() -> smb2_close_cached_fid(), it deletes cfid from
cfids->entries under cfids->cfid_list_lock, unlocks cfid_list_lock, and
calls dput(cfid->dentry) synchronously outside cfid_put_wq. A
concurrent unmount of the superblock owning cfid->dentry can finish
close_all_cached_dirs() and reach kill_anon_super() before that dput()
completes.
Fix the first race by also walking cfids->dying under
cfids->cfid_list_lock in close_all_cached_dirs() and clearing cfid->dentry
under the lock. Fix the second race by detaching cfid->dentry under
cfids->cfid_list_lock in smb2_close_cached_fid() and holding
cifs_sb->outstanding_rreq across dput(dentry) so cifs_kill_sb() waits for
the in-flight dput() before calling kill_anon_super().
Fixes: 3fa640d035e5 ("smb: During unmount, ensure all cached dir instances drop their dentry")
Signed-off-by: Siddharth Chintamaneni <sidchintamaneni@gmail.com>
---
fs/smb/client/cached_dir.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/fs/smb/client/cached_dir.c b/fs/smb/client/cached_dir.c
index 50217f47a0ed1..e5c924409078c 100644
--- a/fs/smb/client/cached_dir.c
+++ b/fs/smb/client/cached_dir.c
@@ -467,6 +467,8 @@ __releases(&cfid->cfids->cfid_list_lock)
{
struct cached_fid *cfid = container_of(ref, struct cached_fid,
refcount);
+ struct cifs_sb_info *cifs_sb = NULL;
+ struct dentry *dentry;
int rc;
lockdep_assert_held(&cfid->cfids->cfid_list_lock);
@@ -476,10 +478,19 @@ __releases(&cfid->cfids->cfid_list_lock)
cfid->on_list = false;
cfid->cfids->num_entries--;
}
+ dentry = cfid->dentry;
+ cfid->dentry = NULL;
+ if (dentry) {
+ cifs_sb = CIFS_SB(dentry->d_sb);
+ atomic_inc(&cifs_sb->outstanding_rreq);
+ }
spin_unlock(&cfid->cfids->cfid_list_lock);
- dput(cfid->dentry);
- cfid->dentry = NULL;
+ if (dentry) {
+ dput(dentry);
+ if (atomic_dec_and_test(&cifs_sb->outstanding_rreq))
+ wake_up_var(&cifs_sb->outstanding_rreq);
+ }
if (cfid->is_open) {
rc = SMB2_close(0, cfid->tcon, cfid->fid.persistent_fid,
@@ -594,6 +605,22 @@ void close_all_cached_dirs(struct cifs_sb_info *cifs_sb)
list_add_tail(&tmp_list->entry, &entry);
}
+ list_for_each_entry(cfid, &cfids->dying, entry) {
+ if (!cfid->dentry)
+ continue;
+ tmp_list = kmalloc_obj(*tmp_list, GFP_ATOMIC);
+ if (!tmp_list) {
+ cifs_tcon_dbg(VFS, "Out of memory while dropping dentries\n");
+ spin_unlock(&cfids->cfid_list_lock);
+ spin_unlock(&cifs_sb->tlink_tree_lock);
+ goto done;
+ }
+
+ tmp_list->dentry = cfid->dentry;
+ cfid->dentry = NULL;
+
+ list_add_tail(&tmp_list->entry, &entry);
+ }
spin_unlock(&cfids->cfid_list_lock);
}
spin_unlock(&cifs_sb->tlink_tree_lock);
--
2.43.0
next prev 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 ` Siddharth Chintamaneni [this message]
2026-11-18 0:25 ` [PATCH v1 2/2] smb: client: fix busy dentry on unmount from cancelled deferred close Siddharth Chintamaneni
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-2-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®