[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v5 27/48] ivshmem: fix pci_ivshmem_exit()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH v5 27/48] ivshmem: fix pci_ivshmem_exit() |
Date: |
Fri, 2 Oct 2015 21:09:30 +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>
Reviewed-by: Claudio Fontana <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 7be3d5e..d1b5d35 100644
--- a/hw/misc/ivshmem.c
+++ b/hw/misc/ivshmem.c
@@ -800,15 +800,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
- Re: [Qemu-devel] [PATCH v5 40/48] glib-compat: add 2.38/2.40/2.46 asserts, (continued)
[Qemu-devel] [PATCH v5 46/48] ivshmem: rename MSI eventfd_table, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 06/48] ivshmem: remove unnecessary dup(), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 14/48] ivshmem: remove useless ivshmem_update_irq() val argument, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 03/48] ivhsmem: read do not accept more than sizeof(long), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 08/48] ivshmem: remove useless doorbell field, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 27/48] ivshmem: fix pci_ivshmem_exit(),
marcandre . lureau <=
[Qemu-devel] [PATCH v5 41/48] tests: add ivshmem qtest, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 35/48] docs: update ivshmem device spec, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 12/48] ivshmem: simplify around increase_dynamic_storage(), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 01/48] char: add qemu_chr_free(), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 13/48] ivshmem: allocate eventfds in resize_peers(), marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 19/48] ivshmem: print error on invalid peer id, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 16/48] ivshmem: remove max_peer field, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 25/48] ivshmem: check shm isn't already initialized, marcandre . lureau, 2015/10/08
[Qemu-devel] [PATCH v5 18/48] ivshmem: improve error handling, marcandre . lureau, 2015/10/08