linux/fs/ext4
Eric Biggers 2f8f5e76c7 ext4: avoid lockdep warning when inheriting encryption context
On a lockdep-enabled kernel, xfstests generic/027 fails due to a lockdep
warning when run on ext4 mounted with -o test_dummy_encryption:

    xfs_io/4594 is trying to acquire lock:
     (jbd2_handle
    ){++++.+}, at:
    [<ffffffff813096ef>] jbd2_log_wait_commit+0x5/0x11b

    but task is already holding lock:
     (jbd2_handle
    ){++++.+}, at:
    [<ffffffff813000de>] start_this_handle+0x354/0x3d8

The abbreviated call stack is:

 [<ffffffff813096ef>] ? jbd2_log_wait_commit+0x5/0x11b
 [<ffffffff8130972a>] jbd2_log_wait_commit+0x40/0x11b
 [<ffffffff813096ef>] ? jbd2_log_wait_commit+0x5/0x11b
 [<ffffffff8130987b>] ? __jbd2_journal_force_commit+0x76/0xa6
 [<ffffffff81309896>] __jbd2_journal_force_commit+0x91/0xa6
 [<ffffffff813098b9>] jbd2_journal_force_commit_nested+0xe/0x18
 [<ffffffff812a6049>] ext4_should_retry_alloc+0x72/0x79
 [<ffffffff812f0c1f>] ext4_xattr_set+0xef/0x11f
 [<ffffffff812cc35b>] ext4_set_context+0x3a/0x16b
 [<ffffffff81258123>] fscrypt_inherit_context+0xe3/0x103
 [<ffffffff812ab611>] __ext4_new_inode+0x12dc/0x153a
 [<ffffffff812bd371>] ext4_create+0xb7/0x161

When a file is created in an encrypted directory, ext4_set_context() is
called to set an encryption context on the new file.  This calls
ext4_xattr_set(), which contains a retry loop where the journal is
forced to commit if an ENOSPC error is encountered.

If the task actually were to wait for the journal to commit in this
case, then it would deadlock because a handle remains open from
__ext4_new_inode(), so the running transaction can't be committed yet.
Fortunately, __jbd2_journal_force_commit() avoids the deadlock by not
allowing the running transaction to be committed while the current task
has it open.  However, the above lockdep warning is still triggered.

This was a false positive which was introduced by: 1eaa566d36: jbd2:
track more dependencies on transaction commit

Fix the problem by passing the handle through the 'fs_data' argument to
ext4_set_context(), then using ext4_xattr_set_handle() instead of
ext4_xattr_set().  And in the case where no journal handle is specified
and ext4_set_context() has to open one, add an ENOSPC retry loop since
in that case it is the outermost transaction.

Signed-off-by: Eric Biggers <ebiggers@google.com>
2016-11-21 11:52:44 -05:00
..
acl.c ext4: use current_time() for inode timestamps 2016-11-14 21:40:10 -05:00
acl.h
balloc.c
bitmap.c
block_validity.c
dir.c
ext4.h ext4: remove unused function ext4_aligned_io() 2016-11-21 11:51:44 -05:00
ext4_extents.h
ext4_jbd2.c
ext4_jbd2.h
extents.c ext4: use current_time() for inode timestamps 2016-11-14 21:40:10 -05:00
extents_status.c
extents_status.h
file.c ext4: convert DAX faults to iomap infrastructure 2016-11-20 18:51:24 -05:00
fsync.c
hash.c
ialloc.c ext4: avoid lockdep warning when inheriting encryption context 2016-11-21 11:52:44 -05:00
indirect.c
inline.c ext4: only set S_DAX if DAX is really supported 2016-11-20 17:32:59 -05:00
inode.c ext4: rip out DAX handling from direct IO path 2016-11-20 18:53:30 -05:00
ioctl.c ext4: use current_time() for inode timestamps 2016-11-14 21:40:10 -05:00
Kconfig
Makefile
mballoc.c ext4: fix stack memory corruption with 64k block size 2016-11-14 21:26:26 -05:00
mballoc.h
migrate.c
mmp.c
move_extent.c
namei.c ext4: use current_time() for inode timestamps 2016-11-14 21:40:10 -05:00
page-io.c
readpage.c
resize.c
super.c ext4: avoid lockdep warning when inheriting encryption context 2016-11-21 11:52:44 -05:00
symlink.c
sysfs.c
truncate.h
xattr.c ext4: remove parameter from ext4_xattr_ibody_set() 2016-11-14 21:56:48 -05:00
xattr.h
xattr_security.c
xattr_trusted.c
xattr_user.c