[PATCH 3/5] hfsplus: give the special files their own extents_lock lockdep class
From: Viacheslav Dubeyko
Date: Thu Nov 19 2026 - 18:41:43 EST
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@xxxxxxxxxxxxxxxxxxx>
cc: Yangtao Li <frank.li@xxxxxxxx>
cc: linux-fsdevel@xxxxxxxxxxxxxxx
Signed-off-by: Viacheslav Dubeyko <slava@xxxxxxxxxxx>
---
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