From: sashiko-bot@kernel.org
To: "William Chuang" <founder@logarcheon.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH] configfs: give the root directory inode its own lockdep class
Date: Tue, 17 Nov 2026 07:13:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-218297@kernel.org> (raw)
In-Reply-To: <20261117065314.4309-1-founder@logarcheon.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] configfs: root inode lockdep class masks real rename() vs
mkdir() deadlock
--
commit 058eebb48180eef94995fcd78f689f610830d617
Author: William Chuang <founder@logarcheon.com>
configfs: give the root directory inode its own lockdep class
This commit assigns a dedicated lockdep class to the configfs root
directory inode's i_rwsem to avoid a lockdep circular dependency report
between USB gadget and target subsystems.
> diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
> index d8cac1cbf3bd5..d20d2fd1e1809 100644
> --- a/fs/configfs/mount.c
> +++ b/fs/configfs/mount.c
> @@ -58,6 +58,15 @@ static struct configfs_dirent configfs_root = {
> .s_iattr = NULL,
> };
>
> +/*
> + * configfs_depend_item_unlocked() takes the root inode's lock while a
> + * subsystem's own locks may be held, but nothing takes a subsystem lock
> + * while holding the root inode's lock. Directories created by mkdir(2)
> + * share the default i_rwsem class and are locked before their subsystem's
> + * su_mutex, so give the root inode a class of its own.
> + */
> +static struct lock_class_key configfs_root_inode_class;
> +
> static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)
> {
> struct inode *inode;
> @@ -74,6 +83,7 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)
> if (inode) {
> inode->i_op = &configfs_root_inode_operations;
> inode->i_fop = &configfs_dir_operations;
> + lockdep_set_class(&inode->i_rwsem, &configfs_root_inode_class);
[Severity: High]
Does assigning a separate lockdep class to the configfs root inode's
i_rwsem hide a real ABBA deadlock between renameat2() and mkdir()?
In filename_renameat2(), __start_renaming() -> lock_rename() ->
lock_two_directories() runs before vfs_rename() checks
old_dir->i_op->rename. When one parent directory is the configfs root
and the other is a descendant directory (such as target/usb_gadget/naa.*),
lock_two_directories() sees that the root is an ancestor and locks
root_inode->i_rwsem before the descendant directory's i_rwsem:
fs/namei.c:lock_two_directories() {
...
r = d_ancestor(p2, p1);
if (r) {
inode_lock_nested(p2->d_inode, I_MUTEX_PARENT);
inode_lock_nested(p1->d_inode, I_MUTEX_PARENT2);
return r;
}
}
Meanwhile, mkdir() on target/usb_gadget/naa.*/tpgt_1 locks those same two
inodes in the opposite order:
CPU0 CPU1
---- ----
lock(&naa_inode->i_rwsem)
lock(&root_inode->i_rwsem)
lock(&naa_inode->i_rwsem)
lock(&root_inode->i_rwsem)
*** DEADLOCK ***
CPU0: do_mkdirat() -> configfs_mkdir() -> target_fabric_make_tpg() ->
usbg_make_tpg() -> configfs_depend_item_unlocked()
CPU1: do_renameat2() -> filename_renameat2() -> __start_renaming() ->
lock_rename() -> lock_two_directories()
Splitting root_inode->i_rwsem into configfs_root_inode_class prevents
lockdep from detecting this lock ordering inversion until a rename()
actually races with mkdir() or symlink().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117065314.4309-1-founder@logarcheon.com?part=1
next prev parent reply other threads:[~2026-11-17 7:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 6:53 [PATCH] configfs: give the root directory inode its own lockdep class William Chuang
2026-11-17 7:13 ` sashiko-bot [this message]
2026-11-17 15:04 ` William Chuang
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=sashiko-outbox-218297@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=founder@logarcheon.com \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.