Skip to contentSkip to conversation

cifs: serialize initialization and cleanup of cfid

bug report Dan Carpenter 2 participants 2 messages May 5, 2025 – May 16, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Shyam Prasad N,

Commit 62adfb82c199 ("cifs: serialize initialization and cleanup of cfid") from Apr 29, 2025 (linux-next), leads to the following Smatch static checker warning:

	fs/smb/client/cached_dir.c:492 drop_cached_dir_by_name()
	warn: sleeping in atomic context

fs/smb/client/cached_dir.c

    476 void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
    477                              const char *name, struct cifs_sb_info *cifs_sb)
    478 {
    479         struct cached_fid *cfid = NULL;
    480         int rc;
    481 
    482         rc = open_cached_dir(xid, tcon, name, cifs_sb, true, &cfid);
    483         if (rc) {
    484                 cifs_dbg(FYI, "no cached dir found for rmdir(%s)\n", name);
    485                 return;
    486         }
    487         spin_lock(&cfid->fid_lock);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
    488         if (cfid->has_lease) {
    489                 /* mark as invalid */
    490                 cfid->has_lease = false;
    491                 kref_put(&cfid->refcount, smb2_close_cached_fid);
                                                  ^^^^^^^^^^^^^^^^^^^^^^

The patch adds mutex but the issue is that drop_cached_dir_by_name() is holding a spinlock and we can't take a mutex if we're already holding a spinlock.

--> 492         }
    493         spin_unlock(&cfid->fid_lock);
    494         close_cached_dir(cfid);
    495 }

regards,
dan carpenter

#1 lore raw
Quoted 33 lines · Dan Carpenter

Hello Shyam Prasad N,

Commit 62adfb82c199 ("cifs: serialize initialization and cleanup of cfid") from Apr 29, 2025 (linux-next), leads to the following Smatch static checker warning:

fs/smb/client/cached_dir.c:492 drop_cached_dir_by_name()
warn: sleeping in atomic context

fs/smb/client/cached_dir.c

    476 void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
    477                              const char *name, struct cifs_sb_info *cifs_sb)
    478 {
    479         struct cached_fid *cfid = NULL;
    480         int rc;
    481
    482         rc = open_cached_dir(xid, tcon, name, cifs_sb, true, &cfid);
    483         if (rc) {
    484                 cifs_dbg(FYI, "no cached dir found for rmdir(%s)\n", name);
    485                 return;
    486         }
    487         spin_lock(&cfid->fid_lock);
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
    488         if (cfid->has_lease) {
    489                 /* mark as invalid */
    490                 cfid->has_lease = false;
    491                 kref_put(&cfid->refcount, smb2_close_cached_fid);
                                                  ^^^^^^^^^^^^^^^^^^^^^^

The patch adds mutex but the issue is that drop_cached_dir_by_name() is holding a spinlock and we can't take a mutex if we're already holding a spinlock.

Quoted 8 lines
--> 492         }
    493         spin_unlock(&cfid->fid_lock);
    494         close_cached_dir(cfid);
    495 }

regards,
dan carpenter

Hi Dan,

Good catches. I'll fix them both.

Signature · 2 lines
Regards,
Shyam