* [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices
@ 2015-07-20 15:14 Lin Ma
2015-07-20 15:36 ` Michael S. Tsirkin
0 siblings, 1 reply; 3+ messages in thread
From: Lin Ma @ 2015-07-20 15:14 UTC (permalink / raw)
To: mst, kraxel@redhat.com >> Gerd Hoffmann
Cc: qemu-devel@nongnu.org Developers
Hi Michael and Gerd,
I found an hotplug/hotunplug issue about virtio 1.0 devices and trying
to fix it.
The bug description is:
(qemu) device_add virtio-gpu-pci,id=gpu0
(qemu) device_del gpu0
(qemu) device_add virtio-gpu-pci,id=gpu0
Duplicate ID 'gpu0' for device
Try "help device_add" for more information
My fix looks like this:
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 283401a..098fc83 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1413,6 +1413,12 @@ static void
virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
virtio_pci_add_mem_cap(proxy, cap);
}
+static void virtio_pci_modern_region_unmap(VirtIOPCIProxy *proxy,
+ VirtIOPCIRegion *region)
+{
+ memory_region_del_subregion(&proxy->modern_bar, ®ion->mr);
+}
+
/* This is called by virtio-bus just after the device is plugged. */
static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
{
@@ -1584,6 +1590,16 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
msix_uninit_exclusive_bar(pci_dev);
address_space_destroy(&proxy->modern_as);
+ object_unparent(OBJECT(&proxy->modern_cfg));
+
+ bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
+ if (modern) {
+ virtio_pci_modern_region_unmap(proxy, &proxy->common);
+ virtio_pci_modern_region_unmap(proxy, &proxy->isr);
+ virtio_pci_modern_region_unmap(proxy, &proxy->device);
+ virtio_pci_modern_region_unmap(proxy, &proxy->notify);
+ }
+ memory_region_unref(&proxy->modern_bar);
}
static void virtio_pci_reset(DeviceState *qdev)
But after applying the fix, I got the following errors:
(qemu) device_add virtio-gpu-pci,id=gpu0
(qemu) device_del gpu0
(qemu) **
ERROR:qom/object.c:825:object_unref: assertion failed: (obj->ref > 0)
......
I think because of the grace period of rcu, the function
memory_region_unref(as->root) in do_address_space_destroy isn't
performed immediately,
The do_address_space_destroy is always performed after virtio_pci_exit,
That caused 'assertion failed: (obj->ref > 0)'.
I have no idea whether my guess is correct or in correct, and don't know
how to avoid this assertion failure in this situation.
Does my fix make sense ? May I have your ideas or suggestions?
Thanks!
Lin
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices
2015-07-20 15:14 [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices Lin Ma
@ 2015-07-20 15:36 ` Michael S. Tsirkin
2015-07-21 5:37 ` Lin Ma
0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2015-07-20 15:36 UTC (permalink / raw)
To: Lin Ma
Cc: kraxel@redhat.com >> Gerd Hoffmann,
qemu-devel@nongnu.org Developers
On Mon, Jul 20, 2015 at 11:14:58PM +0800, Lin Ma wrote:
> Hi Michael and Gerd,
>
> I found an hotplug/hotunplug issue about virtio 1.0 devices and trying to
> fix it.
> The bug description is:
> (qemu) device_add virtio-gpu-pci,id=gpu0
> (qemu) device_del gpu0
At this point, you must wait for guest to ack device removal.
> (qemu) device_add virtio-gpu-pci,id=gpu0
> Duplicate ID 'gpu0' for device
> Try "help device_add" for more information
>
> My fix looks like this:
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 283401a..098fc83 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1413,6 +1413,12 @@ static void
> virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
> virtio_pci_add_mem_cap(proxy, cap);
> }
>
> +static void virtio_pci_modern_region_unmap(VirtIOPCIProxy *proxy,
> + VirtIOPCIRegion *region)
> +{
> + memory_region_del_subregion(&proxy->modern_bar, ®ion->mr);
> +}
> +
> /* This is called by virtio-bus just after the device is plugged. */
> static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
> {
> @@ -1584,6 +1590,16 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
>
> msix_uninit_exclusive_bar(pci_dev);
> address_space_destroy(&proxy->modern_as);
> + object_unparent(OBJECT(&proxy->modern_cfg));
> +
> + bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
> + if (modern) {
> + virtio_pci_modern_region_unmap(proxy, &proxy->common);
> + virtio_pci_modern_region_unmap(proxy, &proxy->isr);
> + virtio_pci_modern_region_unmap(proxy, &proxy->device);
> + virtio_pci_modern_region_unmap(proxy, &proxy->notify);
> + }
> + memory_region_unref(&proxy->modern_bar);
> }
>
> static void virtio_pci_reset(DeviceState *qdev)
>
>
>
> But after applying the fix, I got the following errors:
> (qemu) device_add virtio-gpu-pci,id=gpu0
> (qemu) device_del gpu0
> (qemu) **
> ERROR:qom/object.c:825:object_unref: assertion failed: (obj->ref > 0)
> ......
>
>
> I think because of the grace period of rcu, the function
> memory_region_unref(as->root) in do_address_space_destroy isn't performed
> immediately,
> The do_address_space_destroy is always performed after virtio_pci_exit, That
> caused 'assertion failed: (obj->ref > 0)'.
> I have no idea whether my guess is correct or in correct, and don't know how
> to avoid this assertion failure in this situation.
> Does my fix make sense ? May I have your ideas or suggestions?
>
> Thanks!
> Lin
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices
2015-07-20 15:36 ` Michael S. Tsirkin
@ 2015-07-21 5:37 ` Lin Ma
0 siblings, 0 replies; 3+ messages in thread
From: Lin Ma @ 2015-07-21 5:37 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: kraxel@redhat.com >> Gerd Hoffmann,
qemu-devel@nongnu.org Developers
在 2015年07月20日 23:36, Michael S. Tsirkin 写道:
> On Mon, Jul 20, 2015 at 11:14:58PM +0800, Lin Ma wrote:
>> Hi Michael and Gerd,
>>
>> I found an hotplug/hotunplug issue about virtio 1.0 devices and trying to
>> fix it.
>> The bug description is:
>> (qemu) device_add virtio-gpu-pci,id=gpu0
>> (qemu) device_del gpu0
> At this point, you must wait for guest to ack device removal.
After removing the device from qmp, The DEVICE_DELETED async event was
shown.
So the guest already acked, Then add a device with same id, It always
reports 'Duplicate ID ...'.
The device was completely removed from guest, But still in object list
of qemu.
>
>
>> (qemu) device_add virtio-gpu-pci,id=gpu0
>> Duplicate ID 'gpu0' for device
>> Try "help device_add" for more information
>>
>> My fix looks like this:
>> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
>> index 283401a..098fc83 100644
>> --- a/hw/virtio/virtio-pci.c
>> +++ b/hw/virtio/virtio-pci.c
>> @@ -1413,6 +1413,12 @@ static void
>> virtio_pci_modern_region_map(VirtIOPCIProxy *proxy,
>> virtio_pci_add_mem_cap(proxy, cap);
>> }
>>
>> +static void virtio_pci_modern_region_unmap(VirtIOPCIProxy *proxy,
>> + VirtIOPCIRegion *region)
>> +{
>> + memory_region_del_subregion(&proxy->modern_bar, ®ion->mr);
>> +}
>> +
>> /* This is called by virtio-bus just after the device is plugged. */
>> static void virtio_pci_device_plugged(DeviceState *d, Error **errp)
>> {
>> @@ -1584,6 +1590,16 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
>>
>> msix_uninit_exclusive_bar(pci_dev);
>> address_space_destroy(&proxy->modern_as);
>> + object_unparent(OBJECT(&proxy->modern_cfg));
>> +
>> + bool modern = !(proxy->flags & VIRTIO_PCI_FLAG_DISABLE_MODERN);
>> + if (modern) {
>> + virtio_pci_modern_region_unmap(proxy, &proxy->common);
>> + virtio_pci_modern_region_unmap(proxy, &proxy->isr);
>> + virtio_pci_modern_region_unmap(proxy, &proxy->device);
>> + virtio_pci_modern_region_unmap(proxy, &proxy->notify);
>> + }
>> + memory_region_unref(&proxy->modern_bar);
>> }
>>
>> static void virtio_pci_reset(DeviceState *qdev)
>>
>>
>>
>> But after applying the fix, I got the following errors:
>> (qemu) device_add virtio-gpu-pci,id=gpu0
>> (qemu) device_del gpu0
>> (qemu) **
>> ERROR:qom/object.c:825:object_unref: assertion failed: (obj->ref > 0)
>> ......
>>
>>
>> I think because of the grace period of rcu, the function
>> memory_region_unref(as->root) in do_address_space_destroy isn't performed
>> immediately,
>> The do_address_space_destroy is always performed after virtio_pci_exit, That
>> caused 'assertion failed: (obj->ref > 0)'.
>> I have no idea whether my guess is correct or in correct, and don't know how
>> to avoid this assertion failure in this situation.
>> Does my fix make sense ? May I have your ideas or suggestions?
>>
>> Thanks!
>> Lin
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-21 5:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-20 15:14 [Qemu-devel] [RFC PATCH] Fix hotplug/hotunplug issue about virtio 1.0 devices Lin Ma
2015-07-20 15:36 ` Michael S. Tsirkin
2015-07-21 5:37 ` Lin Ma
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).