On (24/10/03 23:17), Sergey Senozhatsky wrote: > On (24/10/03 23:00), Sergey Senozhatsky wrote: > > On (24/10/03 06:43), Christoph Hellwig wrote: > [..] > > So that mutex_lock(&disk->open_mutex) right before it potentially can > > deadlock (I think it will). > > > > My idea, thus far, was to > > > > if (test_bit(GD_OWNS_QUEUE, &disk->state)) } > > blk_queue_flag_set(QUEUE_FLAG_DYING, disk->queue); > > blk_kick_queue_enter(disk->queue); // this one simply wake_up_all(&q->mq_freeze_wq); > > // if the queue has QUEUE_FLAG_DYING > > } > > > > in del_gendisk() before the very first time del_gendisk() attempts to > > mutex_lock(&disk->open_mutex), because that mutex is already locked > > forever. Dunno. Is something like this completely silly? --- diff --git a/block/genhd.c b/block/genhd.c index 1c05dd4c6980..c968b04ccc7c 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -649,6 +649,13 @@ void del_gendisk(struct gendisk *disk) disk_del_events(disk); + /* + * Mark the queue QUEUE_FLAG_DYING and wakeup ->mq_freeze_wq so + * that the waiters (e.g. blk_queue_enter()) can see blk_queue_dying() + * and error out, unlocking the ->open_mutex. + */ + __blk_mark_disk_dead(disk); + /* * Prevent new openers by unlinked the bdev inode. */ @@ -668,7 +675,6 @@ void del_gendisk(struct gendisk *disk) * Drop all partitions now that the disk is marked dead. */ mutex_lock(&disk->open_mutex); - __blk_mark_disk_dead(disk); xa_for_each_start(&disk->part_tbl, idx, part, 1) drop_partition(part); mutex_unlock(&disk->open_mutex);