From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795954557; b=oKpPUgXzhwzv0AKLrhdmNVEQAgXOnJ9J70knARERW6r8eqbDNDL9bCGAT8qRahQYSFl9 bv8K4MV4bZ4/wAASfKBMxYUNd50k8fQlTCkUduUbrNRF4dpBdIBMda9nfIasaGQCHwwxm Ux2jEHVdeYKxQdDHWdzo+eRdMdCxbTsOfCf0oLrXY5ualuKSVbTbTQKuMHDE8+bFs5LPd bRorKHjbc0JiQTUS21XaGaaueP1oHrvJr6mbUbDDoCzRqihyUh0mNmiPkdmLnRQoF5bN/ Qg8sciG/QBxnJtnriHh9TORo5Nmh5J/0PVgn2dZySu9D9JVJGgI2DHVyPKGt+c4rz0Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795954557; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=ohCymCnWksnL1X/Y0PXYQHltD7CY+frQwNpoejoMRkk=; b=kD8uc/xEGbbN4b1XchIU+g/f/I0xucOsuvO6nOVsl48x6nV7gGHlQukoSwnIUPj2JFZ5 z7iPdM8g6HdH466RF8Ya6LacT97aWhUDVc4aQIK3d5xisjKx0LABXQVEzf+mY08eVwtdL r731cEi4yhsB+hwB3j2xcB1RoP3Qe8YkFXh9VDtOQx47eCgY3meDtU1KCkqrbVrZKM8pM zEawZLzi+5KZYqGcXXtWvtV/sSJeHavWkt8ThPM7fOGc9yXIGSc56/qTey1Xcf9kfAc/j iudUQiucm12RhAUGK6McFfdtqscfGoTBMiFfQPdcbXdPmu0SW1nzYwYgee9JKXNF8EA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bYrC6nKc; arc=none 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 C0AE4606A325; Sun, 29 Nov 2026 12:15:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bYrC6nKc Received: by smtp.kernel.org (Postfix) with ESMTPSA id A28D01F000C1; Sun, 29 Nov 2026 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795954557; bh=ohCymCnWksnL1X/Y0PXYQHltD7CY+frQwNpoejoMRkk=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=bYrC6nKcDJ9u72bHygIqMAKhnOc+3QDUZFQOEKy3IDcunPDWQFMMaTKWOFEaFt2oJ 27O/7Mv8dfPek2PSxgN2fHmh2khG/flRgJiccayFZP54eVeE6r5I/A/vk6UnWQeyQn iFOJXPgIpQWU1uPC5Zhzg5wvUflym8XYt0bSZYXc= Date: Sun, 29 Nov 2026 13:15:53 +0100 From: Greg KH To: macchacat@pm.me Cc: Breno Leitao , 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 Subject: Re: [PATCH RFC] configfs: don't lock the root inode in configfs_depend_item_unlocked() Message-ID: <2026112936-mocha-alienate-6cb2@gregkh> References: <20261129-configfs-depend-root-lock-v1-1-92d4b678e372@pm.me> 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=us-ascii Content-Disposition: inline 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 > > 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: MacchaCat Real name please.