* [PATCH v2] blk-throttle: fix throtl_data leak during disk release
@ 2025-09-17 7:55 Yu Kuai
2025-09-17 13:27 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Yu Kuai @ 2025-09-17 7:55 UTC (permalink / raw)
To: yi.zhang, tj, josef, axboe, hanguangjiang, liangjie, yukuai3
Cc: cgroups, linux-block, linux-kernel, yukuai1, yi.zhang, yangerkun,
johnny.chenyi
From: Yu Kuai <yukuai3@huawei.com>
Tightening the throttle activation check in blk_throtl_activated() to
require both q->td presence and policy bit set introduced a memory leak
during disk release:
blkg_destroy_all() clears the policy bit first during queue deactivation,
causing subsequent blk_throtl_exit() to skip throtl_data cleanup when
blk_throtl_activated() fails policy check.
Idealy we should avoid modifying blk_throtl_exit() activation check because
it's intuitive that blk-throtl start from blk_throtl_init() and end in
blk_throtl_exit(). However, call blk_throtl_exit() before
blkg_destroy_all() will make a long term deadlock problem easier to
trigger[1], hence fix this problem by checking if q->td is NULL from
blk_throtl_exit(), and remove policy deactivation as well since it's
useless.
[1] https://lore.kernel.org/all/CAHj4cs9p9H5yx+ywsb3CMUdbqGPhM+8tuBvhW=9ADiCjAqza9w@mail.gmail.com/#t
Fixes: bd9fd5be6bc0 ("blk-throttle: fix access race during throttle policy activation")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Closes: https://lore.kernel.org/all/CAHj4cs-p-ZwBEKigBj7T6hQCOo-H68-kVwCrV6ZvRovrr9Z+HA@mail.gmail.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
Changes in v2:
- fix the problem by checking q->td directly;
block/blk-throttle.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index f510ae072868..2c5b64b1a724 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1842,12 +1842,15 @@ void blk_throtl_exit(struct gendisk *disk)
{
struct request_queue *q = disk->queue;
- if (!blk_throtl_activated(q))
+ /*
+ * blkg_destroy_all() already deactivate throtl policy, just check and
+ * free throtl data.
+ */
+ if (!q->td)
return;
timer_delete_sync(&q->td->service_queue.pending_timer);
throtl_shutdown_wq(q);
- blkcg_deactivate_policy(disk, &blkcg_policy_throtl);
kfree(q->td);
}
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] blk-throttle: fix throtl_data leak during disk release
2025-09-17 7:55 [PATCH v2] blk-throttle: fix throtl_data leak during disk release Yu Kuai
@ 2025-09-17 13:27 ` Jens Axboe
0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-09-17 13:27 UTC (permalink / raw)
To: yi.zhang, tj, josef, hanguangjiang, liangjie, yukuai3, Yu Kuai
Cc: cgroups, linux-block, linux-kernel, yi.zhang, yangerkun, johnny.chenyi
On Wed, 17 Sep 2025 15:55:39 +0800, Yu Kuai wrote:
> Tightening the throttle activation check in blk_throtl_activated() to
> require both q->td presence and policy bit set introduced a memory leak
> during disk release:
>
> blkg_destroy_all() clears the policy bit first during queue deactivation,
> causing subsequent blk_throtl_exit() to skip throtl_data cleanup when
> blk_throtl_activated() fails policy check.
>
> [...]
Applied, thanks!
[1/1] blk-throttle: fix throtl_data leak during disk release
(no commit info)
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-17 13:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-17 7:55 [PATCH v2] blk-throttle: fix throtl_data leak during disk release Yu Kuai
2025-09-17 13:27 ` Jens Axboe
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®