Hao Xu
a2efc46524
io_uring: don't hold uring_lock when calling io_run_task_work*
...
commit 8bad28d8a305b0e5ae444c8c3051e8744f5a4296 upstream.
Abaci reported the below issue:
[ 141.400455] hrtimer: interrupt took 205853 ns
[ 189.869316] process 'usr/local/ilogtail/ilogtail_0.16.26' started with executable stack
[ 250.188042]
[ 250.188327] ============================================
[ 250.189015] WARNING: possible recursive locking detected
[ 250.189732] 5.11.0-rc4 #1 Not tainted
[ 250.190267] --------------------------------------------
[ 250.190917] a.out/7363 is trying to acquire lock:
[ 250.191506] ffff888114dbcbe8 (&ctx->uring_lock){+.+.}-{3:3}, at: __io_req_task_submit+0x29/0xa0
[ 250.192599]
[ 250.192599] but task is already holding lock:
[ 250.193309] ffff888114dbfbe8 (&ctx->uring_lock){+.+.}-{3:3}, at: __x64_sys_io_uring_register+0xad/0x210
[ 250.194426]
[ 250.194426] other info that might help us debug this:
[ 250.195238] Possible unsafe locking scenario:
[ 250.195238]
[ 250.196019] CPU0
[ 250.196411] ----
[ 250.196803] lock(&ctx->uring_lock);
[ 250.197420] lock(&ctx->uring_lock);
[ 250.197966]
[ 250.197966] *** DEADLOCK ***
[ 250.197966]
[ 250.198837] May be due to missing lock nesting notation
[ 250.198837]
[ 250.199780] 1 lock held by a.out/7363:
[ 250.200373] #0 : ffff888114dbfbe8 (&ctx->uring_lock){+.+.}-{3:3}, at: __x64_sys_io_uring_register+0xad/0x210
[ 250.201645]
[ 250.201645] stack backtrace:
[ 250.202298] CPU: 0 PID: 7363 Comm: a.out Not tainted 5.11.0-rc4 #1
[ 250.203144] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
[ 250.203887] Call Trace:
[ 250.204302] dump_stack+0xac/0xe3
[ 250.204804] __lock_acquire+0xab6/0x13a0
[ 250.205392] lock_acquire+0x2c3/0x390
[ 250.205928] ? __io_req_task_submit+0x29/0xa0
[ 250.206541] __mutex_lock+0xae/0x9f0
[ 250.207071] ? __io_req_task_submit+0x29/0xa0
[ 250.207745] ? 0xffffffffa0006083
[ 250.208248] ? __io_req_task_submit+0x29/0xa0
[ 250.208845] ? __io_req_task_submit+0x29/0xa0
[ 250.209452] ? __io_req_task_submit+0x5/0xa0
[ 250.210083] __io_req_task_submit+0x29/0xa0
[ 250.210687] io_async_task_func+0x23d/0x4c0
[ 250.211278] task_work_run+0x89/0xd0
[ 250.211884] io_run_task_work_sig+0x50/0xc0
[ 250.212464] io_sqe_files_unregister+0xb2/0x1f0
[ 250.213109] __io_uring_register+0x115a/0x1750
[ 250.213718] ? __x64_sys_io_uring_register+0xad/0x210
[ 250.214395] ? __fget_files+0x15a/0x260
[ 250.214956] __x64_sys_io_uring_register+0xbe/0x210
[ 250.215620] ? trace_hardirqs_on+0x46/0x110
[ 250.216205] do_syscall_64+0x2d/0x40
[ 250.216731] entry_SYSCALL_64_after_hwframe+0x44/0xa9
[ 250.217455] RIP: 0033:0x7f0fa17e5239
[ 250.218034] Code: 01 00 48 81 c4 80 00 00 00 e9 f1 fe ff ff 0f 1f 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 3d 01 f0 ff ff 73 01 c3 48 8b 0d 27 ec 2c 00 f7 d8 64 89 01 48
[ 250.220343] RSP: 002b:00007f0fa1eeac48 EFLAGS: 00000246 ORIG_RAX: 00000000000001ab
[ 250.221360] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f0fa17e5239
[ 250.222272] RDX: 0000000000000000 RSI: 0000000000000003 RDI: 0000000000000008
[ 250.223185] RBP: 00007f0fa1eeae20 R08: 0000000000000000 R09: 0000000000000000
[ 250.224091] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
[ 250.224999] R13: 0000000000021000 R14: 0000000000000000 R15: 00007f0fa1eeb700
This is caused by calling io_run_task_work_sig() to do work under
uring_lock while the caller io_sqe_files_unregister() already held
uring_lock.
To fix this issue, briefly drop uring_lock when calling
io_run_task_work_sig(), and there are two things to concern:
- hold uring_lock in io_ring_ctx_free() around io_sqe_files_unregister()
this is for consistency of lock/unlock.
- add new fixed rsrc ref node before dropping uring_lock
it's not safe to do io_uring_enter-->percpu_ref_get() with a dying one.
- check if rsrc_data->refs is dying to avoid parallel io_sqe_files_unregister
Reported-by: Abaci <abaci@linux.alibaba.com>
Fixes: 1ffc54220c44 ("io_uring: fix io_sqe_files_unregister() hangs")
Suggested-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Hao Xu <haoxu@linux.alibaba.com>
[axboe: fixes from Pavel folded in]
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Samiullah Khawaja <skhawaja@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-12-08 11:23:58 +01:00
..
2022-06-22 14:13:12 +02:00
2020-10-24 12:26:05 -07:00
2021-03-04 11:38:37 +01:00
2022-12-08 11:23:56 +01:00
2020-10-16 11:11:22 -07:00
2021-01-06 14:56:52 +01:00
2022-12-08 11:23:54 +01:00
2021-03-30 14:32:07 +02:00
2022-12-02 17:40:03 +01:00
2022-11-25 17:45:48 +01:00
2022-03-02 11:42:52 +01:00
2022-11-10 18:14:25 +01:00
2022-09-15 11:32:03 +02:00
2022-02-01 17:25:39 +01:00
2022-10-26 13:25:08 +02:00
2021-05-26 12:06:55 +02:00
2020-11-25 16:55:02 +01:00
2022-08-21 15:15:35 +02:00
2022-06-06 08:42:42 +02:00
2022-08-21 15:15:28 +02:00
2022-12-02 17:40:02 +01:00
2022-11-10 18:14:29 +01:00
2022-06-09 10:20:58 +02:00
2021-09-18 13:40:15 +02:00
2022-12-02 17:40:07 +01:00
2022-11-25 17:45:56 +01:00
2021-07-31 08:16:12 +02:00
2021-05-19 10:13:10 +02:00
2021-04-14 08:42:06 +02:00
2022-04-27 13:53:54 +02:00
2022-07-07 17:52:19 +02:00
2021-11-12 14:58:33 +01:00
2022-10-26 13:25:13 +02:00
2022-06-14 18:32:35 +02:00
2022-06-09 10:20:57 +02:00
2022-11-03 23:57:50 +09:00
2021-09-18 13:40:30 +02:00
2022-04-13 21:01:01 +02:00
2022-11-25 17:45:40 +01:00
2020-12-30 11:53:45 +01:00
2022-10-26 13:25:45 +02:00
2022-12-08 11:23:57 +01:00
2022-06-09 10:21:03 +02:00
2022-11-25 17:45:57 +01:00
2022-10-30 09:41:15 +01:00
2020-09-22 23:39:45 -04:00
2022-01-20 09:17:50 +01:00
2022-08-21 15:15:23 +02:00
2022-10-30 09:41:19 +01:00
2022-04-08 14:39:56 +02:00
2021-09-30 10:11:08 +02:00
2022-10-26 13:25:09 +02:00
2020-10-16 11:11:22 -07:00
2021-08-12 13:22:19 +02:00
2020-10-24 12:26:05 -07:00
2021-05-19 10:13:10 +02:00
2020-10-02 12:02:30 +02:00
2022-09-20 12:38:31 +02:00
2022-04-13 21:00:53 +02:00
2022-11-16 09:57:17 +01:00
2020-10-24 12:26:05 -07:00
2021-10-17 10:43:33 +02:00
2021-10-06 15:55:46 +02:00
2022-09-28 11:10:29 +02:00
2022-12-02 17:40:05 +01:00
2021-12-14 11:32:40 +01:00
2022-08-21 15:15:22 +02:00
2022-04-08 14:40:44 +02:00
2022-11-03 23:57:49 +09:00
2022-06-09 10:20:47 +02:00
2021-03-17 17:06:35 +01:00
2021-06-03 09:00:45 +02:00
2022-11-25 17:45:56 +01:00
2022-04-08 14:40:45 +02:00
2020-10-14 14:54:45 -07:00
2022-06-09 10:21:16 +02:00
2021-04-14 08:41:58 +02:00
2022-08-21 15:15:28 +02:00
2022-11-03 23:57:49 +09:00
2022-10-30 09:41:18 +01:00
2022-05-18 10:23:48 +02:00
2022-04-08 14:40:30 +02:00
2022-02-08 18:30:36 +01:00
2020-10-13 18:38:27 -07:00
2022-06-09 10:21:22 +02:00
2022-10-15 07:55:51 +02:00
2021-07-31 08:16:11 +02:00
2022-12-08 11:23:58 +01:00
2021-09-18 13:40:06 +02:00
2021-02-13 13:54:56 +01:00
2022-05-25 09:17:54 +02:00
2021-02-17 11:02:21 +01:00
2021-10-27 09:56:51 +02:00
2020-11-22 10:48:22 -08:00
2021-03-20 10:43:44 +01:00
2020-10-23 11:33:41 -07:00
2022-11-25 17:45:56 +01:00
2021-08-26 08:35:57 -04:00
2021-07-14 16:55:59 +02:00
2022-06-06 08:42:41 +02:00
2021-03-17 17:06:13 +01:00
2020-12-30 11:54:02 +01:00
2020-10-23 11:33:41 -07:00
2021-04-21 13:00:54 +02:00
2022-07-21 21:20:01 +02:00
2022-01-29 10:26:11 +01:00
2021-07-20 16:05:59 +02:00
2022-09-05 10:28:58 +02:00
2022-10-17 17:26:07 +02:00
2022-04-27 13:53:54 +02:00
2022-11-10 18:14:25 +01:00
2022-08-31 17:15:14 +02:00
2022-10-26 13:25:17 +02:00
2020-10-13 18:38:27 -07:00