Li Nan
eb120c0aff
blk-iocost: use spin_lock_irqsave in adjust_inuse_and_calc_cost
...
[ Upstream commit 8d211554679d0b23702bd32ba04aeac0c1c4f660 ]
adjust_inuse_and_calc_cost() use spin_lock_irq() and IRQ will be enabled
when unlock. DEADLOCK might happen if we have held other locks and disabled
IRQ before invoking it.
Fix it by using spin_lock_irqsave() instead, which can keep IRQ state
consistent with before when unlock.
================================
WARNING: inconsistent lock state
5.10.0-02758-g8e5f91fd772f #26 Not tainted
--------------------------------
inconsistent {IN-HARDIRQ-W} -> {HARDIRQ-ON-W} usage.
kworker/2:3/388 [HC0[0]:SC0[0]:HE0:SE1] takes:
ffff888118c00c28 (&bfqd->lock){?.-.}-{2:2}, at: spin_lock_irq
ffff888118c00c28 (&bfqd->lock){?.-.}-{2:2}, at: bfq_bio_merge+0x141/0x390
{IN-HARDIRQ-W} state was registered at:
__lock_acquire+0x3d7/0x1070
lock_acquire+0x197/0x4a0
__raw_spin_lock_irqsave
_raw_spin_lock_irqsave+0x3b/0x60
bfq_idle_slice_timer_body
bfq_idle_slice_timer+0x53/0x1d0
__run_hrtimer+0x477/0xa70
__hrtimer_run_queues+0x1c6/0x2d0
hrtimer_interrupt+0x302/0x9e0
local_apic_timer_interrupt
__sysvec_apic_timer_interrupt+0xfd/0x420
run_sysvec_on_irqstack_cond
sysvec_apic_timer_interrupt+0x46/0xa0
asm_sysvec_apic_timer_interrupt+0x12/0x20
irq event stamp: 837522
hardirqs last enabled at (837521): [<ffffffff84b9419d>] __raw_spin_unlock_irqrestore
hardirqs last enabled at (837521): [<ffffffff84b9419d>] _raw_spin_unlock_irqrestore+0x3d/0x40
hardirqs last disabled at (837522): [<ffffffff84b93fa3>] __raw_spin_lock_irq
hardirqs last disabled at (837522): [<ffffffff84b93fa3>] _raw_spin_lock_irq+0x43/0x50
softirqs last enabled at (835852): [<ffffffff84e00558>] __do_softirq+0x558/0x8ec
softirqs last disabled at (835845): [<ffffffff84c010ff>] asm_call_irq_on_stack+0xf/0x20
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock(&bfqd->lock);
<Interrupt>
lock(&bfqd->lock);
*** DEADLOCK ***
3 locks held by kworker/2:3/388:
#0 : ffff888107af0f38 ((wq_completion)kthrotld){+.+.}-{0:0}, at: process_one_work+0x742/0x13f0
#1 : ffff8881176bfdd8 ((work_completion)(&td->dispatch_work)){+.+.}-{0:0}, at: process_one_work+0x777/0x13f0
#2 : ffff888118c00c28 (&bfqd->lock){?.-.}-{2:2}, at: spin_lock_irq
#2 : ffff888118c00c28 (&bfqd->lock){?.-.}-{2:2}, at: bfq_bio_merge+0x141/0x390
stack backtrace:
CPU: 2 PID: 388 Comm: kworker/2:3 Not tainted 5.10.0-02758-g8e5f91fd772f #26
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014
Workqueue: kthrotld blk_throtl_dispatch_work_fn
Call Trace:
__dump_stack lib/dump_stack.c:77 [inline]
dump_stack+0x107/0x167
print_usage_bug
valid_state
mark_lock_irq.cold+0x32/0x3a
mark_lock+0x693/0xbc0
mark_held_locks+0x9e/0xe0
__trace_hardirqs_on_caller
lockdep_hardirqs_on_prepare.part.0+0x151/0x360
trace_hardirqs_on+0x5b/0x180
__raw_spin_unlock_irq
_raw_spin_unlock_irq+0x24/0x40
spin_unlock_irq
adjust_inuse_and_calc_cost+0x4fb/0x970
ioc_rqos_merge+0x277/0x740
__rq_qos_merge+0x62/0xb0
rq_qos_merge
bio_attempt_back_merge+0x12c/0x4a0
blk_mq_sched_try_merge+0x1b6/0x4d0
bfq_bio_merge+0x24a/0x390
__blk_mq_sched_bio_merge+0xa6/0x460
blk_mq_sched_bio_merge
blk_mq_submit_bio+0x2e7/0x1ee0
__submit_bio_noacct_mq+0x175/0x3b0
submit_bio_noacct+0x1fb/0x270
blk_throtl_dispatch_work_fn+0x1ef/0x2b0
process_one_work+0x83e/0x13f0
process_scheduled_works
worker_thread+0x7e3/0xd80
kthread+0x353/0x470
ret_from_fork+0x1f/0x30
Fixes: b0853ab4a238 ("blk-iocost: revamp in-period donation snapbacks")
Signed-off-by: Li Nan <linan122@huawei.com>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20230527091904.3001833-1-linan666@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-07-23 13:46:44 +02:00
..
2022-03-16 14:23:46 +01:00
2020-08-23 17:36:59 -05:00
2022-04-27 14:38:50 +02:00
2023-02-09 11:26:36 +01:00
2023-02-09 11:26:36 +01:00
2022-06-09 10:23:19 +02:00
2022-04-08 14:23:55 +02:00
2023-03-10 09:39:05 +01:00
2022-08-17 14:24:01 +02:00
2021-03-05 11:32:15 -07:00
2019-11-07 12:28:13 -07:00
2023-02-06 07:59:00 +01:00
2023-05-11 23:00:16 +09:00
2021-03-11 07:47:48 -07:00
2023-05-11 23:00:16 +09:00
2023-05-11 23:00:16 +09:00
2021-06-30 15:35:45 -06:00
2022-01-27 11:05:25 +01:00
2021-09-14 20:03:30 -06:00
2022-08-11 13:07:50 +02:00
2023-07-23 13:46:44 +02:00
2022-08-17 14:24:24 +02:00
2021-06-21 15:03:40 -06:00
2021-06-21 15:03:40 -06:00
2021-06-17 15:51:20 +02:00
2022-03-08 19:12:31 +01:00
2023-05-11 23:00:16 +09:00
2020-10-20 07:08:17 -06:00
2019-01-17 21:21:40 -07:00
2022-08-17 14:23:12 +02:00
2019-06-13 03:00:30 -06:00
2019-05-31 15:12:34 -06:00
2019-05-31 15:12:34 -06:00
2023-03-10 09:39:04 +01:00
2021-06-24 18:43:55 -06:00
2022-12-31 13:14:43 +01:00
2021-09-12 19:32:43 -06:00
2021-05-24 06:47:22 -06:00
2020-03-17 20:55:21 +01:00
2023-05-11 23:00:16 +09:00
2021-12-01 09:04:56 +01:00
2022-01-27 11:04:15 +01:00
2021-02-22 06:33:48 -07:00
2021-06-08 15:12:57 -06:00
2022-08-17 14:24:24 +02:00
2023-06-09 10:32:32 +02:00
2020-09-01 16:48:46 -06:00
2022-04-08 14:23:07 +02:00
2022-10-26 12:35:47 +02:00
2020-07-31 16:29:47 -06:00
2022-10-26 12:35:54 +02:00
2021-06-21 15:03:41 -06:00
2021-11-18 19:17:15 +01:00
2021-11-18 19:16:16 +01:00
2021-08-02 13:37:28 -06:00
2021-08-01 13:21:40 -04:00
2021-09-14 00:22:15 -04:00
2021-08-23 12:55:45 -06:00
2022-02-23 12:03:15 +01:00
2023-03-10 09:39:55 +01:00
2022-12-31 13:14:10 +01:00
2022-03-16 14:23:46 +01:00
2022-04-27 14:39:02 +02:00
2022-08-11 13:07:50 +02:00
2021-09-02 15:09:46 -07:00
2021-08-11 13:47:26 -06:00
2023-05-11 23:00:16 +09:00
2021-10-15 21:02:57 -06:00
2022-12-14 11:37:30 +01:00
2023-01-24 07:22:49 +01:00
2020-03-12 08:00:10 -06:00
2022-11-26 09:24:35 +01:00
2021-08-02 13:37:28 -06:00