Skip to content

Commit 2d70105

Browse files
author
Sebastian Andrzej Siewior
committed
block: blk-mq: move blk_queue_usage_counter_release() into process context
| BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:914 | in_atomic(): 1, irqs_disabled(): 0, pid: 255, name: kworker/u257:6 | 5 locks held by kworker/u257:6/255: | #0: ("events_unbound"){.+.+.+}, at: [<ffffffff8108edf1>] process_one_work+0x171/0x5e0 | #1: ((&entry->work)){+.+.+.}, at: [<ffffffff8108edf1>] process_one_work+0x171/0x5e0 | #2: (&shost->scan_mutex){+.+.+.}, at: [<ffffffffa000faa3>] __scsi_add_device+0xa3/0x130 [scsi_mod] | #3: (&set->tag_list_lock){+.+...}, at: [<ffffffff812f09fa>] blk_mq_init_queue+0x96a/0xa50 | #4: (rcu_read_lock_sched){......}, at: [<ffffffff8132887d>] percpu_ref_kill_and_confirm+0x1d/0x120 | Preemption disabled at:[<ffffffff812eff76>] blk_mq_freeze_queue_start+0x56/0x70 | | CPU: 2 PID: 255 Comm: kworker/u257:6 Not tainted 3.18.7-rt0+ #1 | Workqueue: events_unbound async_run_entry_fn | 0000000000000003 ffff8800bc29f998 ffffffff815b3a12 0000000000000000 | 0000000000000000 ffff8800bc29f9b8 ffffffff8109aa16 ffff8800bc29fa28 | ffff8800bc5d1bc8 ffff8800bc29f9e8 ffffffff815b8dd4 ffff880000000000 | Call Trace: | [<ffffffff815b3a12>] dump_stack+0x4f/0x7c | [<ffffffff8109aa16>] __might_sleep+0x116/0x190 | [<ffffffff815b8dd4>] rt_spin_lock+0x24/0x60 | [<ffffffff810b6089>] __wake_up+0x29/0x60 | [<ffffffff812ee06e>] blk_mq_usage_counter_release+0x1e/0x20 | [<ffffffff81328966>] percpu_ref_kill_and_confirm+0x106/0x120 | [<ffffffff812eff76>] blk_mq_freeze_queue_start+0x56/0x70 | [<ffffffff812f0000>] blk_mq_update_tag_set_depth+0x40/0xd0 | [<ffffffff812f0a1c>] blk_mq_init_queue+0x98c/0xa50 | [<ffffffffa000dcf0>] scsi_mq_alloc_queue+0x20/0x60 [scsi_mod] | [<ffffffffa000ea35>] scsi_alloc_sdev+0x2f5/0x370 [scsi_mod] | [<ffffffffa000f494>] scsi_probe_and_add_lun+0x9e4/0xdd0 [scsi_mod] | [<ffffffffa000fb26>] __scsi_add_device+0x126/0x130 [scsi_mod] | [<ffffffffa013033f>] ata_scsi_scan_host+0xaf/0x200 [libata] | [<ffffffffa012b5b6>] async_port_probe+0x46/0x60 [libata] | [<ffffffff810978fb>] async_run_entry_fn+0x3b/0xf0 | [<ffffffff8108ee81>] process_one_work+0x201/0x5e0 percpu_ref_kill_and_confirm() invokes blk_mq_usage_counter_release() in a rcu-sched region. swait based wake queue can't be used due to wake_up_all() usage and disabled interrupts in !RT configs (as reported by Corey Minyard). The wq_has_sleeper() check has been suggested by Peter Zijlstra. Cc: stable-rt@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
1 parent ca3fd6c commit 2d70105

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

block/blk-core.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,12 +814,21 @@ void blk_queue_exit(struct request_queue *q)
814814
percpu_ref_put(&q->q_usage_counter);
815815
}
816816

817+
static void blk_queue_usage_counter_release_swork(struct swork_event *sev)
818+
{
819+
struct request_queue *q =
820+
container_of(sev, struct request_queue, mq_pcpu_wake);
821+
822+
wake_up_all(&q->mq_freeze_wq);
823+
}
824+
817825
static void blk_queue_usage_counter_release(struct percpu_ref *ref)
818826
{
819827
struct request_queue *q =
820828
container_of(ref, struct request_queue, q_usage_counter);
821829

822-
wake_up_all(&q->mq_freeze_wq);
830+
if (wq_has_sleeper(&q->mq_freeze_wq))
831+
swork_queue(&q->mq_pcpu_wake);
823832
}
824833

825834
static void blk_rq_timed_out_timer(unsigned long data)
@@ -896,6 +905,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
896905
__set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
897906

898907
init_waitqueue_head(&q->mq_freeze_wq);
908+
INIT_SWORK(&q->mq_pcpu_wake, blk_queue_usage_counter_release_swork);
899909

900910
/*
901911
* Init percpu_ref in atomic mode so that it's faster to shutdown.
@@ -3623,6 +3633,8 @@ int __init blk_dev_init(void)
36233633
if (!kblockd_workqueue)
36243634
panic("Failed to create kblockd\n");
36253635

3636+
BUG_ON(swork_get());
3637+
36263638
request_cachep = kmem_cache_create("blkdev_requests",
36273639
sizeof(struct request), 0, SLAB_PANIC, NULL);
36283640

include/linux/blkdev.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/percpu-refcount.h>
2828
#include <linux/scatterlist.h>
2929
#include <linux/blkzoned.h>
30+
#include <linux/swork.h>
3031

3132
struct module;
3233
struct scsi_ioctl_command;
@@ -599,6 +600,7 @@ struct request_queue {
599600
#endif
600601
struct rcu_head rcu_head;
601602
wait_queue_head_t mq_freeze_wq;
603+
struct swork_event mq_pcpu_wake;
602604
struct percpu_ref q_usage_counter;
603605
struct list_head all_q_node;
604606

0 commit comments

Comments
 (0)