Skip to content

Commit 5a52215

Browse files
gdawar-xilinxmstsirkin
authored andcommitted
vhost-vdpa: free iommu domain after last use during cleanup
Currently vhost_vdpa_cleanup() unmaps the DMA mappings by calling `iommu_unmap(v->domain, map->start, map->size);` from vhost_vdpa_general_unmap() when the parent vDPA driver doesn't provide DMA config operations. However, the IOMMU domain referred to by `v->domain` is freed in vhost_vdpa_free_domain() before vhost_vdpa_cleanup() in vhost_vdpa_release() which results in NULL pointer de-reference. Accordingly, moving the call to vhost_vdpa_free_domain() in vhost_vdpa_cleanup() would makes sense. This will also help detaching the dma device in error handling of vhost_vdpa_alloc_domain(). This issue was observed on terminating QEMU with SIGQUIT. Fixes: 037d430 ("vhost-vdpa: call vhost_vdpa_cleanup during the release") Signed-off-by: Gautam Dawar <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]>
1 parent 09e65ee commit 5a52215

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/vhost/vdpa.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ static int vhost_vdpa_alloc_domain(struct vhost_vdpa *v)
11691169

11701170
err_attach:
11711171
iommu_domain_free(v->domain);
1172+
v->domain = NULL;
11721173
return ret;
11731174
}
11741175

@@ -1213,6 +1214,7 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v)
12131214
vhost_vdpa_remove_as(v, asid);
12141215
}
12151216

1217+
vhost_vdpa_free_domain(v);
12161218
vhost_dev_cleanup(&v->vdev);
12171219
kfree(v->vdev.vqs);
12181220
}
@@ -1285,7 +1287,6 @@ static int vhost_vdpa_release(struct inode *inode, struct file *filep)
12851287
vhost_vdpa_clean_irq(v);
12861288
vhost_vdpa_reset(v);
12871289
vhost_dev_stop(&v->vdev);
1288-
vhost_vdpa_free_domain(v);
12891290
vhost_vdpa_config_put(v);
12901291
vhost_vdpa_cleanup(v);
12911292
mutex_unlock(&d->mutex);

0 commit comments

Comments
 (0)