Skip to content

Commit 7e62edd

Browse files
TinaZhangZWjoergroedel
authored andcommitted
iommu/virtio: Add map/unmap_pages() callbacks implementation
Map/unmap_pags() allows map and unmap multiple pages of the same size in one call, which can improve performance by reducing the numbers of vmexits. With map/unmap_pages() implemented, the prior map/unmap() callbacks are deprecated. Signed-off-by: Tina Zhang <tina.zhang@intel.com> Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Link: https://lore.kernel.org/r/20220605161152.3171-1-tina.zhang@intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent a111daf commit 7e62edd

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

drivers/iommu/virtio-iommu.c

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

791-
static int viommu_map(struct iommu_domain *domain, unsigned long iova,
792-
phys_addr_t paddr, size_t size, int prot, gfp_t gfp)
791+
static int viommu_map_pages(struct iommu_domain *domain, unsigned long iova,
792+
phys_addr_t paddr, size_t pgsize, size_t pgcount,
793+
int prot, gfp_t gfp, size_t *mapped)
793794
{
794795
int ret;
795796
u32 flags;
797+
size_t size = pgsize * pgcount;
796798
u64 end = iova + size - 1;
797799
struct virtio_iommu_req_map map;
798800
struct viommu_domain *vdomain = to_viommu_domain(domain);
@@ -823,17 +825,21 @@ static int viommu_map(struct iommu_domain *domain, unsigned long iova,
823825
ret = viommu_send_req_sync(vdomain->viommu, &map, sizeof(map));
824826
if (ret)
825827
viommu_del_mappings(vdomain, iova, end);
828+
else if (mapped)
829+
*mapped = size;
826830

827831
return ret;
828832
}
829833

830-
static size_t viommu_unmap(struct iommu_domain *domain, unsigned long iova,
831-
size_t size, struct iommu_iotlb_gather *gather)
834+
static size_t viommu_unmap_pages(struct iommu_domain *domain, unsigned long iova,
835+
size_t pgsize, size_t pgcount,
836+
struct iommu_iotlb_gather *gather)
832837
{
833838
int ret = 0;
834839
size_t unmapped;
835840
struct virtio_iommu_req_unmap unmap;
836841
struct viommu_domain *vdomain = to_viommu_domain(domain);
842+
size_t size = pgsize * pgcount;
837843

838844
unmapped = viommu_del_mappings(vdomain, iova, iova + size - 1);
839845
if (unmapped < size)
@@ -1018,8 +1024,8 @@ static struct iommu_ops viommu_ops = {
10181024
.owner = THIS_MODULE,
10191025
.default_domain_ops = &(const struct iommu_domain_ops) {
10201026
.attach_dev = viommu_attach_dev,
1021-
.map = viommu_map,
1022-
.unmap = viommu_unmap,
1027+
.map_pages = viommu_map_pages,
1028+
.unmap_pages = viommu_unmap_pages,
10231029
.iova_to_phys = viommu_iova_to_phys,
10241030
.iotlb_sync = viommu_iotlb_sync,
10251031
.free = viommu_domain_free,

0 commit comments

Comments
 (0)