diff options
author | Jiufei Xue <jiufei.xjf@alibaba-inc.com> | 2017-10-09 23:13:32 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-10-10 15:09:34 -0400 |
commit | 53cfdc10a95d03fbc82970d682a32696d19ef886 (patch) | |
tree | 1cd5d88450b9e3f6b741f3552348555b64376804 /block/blk-throttle.c | |
parent | 58a9edce0aa912640abe47d3fc039e6230ef848b (diff) |
blk-throttle: fix null pointer dereference while throttling writeback IOs
A null pointer dereference can occur when blkcg is removed manually
with writeback IOs inflight. This is caused by the following case:
Writeback kworker submit the bio and set bio->bi_cg_private to tg
in blk_throtl_assoc_bio.
Then we remove the block cgroup manually, the blkg and tg would be
freed if there is no request inflight.
When the submitted bio come back, blk_throtl_bio_endio() fetch the tg
which was already freed.
Fix this by increasing the refcount of blkg in funcion
blk_throtl_assoc_bio() so that the blkg will not be freed until the
bio_endio called.
Reviewed-by: Shaohua Li <shli@fb.com>
Signed-off-by: Jiufei Xue <jiufei.xjf@alibaba-inc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-throttle.c')
-rw-r--r-- | block/blk-throttle.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 0fea76aa0f3f..fe49c465ec86 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c | |||
@@ -2112,8 +2112,12 @@ static inline void throtl_update_latency_buckets(struct throtl_data *td) | |||
2112 | static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio) | 2112 | static void blk_throtl_assoc_bio(struct throtl_grp *tg, struct bio *bio) |
2113 | { | 2113 | { |
2114 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW | 2114 | #ifdef CONFIG_BLK_DEV_THROTTLING_LOW |
2115 | if (bio->bi_css) | 2115 | if (bio->bi_css) { |
2116 | if (bio->bi_cg_private) | ||
2117 | blkg_put(tg_to_blkg(bio->bi_cg_private)); | ||
2116 | bio->bi_cg_private = tg; | 2118 | bio->bi_cg_private = tg; |
2119 | blkg_get(tg_to_blkg(tg)); | ||
2120 | } | ||
2117 | blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio)); | 2121 | blk_stat_set_issue(&bio->bi_issue_stat, bio_sectors(bio)); |
2118 | #endif | 2122 | #endif |
2119 | } | 2123 | } |
@@ -2283,8 +2287,10 @@ void blk_throtl_bio_endio(struct bio *bio) | |||
2283 | 2287 | ||
2284 | start_time = blk_stat_time(&bio->bi_issue_stat) >> 10; | 2288 | start_time = blk_stat_time(&bio->bi_issue_stat) >> 10; |
2285 | finish_time = __blk_stat_time(finish_time_ns) >> 10; | 2289 | finish_time = __blk_stat_time(finish_time_ns) >> 10; |
2286 | if (!start_time || finish_time <= start_time) | 2290 | if (!start_time || finish_time <= start_time) { |
2291 | blkg_put(tg_to_blkg(tg)); | ||
2287 | return; | 2292 | return; |
2293 | } | ||
2288 | 2294 | ||
2289 | lat = finish_time - start_time; | 2295 | lat = finish_time - start_time; |
2290 | /* this is only for bio based driver */ | 2296 | /* this is only for bio based driver */ |
@@ -2314,6 +2320,8 @@ void blk_throtl_bio_endio(struct bio *bio) | |||
2314 | tg->bio_cnt /= 2; | 2320 | tg->bio_cnt /= 2; |
2315 | tg->bad_bio_cnt /= 2; | 2321 | tg->bad_bio_cnt /= 2; |
2316 | } | 2322 | } |
2323 | |||
2324 | blkg_put(tg_to_blkg(tg)); | ||
2317 | } | 2325 | } |
2318 | #endif | 2326 | #endif |
2319 | 2327 | ||