Josef Bacik
51c62a3357
btrfs: move the dio_sem higher up the callchain
...
commit c495144bc6962186feae31d687596d2472000e45 upstream.
We're getting a lockdep splat because we take the dio_sem under the
log_mutex. What we really need is to protect fsync() from logging an
extent map for an extent we never waited on higher up, so just guard the
whole thing with dio_sem.
======================================================
WARNING: possible circular locking dependency detected
4.18.0-rc4-xfstests-00025-g5de5edbaf1d4 #411 Not tainted
------------------------------------------------------
aio-dio-invalid/30928 is trying to acquire lock:
0000000092621cfd (&mm->mmap_sem){++++}, at: get_user_pages_unlocked+0x5a/0x1e0
but task is already holding lock:
00000000cefe6b35 (&ei->dio_sem){++++}, at: btrfs_direct_IO+0x3be/0x400
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #5 (&ei->dio_sem){++++}:
lock_acquire+0xbd/0x220
down_write+0x51/0xb0
btrfs_log_changed_extents+0x80/0xa40
btrfs_log_inode+0xbaf/0x1000
btrfs_log_inode_parent+0x26f/0xa80
btrfs_log_dentry_safe+0x50/0x70
btrfs_sync_file+0x357/0x540
do_fsync+0x38/0x60
__ia32_sys_fdatasync+0x12/0x20
do_fast_syscall_32+0x9a/0x2f0
entry_SYSENTER_compat+0x84/0x96
-> #4 (&ei->log_mutex){+.+.}:
lock_acquire+0xbd/0x220
__mutex_lock+0x86/0xa10
btrfs_record_unlink_dir+0x2a/0xa0
btrfs_unlink+0x5a/0xc0
vfs_unlink+0xb1/0x1a0
do_unlinkat+0x264/0x2b0
do_fast_syscall_32+0x9a/0x2f0
entry_SYSENTER_compat+0x84/0x96
-> #3 (sb_internal#2){.+.+}:
lock_acquire+0xbd/0x220
__sb_start_write+0x14d/0x230
start_transaction+0x3e6/0x590
btrfs_evict_inode+0x475/0x640
evict+0xbf/0x1b0
btrfs_run_delayed_iputs+0x6c/0x90
cleaner_kthread+0x124/0x1a0
kthread+0x106/0x140
ret_from_fork+0x3a/0x50
-> #2 (&fs_info->cleaner_delayed_iput_mutex){+.+.}:
lock_acquire+0xbd/0x220
__mutex_lock+0x86/0xa10
btrfs_alloc_data_chunk_ondemand+0x197/0x530
btrfs_check_data_free_space+0x4c/0x90
btrfs_delalloc_reserve_space+0x20/0x60
btrfs_page_mkwrite+0x87/0x520
do_page_mkwrite+0x31/0xa0
__handle_mm_fault+0x799/0xb00
handle_mm_fault+0x7c/0xe0
__do_page_fault+0x1d3/0x4a0
async_page_fault+0x1e/0x30
-> #1 (sb_pagefaults){.+.+}:
lock_acquire+0xbd/0x220
__sb_start_write+0x14d/0x230
btrfs_page_mkwrite+0x6a/0x520
do_page_mkwrite+0x31/0xa0
__handle_mm_fault+0x799/0xb00
handle_mm_fault+0x7c/0xe0
__do_page_fault+0x1d3/0x4a0
async_page_fault+0x1e/0x30
-> #0 (&mm->mmap_sem){++++}:
__lock_acquire+0x42e/0x7a0
lock_acquire+0xbd/0x220
down_read+0x48/0xb0
get_user_pages_unlocked+0x5a/0x1e0
get_user_pages_fast+0xa4/0x150
iov_iter_get_pages+0xc3/0x340
do_direct_IO+0xf93/0x1d70
__blockdev_direct_IO+0x32d/0x1c20
btrfs_direct_IO+0x227/0x400
generic_file_direct_write+0xcf/0x180
btrfs_file_write_iter+0x308/0x58c
aio_write+0xf8/0x1d0
io_submit_one+0x3a9/0x620
__ia32_compat_sys_io_submit+0xb2/0x270
do_int80_syscall_32+0x5b/0x1a0
entry_INT80_compat+0x88/0xa0
other info that might help us debug this:
Chain exists of:
&mm->mmap_sem --> &ei->log_mutex --> &ei->dio_sem
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&ei->dio_sem);
lock(&ei->log_mutex);
lock(&ei->dio_sem);
lock(&mm->mmap_sem);
*** DEADLOCK ***
1 lock held by aio-dio-invalid/30928:
#0 : 00000000cefe6b35 (&ei->dio_sem){++++}, at: btrfs_direct_IO+0x3be/0x400
stack backtrace:
CPU: 0 PID: 30928 Comm: aio-dio-invalid Not tainted 4.18.0-rc4-xfstests-00025-g5de5edbaf1d4 #411
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7 04/01/2014
Call Trace:
dump_stack+0x7c/0xbb
print_circular_bug.isra.37+0x297/0x2a4
check_prev_add.constprop.45+0x781/0x7a0
? __lock_acquire+0x42e/0x7a0
validate_chain.isra.41+0x7f0/0xb00
__lock_acquire+0x42e/0x7a0
lock_acquire+0xbd/0x220
? get_user_pages_unlocked+0x5a/0x1e0
down_read+0x48/0xb0
? get_user_pages_unlocked+0x5a/0x1e0
get_user_pages_unlocked+0x5a/0x1e0
get_user_pages_fast+0xa4/0x150
iov_iter_get_pages+0xc3/0x340
do_direct_IO+0xf93/0x1d70
? __alloc_workqueue_key+0x358/0x490
? __blockdev_direct_IO+0x14b/0x1c20
__blockdev_direct_IO+0x32d/0x1c20
? btrfs_run_delalloc_work+0x40/0x40
? can_nocow_extent+0x490/0x490
? kvm_clock_read+0x1f/0x30
? can_nocow_extent+0x490/0x490
? btrfs_run_delalloc_work+0x40/0x40
btrfs_direct_IO+0x227/0x400
? btrfs_run_delalloc_work+0x40/0x40
generic_file_direct_write+0xcf/0x180
btrfs_file_write_iter+0x308/0x58c
aio_write+0xf8/0x1d0
? kvm_clock_read+0x1f/0x30
? __might_fault+0x3e/0x90
io_submit_one+0x3a9/0x620
? io_submit_one+0xe5/0x620
__ia32_compat_sys_io_submit+0xb2/0x270
do_int80_syscall_32+0x5b/0x1a0
entry_INT80_compat+0x88/0xa0
CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-11-13 11:08:59 -08:00
..
2018-08-17 17:27:58 -07:00
2018-08-22 10:52:51 -07:00
2018-10-15 15:31:47 +02:00
2018-08-22 12:34:08 -07:00
2018-06-15 18:10:01 -03:00
2018-11-13 11:08:59 -08:00
2018-10-18 11:32:21 +02:00
2018-09-06 16:18:04 +02:00
2018-11-13 11:08:48 -08:00
2018-07-17 06:14:07 -07:00
2018-11-13 11:08:55 -08:00
2018-11-13 11:08:46 -08:00
2018-06-12 20:52:16 -07:00
2018-08-21 23:54:17 -04:00
2018-06-12 16:19:22 -07:00
2018-07-22 14:13:44 +02:00
2018-07-24 14:43:20 -06:00
2018-09-19 15:03:04 +02:00
2018-11-13 11:08:43 -08:00
2018-11-13 11:08:39 -08:00
2018-10-13 09:31:03 +02:00
2018-10-18 11:32:21 +02:00
2018-08-21 18:47:36 -07:00
2018-11-13 11:08:43 -08:00
2018-08-23 18:48:42 -07:00
2018-08-23 18:48:42 -07:00
2018-08-17 16:20:28 -07:00
2018-08-25 12:42:33 -07:00
2018-08-22 10:52:44 -07:00
2018-08-21 11:37:41 +02:00
2018-11-13 11:08:43 -08:00
2018-11-13 11:08:16 -08:00
2018-08-15 22:47:23 -07:00
2018-08-18 11:44:53 -07:00
2018-11-13 11:08:49 -08:00
2018-11-13 11:08:49 -08:00
2018-11-13 11:08:49 -08:00
2018-09-04 16:45:02 -07:00
2018-11-13 11:08:50 -08:00
2018-08-17 16:20:27 -07:00
2018-10-13 09:31:02 +02:00
2018-08-14 12:07:14 -04:00
2018-10-04 14:49:10 +02:00
2018-11-13 11:08:46 -08:00
2018-09-30 10:15:41 -07:00
2018-08-22 18:17:48 +02:00
2018-08-22 10:52:50 -07:00
2018-08-02 09:34:02 -07:00
2018-08-18 11:44:53 -07:00
2018-08-22 10:52:51 -07:00
2018-07-31 11:32:44 -04:00
2018-10-13 11:05:02 +02:00
2018-08-24 11:13:32 +02:00
2018-08-17 16:20:27 -07:00
2018-10-06 11:44:39 +10:00
2018-08-13 20:56:23 -07:00
2018-07-12 10:04:27 -04:00
2018-07-03 16:44:45 -04:00
2018-07-12 10:04:20 -04:00
2018-06-12 16:19:22 -07:00
2018-08-13 19:24:32 -07:00
2018-07-10 23:29:03 -04:00
2018-08-14 10:23:25 -07:00
2018-08-30 12:56:40 +02:00
2018-07-30 16:21:49 -04:00
2018-10-08 11:38:44 -07:00
2018-08-17 16:20:28 -07:00
2018-06-28 10:40:47 -07:00
2018-08-22 10:52:49 -07:00
2018-08-21 13:47:29 -07:00
2018-08-15 23:03:20 -05:00
2018-08-21 18:19:09 -07:00
2018-08-21 18:19:09 -07:00
2018-08-21 18:19:09 -07:00
2018-09-24 10:54:01 +02:00
2018-09-29 13:51:01 +10:00
2018-06-11 08:22:34 -07:00
2018-08-02 08:06:55 +09:00
2018-08-21 18:19:09 -07:00
2018-06-11 08:22:34 -07:00
2018-06-12 16:19:22 -07:00
2018-08-17 16:20:29 -07:00
2018-08-23 18:48:43 -07:00
2018-08-26 11:48:42 -07:00
2018-08-21 18:19:09 -07:00
2018-08-13 19:58:36 -07:00
2018-09-24 10:54:01 +02:00
2018-06-28 10:40:47 -07:00
2018-08-17 16:20:28 -07:00
2018-06-16 16:21:50 +09:00
2018-06-16 16:21:50 +09:00
2018-07-12 14:49:48 +01:00
2018-08-26 11:48:42 -07:00
2018-08-13 20:56:23 -07:00
2018-11-13 11:08:46 -08:00
2018-09-18 07:30:48 -04:00