Skip to content

Commit 7061b6a

Browse files
jpbruckerjoergroedel
authored andcommitted
iommu/virtio: Return size mapped for a detached domain
When map() is called on a detached domain, the domain does not exist in the device so we do not send a MAP request, but we do update the internal mapping tree, to be replayed on the next attach. Since this constitutes a successful iommu_map() call, return *mapped in this case too. Fixes: 7e62edd ("iommu/virtio: Add map/unmap_pages() callbacks implementation") Signed-off-by: Jean-Philippe Brucker <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 809d081 commit 7061b6a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

drivers/iommu/virtio-iommu.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -833,25 +833,26 @@ static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova,
833833
if (ret)
834834
return ret;
835835

836-
map = (struct virtio_iommu_req_map) {
837-
.head.type = VIRTIO_IOMMU_T_MAP,
838-
.domain = cpu_to_le32(vdomain->id),
839-
.virt_start = cpu_to_le64(iova),
840-
.phys_start = cpu_to_le64(paddr),
841-
.virt_end = cpu_to_le64(end),
842-
.flags = cpu_to_le32(flags),
843-
};
844-
845-
if (!vdomain->nr_endpoints)
846-
return 0;
836+
if (vdomain->nr_endpoints) {
837+
map = (struct virtio_iommu_req_map) {
838+
.head.type = VIRTIO_IOMMU_T_MAP,
839+
.domain = cpu_to_le32(vdomain->id),
840+
.virt_start = cpu_to_le64(iova),
841+
.phys_start = cpu_to_le64(paddr),
842+
.virt_end = cpu_to_le64(end),
843+
.flags = cpu_to_le32(flags),
844+
};
847845

848-
ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
849-
if (ret)
850-
viommu_del_mappings(vdomain, iova, end);
851-
else if (mapped)
846+
ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
847+
if (ret) {
848+
viommu_del_mappings(vdomain, iova, end);
849+
return ret;
850+
}
851+
}
852+
if (mapped)
852853
*mapped = size;
853854

854-
return ret;
855+
return 0;
855856
}
856857

857858
static size_t viommu_unmap_pages(struct iommu_domain *domain, unsigned long iova,

0 commit comments

Comments
 (0)