Skip to content

Commit 4e9b6f2

Browse files
KAGA-KOKOaxboe
authored andcommitted
block: Fix a race between blk_cleanup_queue() and timeout handling
Make sure that if the timeout timer fires after a queue has been marked "dying" that the affected requests are finished. Reported-by: chenxiang (M) <chenxiang66@hisilicon.com> Fixes: commit 287922e ("block: defer timeouts to a workqueue") Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Tested-by: chenxiang (M) <chenxiang66@hisilicon.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Keith Busch <keith.busch@intel.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Ming Lei <ming.lei@redhat.com> Cc: Johannes Thumshirn <jthumshirn@suse.de> Cc: <stable@vger.kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 4d740bc commit 4e9b6f2

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

‎block/blk-core.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ EXPORT_SYMBOL(blk_stop_queue);
333333
void blk_sync_queue(struct request_queue *q)
334334
{
335335
del_timer_sync(&q->timeout);
336+
cancel_work_sync(&q->timeout_work);
336337

337338
if (q->mq_ops) {
338339
struct blk_mq_hw_ctx *hctx;
@@ -844,6 +845,7 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
844845
setup_timer(&q->backing_dev_info->laptop_mode_wb_timer,
845846
laptop_mode_timer_fn, (unsigned long) q);
846847
setup_timer(&q->timeout, blk_rq_timed_out_timer, (unsigned long) q);
848+
INIT_WORK(&q->timeout_work, NULL);
847849
INIT_LIST_HEAD(&q->queue_head);
848850
INIT_LIST_HEAD(&q->timeout_list);
849851
INIT_LIST_HEAD(&q->icq_list);

‎block/blk-timeout.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ void blk_timeout_work(struct work_struct *work)
134134
struct request *rq, *tmp;
135135
int next_set = 0;
136136

137-
if (blk_queue_enter(q, true))
138-
return;
139137
spin_lock_irqsave(q->queue_lock, flags);
140138

141139
list_for_each_entry_safe(rq, tmp, &q->timeout_list, timeout_list)
@@ -145,7 +143,6 @@ void blk_timeout_work(struct work_struct *work)
145143
mod_timer(&q->timeout, round_jiffies_up(next));
146144

147145
spin_unlock_irqrestore(q->queue_lock, flags);
148-
blk_queue_exit(q);
149146
}
150147

151148
/**

0 commit comments

Comments
 (0)