aboutsummaryrefslogtreecommitdiff
path: root/hw/vfio/common.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2015-02-10 10:25:44 -0700
committerAlex Williamson <alex.williamson@redhat.com>2015-02-10 10:25:44 -0700
commit77a10d04d033484a913a5ee76eed31a9acc57bae (patch)
treea0d2f43bccfa7b01a66b8111f0192d588a535e4f /hw/vfio/common.c
parent217e9fdcadb1dc7462f4d92866314f626426fa82 (diff)
vfio: free dynamically-allocated data in instance_finalize
In order to enable out-of-BQL address space lookup, destruction of devices needs to be split in two phases. Unrealize is the first phase; once it complete no new accesses will be started, but there may still be pending memory accesses can still be completed. The second part is freeing the device, which only happens once all memory accesses are complete. At this point the reference count has dropped to zero, an RCU grace period must have completed (because the RCU-protected FlatViews hold a reference to the device via memory_region_ref). This is when instance_finalize is called. Freeing data belongs in an instance_finalize callback, because the dynamically allocated memory can still be used after unrealize by the pending memory accesses. This starts the process by creating an instance_finalize callback and freeing most of the dynamically-allocated data in instance_finalize. Because instance_finalize is also called on error paths or also when the device is actually not realized, the common code needs some changes to be ready for this. The error path in vfio_initfn can be simplified too. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'hw/vfio/common.c')
-rw-r--r--hw/vfio/common.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 6e299b3dfd..b230ef102b 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -847,7 +847,7 @@ free_group_exit:
void vfio_put_group(VFIOGroup *group)
{
- if (!QLIST_EMPTY(&group->device_list)) {
+ if (!group || !QLIST_EMPTY(&group->device_list)) {
return;
}
@@ -902,6 +902,9 @@ int vfio_get_device(VFIOGroup *group, const char *name,
void vfio_put_base_device(VFIODevice *vbasedev)
{
+ if (!vbasedev->group) {
+ return;
+ }
QLIST_REMOVE(vbasedev, next);
vbasedev->group = NULL;
trace_vfio_put_base_device(vbasedev->fd);