All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
@ 2018-04-12  1:58 Bart Van Assche
  2018-04-12  4:20 ` Alexandru Moise
                   ` (3 more replies)
  0 siblings, 4 replies; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12  1:58 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Bart Van Assche, Alexandru Moise,
	Tejun Heo

Several block drivers call alloc_disk() followed by put_disk() if
something fails before device_add_disk() is called without calling
blk_cleanup_queue(). Make sure that also for this scenario a request
queue is dissociated from the cgroup controller. This patch avoids
that loading the parport_pc, paride and pf drivers triggers the
following kernel crash:

BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
Read of size 4 at addr 0000000000000008 by task modprobe/744
Call Trace:
dump_stack+0x9a/0xeb
kasan_report+0x139/0x350
pi_init+0x42e/0x580 [paride]
pf_init+0x2bb/0x1000 [pf]
do_one_initcall+0x8e/0x405
do_init_module+0xd9/0x2f2
load_module+0x3ab4/0x4700
SYSC_finit_module+0x176/0x1a0
do_syscall_64+0xee/0x2b0
entry_SYSCALL_64_after_hwframe+0x42/0xb7

Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Alexandru Moise <00moses.alexander00@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
---
 block/blk-sysfs.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index f8457d6f0190..2e134da78f82 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -788,11 +788,37 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head)
 static void __blk_release_queue(struct work_struct *work)
 {
 	struct request_queue *q = container_of(work, typeof(*q), release_work);
+	struct blkcg_gq *gq;
 
 	if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags))
 		blk_stat_remove_callback(q, q->poll_cb);
 	blk_stat_free_callback(q->poll_cb);
 
+	if (!blk_queue_dead(q)) {
+		/*
+		 * Last reference was dropped without having called
+		 * blk_cleanup_queue().
+		 */
+		WARN_ONCE(blk_queue_init_done(q),
+			  "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n",
+			  q);
+		bdi_put(q->backing_dev_info);
+		blkcg_exit_queue(q);
+
+		if (q->elevator) {
+			ioc_clear_queue(q);
+			elevator_exit(q, q->elevator);
+		}
+	}
+
+	rcu_read_lock();
+	gq = blkg_lookup(&blkcg_root, q);
+	rcu_read_unlock();
+
+	WARN(gq,
+	     "request queue %p is being released but it has not yet been removed from the blkcg controller\n",
+	     q);
+
 	blk_free_queue_stats(q->stats);
 
 	blk_exit_rl(q, &q->root_rl);
-- 
2.16.2

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  1:58 [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Bart Van Assche
@ 2018-04-12  4:20 ` Alexandru Moise
  2018-04-12  4:32   ` Alexandru Moise
  2018-04-12  4:22 ` Alexandru Moise
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 22+ messages in thread
From: Alexandru Moise @ 2018-04-12  4:20 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Tejun Heo

On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> Several block drivers call alloc_disk() followed by put_disk() if
> something fails before device_add_disk() is called without calling
> blk_cleanup_queue(). Make sure that also for this scenario a request
> queue is dissociated from the cgroup controller. This patch avoids
> that loading the parport_pc, paride and pf drivers triggers the
> following kernel crash:
> 
> BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
> Read of size 4 at addr 0000000000000008 by task modprobe/744
> Call Trace:
> dump_stack+0x9a/0xeb
> kasan_report+0x139/0x350
> pi_init+0x42e/0x580 [paride]
> pf_init+0x2bb/0x1000 [pf]
> do_one_initcall+0x8e/0x405
> do_init_module+0xd9/0x2f2
> load_module+0x3ab4/0x4700
> SYSC_finit_module+0x176/0x1a0
> do_syscall_64+0xee/0x2b0
> entry_SYSCALL_64_after_hwframe+0x42/0xb7
> 
> Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Alexandru Moise <00moses.alexander00@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>
> ---
>  block/blk-sysfs.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index f8457d6f0190..2e134da78f82 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -788,11 +788,37 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head)
>  static void __blk_release_queue(struct work_struct *work)
>  {
>  	struct request_queue *q = container_of(work, typeof(*q), release_work);
> +	struct blkcg_gq *gq;
>  
>  	if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags))
>  		blk_stat_remove_callback(q, q->poll_cb);
>  	blk_stat_free_callback(q->poll_cb);
>  
> +	if (!blk_queue_dead(q)) {
> +		/*
> +		 * Last reference was dropped without having called
> +		 * blk_cleanup_queue().
> +		 */
> +		WARN_ONCE(blk_queue_init_done(q),
> +			  "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n",
> +			  q);
> +		bdi_put(q->backing_dev_info);
> +		blkcg_exit_queue(q);
> +
> +		if (q->elevator) {
> +			ioc_clear_queue(q);
> +			elevator_exit(q, q->elevator);
> +		}
> +	}
> +
> +	rcu_read_lock();
> +	gq = blkg_lookup(&blkcg_root, q);
> +	rcu_read_unlock();
> +
> +	WARN(gq,
> +	     "request queue %p is being released but it has not yet been removed from the blkcg controller\n",
> +	     q);
> +
>  	blk_free_queue_stats(q->stats);

This solution is good. Thanks for fixing this!

Tested-by: Alexandru Moise <00moses.alexander00@gmail.com>

../Alex

>  
>  	blk_exit_rl(q, &q->root_rl);
> -- 
> 2.16.2
> 

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  1:58 [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Bart Van Assche
  2018-04-12  4:20 ` Alexandru Moise
@ 2018-04-12  4:22 ` Alexandru Moise
  2018-04-12  5:34 ` Christoph Hellwig
  2018-04-12 13:51 ` Tejun Heo
  3 siblings, 0 replies; 22+ messages in thread
From: Alexandru Moise @ 2018-04-12  4:22 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Tejun Heo

On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> Several block drivers call alloc_disk() followed by put_disk() if
> something fails before device_add_disk() is called without calling
> blk_cleanup_queue(). Make sure that also for this scenario a request
> queue is dissociated from the cgroup controller. This patch avoids
> that loading the parport_pc, paride and pf drivers triggers the
> following kernel crash:
> 
> BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
> Read of size 4 at addr 0000000000000008 by task modprobe/744
> Call Trace:
> dump_stack+0x9a/0xeb
> kasan_report+0x139/0x350
> pi_init+0x42e/0x580 [paride]
> pf_init+0x2bb/0x1000 [pf]
> do_one_initcall+0x8e/0x405
> do_init_module+0xd9/0x2f2
> load_module+0x3ab4/0x4700
> SYSC_finit_module+0x176/0x1a0
> do_syscall_64+0xee/0x2b0
> entry_SYSCALL_64_after_hwframe+0x42/0xb7
> 
> Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Alexandru Moise <00moses.alexander00@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>
> ---
>  block/blk-sysfs.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index f8457d6f0190..2e134da78f82 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -788,11 +788,37 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head)
>  static void __blk_release_queue(struct work_struct *work)
>  {
>  	struct request_queue *q = container_of(work, typeof(*q), release_work);
> +	struct blkcg_gq *gq;
>  
>  	if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags))
>  		blk_stat_remove_callback(q, q->poll_cb);
>  	blk_stat_free_callback(q->poll_cb);
>  
> +	if (!blk_queue_dead(q)) {
> +		/*
> +		 * Last reference was dropped without having called
> +		 * blk_cleanup_queue().
> +		 */
> +		WARN_ONCE(blk_queue_init_done(q),
> +			  "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n",
> +			  q);
> +		bdi_put(q->backing_dev_info);
> +		blkcg_exit_queue(q);
> +
> +		if (q->elevator) {
> +			ioc_clear_queue(q);
> +			elevator_exit(q, q->elevator);
> +		}
> +	}
> +
> +	rcu_read_lock();
> +	gq = blkg_lookup(&blkcg_root, q);
> +	rcu_read_unlock();
> +
> +	WARN(gq,
> +	     "request queue %p is being released but it has not yet been removed from the blkcg controller\n",
> +	     q);
> +
>  	blk_free_queue_stats(q->stats);

This solution is good. Thanks for fixing this!

Tested-by: Alexandru Moise <00moses.alexander00@gmail.com>

../Alex

>  
>  	blk_exit_rl(q, &q->root_rl);
> -- 
> 2.16.2
> 

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  4:20 ` Alexandru Moise
@ 2018-04-12  4:32   ` Alexandru Moise
  0 siblings, 0 replies; 22+ messages in thread
From: Alexandru Moise @ 2018-04-12  4:32 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Tejun Heo

On Thu, Apr 12, 2018 at 06:20:34AM +0200, Alexandru Moise wrote:
> On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> > Several block drivers call alloc_disk() followed by put_disk() if
> > something fails before device_add_disk() is called without calling
> > blk_cleanup_queue(). Make sure that also for this scenario a request
> > queue is dissociated from the cgroup controller. This patch avoids
> > that loading the parport_pc, paride and pf drivers triggers the
> > following kernel crash:
> > 
> > BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
> > Read of size 4 at addr 0000000000000008 by task modprobe/744
> > Call Trace:
> > dump_stack+0x9a/0xeb
> > kasan_report+0x139/0x350
> > pi_init+0x42e/0x580 [paride]
> > pf_init+0x2bb/0x1000 [pf]
> > do_one_initcall+0x8e/0x405
> > do_init_module+0xd9/0x2f2
> > load_module+0x3ab4/0x4700
> > SYSC_finit_module+0x176/0x1a0
> > do_syscall_64+0xee/0x2b0
> > entry_SYSCALL_64_after_hwframe+0x42/0xb7
> > 
> > Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
> > Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
> > Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> > Cc: Alexandru Moise <00moses.alexander00@gmail.com>
> > Cc: Tejun Heo <tj@kernel.org>
> > ---
> >  block/blk-sysfs.c | 26 ++++++++++++++++++++++++++
> >  1 file changed, 26 insertions(+)
> > 
> > diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> > index f8457d6f0190..2e134da78f82 100644
> > --- a/block/blk-sysfs.c
> > +++ b/block/blk-sysfs.c
> > @@ -788,11 +788,37 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head)
> >  static void __blk_release_queue(struct work_struct *work)
> >  {
> >  	struct request_queue *q = container_of(work, typeof(*q), release_work);
> > +	struct blkcg_gq *gq;
> >  
> >  	if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags))
> >  		blk_stat_remove_callback(q, q->poll_cb);
> >  	blk_stat_free_callback(q->poll_cb);
> >  
> > +	if (!blk_queue_dead(q)) {
> > +		/*
> > +		 * Last reference was dropped without having called
> > +		 * blk_cleanup_queue().
> > +		 */
> > +		WARN_ONCE(blk_queue_init_done(q),
> > +			  "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n",
> > +			  q);
> > +		bdi_put(q->backing_dev_info);
> > +		blkcg_exit_queue(q);
> > +
> > +		if (q->elevator) {
> > +			ioc_clear_queue(q);
> > +			elevator_exit(q, q->elevator);
> > +		}
> > +	}
> > +
> > +	rcu_read_lock();
> > +	gq = blkg_lookup(&blkcg_root, q);
> > +	rcu_read_unlock();
> > +
> > +	WARN(gq,
> > +	     "request queue %p is being released but it has not yet been removed from the blkcg controller\n",
> > +	     q);
> > +
> >  	blk_free_queue_stats(q->stats);
> 
> This solution is good. Thanks for fixing this!
> 
> Tested-by: Alexandru Moise <00moses.alexander00@gmail.com>
> 
> ../Alex

Oh, you also need the no-ops for !CONFIG_BLK_CGROUP, also there is no
blkcg_root then as well.

Thanks,
../Alex
> 
> >  
> >  	blk_exit_rl(q, &q->root_rl);
> > -- 
> > 2.16.2
> > 

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  1:58 [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Bart Van Assche
  2018-04-12  4:20 ` Alexandru Moise
  2018-04-12  4:22 ` Alexandru Moise
@ 2018-04-12  5:34 ` Christoph Hellwig
  2018-04-12 11:52   ` Bart Van Assche
  2018-04-12 13:51 ` Tejun Heo
  3 siblings, 1 reply; 22+ messages in thread
From: Christoph Hellwig @ 2018-04-12  5:34 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Alexandru Moise, Tejun Heo

On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> Several block drivers call alloc_disk() followed by put_disk() if
> something fails before device_add_disk() is called without calling
> blk_cleanup_queue(). Make sure that also for this scenario a request
> queue is dissociated from the cgroup controller. This patch avoids
> that loading the parport_pc, paride and pf drivers triggers the
> following kernel crash:

Can we move the cleanup to put_disk in general and not just for
this case?  Having alloc/free routines pair up generally avoids
a lot of confusion.

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  5:34 ` Christoph Hellwig
@ 2018-04-12 11:52   ` Bart Van Assche
  2018-04-12 13:14     ` hch
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 11:52 UTC (permalink / raw)
  To: hch; +Cc: tj, linux-block, 00moses.alexander00, axboe

T24gVGh1LCAyMDE4LTA0LTEyIGF0IDA3OjM0ICswMjAwLCBDaHJpc3RvcGggSGVsbHdpZyB3cm90
ZToNCj4gT24gV2VkLCBBcHIgMTEsIDIwMTggYXQgMDc6NTg6NTJQTSAtMDYwMCwgQmFydCBWYW4g
QXNzY2hlIHdyb3RlOg0KPiA+IFNldmVyYWwgYmxvY2sgZHJpdmVycyBjYWxsIGFsbG9jX2Rpc2so
KSBmb2xsb3dlZCBieSBwdXRfZGlzaygpIGlmDQo+ID4gc29tZXRoaW5nIGZhaWxzIGJlZm9yZSBk
ZXZpY2VfYWRkX2Rpc2soKSBpcyBjYWxsZWQgd2l0aG91dCBjYWxsaW5nDQo+ID4gYmxrX2NsZWFu
dXBfcXVldWUoKS4gTWFrZSBzdXJlIHRoYXQgYWxzbyBmb3IgdGhpcyBzY2VuYXJpbyBhIHJlcXVl
c3QNCj4gPiBxdWV1ZSBpcyBkaXNzb2NpYXRlZCBmcm9tIHRoZSBjZ3JvdXAgY29udHJvbGxlci4g
VGhpcyBwYXRjaCBhdm9pZHMNCj4gPiB0aGF0IGxvYWRpbmcgdGhlIHBhcnBvcnRfcGMsIHBhcmlk
ZSBhbmQgcGYgZHJpdmVycyB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kX2Rp
c2soKQ0KaGFzIG5vdCBiZWVuIGNhbGxlZCB0byBhdm9pZCB0aGF0IHB1dF9kaXNrKCkgY2F1c2Vz
IGEgcmVxdWVzdCBxdWV1ZQ0KcmVmZXJlbmNlIGNvdW50IGltYmFsYW5jZS4NCg0KQmFydC4NCg0K
DQoNCg==

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 11:52   ` Bart Van Assche
@ 2018-04-12 13:14     ` hch
  2018-04-12 13:48       ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: hch @ 2018-04-12 13:14 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: hch, tj, linux-block, 00moses.alexander00, axboe

On Thu, Apr 12, 2018 at 11:52:11AM +0000, Bart Van Assche wrote:
> On Thu, 2018-04-12 at 07:34 +0200, Christoph Hellwig wrote:
> > On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> > > Several block drivers call alloc_disk() followed by put_disk() if
> > > something fails before device_add_disk() is called without calling
> > > blk_cleanup_queue(). Make sure that also for this scenario a request
> > > queue is dissociated from the cgroup controller. This patch avoids
> > > that loading the parport_pc, paride and pf drivers triggers the
> > > following kernel crash:
> > 
> > Can we move the cleanup to put_disk in general and not just for
> > this case?  Having alloc/free routines pair up generally avoids
> > a lot of confusion.
> 
> Hello Christoph,
> 
> At least the SCSI ULP drivers drop the last reference to a disk after
> the blk_cleanup_queue() call. As explained in the description of commit
> a063057d7c73, removing a request queue from blkcg must happen before
> blk_cleanup_queue() finishes because a block driver may free the
> request queue spinlock immediately after blk_cleanup_queue() returns.
> So I don't think that we can move the code that removes a request
> queue from blkcg into put_disk(). Another challenge is that some block
> drivers (e.g. skd) clear the disk->queue pointer if device_add_disk()
> has not been called to avoid that put_disk() causes a request queue
> reference count imbalance.

Which sounds like a very good reason not to use a driver controller
lock for internals like blkcq.

In fact splitting the lock used for synchronizing access to queue
fields from the driver controller lock used to synchronize I/O
in the legacy path in long overdue.

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 13:14     ` hch
@ 2018-04-12 13:48       ` tj
  2018-04-12 13:56         ` hch
  0 siblings, 1 reply; 22+ messages in thread
From: tj @ 2018-04-12 13:48 UTC (permalink / raw)
  To: hch; +Cc: Bart Van Assche, linux-block, 00moses.alexander00, axboe

Hello,

On Thu, Apr 12, 2018 at 03:14:40PM +0200, hch@lst.de wrote:
> > At least the SCSI ULP drivers drop the last reference to a disk after
> > the blk_cleanup_queue() call. As explained in the description of commit
> > a063057d7c73, removing a request queue from blkcg must happen before
> > blk_cleanup_queue() finishes because a block driver may free the
> > request queue spinlock immediately after blk_cleanup_queue() returns.
> > So I don't think that we can move the code that removes a request
> > queue from blkcg into put_disk(). Another challenge is that some block
> > drivers (e.g. skd) clear the disk->queue pointer if device_add_disk()
> > has not been called to avoid that put_disk() causes a request queue
> > reference count imbalance.
> 
> Which sounds like a very good reason not to use a driver controller
> lock for internals like blkcq.
> 
> In fact splitting the lock used for synchronizing access to queue
> fields from the driver controller lock used to synchronize I/O
> in the legacy path in long overdue.

It'd be probably a lot easier to make sure the shared lock doesn't go
away till all the request_queues using it go away.  The choice is
between refcnting something which carries the lock and double locking
in hot paths.  Can't think of many downsides of the former approach.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12  1:58 [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Bart Van Assche
                   ` (2 preceding siblings ...)
  2018-04-12  5:34 ` Christoph Hellwig
@ 2018-04-12 13:51 ` Tejun Heo
  2018-04-12 14:09   ` Bart Van Assche
  3 siblings, 1 reply; 22+ messages in thread
From: Tejun Heo @ 2018-04-12 13:51 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Alexandru Moise

On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
> Several block drivers call alloc_disk() followed by put_disk() if
> something fails before device_add_disk() is called without calling
> blk_cleanup_queue(). Make sure that also for this scenario a request
> queue is dissociated from the cgroup controller. This patch avoids
> that loading the parport_pc, paride and pf drivers triggers the
> following kernel crash:
> 
> BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
> Read of size 4 at addr 0000000000000008 by task modprobe/744
> Call Trace:
> dump_stack+0x9a/0xeb
> kasan_report+0x139/0x350
> pi_init+0x42e/0x580 [paride]
> pf_init+0x2bb/0x1000 [pf]
> do_one_initcall+0x8e/0x405
> do_init_module+0xd9/0x2f2
> load_module+0x3ab4/0x4700
> SYSC_finit_module+0x176/0x1a0
> do_syscall_64+0xee/0x2b0
> entry_SYSCALL_64_after_hwframe+0x42/0xb7
> 
> Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Alexandru Moise <00moses.alexander00@gmail.com>
> Cc: Tejun Heo <tj@kernel.org>

So, this might be correct for this reported case but I don't think
it's correct in general.  There's no synchronization between blkcg
q->lock usages and blk_cleanup_queue().  e.g. hotunplugging and
shutting down a device while file operations are still in progress can
easily blow this up.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 13:48       ` tj
@ 2018-04-12 13:56         ` hch
  2018-04-12 13:58           ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: hch @ 2018-04-12 13:56 UTC (permalink / raw)
  To: tj; +Cc: hch, Bart Van Assche, linux-block, 00moses.alexander00, axboe

On Thu, Apr 12, 2018 at 06:48:12AM -0700, tj@kernel.org wrote:
> > Which sounds like a very good reason not to use a driver controller
> > lock for internals like blkcq.
> > 
> > In fact splitting the lock used for synchronizing access to queue
> > fields from the driver controller lock used to synchronize I/O
> > in the legacy path in long overdue.
> 
> It'd be probably a lot easier to make sure the shared lock doesn't go
> away till all the request_queues using it go away.  The choice is
> between refcnting something which carries the lock and double locking
> in hot paths.  Can't think of many downsides of the former approach.

We've stopped sharing request_queues between different devices a while
ago.  The problem is just that for legacy devices the driver still controls
the lock life time, and it might be shorter than the queue lifetime.
Note that for blk-mq we basically don't use the queue_lock at all,
and certainly not in the hot path.

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 13:56         ` hch
@ 2018-04-12 13:58           ` tj
  2018-04-12 14:07             ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: tj @ 2018-04-12 13:58 UTC (permalink / raw)
  To: hch; +Cc: Bart Van Assche, linux-block, 00moses.alexander00, axboe

Hello,

On Thu, Apr 12, 2018 at 03:56:51PM +0200, hch@lst.de wrote:
> On Thu, Apr 12, 2018 at 06:48:12AM -0700, tj@kernel.org wrote:
> > > Which sounds like a very good reason not to use a driver controller
> > > lock for internals like blkcq.
> > > 
> > > In fact splitting the lock used for synchronizing access to queue
> > > fields from the driver controller lock used to synchronize I/O
> > > in the legacy path in long overdue.
> > 
> > It'd be probably a lot easier to make sure the shared lock doesn't go
> > away till all the request_queues using it go away.  The choice is
> > between refcnting something which carries the lock and double locking
> > in hot paths.  Can't think of many downsides of the former approach.
> 
> We've stopped sharing request_queues between different devices a while
> ago.  The problem is just that for legacy devices the driver still controls
> the lock life time, and it might be shorter than the queue lifetime.
> Note that for blk-mq we basically don't use the queue_lock at all,
> and certainly not in the hot path.

Cool, can we just factor out the queue lock from those drivers?  It's
just really messy to be switching locks like we do in the cleanup
path.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 13:58           ` tj
@ 2018-04-12 14:07             ` tj
  0 siblings, 0 replies; 22+ messages in thread
From: tj @ 2018-04-12 14:07 UTC (permalink / raw)
  To: hch; +Cc: Bart Van Assche, linux-block, 00moses.alexander00, axboe

On Thu, Apr 12, 2018 at 06:58:21AM -0700, tj@kernel.org wrote:
> Cool, can we just factor out the queue lock from those drivers?  It's
> just really messy to be switching locks like we do in the cleanup
> path.

So, looking at a couple drivers, it looks like all we'd need is a
struct which contains a spinlock and a refcnt.  Switching the drivers
to use that is a bit tedious but straight-forward and the block layer
can simply put that struct on queue release.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 13:51 ` Tejun Heo
@ 2018-04-12 14:09   ` Bart Van Assche
  2018-04-12 15:37     ` Tejun Heo
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 14:09 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Jens Axboe, linux-block, Christoph Hellwig, Alexandru Moise

On 04/12/18 07:51, Tejun Heo wrote:
> On Wed, Apr 11, 2018 at 07:58:52PM -0600, Bart Van Assche wrote:
>> Several block drivers call alloc_disk() followed by put_disk() if
>> something fails before device_add_disk() is called without calling
>> blk_cleanup_queue(). Make sure that also for this scenario a request
>> queue is dissociated from the cgroup controller. This patch avoids
>> that loading the parport_pc, paride and pf drivers triggers the
>> following kernel crash:
>>
>> BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride]
>> Read of size 4 at addr 0000000000000008 by task modprobe/744
>> Call Trace:
>> dump_stack+0x9a/0xeb
>> kasan_report+0x139/0x350
>> pi_init+0x42e/0x580 [paride]
>> pf_init+0x2bb/0x1000 [pf]
>> do_one_initcall+0x8e/0x405
>> do_init_module+0xd9/0x2f2
>> load_module+0x3ab4/0x4700
>> SYSC_finit_module+0x176/0x1a0
>> do_syscall_64+0xee/0x2b0
>> entry_SYSCALL_64_after_hwframe+0x42/0xb7
>>
>> Reported-by: Alexandru Moise <00moses.alexander00@gmail.com>
>> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller")
>> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
>> Cc: Alexandru Moise <00moses.alexander00@gmail.com>
>> Cc: Tejun Heo <tj@kernel.org>
> 
> So, this might be correct for this reported case but I don't think
> it's correct in general.  There's no synchronization between blkcg
> q->lock usages and blk_cleanup_queue().  e.g. hotunplugging and
> shutting down a device while file operations are still in progress can
> easily blow this up.

Hello Tejun,

I have retested hotunplugging by rerunning the srp-test software. It 
seems like you overlooked that this patch does not remove the 
blkcg_exit_queue() call from blk_cleanup_queue()? If a device is 
hotunplugged it is up to the block driver to call blk_cleanup_queue(). 
And blk_cleanup_queue() will call blkcg_exit_queue().

Bart.

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 14:09   ` Bart Van Assche
@ 2018-04-12 15:37     ` Tejun Heo
  2018-04-12 16:03       ` Bart Van Assche
  0 siblings, 1 reply; 22+ messages in thread
From: Tejun Heo @ 2018-04-12 15:37 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Alexandru Moise

Hello, Bart.

On Thu, Apr 12, 2018 at 08:09:17AM -0600, Bart Van Assche wrote:
> I have retested hotunplugging by rerunning the srp-test software. It
> seems like you overlooked that this patch does not remove the
> blkcg_exit_queue() call from blk_cleanup_queue()? If a device is
> hotunplugged it is up to the block driver to call
> blk_cleanup_queue(). And blk_cleanup_queue() will call
> blkcg_exit_queue().

Hmm... what'd prevent blg_lookup_and_create() racing against that?

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 15:37     ` Tejun Heo
@ 2018-04-12 16:03       ` Bart Van Assche
  2018-04-12 16:12         ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 16:03 UTC (permalink / raw)
  To: tj; +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dGVkIG9uIHRoZSBsaW51eC1ibG9jayBtYWlsaW5nDQpsaXN0IHJlY2VudGx5
IHRoYXQgc3Vycm91bmRzIHRoYXQgY2FsbCB3aXRoIGJsa19xdWV1ZV9lbnRlcigpIC8gYmxrX3F1
ZXVlX2V4aXQoKS4NCkkgdGhpbmsgdGhhdCBwcmV2ZW50cyB0aGF0IGJsa2NnX2V4aXRfcXVldWUo
KSBpcyBjYWxsZWQgY29uY3VycmVudGx5IHdpdGgNCmJsa2dfbG9va3VwX2NyZWF0ZSgpLg0KDQpC
YXJ0Lg0KDQoNCg0K

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 16:03       ` Bart Van Assche
@ 2018-04-12 16:12         ` tj
  2018-04-12 16:29           ` Bart Van Assche
  0 siblings, 1 reply; 22+ messages in thread
From: tj @ 2018-04-12 16:12 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: hch, linux-block, 00moses.alexander00, axboe

Hello,

On Thu, Apr 12, 2018 at 04:03:52PM +0000, Bart Van Assche wrote:
> On Thu, 2018-04-12 at 08:37 -0700, Tejun Heo wrote:
> > On Thu, Apr 12, 2018 at 08:09:17AM -0600, Bart Van Assche wrote:
> > > I have retested hotunplugging by rerunning the srp-test software. It
> > > seems like you overlooked that this patch does not remove the
> > > blkcg_exit_queue() call from blk_cleanup_queue()? If a device is
> > > hotunplugged it is up to the block driver to call
> > > blk_cleanup_queue(). And blk_cleanup_queue() will call
> > > blkcg_exit_queue().
> > 
> > Hmm... what'd prevent blg_lookup_and_create() racing against that?
> 
> Hello Tejun,
> 
> Did you perhaps mean blkg_lookup_create()? That function has one caller,

Ah yeah, sorry about the sloppiness.

> namely blkcg_bio_issue_check(). The only caller of that function is
> generic_make_request_checks(). A patch was posted on the linux-block mailing
> list recently that surrounds that call with blk_queue_enter() / blk_queue_exit().
> I think that prevents that blkcg_exit_queue() is called concurrently with
> blkg_lookup_create().

Yeah, that'd solve the problem for that particular path, but what
that's doing is adding another layer of refcnting which is used to
implement the revoke (or sever) semantics.  This is a fragile approach
tho because it isn't clear who's protecting what and there's nothing
in blkg's usage which suggests it'd be protected that way and we're
basically working around a different underlying problem (lock
switching) by expanding the coverage of a different lock.

I'd much prefer fixing the lock switching problem properly than
working around that shortcoming this way.

Thans.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 16:12         ` tj
@ 2018-04-12 16:29           ` Bart Van Assche
  2018-04-12 18:11             ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 16:29 UTC (permalink / raw)
  To: tj; +Cc: hch, linux-block, 00moses.alexander00, axboe

T24gVGh1LCAyMDE4LTA0LTEyIGF0IDA5OjEyIC0wNzAwLCB0akBrZXJuZWwub3JnIHdyb3RlOg0K
PiA+IERpZCB5b3UgcGVyaGFwcyBtZWFuIGJsa2dfbG9va3VwX2NyZWF0ZSgpPyBUaGF0IGZ1bmN0
aW9uIGhhcyBvbmUgY2FsbGVyLA0KPiA+IG5hbWVseSBibGtjZ19iaW9faXNzdWVfY2hlY2soKS4g
VGhlIG9ubHkgY2FsbGVyIG9mIHRoYXQgZnVuY3Rpb24gaXMNCj4gPiBnZW5lcmljX21ha2VfcmVx
dWVzdF9jaGVja3MoKS4gQSBwYXRjaCB3YXMgcG9zdGVkIG9uIHRoZSBsaW51eC1ibG9jayBtYWls
aW5nDQo+ID4gbGlzdCByZWNlbnRseSB0aGF0IHN1cnJvdW5kcyB0aGF0IGNhbGwgd2l0aCBibGtf
cXVldWVfZW50ZXIoKSAvIGJsa19xdWV1ZV9leGl0KCkuDQo+ID4gSSB0aGluayB0aGF0IHByZXZl
bnRzIHRoYXQgYmxrY2dfZXhpdF9xdWV1ZSgpIGlzIGNhbGxlZCBjb25jdXJyZW50bHkgd2l0aA0K
PiA+IGJsa2dfbG9va3VwX2NyZWF0ZSgpLg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5lbC5vcmcvcHViL3NjbS9saW51eC9rZXJuZWwvZ2l0L2F4Ym9lL2xpbnV4LWJsb2NrLmdpdC9j
b21taXQvP2g9Zm9yLWxpbnVzJmlkPTM3Zjk1NzlmNGMzMWE2ZDY5OGRiZjMwMTZkN2JmMTMyZjky
ODhkMzANCg0KVGhhbmtzLA0KDQpCYXJ0Lg0KDQoNCg==

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 16:29           ` Bart Van Assche
@ 2018-04-12 18:11             ` tj
  2018-04-12 18:56               ` Bart Van Assche
  0 siblings, 1 reply; 22+ messages in thread
From: tj @ 2018-04-12 18:11 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: hch, linux-block, 00moses.alexander00, axboe

Hello,

On Thu, Apr 12, 2018 at 04:29:09PM +0000, Bart Van Assche wrote:
> Any code that submits a bio or request needs blk_queue_enter() /
> blk_queue_exit() anyway. Please have a look at the following commit - you will
> see that that commit reduces the number of blk_queue_enter() / blk_queue_exit()
> calls in the hot path:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git/commit/?h=for-linus&id=37f9579f4c31a6d698dbf3016d7bf132f9288d30

So, this can work, but it's still pretty fragile.

* Lock switching is fragile and we really should get rid of it.  This
  is very likely to come back and bite us.

* Right now, blk_queue_enter/exit() doesn't have any annotations.
  IOW, there's no way for paths which need enter locked to actually
  assert that.  If we're gonna protect more things with queue
  enter/exit, it gotta be annotated.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 18:11             ` tj
@ 2018-04-12 18:56               ` Bart Van Assche
  2018-04-12 19:09                 ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 18:56 UTC (permalink / raw)
  To: tj; +Cc: hch, linux-block, 00moses.alexander00, axboe

T24gVGh1LCAyMDE4LTA0LTEyIGF0IDExOjExIC0wNzAwLCB0akBrZXJuZWwub3JnIHdyb3RlOg0K
PiAqIFJpZ2h0IG5vdywgYmxrX3F1ZXVlX2VudGVyL2V4aXQoKSBkb2Vzbid0IGhhdmUgYW55IGFu
bm90YXRpb25zLg0KPiAgIElPVywgdGhlcmUncyBubyB3YXkgZm9yIHBhdGhzIHdoaWNoIG5lZWQg
ZW50ZXIgbG9ja2VkIHRvIGFjdHVhbGx5DQo+ICAgYXNzZXJ0IHRoYXQuICBJZiB3ZSdyZSBnb25u
YSBwcm90ZWN0IG1vcmUgdGhpbmdzIHdpdGggcXVldWUNCj4gICBlbnRlci9leGl0LCBpdCBnb3R0
YSBiZSBhbm5vdGF0ZWQuDQoNCkhlbGxvIFRlanVuLA0KDQpPbmUgcG9zc2liaWxpdHkgaXMgdG8g
Y2hlY2sgdGhlIGNvdW50IGZvciB0aGUgbG9jYWwgQ1BVIG9mIHEtPnFfdXNhZ2VfY291bnRlcg0K
YXQgcnVudGltZSwgZS5nLiB1c2luZyBXQVJOX09OX09OQ0UoKS4gSG93ZXZlciwgdGhhdCBtaWdo
dCBoYXZlIGEgcnVudGltZQ0Kb3ZlcmhlYWQuIEFub3RoZXIgcG9zc2liaWxpdHkgaXMgdG8gZm9s
bG93IHRoZSBleGFtcGxlIG9mIGtlcm5mcyBhbmQgdG8gdXNlDQphIGxvY2tkZXAgbWFwIGFuZCBs
b2NrZGVwX2Fzc2VydF9oZWxkKCkuIFRoZXJlIG1pZ2h0IGJlIG90aGVyIGFsdGVybmF0aXZlcyBJ
DQpoYXZlIG5vdCB0aG91Z2h0IG9mLg0KDQpCYXJ0Lg0KDQoNCg0K

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 18:56               ` Bart Van Assche
@ 2018-04-12 19:09                 ` tj
  2018-04-12 22:40                   ` Bart Van Assche
  0 siblings, 1 reply; 22+ messages in thread
From: tj @ 2018-04-12 19:09 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: hch, linux-block, 00moses.alexander00, axboe

Hello,

On Thu, Apr 12, 2018 at 06:56:26PM +0000, Bart Van Assche wrote:
> On Thu, 2018-04-12 at 11:11 -0700, tj@kernel.org wrote:
> > * Right now, blk_queue_enter/exit() doesn't have any annotations.
> >   IOW, there's no way for paths which need enter locked to actually
> >   assert that.  If we're gonna protect more things with queue
> >   enter/exit, it gotta be annotated.
> 
> Hello Tejun,
> 
> One possibility is to check the count for the local CPU of q->q_usage_counter
> at runtime, e.g. using WARN_ON_ONCE(). However, that might have a runtime
> overhead. Another possibility is to follow the example of kernfs and to use
> a lockdep map and lockdep_assert_held(). There might be other alternatives I
> have not thought of.

Oh, I'd just do straight-forward lockdep annotation on
queue_enter/exit functions and provide the necessary assert helpers.

Thanks.

-- 
tejun

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 19:09                 ` tj
@ 2018-04-12 22:40                   ` Bart Van Assche
  2018-04-13 15:18                     ` tj
  0 siblings, 1 reply; 22+ messages in thread
From: Bart Van Assche @ 2018-04-12 22:40 UTC (permalink / raw)
  To: tj; +Cc: hch, linux-block, 00moses.alexander00, axboe

T24gVGh1LCAyMDE4LTA0LTEyIGF0IDEyOjA5IC0wNzAwLCB0akBrZXJuZWwub3JnIHdyb3RlOg0K
PiBPbiBUaHUsIEFwciAxMiwgMjAxOCBhdCAwNjo1NjoyNlBNICswMDAwLCBCYXJ0IFZhbiBBc3Nj
aGUgd3JvdGU6DQo+ID4gT24gVGh1LCAyMDE4LTA0LTEyIGF0IDExOjExIC0wNzAwLCB0akBrZXJu
ZWwub3JnIHdyb3RlOg0KPiA+ID4gKiBSaWdodCBub3csIGJsa19xdWV1ZV9lbnRlci9leGl0KCkg
ZG9lc24ndCBoYXZlIGFueSBhbm5vdGF0aW9ucy4NCj4gPiA+ICAgSU9XLCB0aGVyZSdzIG5vIHdh
eSBm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fYmxrZ19sb29rdXAoc3RydWN0IGJsa2NnICpibGtjZywNCiB7DQogCXN0cnVjdCBibGtj
Z19ncSAqYmxrZzsNCiANCisJbG9ja19pc19oZWxkKCZxLT5xX2VudGVyX21hcCk7DQorDQogCWlm
IChibGtjZyA9PSAmYmxrY2dfcm9vdCkNCiAJCXJldHVybiBxLT5yb290X2Jsa2c7DQogDQpkaWZm
IC0tZ2l0IGEvaW5jbHVkZS9saW51eC9ibGtkZXYuaCBiL2luY2x1ZGUvbGludXgvYmxrZGV2LmgN
CmluZGV4IDBkMjJmMzUxYTc0Yi4uYTBiMWFkYmQ0NDA2IDEwMDY0NA0KLS0tIGEvaW5jbHVkZS9s
aW51eC9ibGtkZXYuaA0KKysrIGIvaW5jbHVkZS9saW51eC9ibGtkZXYuaA0KQEAgLTYzMSw2ICs2
MzEsNyBAQCBzdHJ1Y3QgcmVxdWVzdF9xdWV1ZSB7DQogCXN0cnVjdCByY3VfaGVhZAkJcmN1X2hl
YWQ7DQogCXdhaXRfcXVldWVfaGVhZF90CW1xX2ZyZWV6ZV93cTsNCiAJc3RydWN0IHBlcmNwdV9y
ZWYJcV91c2FnZV9jb3VudGVyOw0KKwlzdHJ1Y3QgbG9ja2RlcF9tYXAJcV9lbnRlcl9tYXA7DQog
CXN0cnVjdCBsaXN0X2hlYWQJYWxsX3Ffbm9kZTsNCiANCiAJc3RydWN0IGJsa19tcV90YWdfc2V0
CSp0YWdfc2V0Ow0K

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

* Re: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller
  2018-04-12 22:40                   ` Bart Van Assche
@ 2018-04-13 15:18                     ` tj
  0 siblings, 0 replies; 22+ messages in thread
From: tj @ 2018-04-13 15:18 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: hch, linux-block, 00moses.alexander00, axboe

Hello, Bart.

On Thu, Apr 12, 2018 at 10:40:52PM +0000, Bart Van Assche wrote:
> Is something like the patch below perhaps what you had in mind?

Yeah, exactly.  It'd be really great to have the lockdep asserts add
to the right places.

Thanks.

-- 
tejun

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

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

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-12  1:58 [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Bart Van Assche
2018-04-12  4:20 ` Alexandru Moise
2018-04-12  4:32   ` Alexandru Moise
2018-04-12  4:22 ` Alexandru Moise
2018-04-12  5:34 ` Christoph Hellwig
2018-04-12 11:52   ` Bart Van Assche
2018-04-12 13:14     ` hch
2018-04-12 13:48       ` tj
2018-04-12 13:56         ` hch
2018-04-12 13:58           ` tj
2018-04-12 14:07             ` tj
2018-04-12 13:51 ` Tejun Heo
2018-04-12 14:09   ` Bart Van Assche
2018-04-12 15:37     ` Tejun Heo
2018-04-12 16:03       ` Bart Van Assche
2018-04-12 16:12         ` tj
2018-04-12 16:29           ` Bart Van Assche
2018-04-12 18:11             ` tj
2018-04-12 18:56               ` Bart Van Assche
2018-04-12 19:09                 ` tj
2018-04-12 22:40                   ` Bart Van Assche
2018-04-13 15:18                     ` tj

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.