Skip to content

Commit 4a0b75c

Browse files
Shaohua Liaxboe
authored andcommitted
block, cfq: fix empty queue crash caused by request merge
All requests of a queue could be merged to other requests of other queue. Such queue will not have request in it, but it's in service tree. This will cause kernel oops. I encounter a BUG_ON() in cfq_dispatch_request() with next patch, but the issue should exist without the patch. Signed-off-by: Shaohua Li <shaohua.li@intel.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent f1f8cc9 commit 4a0b75c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎block/cfq-iosched.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,8 @@ cfq_merged_requests(struct request_queue *q, struct request *rq,
16561656
struct request *next)
16571657
{
16581658
struct cfq_queue *cfqq = RQ_CFQQ(rq);
1659+
struct cfq_data *cfqd = q->elevator->elevator_data;
1660+
16591661
/*
16601662
* reposition in fifo if next is older than rq
16611663
*/
@@ -1670,6 +1672,16 @@ cfq_merged_requests(struct request_queue *q, struct request *rq,
16701672
cfq_remove_request(next);
16711673
cfq_blkiocg_update_io_merged_stats(&(RQ_CFQG(rq))->blkg,
16721674
rq_data_dir(next), rq_is_sync(next));
1675+
1676+
cfqq = RQ_CFQQ(next);
1677+
/*
1678+
* all requests of this queue are merged to other queues, delete it
1679+
* from the service tree. If it's the active_queue,
1680+
* cfq_dispatch_requests() will choose to expire it or do idle
1681+
*/
1682+
if (cfq_cfqq_on_rr(cfqq) && RB_EMPTY_ROOT(&cfqq->sort_list) &&
1683+
cfqq != cfqd->active_queue)
1684+
cfq_del_cfqq_rr(cfqd, cfqq);
16731685
}
16741686

16751687
static int cfq_allow_merge(struct request_queue *q, struct request *rq,

0 commit comments

Comments
 (0)