Re: block: del_gendisk() vs blk_queue_enter() race condition

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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);




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux