Skip to contentSkip to conversation

ocfs2: don't reuse SINGLE_DEPTH_NESTING for unpublished inode ip_alloc_sem

PATCH In review Nguyen Ngoc Thang 2 participants 2 messages Nov 15 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: don't reuse SINGLE_DEPTH_NESTING for unpublished inode ip_alloc_sem

Commit c204bf5ac3ee ("ocfs2: fix deadlock in inline-data truncate transactions") made ocfs2_xattr_set_handle() take ip_alloc_sem of a not-yet-published inode inside the create transaction, under subclass OCFS2_IP_ALLOC_SEM_UNPUBLISHED = 1, so lockdep records:

sb_internal -> j_trans_barrier -> ip_alloc_sem/1

But subclass 1 is SINGLE_DEPTH_NESTING, which ocfs2_remap_file_range() already uses for the destination inode, and the remap then starts a transaction in ocfs2_duplicate_inline_data():

ip_alloc_sem/1 -> sb_internal

Lockdep merges the two and reports a circular dependency. It cannot deadlock, since the unpublished inode is unreachable by anyone else, but the warning hides real reports.

Give the unpublished subclass its own value past SINGLE_DEPTH_NESTING.

Fixes c204bf5ac3ee ("ocfs2: fix deadlock in inline-data truncate transactions")
Reported-by [email protected]

---
Tested in QEMU (x86_64, syzbot config with lockdep) using the syzbot C reproducer on top of 23c62304dde2:
- before: "possible circular locking dependency" after ~8s
- after: no lockdep report in 3 x 180s runs, debug_locks stays 1; /proc/lockdep shows both ip_alloc_sem/2 (create) and ip_alloc_sem/1 (remap) exercised.

 fs/ocfs2/xattr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/xattr.c +3 -2
index 71e5986bafaa..9f2d5797e4d6 100644
@@ -3867,10 +3867,11 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,
  * ip_alloc_sem there adds a transaction -> ip_alloc_sem order that would
  * form a lockdep cycle with the ip_alloc_sem -> transaction order used
  * elsewhere, if not for this separate subclass.  The inode is unpublished
- * so the acquisition can never contend.
+ * so the acquisition can never contend.  It must not collide with the
+ * SINGLE_DEPTH_NESTING subclass ocfs2_remap_file_range() uses.
  */
 enum {
-	OCFS2_IP_ALLOC_SEM_UNPUBLISHED = 1,
+	OCFS2_IP_ALLOC_SEM_UNPUBLISHED = SINGLE_DEPTH_NESTING + 1,
 };
 
 /*
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Nguyen Ngoc Thang

Commit c204bf5ac3ee ("ocfs2: fix deadlock in inline-data truncate transactions") made ocfs2_xattr_set_handle() take ip_alloc_sem of a not-yet-published inode inside the create transaction, under subclass OCFS2_IP_ALLOC_SEM_UNPUBLISHED = 1, so lockdep records:

sb_internal -> j_trans_barrier -> ip_alloc_sem/1

But subclass 1 is SINGLE_DEPTH_NESTING, which ocfs2_remap_file_range() already uses for the destination inode, and the remap then starts a transaction in ocfs2_duplicate_inline_data():

ip_alloc_sem/1 -> sb_internal

Lockdep merges the two and reports a circular dependency. It cannot deadlock, since the unpublished inode is unreachable by anyone else, but the warning hides real reports.

Quoted 6 lines

Give the unpublished subclass its own value past SINGLE_DEPTH_NESTING.

Fixes c204bf5ac3ee ("ocfs2: fix deadlock in inline-data truncate transactions")
Reported-by [email protected]

It takes no runtime effect. But the collision is real.

Quoted 29 lines

---
Tested in QEMU (x86_64, syzbot config with lockdep) using the syzbot C reproducer on top of 23c62304dde2:
- before: "possible circular locking dependency" after ~8s
- after: no lockdep report in 3 x 180s runs, debug_locks stays 1; /proc/lockdep shows both ip_alloc_sem/2 (create) and ip_alloc_sem/1 (remap) exercised.

 fs/ocfs2/xattr.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ocfs2/xattr.c +3 -2
index 71e5986bafaa..9f2d5797e4d6 100644
@@ -3867,10 +3867,11 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,
  * ip_alloc_sem there adds a transaction -> ip_alloc_sem order that would
  * form a lockdep cycle with the ip_alloc_sem -> transaction order used
  * elsewhere, if not for this separate subclass.  The inode is unpublished
- * so the acquisition can never contend.
+ * so the acquisition can never contend.  It must not collide with the
+ * SINGLE_DEPTH_NESTING subclass ocfs2_remap_file_range() uses.
  */
 enum {
-	OCFS2_IP_ALLOC_SEM_UNPUBLISHED = 1,
+	OCFS2_IP_ALLOC_SEM_UNPUBLISHED = SINGLE_DEPTH_NESTING + 1,
 };
 
 /*