Skip to content

Commit 14afc59

Browse files
carlo-nonatoaxboe
authored andcommitted
block, bfq: fix overwrite of bfq_group pointer in bfq_find_set_group()
The bfq_find_set_group() function takes as input a blkcg (which represents a cgroup) and retrieves the corresponding bfq_group, then it updates the bfq internal group hierarchy (see comments inside the function for why this is needed) and finally it returns the bfq_group. In the hierarchy update cycle, the pointer holding the correct bfq_group that has to be returned is mistakenly used to traverse the hierarchy bottom to top, meaning that in each iteration it gets overwritten with the parent of the current group. Since the update cycle stops at root's children (depth = 2), the overwrite becomes a problem only if the blkcg describes a cgroup at a hierarchy level deeper than that (depth > 2). In this case the root's child that happens to be also an ancestor of the correct bfq_group is returned. The main consequence is that processes contained in a cgroup at depth greater than 2 are wrongly placed in the group described above by BFQ. This commits fixes this problem by using a different bfq_group pointer in the update cycle in order to avoid the overwrite of the variable holding the original group reference. Reported-by: Kwon Je Oh <[email protected]> Signed-off-by: Carlo Nonato <[email protected]> Signed-off-by: Paolo Valente <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 153031a commit 14afc59

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

block/bfq-cgroup.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,13 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd,
610610
*/
611611
entity = &bfqg->entity;
612612
for_each_entity(entity) {
613-
bfqg = container_of(entity, struct bfq_group, entity);
614-
if (bfqg != bfqd->root_group) {
615-
parent = bfqg_parent(bfqg);
613+
struct bfq_group *curr_bfqg = container_of(entity,
614+
struct bfq_group, entity);
615+
if (curr_bfqg != bfqd->root_group) {
616+
parent = bfqg_parent(curr_bfqg);
616617
if (!parent)
617618
parent = bfqd->root_group;
618-
bfq_group_set_parent(bfqg, parent);
619+
bfq_group_set_parent(curr_bfqg, parent);
619620
}
620621
}
621622

0 commit comments

Comments
 (0)