Re: [PATCH v2] blk-cgroup: remove entries in blkg_tree before queue release

From: Tejun Heo
Date: Wed Apr 11 2018 - 10:56:41 EST


Hello, again.

On Wed, Apr 11, 2018 at 07:51:23AM -0700, Tejun Heo wrote:
> Oh, it wasn't Joseph's change. It was Bart's fix for a problem
> reported by Joseph. Bart, a063057d7c73 ("block: Fix a race between
> request queue removal and the block cgroup controller") created a
> regression where a request_queue can be destroyed with blkgs still
> attached. The original report is..
>
> http://lkml.kernel.org/r/20180407102148.GA9729@xxxxxxxxx

And looking at the change, it looks like the right thing we should
have done is caching @lock on the print_blkg side and when switching
locks make sure both locks are held. IOW, do the following in
blk_cleanup_queue()

spin_lock_irq(lock);
if (q->queue_lock != &q->__queue_lock) {
spin_lock(&q->__queue_lock);
q->queue_lock = &q->__queue_lock;
spin_unlock(&q->__queue_lock);
}
spin_unlock_irq(lock);

Otherwise, there can be two lock holders thinking they have exclusive
access to the request_queue.

Thanks.

--
tejun