All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2] block: release disk reference in hd_struct_free_work
@ 2020-09-01 10:07 Ming Lei
  2020-09-01 10:09 ` Christoph Hellwig
  2020-09-01 14:34 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2020-09-01 10:07 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Ming Lei, Ilya Dryomov, Luis Chamberlain,
	Christoph Hellwig, Bart Van Assche

Commit e8c7d14ac6c3 ("block: revert back to synchronous request_queue removal")
stops to release request queue from wq context because that commit
supposed all blk_put_queue() is called in context which is allowed
to sleep. However, this assumption isn't true because we release disk's
reference in partition's percpu_ref's ->release() which doesn't allow
to sleep, because the ->release() is run via call_rcu().

Fixes this issue by moving put disk reference into hd_struct_free_work()

Signed-off-by: Ming Lei <ming.lei@redhat.com>
Fixes: e8c7d14ac6c3 ("block: revert back to synchronous request_queue removal")
Reported-by: Ilya Dryomov <idryomov@gmail.com>
Tested-by: Ilya Dryomov <idryomov@gmail.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Bart Van Assche <bvanassche@acm.org>
---
V2:
	- take Christoph's comment

 block/partitions/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/block/partitions/core.c b/block/partitions/core.c
index e62a98a8eeb7..5a18c8edabbc 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -278,6 +278,15 @@ static void hd_struct_free_work(struct work_struct *work)
 {
 	struct hd_struct *part =
 		container_of(to_rcu_work(work), struct hd_struct, rcu_work);
+	struct gendisk *disk = part_to_disk(part);
+
+	/*
+	 * Release the disk reference acquired in delete_partition here.
+	 * We can't release it in hd_struct_free because the final put_device
+	 * needs process context and thus can't be run directly from a
+	 * percpu_ref ->release handler.
+	 */
+	put_device(disk_to_dev(disk));
 
 	part->start_sect = 0;
 	part->nr_sects = 0;
@@ -293,7 +302,6 @@ static void hd_struct_free(struct percpu_ref *ref)
 		rcu_dereference_protected(disk->part_tbl, 1);
 
 	rcu_assign_pointer(ptbl->last_lookup, NULL);
-	put_device(disk_to_dev(disk));
 
 	INIT_RCU_WORK(&part->rcu_work, hd_struct_free_work);
 	queue_rcu_work(system_wq, &part->rcu_work);
-- 
2.25.2


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

* Re: [PATCH V2] block: release disk reference in hd_struct_free_work
  2020-09-01 10:07 [PATCH V2] block: release disk reference in hd_struct_free_work Ming Lei
@ 2020-09-01 10:09 ` Christoph Hellwig
  2020-09-01 14:34 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-09-01 10:09 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Ilya Dryomov, Luis Chamberlain,
	Christoph Hellwig, Bart Van Assche

On Tue, Sep 01, 2020 at 06:07:38PM +0800, Ming Lei wrote:
> Commit e8c7d14ac6c3 ("block: revert back to synchronous request_queue removal")
> stops to release request queue from wq context because that commit
> supposed all blk_put_queue() is called in context which is allowed
> to sleep. However, this assumption isn't true because we release disk's
> reference in partition's percpu_ref's ->release() which doesn't allow
> to sleep, because the ->release() is run via call_rcu().
> 
> Fixes this issue by moving put disk reference into hd_struct_free_work()
> 
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> Fixes: e8c7d14ac6c3 ("block: revert back to synchronous request_queue removal")
> Reported-by: Ilya Dryomov <idryomov@gmail.com>
> Tested-by: Ilya Dryomov <idryomov@gmail.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Bart Van Assche <bvanassche@acm.org>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH V2] block: release disk reference in hd_struct_free_work
  2020-09-01 10:07 [PATCH V2] block: release disk reference in hd_struct_free_work Ming Lei
  2020-09-01 10:09 ` Christoph Hellwig
@ 2020-09-01 14:34 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-09-01 14:34 UTC (permalink / raw)
  To: Ming Lei
  Cc: linux-block, Ilya Dryomov, Luis Chamberlain, Christoph Hellwig,
	Bart Van Assche

On 9/1/20 4:07 AM, Ming Lei wrote:
> Commit e8c7d14ac6c3 ("block: revert back to synchronous request_queue removal")
> stops to release request queue from wq context because that commit
> supposed all blk_put_queue() is called in context which is allowed
> to sleep. However, this assumption isn't true because we release disk's
> reference in partition's percpu_ref's ->release() which doesn't allow
> to sleep, because the ->release() is run via call_rcu().
> 
> Fixes this issue by moving put disk reference into hd_struct_free_work()

Applied, thanks Ming.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-09-01 14:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 10:07 [PATCH V2] block: release disk reference in hd_struct_free_work Ming Lei
2020-09-01 10:09 ` Christoph Hellwig
2020-09-01 14:34 ` Jens Axboe

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.