From: Greg KH <gregkh@linuxfoundation.org>
To: macchacat@pm.me
Cc: Breno Leitao <leitao@debian.org>,
Andreas Hindborg <a.hindborg@kernel.org>,
Slawomir Stepien <sst@poczta.fm>,
William Chuang <founder@logarcheon.com>,
Roy <rongh7426@gmail.com>,
linux-fsdevel@vger.kernel.org, linux-usb@vger.kernel.org,
target-devel@vger.kernel.org, linux-kernel@vger.kernel.org,
syzbot+8c0a48f6c8357c9da819@syzkaller.appspotmail.com
Subject: Re: [PATCH RFC] configfs: don't lock the root inode in configfs_depend_item_unlocked()
Date: Sun, 29 Nov 2026 13:15:53 +0100 [thread overview]
Message-ID: <2026112936-mocha-alienate-6cb2@gregkh> (raw)
In-Reply-To: <20261129-configfs-depend-root-lock-v1-1-92d4b678e372@pm.me>
On Sun, Nov 29, 2026 at 10:02:18AM +0900, MacchaCat via B4 Relay wrote:
> From: MacchaCat <macchacat@pm.me>
>
> configfs_depend_item_unlocked() is meant to be called from configfs
> callbacks. Directory operation callbacks such as ->make_group() run
> with a directory inode locked by the VFS. When the target item lives in
> another subsystem, configfs_depend_item_unlocked() additionally locks
> the configfs root inode, so that the target subsystem cannot be
> unregistered while it is looked up and the dependency is taken.
>
> >From such a callback, that nests the root inode lock inside a directory
> inode lock. A rename() whose two parent directories are the configfs
> root and a directory below it nests them the other way round:
> lock_rename() locks both parents before the last components are looked
> up and before vfs_rename() gets to fail, and lock_two_directories()
> locks the ancestor first. f_tcm runs into this on mkdir of
> target/usb_gadget/<wwn>/tpgt_N: configfs_mkdir() calls the
> ->make_group() callback, target_fabric_make_tpg(), with the VFS still
> holding the <wwn> directory lock, and its usbg_make_tpg() depends on the
> tcm function instance under usb_gadget/:
>
> mkdir(.../naa.X/tpgt_1) rename(".../config/a",
> ".../naa.X/a")
> inode_lock(naa.X) [VFS]
> lock_two_directories()
> inode_lock(root)
> inode_lock(naa.X)
> usbg_make_tpg()
> configfs_depend_item_unlocked()
> inode_lock(root)
>
> Sashiko pointed this inversion out in review, and William Chuang
> reproduced the hang: one process looping over mkdir/rmdir of tpgt_1 and
> another looping over rename() attempts like the one above (the source
> does not even exist) both hang within about a second. Giving the root
> inode its own lockdep class makes lockdep stop reporting the cycle, but
> the deadlock is still there. With that class split applied, the same
> two loops stop after the first mkdir of tpgt_1, lockdep reports
> nothing, and only the hung task detector notices:
>
> INFO: task rename_vs_mkdir:92 blocked for more than 30 seconds.
> down_write+0x1ae/0x1e0
> configfs_depend_item_unlocked+0xd8/0x5c0
> usbg_make_tpg+0x1f5/0x650
> target_fabric_make_tpg+0xa6/0x7f0
> configfs_mkdir+0x4ea/0xfe0
> vfs_mkdir+0x2b7/0x920
> INFO: task rename_vs_mkdir:93 blocked for more than 30 seconds.
> down_write_nested+0x1bd/0x1f0
> lock_two_directories+0x186/0x330
> __start_renaming+0xff/0x4e0
> filename_renameat2+0x5bf/0x920
>
> The root inode lock is not needed for what it protects here.
> Subsystem directories are added to and removed from the root's
> s_children under configfs_dirent_lock. A subsystem's dirent carries
> CONFIGFS_USET_CREATING until configfs_register_subsystem() has attached
> it, and configfs_unregister_subsystem() marks the subsystem's fragment
> dead before it takes the root inode lock, and later gives the dirent
> CONFIGFS_USET_DROPPING in configfs_detach_prep() under
> configfs_dirent_lock. So look the target subsystem up, check that it is
> neither being registered nor being unregistered, and take the
> dependency, all in one configfs_dirent_lock section, and don't take the
> root inode lock at all.
>
> The one s_type update of a subsystem dirent that was only covered by
> the root inode lock, setting CONFIGFS_USET_DIR in
> configfs_attach_group(), happens after the dirent is already on the
> root's s_children, so move it under configfs_dirent_lock too. frag_dead
> is now read without frag_sem here, so write it with WRITE_ONCE() in
> configfs_unregister_subsystem().
>
> A depend that used to wait for a concurrent register of the target
> subsystem now fails with -ENOENT while the subsystem is not on the
> root's s_children yet or still marked CONFIGFS_USET_CREATING; once
> configfs_dir_set_ready() has cleared that, it goes on to the usual scan
> for the target. One that races with unregister fails with -ENOENT once
> it observes the fragment marked dead or the dirent marked
> CONFIGFS_USET_DROPPING. As before, unregister marks the fragment dead
> before it takes the root inode lock.
> configfs_unregister_subsystem() still does not look at
> s_dependent_count; that is unchanged.
>
> The same-subsystem case and configfs_depend_item() are unchanged.
>
> Claude Opus 5.5 (Claude Code) was used to analyse the problem and to
> write the code, this changelog and the test programs. The result was
> reviewed by me and cross-checked with GPT-6.2-Sol and Gemini 4 Carbon.
>
> Fixes: d79d75b5c518 ("fs: configfs: Add unlocked version of configfs_depend_item()")
> Reported-by: William Chuang <founder@logarcheon.com>
> Closes: https://lore.kernel.org/all/20261117150358.8149-1-founder@logarcheon.com/
> Reported-by: syzbot+8c0a48f6c8357c9da819@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=8c0a48f6c8357c9da819
> Signed-off-by: MacchaCat <macchacat@pm.me>
Real name please.
next prev parent reply other threads:[~2026-11-29 12:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 1:02 [PATCH RFC] configfs: don't lock the root inode in configfs_depend_item_unlocked() MacchaCat via B4 Relay
2026-11-29 1:10 ` sashiko-bot
2026-11-29 12:15 ` Greg KH [this message]
2026-11-29 12:37 ` macchacat
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=2026112936-mocha-alienate-6cb2@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=a.hindborg@kernel.org \
--cc=founder@logarcheon.com \
--cc=leitao@debian.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=macchacat@pm.me \
--cc=rongh7426@gmail.com \
--cc=sst@poczta.fm \
--cc=syzbot+8c0a48f6c8357c9da819@syzkaller.appspotmail.com \
--cc=target-devel@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