Chao Yu
a02982545e
f2fs: quota: fix potential deadlock
...
[ Upstream commit 9de71ede81e6d1a111fdd868b2d78d459fa77f80 ]
xfstest generic/587 reports a deadlock issue as below:
======================================================
WARNING: possible circular locking dependency detected
5.14.0-rc1 #69 Not tainted
------------------------------------------------------
repquota/8606 is trying to acquire lock:
ffff888022ac9320 (&sb->s_type->i_mutex_key#18){+.+.}-{3:3}, at: f2fs_quota_sync+0x207/0x300 [f2fs]
but task is already holding lock:
ffff8880084bcde8 (&sbi->quota_sem){.+.+}-{3:3}, at: f2fs_quota_sync+0x59/0x300 [f2fs]
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #2 (&sbi->quota_sem){.+.+}-{3:3}:
__lock_acquire+0x648/0x10b0
lock_acquire+0x128/0x470
down_read+0x3b/0x2a0
f2fs_quota_sync+0x59/0x300 [f2fs]
f2fs_quota_on+0x48/0x100 [f2fs]
do_quotactl+0x5e3/0xb30
__x64_sys_quotactl+0x23a/0x4e0
do_syscall_64+0x3b/0x90
entry_SYSCALL_64_after_hwframe+0x44/0xae
-> #1 (&sbi->cp_rwsem){++++}-{3:3}:
__lock_acquire+0x648/0x10b0
lock_acquire+0x128/0x470
down_read+0x3b/0x2a0
f2fs_unlink+0x353/0x670 [f2fs]
vfs_unlink+0x1c7/0x380
do_unlinkat+0x413/0x4b0
__x64_sys_unlinkat+0x50/0xb0
do_syscall_64+0x3b/0x90
entry_SYSCALL_64_after_hwframe+0x44/0xae
-> #0 (&sb->s_type->i_mutex_key#18){+.+.}-{3:3}:
check_prev_add+0xdc/0xb30
validate_chain+0xa67/0xb20
__lock_acquire+0x648/0x10b0
lock_acquire+0x128/0x470
down_write+0x39/0xc0
f2fs_quota_sync+0x207/0x300 [f2fs]
do_quotactl+0xaff/0xb30
__x64_sys_quotactl+0x23a/0x4e0
do_syscall_64+0x3b/0x90
entry_SYSCALL_64_after_hwframe+0x44/0xae
other info that might help us debug this:
Chain exists of:
&sb->s_type->i_mutex_key#18 --> &sbi->cp_rwsem --> &sbi->quota_sem
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(&sbi->quota_sem);
lock(&sbi->cp_rwsem);
lock(&sbi->quota_sem);
lock(&sb->s_type->i_mutex_key#18);
*** DEADLOCK ***
3 locks held by repquota/8606:
#0 : ffff88801efac0e0 (&type->s_umount_key#53){++++}-{3:3}, at: user_get_super+0xd9/0x190
#1 : ffff8880084bc380 (&sbi->cp_rwsem){++++}-{3:3}, at: f2fs_quota_sync+0x3e/0x300 [f2fs]
#2 : ffff8880084bcde8 (&sbi->quota_sem){.+.+}-{3:3}, at: f2fs_quota_sync+0x59/0x300 [f2fs]
stack backtrace:
CPU: 6 PID: 8606 Comm: repquota Not tainted 5.14.0-rc1 #69
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
Call Trace:
dump_stack_lvl+0xce/0x134
dump_stack+0x17/0x20
print_circular_bug.isra.0.cold+0x239/0x253
check_noncircular+0x1be/0x1f0
check_prev_add+0xdc/0xb30
validate_chain+0xa67/0xb20
__lock_acquire+0x648/0x10b0
lock_acquire+0x128/0x470
down_write+0x39/0xc0
f2fs_quota_sync+0x207/0x300 [f2fs]
do_quotactl+0xaff/0xb30
__x64_sys_quotactl+0x23a/0x4e0
do_syscall_64+0x3b/0x90
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f883b0b4efe
The root cause is ABBA deadlock of inode lock and cp_rwsem,
reorder locks in f2fs_quota_sync() as below to fix this issue:
- lock inode
- lock cp_rwsem
- lock quota_sem
Fixes: db6ec53b7e03 ("f2fs: add a rw_sem to cover quota flag changes")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-09-22 12:26:22 +02:00
..
2020-11-05 11:43:34 +01:00
2019-07-19 11:33:22 -07:00
2021-03-04 10:26:48 +01:00
2021-07-28 13:30:58 +02:00
2019-10-25 00:03:11 -04:00
2019-08-30 07:27:17 -07:00
2021-01-06 14:48:39 +01:00
2021-09-22 12:26:19 +02:00
2020-11-05 11:43:36 +01:00
2021-08-18 08:57:04 +02:00
2021-09-15 09:47:36 +02:00
2019-09-19 09:42:37 -07:00
2021-07-14 16:53:46 +02:00
2019-11-23 21:44:49 -05:00
2021-09-12 08:56:38 +02:00
2021-09-15 09:47:33 +02:00
2019-09-03 09:30:56 -04:00
2021-07-14 16:53:17 +02:00
2021-05-26 12:05:19 +02:00
2020-12-02 08:49:53 +01:00
2019-08-30 07:27:17 -07:00
2021-05-11 14:04:02 +02:00
2019-11-10 11:56:05 -05:00
2020-09-09 19:12:30 +02:00
2021-09-12 08:56:38 +02:00
2021-09-22 12:26:22 +02:00
2020-06-17 16:40:36 +02:00
2019-08-30 07:27:17 -07:00
2021-09-15 09:47:41 +02:00
2021-06-18 09:58:59 +02:00
2021-07-31 08:19:38 +02:00
2021-05-19 10:08:29 +02:00
2021-04-14 08:24:14 +02:00
2019-08-30 08:11:25 -07:00
2021-07-28 13:31:01 +02:00
2021-09-15 09:47:35 +02:00
2021-09-15 09:47:27 +02:00
2020-11-18 19:20:30 +01:00
2021-05-11 14:04:16 +02:00
2021-07-20 16:10:42 +02:00
2020-08-19 08:16:12 +02:00
2021-09-15 09:47:35 +02:00
2020-08-21 13:05:37 +02:00
2021-07-20 16:10:50 +02:00
2020-12-30 11:51:22 +01:00
2021-09-15 09:47:35 +02:00
2021-06-30 08:47:50 -04:00
2020-06-17 16:40:24 +02:00
2021-07-14 16:53:01 +02:00
2021-08-04 12:27:37 +02:00
2019-08-30 08:11:25 -07:00
2019-07-19 10:42:02 -07:00
2021-07-20 16:10:48 +02:00
2021-09-03 10:08:12 +02:00
2021-09-03 10:08:12 +02:00
2021-03-04 10:26:45 +01:00
2019-08-30 07:27:17 -07:00
2019-08-30 07:27:17 -07:00
2021-03-04 10:26:26 +01:00
2020-10-29 09:57:53 +01:00
2021-08-12 13:21:05 +02:00
2020-08-26 10:40:51 +02:00
2021-05-19 10:08:29 +02:00
2021-03-07 12:20:48 +01:00
2019-08-30 07:27:18 -07:00
2019-10-12 20:49:07 -04:00
2021-09-12 08:56:39 +02:00
2021-09-15 09:47:28 +02:00
2020-08-21 13:05:37 +02:00
2019-09-17 11:48:24 -04:00
2019-08-12 19:33:50 -07:00
2021-03-07 12:20:42 +01:00
2020-06-17 16:40:24 +02:00
2019-07-19 10:42:02 -07:00
2020-02-11 04:35:12 -08:00
2020-06-03 08:21:27 +02:00
2020-09-03 11:26:39 +02:00
2021-03-17 17:03:57 +01:00
2021-05-22 11:38:29 +02:00
2020-11-05 11:43:24 +01:00
2020-01-14 20:08:18 +01:00
2020-01-09 10:20:05 +01:00
2020-12-11 13:23:30 +01:00
2020-10-29 09:57:45 +01:00
2021-07-14 16:53:25 +02:00
2020-10-01 13:17:19 +02:00
2021-04-14 08:24:11 +02:00
2020-01-12 12:21:37 +01:00
2020-02-11 04:35:37 -08:00
2020-10-07 08:01:31 +02:00
2021-01-09 13:44:55 +01:00
2021-09-15 09:47:28 +02:00
2019-08-07 21:51:47 -04:00
2019-08-19 11:00:39 -04:00
2020-05-27 17:46:12 +02:00
2020-04-17 10:50:21 +02:00
2019-09-06 21:28:49 +02:00
2019-09-12 21:06:14 -04:00
2021-07-14 16:53:35 +02:00
2019-07-19 10:42:02 -07:00
2020-03-25 08:25:58 +01:00
2021-07-31 08:19:37 +02:00
2021-01-30 13:54:10 +01:00
2019-12-17 19:55:30 +01:00
2019-09-18 16:59:14 -07:00
2020-11-24 13:29:19 +01:00
2020-03-25 08:25:41 +01:00
2019-09-18 16:59:14 -07:00
2020-01-17 19:48:21 +01:00
2020-03-05 16:43:48 +01:00
2021-08-26 08:36:22 -04:00
2020-03-18 07:17:51 +01:00
2021-08-12 13:21:02 +02:00
2020-05-02 08:48:44 +02:00
2021-03-17 17:03:33 +01:00
2019-09-06 21:28:49 +02:00
2020-02-11 04:35:23 -08:00
2021-04-21 12:56:16 +02:00
2021-03-24 11:26:44 +01:00
2021-07-20 16:10:54 +02:00
2020-08-26 10:40:58 +02:00
2019-12-17 19:56:52 +01:00
2019-10-03 14:21:35 -07:00
2020-11-24 13:29:01 +01:00
2019-08-01 20:51:23 +02:00
2021-07-28 13:31:01 +02:00
2020-02-11 04:35:12 -08:00
2020-08-11 15:33:39 +02:00