]> www.infradead.org Git - users/willy/linux.git/commit
blkcg: fix ref count issue with bio_blkcg() using task_css
authorDennis Zhou <dennis@kernel.org>
Wed, 5 Dec 2018 17:10:26 +0000 (12:10 -0500)
committerJens Axboe <axboe@kernel.dk>
Wed, 5 Dec 2018 17:19:33 +0000 (10:19 -0700)
commitab4c63c9be16f4dad7ad7c6a2221c3b0701476e9
tree6e0c3b6c0a6e47cdb0f70f8d213daa19cdf87703
parentc754a9bf7ee8fead9f66a359990a33a5c7f1161e
blkcg: fix ref count issue with bio_blkcg() using task_css

The bio_blkcg() function turns out to be inconsistent and consequently
dangerous to use. The first part returns a blkcg where a reference is
owned by the bio meaning it does not need to be rcu protected. However,
the third case, the last line, is problematic:

return css_to_blkcg(task_css(current, io_cgrp_id));

This can race against task migration and the cgroup dying. It is also
semantically different as it must be called rcu protected and is
susceptible to failure when trying to get a reference to it.

This patch adds association ahead of calling bio_blkcg() rather than
after. This makes association a required and explicit step along the
code paths for calling bio_blkcg(). In blk-iolatency, association is
moved above the bio_blkcg() call to ensure it will not return %NULL.

BFQ uses the old bio_blkcg() function, but I do not want to address it
in this series due to the complexity. I have created a private version
documenting the inconsistency and noting not to use it.

Signed-off-by: Dennis Zhou <dennis@kernel.org>
Acked-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bfq-cgroup.c
block/bfq-iosched.c
block/bio.c
block/blk-iolatency.c
include/linux/blk-cgroup.h