Skip to content

Commit 684e151

Browse files
Algodev-githubgregkh
authored andcommitted
block, bfq: move forward the getting of an extra ref in bfq_bfqq_move
[ Upstream commit fd1bb3a ] Commit ecedd3d ("block, bfq: get extra ref to prevent a queue from being freed during a group move") gets an extra reference to a bfq_queue before possibly deactivating it (temporarily), in bfq_bfqq_move(). This prevents the bfq_queue from disappearing before being reactivated in its new group. Yet, the bfq_queue may also be expired (i.e., its service may be stopped) before the bfq_queue is deactivated. And also an expiration may lead to a premature freeing. This commit fixes this issue by simply moving forward the getting of the extra reference already introduced by commit ecedd3d ("block, bfq: get extra ref to prevent a queue from being freed during a group move"). Reported-by: cki-project@redhat.com Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente <paolo.valente@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6bca328 commit 684e151

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎block/bfq-cgroup.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
641641
{
642642
struct bfq_entity *entity = &bfqq->entity;
643643

644+
/*
645+
* Get extra reference to prevent bfqq from being freed in
646+
* next possible expire or deactivate.
647+
*/
648+
bfqq->ref++;
649+
644650
/* If bfqq is empty, then bfq_bfqq_expire also invokes
645651
* bfq_del_bfqq_busy, thereby removing bfqq and its entity
646652
* from data structures related to current group. Otherwise we
@@ -651,12 +657,6 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
651657
bfq_bfqq_expire(bfqd, bfqd->in_service_queue,
652658
false, BFQQE_PREEMPTED);
653659

654-
/*
655-
* get extra reference to prevent bfqq from being freed in
656-
* next possible deactivate
657-
*/
658-
bfqq->ref++;
659-
660660
if (bfq_bfqq_busy(bfqq))
661661
bfq_deactivate_bfqq(bfqd, bfqq, false, false);
662662
else if (entity->on_st)
@@ -676,7 +676,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
676676

677677
if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
678678
bfq_schedule_dispatch(bfqd);
679-
/* release extra ref taken above */
679+
/* release extra ref taken above, bfqq may happen to be freed now */
680680
bfq_put_queue(bfqq);
681681
}
682682

0 commit comments

Comments
 (0)