ocfs2: don't reuse SINGLE_DEPTH_NESTING for unpublished inode ip_alloc_sem
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.
---
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
@@ -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
Quoted 17 lines · Nguyen Ngoc Thang
Commit
c204bf5ac3ee("ocfs2: fix deadlock in inline-data truncate transactions") madeocfs2_xattr_set_handle()takeip_alloc_semof a not-yet-published inode inside the create transaction, under subclassOCFS2_IP_ALLOC_SEM_UNPUBLISHED= 1, so lockdep records:
sb_internal->j_trans_barrier-> ip_alloc_sem/1But subclass 1 is
SINGLE_DEPTH_NESTING, whichocfs2_remap_file_range()already uses for the destination inode, and the remap then starts a transaction inocfs2_duplicate_inline_data():ip_alloc_sem/1 ->
sb_internalLockdep 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]Signed-off-by Nguyen Ngoc Thang <[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 of23c62304dde2:
- before: "possible circular locking dependency" after ~8s
- after: no lockdep report in 3 x 180s runs,debug_locksstays 1;/proc/lockdepshows 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@@ -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 , };/*