Skip to content

Commit 0273ac3

Browse files
dennisszhouaxboe
authored andcommitted
blkcg: handle dying request_queue when associating a blkg
Between v3 [1] and v4 [2] of the blkg association series, the association point moved from generic_make_request_checks(), which is called after the request enters the queue, to bio_set_dev(), which is when the bio is formed before submit_bio(). When the request_queue goes away, the blkgs supporting the request_queue are destroyed and then the q->root_blkg is set to %NULL. This patch adds a %NULL check to blkg_tryget_closest() to prevent the NPE caused by the above. It also adds a guard to see if the request_queue is dying when creating a blkg to prevent creating a blkg for a dead request_queue. [1] https://lore.kernel.org/lkml/20180911184137.35897-1-dennisszhou@gmail.com/ [2] https://lore.kernel.org/lkml/20181126211946.77067-1-dennis@kernel.org/ Fixes: 5cdf2e3 ("blkcg: associate blkg when associating a device") Reported-and-tested-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Dennis Zhou <dennis@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 544fbd1 commit 0273ac3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

block/blk-cgroup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
202202
WARN_ON_ONCE(!rcu_read_lock_held());
203203
lockdep_assert_held(&q->queue_lock);
204204

205+
/* request_queue is dying, do not create/recreate a blkg */
206+
if (blk_queue_dying(q)) {
207+
ret = -ENODEV;
208+
goto err_free_blkg;
209+
}
210+
205211
/* blkg holds a reference to blkcg */
206212
if (!css_tryget_online(&blkcg->css)) {
207213
ret = -ENODEV;

include/linux/blk-cgroup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ static inline bool blkg_tryget(struct blkcg_gq *blkg)
511511
*/
512512
static inline struct blkcg_gq *blkg_tryget_closest(struct blkcg_gq *blkg)
513513
{
514-
while (!percpu_ref_tryget(&blkg->refcnt))
514+
while (blkg && !percpu_ref_tryget(&blkg->refcnt))
515515
blkg = blkg->parent;
516516

517517
return blkg;

0 commit comments

Comments
 (0)