[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 27/46] ivshmem: fix pci_ivshmem_exit()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v3 27/46] ivshmem: fix pci_ivshmem_exit() |
Date: |
Tue, 15 Sep 2015 18:07:44 +0200 |
From: Marc-André Lureau <address@hidden>
Free all objects owned by the device, making sure the device is free,
fixing hot-unplug.
Signed-off-by: Marc-André Lureau <address@hidden>
---
hw/misc/ivshmem.c | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
index 5e96360..6acdc56 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -798,15 +798,47 @@ static void pci_ivshmem_realize(PCIDevice *dev, Error
**errp)
static void pci_ivshmem_exit(PCIDevice *dev)
{
IVShmemState *s = IVSHMEM(dev);
+ int i;
+
+ fifo8_destroy(&s->incoming_fifo);
if (s->migration_blocker) {
migrate_del_blocker(s->migration_blocker);
error_free(s->migration_blocker);
}
- memory_region_del_subregion(&s->bar, &s->ivshmem);
- vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
- fifo8_destroy(&s->incoming_fifo);
+ if (s->shm_fd >= 0) {
+ void *addr = memory_region_get_ram_ptr(&s->ivshmem);
+
+ vmstate_unregister_ram(&s->ivshmem, DEVICE(dev));
+ memory_region_del_subregion(&s->bar, &s->ivshmem);
+
+ if (munmap(addr, s->ivshmem_size) == -1) {
+ error_report("Failed to munmap shared memory %s", strerror(errno));
+ }
+ }
+
+ if (s->eventfd_chr) {
+ for (i = 0; i < s->vectors; i++) {
+ if (s->eventfd_chr[i]) {
+ qemu_chr_free(s->eventfd_chr[i]);
+ }
+ }
+ g_free(s->eventfd_chr);
+ }
+
+ if (s->peers) {
+ for (i = 0; i < s->nb_peers; i++) {
+ close_guest_eventfds(s, i);
+ }
+ g_free(s->peers);
+ }
+
+ if (ivshmem_has_feature(s, IVSHMEM_MSI)) {
+ msix_uninit_exclusive_bar(dev);
+ }
+
+ g_free(s->eventfd_table);
}
static bool test_msix(void *opaque, int version_id)
--
2.4.3
- [Qemu-devel] [PATCH v3 19/46] ivshmem: print error on invalid peer id, (continued)
- [Qemu-devel] [PATCH v3 19/46] ivshmem: print error on invalid peer id, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 21/46] ivshmem: use common return, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 22/46] ivshmem: use common is_power_of_2(), marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 23/46] ivshmem: migrate with VMStateDescription, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 25/46] ivshmem: check shm isn't already initialized, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 24/46] ivshmem: shmfd can be 0, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 27/46] ivshmem: fix pci_ivshmem_exit(),
marcandre . lureau <=
- [Qemu-devel] [PATCH v3 26/46] ivshmem: add device description, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 28/46] ivshmem: replace 'guest' for 'peer' appropriately, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 29/46] ivshmem: error on too many eventfd received, marcandre . lureau, 2015/09/15
- [Qemu-devel] [PATCH v3 30/46] ivshmem: reset mask on device reset, marcandre . lureau, 2015/09/15