* [Qemu-devel] [PATCH] fix: unrealize virtio device if we fail to hotplug it
@ 2017-10-31 8:03 linzhecheng
2017-11-03 10:29 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: linzhecheng @ 2017-10-31 8:03 UTC (permalink / raw)
To: qemu-devel; +Cc: mst, stefanha, linzhecheng
If we fail to hotplug virtio-blk device and then suspend
or shutdown VM, qemu is likely to crash.
Re-production steps:
1. Run VM named vm001
2. Create a virtio-blk.xml which contains wrong configurations:
<disk device="lun" rawio="yes" type="block">
<driver cache="none" io="native" name="qemu" type="raw" />
<source dev="/dev/mapper/11-dm" />
<target bus="virtio" dev="vdx" />
</disk>
3. Run command : virsh attach-device vm001 virtio-blk.xml
error: Failed to attach device from blk-scsi.xml
error: internal error: unable to execute QEMU command 'device_add': Please set scsi=off for virtio-blk devices in order to use virtio 1.0
it means hotplug virtio-blk device failed.
4. Suspend or shutdown VM will leads to qemu crash
Problem happens in virtio_vmstate_change which is called by
vm_state_notify:
vdev’s parent_bus is NULL, so qdev_get_parent_bus(DEVICE(vdev)) will crash.
virtio_vmstate_change is added to the list vm_change_state_head at virtio_blk_device_realize(virtio_init),
but after hotplug virtio-blk failed, virtio_vmstate_change will not be removed from vm_change_state_head.
Adding unrealize function of virtio-blk device can solve this problem.
Signed-off-by: linzhecheng <linzhecheng@huawei.com>
---
hw/virtio/virtio.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5884ce3480..ea532dc35f 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2491,6 +2491,7 @@ static void virtio_device_realize(DeviceState *dev, Error **errp)
virtio_bus_device_plugged(vdev, &err);
if (err != NULL) {
error_propagate(errp, err);
+ vdc->unrealize(dev, NULL);
return;
}
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] fix: unrealize virtio device if we fail to hotplug it
2017-10-31 8:03 [Qemu-devel] [PATCH] fix: unrealize virtio device if we fail to hotplug it linzhecheng
@ 2017-11-03 10:29 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2017-11-03 10:29 UTC (permalink / raw)
To: linzhecheng; +Cc: qemu-devel, stefanha, mst
[-- Attachment #1: Type: text/plain, Size: 1487 bytes --]
On Tue, Oct 31, 2017 at 04:03:03PM +0800, linzhecheng wrote:
> If we fail to hotplug virtio-blk device and then suspend
> or shutdown VM, qemu is likely to crash.
>
> Re-production steps:
> 1. Run VM named vm001
> 2. Create a virtio-blk.xml which contains wrong configurations:
> <disk device="lun" rawio="yes" type="block">
> <driver cache="none" io="native" name="qemu" type="raw" />
> <source dev="/dev/mapper/11-dm" />
> <target bus="virtio" dev="vdx" />
> </disk>
> 3. Run command : virsh attach-device vm001 virtio-blk.xml
> error: Failed to attach device from blk-scsi.xml
> error: internal error: unable to execute QEMU command 'device_add': Please set scsi=off for virtio-blk devices in order to use virtio 1.0
> it means hotplug virtio-blk device failed.
> 4. Suspend or shutdown VM will leads to qemu crash
>
> Problem happens in virtio_vmstate_change which is called by
> vm_state_notify:
> vdev’s parent_bus is NULL, so qdev_get_parent_bus(DEVICE(vdev)) will crash.
> virtio_vmstate_change is added to the list vm_change_state_head at virtio_blk_device_realize(virtio_init),
> but after hotplug virtio-blk failed, virtio_vmstate_change will not be removed from vm_change_state_head.
> Adding unrealize function of virtio-blk device can solve this problem.
>
> Signed-off-by: linzhecheng <linzhecheng@huawei.com>
> ---
> hw/virtio/virtio.c | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-03 10:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-31 8:03 [Qemu-devel] [PATCH] fix: unrealize virtio device if we fail to hotplug it linzhecheng
2017-11-03 10:29 ` Stefan Hajnoczi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).