* [PATCH RFC] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move()
@ 2021-12-10 8:16 Yu Kuai
2021-12-18 9:09 ` yukuai (C)
0 siblings, 1 reply; 2+ messages in thread
From: Yu Kuai @ 2021-12-10 8:16 UTC (permalink / raw)
To: paolo.valente, axboe, tj
Cc: linux-block, cgroups, linux-kernel, yukuai3, yi.zhang
During code review, we found that if bfqq is not busy in
bfq_bfqq_move(), bfq_pos_tree_add_move() won't be called for the bfqq,
thus bfqq->pos_root still points to the old bfqg. However, the ref
that bfqq hold for the old bfqg will be released, so it's possible
that the old bfqg can be freed. This is problematic because the freed
bfqg can still be accessed by bfqq->pos_root.
Fix the problem by calling bfq_pos_tree_add_move() for idle bfqq
as well.
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
block/bfq-cgroup.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
index 24a5c5329bcd..85f34c29b909 100644
--- a/block/bfq-cgroup.c
+++ b/block/bfq-cgroup.c
@@ -645,6 +645,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
struct bfq_group *bfqg)
{
struct bfq_entity *entity = &bfqq->entity;
+ struct bfq_group *old_parent = bfqq_group(bfqq);
/*
* Get extra reference to prevent bfqq from being freed in
@@ -666,7 +667,6 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
bfq_deactivate_bfqq(bfqd, bfqq, false, false);
else if (entity->on_st_or_in_serv)
bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
- bfqg_and_blkg_put(bfqq_group(bfqq));
if (entity->parent &&
entity->parent->last_bfqq_created == bfqq)
@@ -679,11 +679,16 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
/* pin down bfqg and its associated blkg */
bfqg_and_blkg_get(bfqg);
- if (bfq_bfqq_busy(bfqq)) {
- if (unlikely(!bfqd->nonrot_with_queueing))
- bfq_pos_tree_add_move(bfqd, bfqq);
+ /*
+ * Don't leave the pos_root to old bfqg, since the ref to old bfqg will
+ * be released and the bfqg might be freed.
+ */
+ if (unlikely(!bfqd->nonrot_with_queueing))
+ bfq_pos_tree_add_move(bfqd, bfqq);
+ bfqg_and_blkg_put(old_parent);
+
+ if (bfq_bfqq_busy(bfqq))
bfq_activate_bfqq(bfqd, bfqq);
- }
if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
bfq_schedule_dispatch(bfqd);
--
2.31.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH RFC] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move()
2021-12-10 8:16 [PATCH RFC] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move() Yu Kuai
@ 2021-12-18 9:09 ` yukuai (C)
0 siblings, 0 replies; 2+ messages in thread
From: yukuai (C) @ 2021-12-18 9:09 UTC (permalink / raw)
To: paolo.valente, axboe, tj; +Cc: linux-block, cgroups, linux-kernel, yi.zhang
在 2021/12/10 16:16, Yu Kuai 写道:
> During code review, we found that if bfqq is not busy in
> bfq_bfqq_move(), bfq_pos_tree_add_move() won't be called for the bfqq,
> thus bfqq->pos_root still points to the old bfqg. However, the ref
> that bfqq hold for the old bfqg will be released, so it's possible
> that the old bfqg can be freed. This is problematic because the freed
> bfqg can still be accessed by bfqq->pos_root.
>
> Fix the problem by calling bfq_pos_tree_add_move() for idle bfqq
> as well.
>
Friendly ping ...
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
> block/bfq-cgroup.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
> index 24a5c5329bcd..85f34c29b909 100644
> --- a/block/bfq-cgroup.c
> +++ b/block/bfq-cgroup.c
> @@ -645,6 +645,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
> struct bfq_group *bfqg)
> {
> struct bfq_entity *entity = &bfqq->entity;
> + struct bfq_group *old_parent = bfqq_group(bfqq);
>
> /*
> * Get extra reference to prevent bfqq from being freed in
> @@ -666,7 +667,6 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
> bfq_deactivate_bfqq(bfqd, bfqq, false, false);
> else if (entity->on_st_or_in_serv)
> bfq_put_idle_entity(bfq_entity_service_tree(entity), entity);
> - bfqg_and_blkg_put(bfqq_group(bfqq));
>
> if (entity->parent &&
> entity->parent->last_bfqq_created == bfqq)
> @@ -679,11 +679,16 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq,
> /* pin down bfqg and its associated blkg */
> bfqg_and_blkg_get(bfqg);
>
> - if (bfq_bfqq_busy(bfqq)) {
> - if (unlikely(!bfqd->nonrot_with_queueing))
> - bfq_pos_tree_add_move(bfqd, bfqq);
> + /*
> + * Don't leave the pos_root to old bfqg, since the ref to old bfqg will
> + * be released and the bfqg might be freed.
> + */
> + if (unlikely(!bfqd->nonrot_with_queueing))
> + bfq_pos_tree_add_move(bfqd, bfqq);
> + bfqg_and_blkg_put(old_parent);
> +
> + if (bfq_bfqq_busy(bfqq))
> bfq_activate_bfqq(bfqd, bfqq);
> - }
>
> if (!bfqd->in_service_queue && !bfqd->rq_in_driver)
> bfq_schedule_dispatch(bfqd);
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-18 9:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-10 8:16 [PATCH RFC] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move() Yu Kuai
2021-12-18 9:09 ` yukuai (C)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®