This is a note to let you know that I've just added the patch titled virtio-blk: Fix hot-unplug race in remove method to the 3.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: virtio-blk-fix-hot-unplug-race-in-remove-method.patch and it can be found in the queue-3.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From e5000b33460e5008a3a189dc2107d274d8096eff Mon Sep 17 00:00:00 2001 From: Asias He <asias@xxxxxxxxxx> Date: Fri, 4 May 2012 20:22:04 +0800 Subject: virtio-blk: Fix hot-unplug race in remove method From: Asias He <asias@xxxxxxxxxx> commit b79d866c8b7014a51f611a64c40546109beaf24a upstream. If we reset the virtio-blk device before the requests already dispatched to the virtio-blk driver from the block layer are finised, we will stuck in blk_cleanup_queue() and the remove will fail. blk_cleanup_queue() calls blk_drain_queue() to drain all requests queued before DEAD marking. However it will never success if the device is already stopped. We'll have q->in_flight[] > 0, so the drain will not finish. How to reproduce the race: 1. hot-plug a virtio-blk device 2. keep reading/writing the device in guest 3. hot-unplug while the device is busy serving I/O Test: ~1000 rounds of hot-plug/hot-unplug test passed with this patch. Changes in v3: - Drop blk_abort_queue and blk_abort_request - Use __blk_end_request_all to complete request dispatched to driver Changes in v2: - Drop req_in_flight - Use virtqueue_detach_unused_buf to get request dispatched to driver Signed-off-by: Asias He <asias@xxxxxxxxxx> Signed-off-by: Rusty Russell <rusty@xxxxxxxxxxxxxxx> Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx> Cc: Yijing Wang <wangyijing@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/block/virtio_blk.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -573,6 +573,8 @@ static void __devexit virtblk_remove(str { struct virtio_blk *vblk = vdev->priv; int index = vblk->index; + struct virtblk_req *vbr; + unsigned long flags; /* Prevent config work handler from accessing the device. */ mutex_lock(&vblk->config_lock); @@ -585,6 +587,15 @@ static void __devexit virtblk_remove(str flush_work(&vblk->config_work); del_gendisk(vblk->disk); + + /* Abort requests dispatched to driver. */ + spin_lock_irqsave(&vblk->lock, flags); + while ((vbr = virtqueue_detach_unused_buf(vblk->vq))) { + __blk_end_request_all(vbr->req, -EIO); + mempool_free(vbr, vblk->pool); + } + spin_unlock_irqrestore(&vblk->lock, flags); + blk_cleanup_queue(vblk->disk->queue); put_disk(vblk->disk); mempool_destroy(vblk->pool); Patches currently in stable-queue which might be from asias@xxxxxxxxxx are queue-3.4/virtio-blk-fix-hot-unplug-race-in-remove-method.patch queue-3.4/virtio-blk-call-del_gendisk-before-disable-guest-kick.patch queue-3.4/virtio_blk-drop-unused-request-tracking-list.patch queue-3.4/virtio-blk-reset-device-after-blk_cleanup_queue.patch -- To unsubscribe from this list: send the line "unsubscribe stable" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html