From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjXoB-0001ax-Mn for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:22:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZjXnf-0005aF-PB for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:21:55 -0400 Received: from mail-qg0-x22c.google.com ([2607:f8b0:400d:c04::22c]:35175) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZjXnf-0005Wm-13 for qemu-devel@nongnu.org; Tue, 06 Oct 2015 15:21:23 -0400 Received: by qgt47 with SMTP id 47so183774070qgt.2 for ; Tue, 06 Oct 2015 12:21:22 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Tue, 6 Oct 2015 21:19:23 +0200 Message-Id: <1444159184-18153-28-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1444159184-18153-1-git-send-email-marcandre.lureau@redhat.com> References: <1444159184-18153-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PULL 27/48] ivshmem: fix pci_ivshmem_exit() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.maydell@linaro.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , qemu-devel@nongnu.org From: Marc-André Lureau Free all objects owned by the device, making sure the device is free, fixing hot-unplug. Signed-off-by: Marc-André Lureau Reviewed-by: Claudio Fontana --- 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