linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] blkcg: init root blkcg_gq under lock
@ 2018-04-19  4:06 Jiang Biao
  2018-04-26 19:18 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Jiang Biao @ 2018-04-19  4:06 UTC (permalink / raw)
  To: axboe
  Cc: linux-block, linux-kernel, tj, jiang.biao2, zhong.weidong, wen.yang99

The initializing of q->root_blkg is currently outside of queue lock
and rcu, so the blkg may be destroied before the initializing, which
may cause dangling/null references. On the other side, the destroys
of blkg are protected by queue lock or rcu. Put the initializing
inside the queue lock and rcu to make it safer.

Signed-off-by: Jiang Biao <jiang.biao2@zte.com.cn>
Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
CC: Tejun Heo <tj@kernel.org>
CC: Jens Axboe <axboe@kernel.dk>
---
 block/blk-cgroup.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 07e3359..ec86837 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1138,18 +1138,16 @@ int blkcg_init_queue(struct request_queue *q)
 	rcu_read_lock();
 	spin_lock_irq(q->queue_lock);
 	blkg = blkg_create(&blkcg_root, q, new_blkg);
+	if (IS_ERR(blkg))
+		goto err_unlock;
+	q->root_blkg = blkg;
+	q->root_rl.blkg = blkg;
 	spin_unlock_irq(q->queue_lock);
 	rcu_read_unlock();
 
 	if (preloaded)
 		radix_tree_preload_end();
 
-	if (IS_ERR(blkg))
-		return PTR_ERR(blkg);
-
-	q->root_blkg = blkg;
-	q->root_rl.blkg = blkg;
-
 	ret = blk_throtl_init(q);
 	if (ret) {
 		spin_lock_irq(q->queue_lock);
@@ -1157,6 +1155,13 @@ int blkcg_init_queue(struct request_queue *q)
 		spin_unlock_irq(q->queue_lock);
 	}
 	return ret;
+
+err_unlock:
+	spin_unlock_irq(q->queue_lock);
+	rcu_read_unlock();
+	if (preloaded)
+		radix_tree_preload_end();
+	return PTR_ERR(blkg);
 }
 
 /**
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/2] blkcg: init root blkcg_gq under lock
  2018-04-19  4:06 [PATCH 2/2] blkcg: init root blkcg_gq under lock Jiang Biao
@ 2018-04-26 19:18 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2018-04-26 19:18 UTC (permalink / raw)
  To: Jiang Biao; +Cc: axboe, linux-block, linux-kernel, zhong.weidong, wen.yang99

Hello,

On Thu, Apr 19, 2018 at 12:06:09PM +0800, Jiang Biao wrote:
> The initializing of q->root_blkg is currently outside of queue lock
> and rcu, so the blkg may be destroied before the initializing, which
> may cause dangling/null references. On the other side, the destroys
> of blkg are protected by queue lock or rcu. Put the initializing
> inside the queue lock and rcu to make it safer.

Hmm... I can't think of a scenario where the above could happen.  The
queue is still being initialized and no one else has access to it, so
I can't see how it could be destroyed.  Can you please describe the
sequence of events?  Have you actually observed this happening?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-26 19:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-19  4:06 [PATCH 2/2] blkcg: init root blkcg_gq under lock Jiang Biao
2018-04-26 19:18 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).