ext2: Silence lockdep warning about reclaim under xattr_sem
PATCH 1/1 ext2: Silence lockdep warning about reclaim under xattr_sem
Lockdep complains about a chain:
sb_internal#2 --> &ei->xattr_sem#2 --> fs_reclaim
and shrink_dentry_list -> ext2_evict_inode -> ext2_xattr_delete_inode -> down_write(ei->xattr_sem) creating a locking cycle in the reclaim path. This is however a false positive because when we are in ext2_evict_inode() we are the only holder of the inode reference and nobody else should touch xattr_sem of that inode. So we cannot ever block on acquiring the xattr_sem in the reclaim path.
Silence the lockdep warning by using down_write_trylock() in ext2_xattr_delete_inode() to not create false locking dependency.
--- fs/ext2/xattr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
I plan to queue this patch to my tree.
fs/ext2/xattr.c +9 -1
@@ -790,7 +790,15 @@ ext2_xattr_delete_inode(struct inode *inode)struct buffer_head *bh =NULL ;struct ext2_sb_info *sbi =EXT2_SB (inode->i_sb); -down_write (&EXT2_I (inode)->xattr_sem); +/* +* We are the only ones holding inode reference. The xattr_sem should +* better be unlocked! We could as well just not acquire xattr_sem at +* all but this makes the code more futureproof. OTOH we need trylock +* here to avoid false-positive warning from lockdep about reclaim +* circular dependency. +*/ +if (WARN_ON (!down_write_trylock (&EXT2_I (inode)->xattr_sem))) +return ;if (!EXT2_I (inode)->i_file_acl) goto cleanup;
Signature · 1 line
2.16.4
fs/ext2/xattr.c ext2_xattr_delete_inode(struct inode *inode) · line 801
Quoted 9 lines · Jan Kara
fs/ext2/xattr.c +9
-0+/* +* We are the only ones holding inode reference. The xattr_sem should +* better be unlocked! We could as well just not acquire xattr_sem at +* all but this makes the code more futureproof. OTOH we need trylock +* here to avoid false-positive warning from lockdep about reclaim +* circular dependency. +*/ +if (WARN_ON (!down_write_trylock (&EXT2_I (inode)->xattr_sem))) +return ;
Shouldn't this be a WARN_ON_ONCE? Just in case the impossible happens that avoids spamming dmesg over and over.
Quoted 13 lines · Christoph Hellwig
fs/ext2/xattr.c ext2_xattr_delete_inode(struct inode *inode) · line 801
Quoted 9 lines · Jan Kara
fs/ext2/xattr.c +9
-0+/* +* We are the only ones holding inode reference. The xattr_sem should +* better be unlocked! We could as well just not acquire xattr_sem at +* all but this makes the code more futureproof. OTOH we need trylock +* here to avoid false-positive warning from lockdep about reclaim +* circular dependency. +*/ +if (WARN_ON (!down_write_trylock (&EXT2_I (inode)->xattr_sem))) +return ;Shouldn't this be a
WARN_ON_ONCE? Just in case the impossible happens that avoids spamming dmesg over and over.
Fair enough, I'll switch to WARN_ON_ONCE here. Thanks for the review.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR