From: Yu Kuai <[email protected]>

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=9adicjaqz...@mail.gmail.com/#t

Fixes: bd9fd5be6bc0 ("blk-throttle: fix access race during throttle policy 
activation")
Reported-by: Yi Zhang <[email protected]>
Closes: 
https://lore.kernel.org/all/cahj4cs-p-zwbekigbj7t6hqcoo-h68-kvwcrv6zvrovrr9z...@mail.gmail.com/
Signed-off-by: Yu Kuai <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
(cherry picked from commit 336aec7b06be860477be80a4299263a2e9355789)

https://virtuozzo.atlassian.net/browse/VSTOR-152993
Feature: fix ms/block

Signed-off-by: Denis V. Lunev <[email protected]>
---
 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 cfa1cd60d2c5..95bf175c2a13 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.53.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to