Skip to content

Commit cafe01e

Browse files
Ming Leiaxboe
authored andcommitted
block: release disk reference in hd_struct_free_work
Commit e8c7d14 ("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() Fixes: e8c7d14 ("block: revert back to synchronous request_queue removal") Reported-by: Ilya Dryomov <[email protected]> Signed-off-by: Ming Lei <[email protected]> Tested-by: Ilya Dryomov <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Bart Van Assche <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent de1b0ee commit cafe01e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

block/partitions/core.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,15 @@ static void hd_struct_free_work(struct work_struct *work)
278278
{
279279
struct hd_struct *part =
280280
container_of(to_rcu_work(work), struct hd_struct, rcu_work);
281+
struct gendisk *disk = part_to_disk(part);
282+
283+
/*
284+
* Release the disk reference acquired in delete_partition here.
285+
* We can't release it in hd_struct_free because the final put_device
286+
* needs process context and thus can't be run directly from a
287+
* percpu_ref ->release handler.
288+
*/
289+
put_device(disk_to_dev(disk));
281290

282291
part->start_sect = 0;
283292
part->nr_sects = 0;
@@ -293,7 +302,6 @@ static void hd_struct_free(struct percpu_ref *ref)
293302
rcu_dereference_protected(disk->part_tbl, 1);
294303

295304
rcu_assign_pointer(ptbl->last_lookup, NULL);
296-
put_device(disk_to_dev(disk));
297305

298306
INIT_RCU_WORK(&part->rcu_work, hd_struct_free_work);
299307
queue_rcu_work(system_wq, &part->rcu_work);

0 commit comments

Comments
 (0)