From: Viacheslav Dubeyko <slava@dubeyko.com>
To: glaubitz@physik.fu-berlin.de, frank.li@vivo.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
vdubeyko@coreweave.com, Viacheslav Dubeyko <slava@dubeyko.com>
Subject: [PATCH 3/5] hfsplus: give the special files their own extents_lock lockdep class
Date: Thu, 19 Nov 2026 15:41:10 -0800 [thread overview]
Message-ID: <20261119234112.720963-4-slava@dubeyko.com> (raw)
In-Reply-To: <20261119234112.720963-1-slava@dubeyko.com>
Writing a new extent record of a file can grow the extents B-tree. The
B-tree file is then extended with the file's extents_lock and the
B-tree's tree_lock held, and takes its own extents_lock:
hfsplus_file_extend() file's extents_lock
hfsplus_ext_read_extent()
__hfsplus_ext_write_extent() extents B-tree's tree_lock
hfs_bmap_reserve()
hfsplus_file_extend(ext_tree->inode)
B-tree file's extents_lock
All inodes read by hfsplus_iget() share one lockdep class for
extents_lock, so lockdep sees the file's extents_lock -> tree_lock ->
extents_lock chain as a cycle:
WARNING: possible circular locking dependency detected
dd/1553 is trying to acquire lock:
(&tree->tree_lock/1){+.+.}-{4:4}, at: hfsplus_find_init
but task is already holding lock:
(&HFSPLUS_I(inode)->extents_lock){+.+.}-{4:4}, at: hfsplus_file_extend
This is a false positive: the B-tree file's extents_lock always nests
inside the other file's, never the other way around. But lockdep turns
itself off after the first report, which hides any later real problem.
Give the extents_lock of each special file its own named lockdep class
when its inode is read from the volume header.
The report is reproduced on a valid volume created with "mkfs.hfsplus
-c e=1,d=1", whose extents B-tree has no free node, by interleaving
appends to two files that were created before a remount until a file
needs an extent record in the extents B-tree. The remount matters,
because hfsplus_new_inode() initializes extents_lock in a different
lockdep class than hfsplus_iget().
Tested on a KASAN and lockdep kernel: the report is gone and generic/001,
002, 013, 075 and 112 pass.
cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
cc: Yangtao Li <frank.li@vivo.com>
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Viacheslav Dubeyko <slava@dubeyko.com>
---
fs/hfsplus/super.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c
index e568a5508b5e..d23594d12064 100644
--- a/fs/hfsplus/super.c
+++ b/fs/hfsplus/super.c
@@ -50,30 +50,48 @@ static int hfsplus_system_read_fork(struct inode *inode,
return 0;
}
+static struct lock_class_key hfsplus_ext_extents_lock_key;
+static struct lock_class_key hfsplus_cat_extents_lock_key;
+static struct lock_class_key hfsplus_alloc_extents_lock_key;
+static struct lock_class_key hfsplus_start_extents_lock_key;
+static struct lock_class_key hfsplus_attr_extents_lock_key;
+
static int hfsplus_system_read_inode(struct inode *inode)
{
struct hfsplus_vh *vhdr = HFSPLUS_SB(inode->i_sb)->s_vhdr;
+ struct lock_class_key *key;
+ const char *name;
int err;
switch (inode->i_ino) {
case HFSPLUS_EXT_CNID:
err = hfsplus_system_read_fork(inode, &vhdr->ext_file);
inode->i_mapping->a_ops = &hfsplus_btree_aops;
+ key = &hfsplus_ext_extents_lock_key;
+ name = "ext_file_extents_lock";
break;
case HFSPLUS_CAT_CNID:
err = hfsplus_system_read_fork(inode, &vhdr->cat_file);
inode->i_mapping->a_ops = &hfsplus_btree_aops;
+ key = &hfsplus_cat_extents_lock_key;
+ name = "cat_file_extents_lock";
break;
case HFSPLUS_ALLOC_CNID:
err = hfsplus_system_read_fork(inode, &vhdr->alloc_file);
inode->i_mapping->a_ops = &hfsplus_aops;
+ key = &hfsplus_alloc_extents_lock_key;
+ name = "alloc_file_extents_lock";
break;
case HFSPLUS_START_CNID:
err = hfsplus_system_read_fork(inode, &vhdr->start_file);
+ key = &hfsplus_start_extents_lock_key;
+ name = "start_file_extents_lock";
break;
case HFSPLUS_ATTR_CNID:
err = hfsplus_system_read_fork(inode, &vhdr->attr_file);
inode->i_mapping->a_ops = &hfsplus_btree_aops;
+ key = &hfsplus_attr_extents_lock_key;
+ name = "attr_file_extents_lock";
break;
default:
return -EIO;
@@ -82,6 +100,8 @@ static int hfsplus_system_read_inode(struct inode *inode)
if (err)
return err;
+ lockdep_set_class_and_name(&HFSPLUS_I(inode)->extents_lock, key, name);
+
/*
* Assign a dummy file type, for may_open() requires that
* an inode has a valid file type.
--
2.53.0
next prev parent reply other threads:[~2026-11-19 23:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 23:41 [PATCH 0/5] hfsplus: fix locking and validation of the special files Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 1/5] hfsplus: reject special files larger than their allocation at mount Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 2/5] hfsplus: map the allocation file without the extents B-tree Viacheslav Dubeyko
2026-11-19 23:41 ` Viacheslav Dubeyko [this message]
2026-11-19 23:41 ` [PATCH 4/5] hfsplus: reject an allocation bitmap that does not cover the volume Viacheslav Dubeyko
2026-11-19 23:41 ` [PATCH 5/5] hfsplus: name the constants of the allocation bitmap check Viacheslav Dubeyko
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=20261119234112.720963-4-slava@dubeyko.com \
--to=slava@dubeyko.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vdubeyko@coreweave.com \
/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
all inboxes | Powered by JetHome®