[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 10/38] msix: split msix_free from msix_uninit
From: |
Michael S. Tsirkin |
Subject: |
Re: [Qemu-devel] [PATCH 10/38] msix: split msix_free from msix_uninit |
Date: |
Tue, 17 Sep 2013 12:21:37 +0300 |
On Tue, Sep 03, 2013 at 02:33:01PM +0200, Paolo Bonzini wrote:
> Signed-off-by: Paolo Bonzini <address@hidden>
> ---
> hw/misc/vfio.c | 1 +
> hw/net/vmxnet3.c | 3 +++
> hw/pci/msix.c | 22 ++++++++++++++++------
> hw/virtio/virtio-pci.c | 1 +
> include/hw/pci/msix.h | 1 +
> 5 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
> index a1c08fb..1311d0e 100644
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -2144,6 +2144,7 @@ static void vfio_teardown_msi(VFIODevice *vdev)
> if (vdev->msix) {
> msix_uninit(&vdev->pdev, &vdev->bars[vdev->msix->table_bar].mem,
> &vdev->bars[vdev->msix->pba_bar].mem);
> + msix_free(&vdev->pdev);
> }
> }
>
> diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
> index 49c2466..2a79e52 100644
> --- a/hw/net/vmxnet3.c
> +++ b/hw/net/vmxnet3.c
> @@ -1979,6 +1979,7 @@ vmxnet3_init_msix(VMXNET3State *s)
> if (!vmxnet3_use_msix_vectors(s, VMXNET3_MAX_INTRS)) {
> VMW_WRPRN("Failed to use MSI-X vectors, error %d", res);
> msix_uninit(d, &s->msix_bar, &s->msix_bar);
> + msix_free(d);
> s->msix_used = false;
> } else {
> s->msix_used = true;
> @@ -1996,6 +1997,8 @@ vmxnet3_cleanup_msix(VMXNET3State *s)
> msix_vector_unuse(d, VMXNET3_MAX_INTRS);
> msix_uninit(d, &s->msix_bar, &s->msix_bar);
> }
> +
> + msix_free(d);
> }
>
> #define VMXNET3_MSI_NUM_VECTORS (1)
> diff --git a/hw/pci/msix.c b/hw/pci/msix.c
> index 3430770..0618e3b 100644
> --- a/hw/pci/msix.c
> +++ b/hw/pci/msix.c
> @@ -359,16 +359,26 @@ void msix_uninit(PCIDevice *dev, MemoryRegion
> *table_bar, MemoryRegion *pba_bar)
> msix_free_irq_entries(dev);
> dev->msix_entries_nr = 0;
> memory_region_del_subregion(pba_bar, &dev->msix_pba_mmio);
> - memory_region_destroy(&dev->msix_pba_mmio);
> - g_free(dev->msix_pba);
> - dev->msix_pba = NULL;
> memory_region_del_subregion(table_bar, &dev->msix_table_mmio);
> - memory_region_destroy(&dev->msix_table_mmio);
> - g_free(dev->msix_table);
> + dev->cap_present &= ~QEMU_PCI_CAP_MSIX;
> +}
> +
> +void msix_free(PCIDevice *dev)
> +{
> + if (dev->msix_pba) {
> + memory_region_destroy(&dev->msix_pba_mmio);
> + g_free(dev->msix_pba);
> + }
> + dev->msix_pba = NULL;
> +
> + if (dev->msix_table) {
> + memory_region_destroy(&dev->msix_table_mmio);
> + g_free(dev->msix_table);
> + }
> dev->msix_table = NULL;
> +
> g_free(dev->msix_entry_used);
> dev->msix_entry_used = NULL;
> - dev->cap_present &= ~QEMU_PCI_CAP_MSIX;
> }
>
I dislike the if (...) here. This only works as long
as all data is pointers.
So I'd prefer QEMU_PCI_CAP_MSIX to be cleared in msix_free.
This way msix_free can just check QEMU_PCI_CAP_MSIX
and return if not there.
> void msix_uninit_exclusive_bar(PCIDevice *dev)
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index f2c489b..ff6bed5 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -999,6 +999,7 @@ static void virtio_pci_exit(PCIDevice *pci_dev)
> virtio_pci_stop_ioeventfd(proxy);
> memory_region_destroy(&proxy->bar);
> msix_uninit_exclusive_bar(pci_dev);
> + msix_free(pci_dev);
> }
>
> static void virtio_pci_reset(DeviceState *qdev)
> diff --git a/include/hw/pci/msix.h b/include/hw/pci/msix.h
> index 954d82b..34e3ba2 100644
> --- a/include/hw/pci/msix.h
> +++ b/include/hw/pci/msix.h
> @@ -18,6 +18,7 @@ void msix_write_config(PCIDevice *dev, uint32_t address,
> uint32_t val, int len);
> void msix_uninit(PCIDevice *dev, MemoryRegion *table_bar,
> MemoryRegion *pba_bar);
> void msix_uninit_exclusive_bar(PCIDevice *dev);
> +void msix_free(PCIDevice *dev);
>
> unsigned int msix_nr_vectors_allocated(const PCIDevice *dev);
>
> --
> 1.8.3.1
>
- Re: [Qemu-devel] [PATCH 02/38] pci: split exit and finalize, (continued)
- [Qemu-devel] [PATCH 03/38] ac97: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 04/38] es1370: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 05/38] hda: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 07/38] tpci200: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 06/38] serial: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 08/38] pci-assign: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 09/38] ahci: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 10/38] msix: split msix_free from msix_uninit, Paolo Bonzini, 2013/09/03
- Re: [Qemu-devel] [PATCH 10/38] msix: split msix_free from msix_uninit,
Michael S. Tsirkin <=
- [Qemu-devel] [PATCH 11/38] cmd646: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 12/38] ide/piix: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 13/38] ide/via: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 14/38] ivshmem: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 15/38] pci-testdev: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 16/38] vfio: reclaim memory in instance_finalize instead of exit, Paolo Bonzini, 2013/09/03
- [Qemu-devel] [PATCH 17/38] e1000: use instance_finalize instead of exit, Paolo Bonzini, 2013/09/03