From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795957117; b=3+IxNckwJHQTzLK4x325HNC2Du4zkBqofScazMdZClW0I14pigxs+dbq20ftrEDP/T4N v1dTzuaf8hLzYa3h/WH071C5h1RPdGMh5lDQ8cGFOHPUo64p476DxNqpD2oZc2WWBrcTv u+S/raTGi6xXfdGEUlasshS7b1N/5UAIDIAoGcRXJ8JAtJ8bNQwLXRlSRtmn0VXeCPbnm QCfVlkl5OvNDeoBCyLyRPAPcyXYhYmL7tIQBxWtBJVzjOJlSxcCpUpMK7qPrRPZFjJhRJ GEgDFVsSyplLutmUGY/RBTxvOblmFdOWOMhBP+TF5108XyycmpMGwjZhGVbgDhpSfTA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795957117; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=dfBtehD0NFbB2OhBDsC6UDURQcHi3Fj2Zhw34DhkOR4=; b=rHB00l9+oeJuMd/1CbCuiwBU98Y/7uYr1HzZbxNBmE7Xb8MPtjtFG5CquNhkw2k6lAVd yBE7sGcBd8X5fBgfOn3PsHUnMSdulxe4P6N1TQ8it0RI6PHMUExNnePwUsHUMdc79a9eQ HwnEQClgh+yt6rAalonL8Dj35nmraiGWZvgKVtOZNKwkzB0sYR/mqJaP6Gl9WvzNMheT5 ar5UNSS42BoRe9eHLUpAabgyf6DBDU8MT94AnorsB7Ju3/SigwnAzCNReQy4SYpO5z7hZ 6HVyyn6QVdU9MWOj6fbKbK61y2wgyNFSzq0q9U2BlP7TNW+uhNMdS4tYsr9f/UqNhyA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lk6kV36S; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EBDA606A31C; Sun, 29 Nov 2026 12:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Lk6kV36S Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1795957117; b=M8/X/3RD4+Fe512lgB808I4vGetIvm1JU/q02VEB0F5rtMsucubgvIqeMi7xJ4R4ajwo 3V+Se2fDdKwtMlHOnFWNo20tqt2RZAHFVQEe1jEiGq3NkTVKNEdRlMGyGfb9ec/Eq+4zI S02nB0TTpUwtrV637Ot15ydIEXgv9USxSqcvq8F0kS6hSqeGLUAowq0wx6mi42qy1Wlli UlGjwNB/68739ouyVmd8jQTvwyF/M4TXTzKrCeg/dep9leTPjCS07asrCaqQWBDBCZgyo NWytxy0JlV4JNmxsTdb0wcw3msvaqOXQmKYCVIA6CT+jy7L5DjvJBwSxFATiyM6QB6w== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795957117; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:X-B4-Tracking:X-Change-ID:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=dfBtehD0NFbB2OhBDsC6UDURQcHi3Fj2Zhw34DhkOR4=; b=mXjMMtzxUTt9wWOd9y6wqMKuA1zXiXJUWbFJ6RDBkTppQADDUyMj/vXoosjHskOjtoV2 oZuDuZBOSUFRFK0rFg4tY8zf8yGnJNIKSzGSDSjVu7vFQrfsy+PB7ExN1mF+nBu0SW7zh nK6mWMyxYDi8YbjW+71zzARX+582lF7fNkVBaQa/d6I0JEcIy0TxMNT8OAQ52oSz9LBsd OTGwC2N3hWYgcxALX5MuGQpmo/MD4Z4u+nw9Qa7qcc+3a/Pet3YNEAexu3HtbU668OLAB WTnU1J8yhfHD87kaOXfx2ggQraQvCobN7XCd1gyyRyKjubXHCWA5isEqPSfmv9iZFpQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C613F1F00898; Sun, 29 Nov 2026 12:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795957116; bh=dfBtehD0NFbB2OhBDsC6UDURQcHi3Fj2Zhw34DhkOR4=; h=From:Date:Subject:To:Cc:Reply-To; b=Lk6kV36SqlMTLS15kfHb6Qj66Urmn08Iv8puG3pNT4ulcDF8XtaeJyu22C35qykKa 8XpUILDyy8TpDsNg+7rxN45C89zBgkWmFFpIjW9cvcICSANRG6kSuxCxv3+8IArajF ExxW4O3kavO6aabFoIYjjxoFixVyDkf2+hnFK2bdmoqKk7AeJzfk0s4biVI4CNYvLq s5OVsadu2haiLLWfh5gSq8j8k0XgkmHYHUU+2cYddYjQnpi9ttqFSIL4CDEX4dg0ga TrRBH90uhcPN//5h5mxHcJjtHm+Lhmu9jUR6hdX5DAYsFKMQDd3ADeFeAdZl/fknRz MX9ey1h5DzLDg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 282F84E4A9; Sun, 29 Nov 2026 12:58:35 +0000 (UTC) From: Haruka Amakawa via B4 Relay Date: Sun, 29 Nov 2026 21:56:21 +0900 Subject: [PATCH RFC v3] configfs: don't lock the root inode in configfs_depend_item_unlocked() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261129-configfs-depend-root-lock-v3-1-82417fbbaba0@pm.me> X-B4-Tracking: v=1; b=H4sIAAAAAAAC/42OQQ6CMBREr0K6toZ+sKArExMP4Na4gPYXqtKSF hsN4e4WjHuWM5l5MyPx6DR6ckhG4jBor62JItskRLSVaZBqGTWBFDhjsKfCGqUb5anEHo2kztq BPq140B0v61JyxUEqEvu9Q6XfC/tKLucTuf1M/6rvKIaZOsda7QfrPsuDwJbwirHAKKN7kHnNi xKzAo59t+1w2QiwmgKRUmIBLFWVyFX2p0zT9AW7zintGwEAAA== X-Change-ID: 20261129-configfs-depend-root-lock-568b8d6f62df To: Breno Leitao Cc: Greg Kroah-Hartman , Andreas Hindborg , Slawomir Stepien , William Chuang , Roy , 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, Haruka Amakawa , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , llvm@lists.linux.dev X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795956981; l=16960; i=macchacat@pm.me; s=arch214; h=from:subject:message-id; bh=UNBD/B60KrZu/NrEbHrnyfzblELTlXLS4y3d/Sr6Bpc=; b=iAH9sEsOhowMsJk1W6V4rdXyXqeab1Q6qK/00sV3CylauGuqpovEOzStXVmnPBp9gqax7wVLW sdonZSb6+XmCS4Vs8pDyM1lDHJyuClZCWyj4uB4xLpQia6vD8j9iLlH X-Developer-Key: i=macchacat@pm.me; a=ed25519; pk=r6NpNWPLq1yPUwtaO/MpNl2rZY3S0JrA2xPu9HXWuac= X-Endpoint-Received: by B4 Relay for macchacat@pm.me/arch214 with auth_id=1683 X-Original-From: Haruka Amakawa Reply-To: macchacat@pm.me Content-Transfer-Encoding: 7bit From: Haruka Amakawa 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//tpgt_N: configfs_mkdir() calls the ->make_group() callback, target_fabric_make_tpg(), with the VFS still holding the 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 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: Haruka Amakawa --- RFC because it changes how a cross-subsystem depend synchronizes with subsystem (un)registration, and because of the lockdep-class commit below. Breno: "configfs: give the root inode its own lockdep class" (https://patch.msgid.link/20261022134443.1122318-2-sst@poczta.fm) is queued in configfs-next. Its changelog says that no holder of the root inode lock waits for a directory inode lock held by a depend caller; for the rename path above, though, lock_two_directories() can hold the root inode lock while waiting for the descendant's inode lock, and with the class split applied lockdep no longer reports that hang. With this patch the root inode lock is no longer taken under a directory inode lock on this path, so the class split is not needed for it either. If this approach looks right, would you consider dropping the queued class split? I tested this patch both on configfs-next and on configfs-next with that commit reverted, with the same pass/fail results. Testing (QEMU/KVM via virtme-ng, x86_64, PROVE_LOCKING + KASAN + hung task detector at 30s). "Without the patch" is mainline 946d9ed1aa02 and next-20261127; "with" is configfs-next 2e0fad9d2eae plus this patch: - 60s loop of mkdir/rmdir of target/usb_gadget/naa.X/tpgt_1 against a loop of rename("/sys/kernel/config/nonexistent", ".../naa.X/nonexistent"): without the patch both loops stop (on mainline after 5 successful mkdirs, within the first second; on next-20261127 after the first one) and the hung task detector fires twice; with the patch, 5616 successful mkdirs and 17070 rename() calls (5328 and 21653 with the class split reverted), no lockdep, hung task or KASAN reports. rmdir of functions/tcm.usb0 still fails with -EBUSY while tpgt_1 exists, and succeeds after it is removed. - syzbot C reproducers for 8c0a48f6c8357c9da819 (uvc_func_allow_link) and 300213c2b5b55c0244f4 (uvcg_extension_bm_controls_store): lockdep report on mainline, none with the patch (also with the class commit reverted). I did not add tags for the latter, since usb-next already breaks that cycle on the UVC side with commit a3f3e1390f47 ("usb: gadget: uvc: remove su_mutex from configfs _show/_store callbacks", https://patch.msgid.link/20261119161742.758715-1-timo.joannin@gmail.com). - tools/testing/selftests/filesystems/configfs: 25/25. - Not tested: a depend racing with configfs_register_subsystem() or configfs_unregister_subsystem() of the target subsystem. Not in this patch, but found while looking at this: - configfs_depend_item() takes the root inode lock the same way, and at least vhost-scsi can call it with a mutex held that its ->make_group() takes under a directory inode lock: vhost_scsi_set_endpoint() holds vhost_scsi_mutex across target_depend_item(), and vhost_scsi_make_tpg() takes vhost_scsi_mutex on mkdir of target/vhost//tpgt_N with the directory locked. Together with an analogous rename() whose destination parent is target/vhost/, that looks like a three-task cycle. I have only checked this by reading the code, not reproduced it. If this approach is acceptable I can send the same change for configfs_depend_item() as a follow-up. - configfs_depend_item_unlocked() still walks target->ci_group up to the root without any lock, as before; and the comment in f_tcm's usbg_make_tpg() about the root inode lock becomes stale with this patch. --- Changes in v3: - Annotate the two new helpers with __must_hold(&configfs_dirent_lock) instead of a comment, as Greg asked; no other code changes. Checked with CONFIG_WARN_CONTEXT_ANALYSIS and CONTEXT_ANALYSIS=y for fs/configfs (clang 23): no warnings, and dropping the spin_lock() in front of them makes it report the calls. - Link to v2: https://patch.msgid.link/20261129-configfs-depend-root-lock-v2-1-8e7210fac4f3@pm.me Changes in v2: - Use my real name for the author and Signed-off-by, as Greg asked (no code changes). - Link to v1: https://patch.msgid.link/20261129-configfs-depend-root-lock-v1-1-92d4b678e372@pm.me To: Breno Leitao To: Andreas Hindborg To: Nathan Chancellor To: Nick Desaulniers To: Bill Wendling To: Justin Stitt Cc: linux-kernel@vger.kernel.org Cc: llvm@lists.linux.dev --- fs/configfs/dir.c | 125 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 50 deletions(-) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index c4f570686bd2..09bd2a6c7750 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -907,7 +907,9 @@ static int configfs_attach_group(struct config_item *item, ret = configfs_attach_item(item, dentry, frag); if (!ret) { sd = dentry->d_fsdata; + spin_lock(&configfs_dirent_lock); sd->s_type |= CONFIGFS_USET_DIR; + spin_unlock(&configfs_dirent_lock); /* * FYI, we're faking mkdir in populate_groups() @@ -1103,17 +1105,19 @@ static int configfs_depend_prep(struct configfs_dirent *sd, return ret; } -static int configfs_do_depend_item(struct configfs_dirent *subsys_sd, - struct config_item *target) +static int __configfs_do_depend_item(struct configfs_dirent *subsys_sd, + struct config_item *target) + __must_hold(&configfs_dirent_lock) { struct configfs_dirent *p; int ret; - spin_lock(&configfs_dirent_lock); + lockdep_assert_held(&configfs_dirent_lock); + /* Scan the tree, return 0 if found */ ret = configfs_depend_prep(subsys_sd, target); if (ret) - goto out_unlock_dirent_lock; + return ret; /* * We are sure that the item is not about to be removed by rmdir(), and @@ -1122,27 +1126,47 @@ static int configfs_do_depend_item(struct configfs_dirent *subsys_sd, p = target->ci_dentry->d_fsdata; p->s_dependent_count += 1; -out_unlock_dirent_lock: + return 0; +} + +static int configfs_do_depend_item(struct configfs_dirent *subsys_sd, + struct config_item *target) +{ + int ret; + + spin_lock(&configfs_dirent_lock); + ret = __configfs_do_depend_item(subsys_sd, target); spin_unlock(&configfs_dirent_lock); return ret; } -static inline struct configfs_dirent * -configfs_find_subsys_dentry(struct configfs_dirent *root_sd, - struct config_item *subsys_item) +static struct configfs_dirent * +__configfs_find_subsys_dentry(struct configfs_dirent *root_sd, + struct config_item *subsys_item) + __must_hold(&configfs_dirent_lock) { struct configfs_dirent *p; - struct configfs_dirent *ret = NULL; - spin_lock(&configfs_dirent_lock); + lockdep_assert_held(&configfs_dirent_lock); + list_for_each_entry(p, &root_sd->s_children, s_sibling) { if (p->s_type & CONFIGFS_DIR && - p->s_element == subsys_item) { - ret = p; - break; - } + p->s_element == subsys_item) + return p; } + + return NULL; +} + +static struct configfs_dirent * +configfs_find_subsys_dentry(struct configfs_dirent *root_sd, + struct config_item *subsys_item) +{ + struct configfs_dirent *ret; + + spin_lock(&configfs_dirent_lock); + ret = __configfs_find_subsys_dentry(root_sd, subsys_item); spin_unlock(&configfs_dirent_lock); return ret; @@ -1224,19 +1248,26 @@ EXPORT_SYMBOL(configfs_undepend_item); /* * caller_subsys is a caller's subsystem not target's. This is used to - * determine if we should lock root and check subsys or not. When we are - * in the same subsystem as our target there is no need to do locking as - * we know that subsys is valid and is not unregistered during this function - * as we are called from callback of one of his children and VFS holds a lock - * on some inode. Otherwise we have to lock our root to ensure that target's - * subsystem it is not unregistered during this function. + * determine if we have to check that the target's subsystem is still + * registered. When we are in the same subsystem as our target there is no + * need to, as we know that subsys is valid and is not unregistered during + * this function as we are called from callback of one of his children and + * VFS holds a lock on some inode. + * + * Otherwise the target's subsystem is looked up and the dependency is taken + * in one configfs_dirent_lock section, so the subsystem cannot be unlinked + * from the root in between. This must not take the root inode lock: the + * caller may be a directory operation callback such as ->make_group(), which + * runs with a directory inode locked by VFS, and a rename() between the root + * and a directory below it locks the root inode first (see + * lock_two_directories()), so that would be an ABBA deadlock. */ int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys, struct config_item *target) { struct configfs_subsystem *target_subsys; + struct configfs_dirent *subsys_sd, *root_sd; struct config_group *root, *parent; - struct configfs_dirent *subsys_sd; int ret = -ENOENT; /* Disallow this function for configfs root */ @@ -1260,43 +1291,36 @@ int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys, root = parent; } else { target_subsys = parent->cg_subsys; - /* Find a cofnigfs root as we may need it for locking */ + /* Find the configfs root to look the subsystem up from */ for (root = parent; !configfs_is_root(&root->cg_item); root = root->cg_item.ci_group) ; } - if (target_subsys != caller_subsys) { - /* - * We are in other configfs subsystem, so we have to do - * additional locking to prevent other subsystem from being - * unregistered - */ - inode_lock(d_inode(root->cg_item.ci_dentry)); - - /* - * As we are trying to depend item from other subsystem - * we have to check if this subsystem is still registered - */ - subsys_sd = configfs_find_subsys_dentry( - root->cg_item.ci_dentry->d_fsdata, - &target_subsys->su_group.cg_item); - if (!subsys_sd) - goto out_root_unlock; - } else { + if (target_subsys == caller_subsys) { subsys_sd = target_subsys->su_group.cg_item.ci_dentry->d_fsdata; + return configfs_do_depend_item(subsys_sd, target); } - /* Now we can execute core of depend item */ - ret = configfs_do_depend_item(subsys_sd, target); + /* + * The target is in another subsystem: check that it is still + * registered, and not being registered or unregistered, and take the + * dependency without dropping configfs_dirent_lock in between. + * configfs_unregister_subsystem() marks the subsystem's fragment dead + * before it takes the root inode lock, and the dirent + * CONFIGFS_USET_DROPPING later. + */ + root_sd = root->cg_item.ci_dentry->d_fsdata; - if (target_subsys != caller_subsys) -out_root_unlock: - /* - * We were called from subsystem other than our target so we - * took some locks so now it's time to release them - */ - inode_unlock(d_inode(root->cg_item.ci_dentry)); + spin_lock(&configfs_dirent_lock); + subsys_sd = __configfs_find_subsys_dentry(root_sd, + &target_subsys->su_group.cg_item); + if (subsys_sd && + !(subsys_sd->s_type & (CONFIGFS_USET_CREATING | + CONFIGFS_USET_DROPPING)) && + !READ_ONCE(subsys_sd->s_frag->frag_dead)) + ret = __configfs_do_depend_item(subsys_sd, target); + spin_unlock(&configfs_dirent_lock); return ret; } @@ -1963,7 +1987,8 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys) } down_write(&frag->frag_sem); - frag->frag_dead = true; + /* Read locklessly by configfs_depend_item_unlocked() */ + WRITE_ONCE(frag->frag_dead, true); up_write(&frag->frag_sem); inode_lock_nested(d_inode(root), --- base-commit: 2e0fad9d2eaec7d4ce24ecb087d7f58ed9ad57e2 change-id: 20261129-configfs-depend-root-lock-568b8d6f62df Best regards, -- Haruka Amakawa