Skip to content

Commit db5f1fc

Browse files
Algodev-githubgregkh
authored andcommitted
block, bfq: get a ref to a group when adding it to a service tree
[ Upstream commit db37a34 ] BFQ schedules generic entities, which may represent either bfq_queues or groups of bfq_queues. When an entity is inserted into a service tree, a reference must be taken, to make sure that the entity does not disappear while still referred in the tree. Unfortunately, such a reference is mistakenly taken only if the entity represents a bfq_queue. This commit takes a reference also in case the entity represents a group. Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name> Tested-by: Chris Evich <cevich@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 21b6198 commit db5f1fc

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎block/bfq-cgroup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static void bfqg_put(struct bfq_group *bfqg)
332332
kfree(bfqg);
333333
}
334334

335-
static void bfqg_and_blkg_get(struct bfq_group *bfqg)
335+
void bfqg_and_blkg_get(struct bfq_group *bfqg)
336336
{
337337
/* see comments in bfq_bic_update_cgroup for why refcounting bfqg */
338338
bfqg_get(bfqg);

‎block/bfq-iosched.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
984984
struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg);
985985
struct bfq_group *bfqq_group(struct bfq_queue *bfqq);
986986
struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node);
987+
void bfqg_and_blkg_get(struct bfq_group *bfqg);
987988
void bfqg_and_blkg_put(struct bfq_group *bfqg);
988989

989990
#ifdef CONFIG_BFQ_GROUP_IOSCHED

‎block/bfq-wf2q.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,9 @@ static void bfq_get_entity(struct bfq_entity *entity)
536536
bfqq->ref++;
537537
bfq_log_bfqq(bfqq->bfqd, bfqq, "get_entity: %p %d",
538538
bfqq, bfqq->ref);
539-
}
539+
} else
540+
bfqg_and_blkg_get(container_of(entity, struct bfq_group,
541+
entity));
540542
}
541543

542544
/**
@@ -650,8 +652,14 @@ static void bfq_forget_entity(struct bfq_service_tree *st,
650652

651653
entity->on_st = false;
652654
st->wsum -= entity->weight;
653-
if (bfqq && !is_in_service)
655+
if (is_in_service)
656+
return;
657+
658+
if (bfqq)
654659
bfq_put_queue(bfqq);
660+
else
661+
bfqg_and_blkg_put(container_of(entity, struct bfq_group,
662+
entity));
655663
}
656664

657665
/**

0 commit comments

Comments
 (0)