From: Jan Kara <jack-AlSwsSmVLrQ@public.gmane.org>
To: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
Cc: tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org,
paolo.valente-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
jack-AlSwsSmVLrQ@public.gmane.org,
fchecconi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
avanzini.arianna-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
yi.zhang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 4/4] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move()
Date: Tue, 21 Dec 2021 12:50:01 +0100 [thread overview]
Message-ID: <20211221115001.GD24748@quack2.suse.cz> (raw)
In-Reply-To: <20211221032135.878550-5-yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
On Tue 21-12-21 11:21:35, Yu Kuai wrote:
> 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.
>
> Fixes: e21b7a0b9887 ("block, bfq: add full hierarchical scheduling and cgroups support")
> Signed-off-by: Yu Kuai <yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
I'm just wondering, how can it happen that !bfq_bfqq_busy() queue is in
pos_tree? Because bfq_remove_request() takes care to remove bfqq from the
pos_tree...
Honza
> ---
> block/bfq-cgroup.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c
> index 8e8cf6b3d946..822dd28ecf53 100644
> --- a/block/bfq-cgroup.c
> +++ b/block/bfq-cgroup.c
> @@ -677,7 +677,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(old_parent);
>
> if (entity->parent &&
> entity->parent->last_bfqq_created == bfqq)
> @@ -690,11 +689,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
>
--
Jan Kara <jack-IBi9RG/b67k@public.gmane.org>
SUSE Labs, CR
next prev parent reply other threads:[~2021-12-21 11:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-21 3:21 [PATCH 0/4] block, bfq: minor cleanup and fix Yu Kuai
[not found] ` <20211221032135.878550-1-yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-21 3:21 ` [PATCH 1/4] block, bfq: cleanup bfq_bfqq_to_bfqg() Yu Kuai
2021-12-21 10:15 ` Jan Kara
2021-12-21 3:21 ` [PATCH 2/4] block, bfq: avoid moving bfqq to it's parent bfqg Yu Kuai
[not found] ` <20211221032135.878550-3-yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-21 10:16 ` Jan Kara
2021-12-21 11:08 ` yukuai (C)
[not found] ` <d1c91a5f-33f3-ffad-e1ad-fb91482eb864-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-21 11:52 ` Jan Kara
2021-12-21 3:21 ` [PATCH 3/4] block, bfq: don't move oom_bfqq Yu Kuai
[not found] ` <20211221032135.878550-4-yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-21 10:18 ` Jan Kara
2021-12-21 3:21 ` [PATCH 4/4] block, bfq: update pos_root for idle bfq_queue in bfq_bfqq_move() Yu Kuai
[not found] ` <20211221032135.878550-5-yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-21 11:50 ` Jan Kara [this message]
[not found] ` <20211221115001.GD24748-4I4JzKEfoa/jFM9bn6wA6Q@public.gmane.org>
2021-12-22 3:12 ` yukuai (C)
[not found] ` <6ca1e924-47fa-b94e-598c-69a9549eb68e-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-22 14:17 ` Jan Kara
2021-12-23 1:03 ` yukuai (C)
2021-12-25 1:19 ` yukuai (C)
[not found] ` <9743fc5a-f3f0-a23a-5d21-0c04c90e90e1-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2021-12-25 7:44 ` yukuai (C)
2022-01-03 15:37 ` Jan Kara
2022-01-07 1:04 ` yukuai (C)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211221115001.GD24748@quack2.suse.cz \
--to=jack-alswssmvlrq@public.gmane.org \
--cc=avanzini.arianna-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=axboe-tSWWG44O7X1aa/9Udqfwiw@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=fchecconi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-block-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=paolo.valente-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=yi.zhang-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
--cc=yukuai3-hv44wF8Li93QT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox