Skip to contentSkip to conversation

vfio-pci: Fix missing unparent of dynamically allocated MemoryRegion

PATCH In review Alex Williamson 2 participants 2 messages Feb 1, 2015 – Feb 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfio-pci: Fix missing unparent of dynamically allocated MemoryRegion

Commit d8d95814609e added explicit object_unparent() calls for dynamically allocated MemoryRegions. The VFIOMSIXInfo structure also contains such a MemoryRegion, covering the mmap'd region of a PCI BAR above the MSI-X table. This structure is freed as part of the class exit function and therefore also needs an explicit object_unparent(). Failing to do this results in random segfaults due to fields within the structure, often the class pointer, being reclaimed and corrupted by the time object_finalize_child_property() is called for the object.

---

 hw/vfio/pci.c |    1 +
 1 file changed, 1 insertion(+)
hw/vfio/pci.c +1 -0
index 014a92c..29caabc 100644
@@ -3065,6 +3065,7 @@ static void vfio_put_device(VFIOPCIDevice *vdev)
 {
     g_free(vdev->vbasedev.name);
     if (vdev->msix) {
+        object_unparent(OBJECT(&vdev->msix->mmap_mem));
         g_free(vdev->msix);
         vdev->msix = NULL;
     }
Reviewed-by on v2 1/1
#1 lore raw
Quoted 23 lines · Alex Williamson

Commit d8d95814609e added explicit object_unparent() calls for dynamically allocated MemoryRegions. The VFIOMSIXInfo structure also contains such a MemoryRegion, covering the mmap'd region of a PCI BAR above the MSI-X table. This structure is freed as part of the class exit function and therefore also needs an explicit object_unparent(). Failing to do this results in random segfaults due to fields within the structure, often the class pointer, being reclaimed and corrupted by the time object_finalize_child_property() is called for the object.

---

 hw/vfio/pci.c |    1 +
 1 file changed, 1 insertion(+)
hw/vfio/pci.c +0 -0
index 014a92c..29caabc 100644

hw/vfio/pci.c static void vfio_put_device(VFIOPCIDevice *vdev) · line 3071

Quoted 7 lines
hw/vfio/pci.c +1 -0
@@ -3065,6 +3065,7 @@ static void vfio_put_device(VFIOPCIDevice *vdev)
 {
     g_free(vdev->vbasedev.name);
     if (vdev->msix) {
+        object_unparent(OBJECT(&vdev->msix->mmap_mem));
         g_free(vdev->msix);
         vdev->msix = NULL;
     }

Perhaps specify "# 2.2" on the "Cc: [email protected]" line and/or add a "Fixes: ..." line.

Paolo