Skip to content

Commit 809d081

Browse files
jpbruckerjoergroedel
authored andcommitted
iommu/virtio: Detach domain on endpoint release
When an endpoint is released, for example a PCIe VF being destroyed or a function hot-unplugged, it should be detached from its domain. Send a DETACH request. Fixes: edcd69a ("iommu: Add virtio-iommu driver") Reported-by: Akihiko Odaki <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Jean-Philippe Brucker <[email protected]> Tested-by: Akihiko Odaki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 44c026a commit 809d081

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

drivers/iommu/virtio-iommu.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,29 @@ static int viommu_attach_dev(struct iommu_domain *domain, struct device *dev)
788788
return 0;
789789
}
790790

791+
static void viommu_detach_dev(struct viommu_endpoint *vdev)
792+
{
793+
int i;
794+
struct virtio_iommu_req_detach req;
795+
struct viommu_domain *vdomain = vdev->vdomain;
796+
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(vdev->dev);
797+
798+
if (!vdomain)
799+
return;
800+
801+
req = (struct virtio_iommu_req_detach) {
802+
.head.type = VIRTIO_IOMMU_T_DETACH,
803+
.domain = cpu_to_le32(vdomain->id),
804+
};
805+
806+
for (i = 0; i < fwspec->num_ids; i++) {
807+
req.endpoint = cpu_to_le32(fwspec->ids[i]);
808+
WARN_ON(viommu_send_req_sync(vdev->viommu, &req, sizeof(req)));
809+
}
810+
vdomain->nr_endpoints--;
811+
vdev->vdomain = NULL;
812+
}
813+
791814
static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova,
792815
phys_addr_t paddr, size_t pgsize, size_t pgcount,
793816
int prot, gfp_t gfp, size_t *mapped)
@@ -990,6 +1013,7 @@ static void viommu_release_device(struct device *dev)
9901013
{
9911014
struct viommu_endpoint *vdev = dev_iommu_priv_get(dev);
9921015

1016+
viommu_detach_dev(vdev);
9931017
iommu_put_resv_regions(dev, &vdev->resv_regions);
9941018
kfree(vdev);
9951019
}

0 commit comments

Comments
 (0)