Skip to content

Commit 07970d0

Browse files
jgunthorpeawilliam
authored andcommitted
vfio/type1: Remove Fine Grained Superpages detection
VFIO is looking to enable an optimization where it can rely on a fast unmap operation that returned the size of a larger IOPTE. Due to how the test was constructed this would only ever succeed on the AMDv1 page table that supported an 8k contiguous size. Nothing else supports this. Alex says the performance win was fairly minor, so lets remove this code. Always use iommu_iova_to_phys() to extent contiguous pages. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Link: https://lore.kernel.org/r/0-v2-97fa1da8d983+412-vfio_fgsp_jgg@nvidia.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent a5806cd commit 07970d0

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed

drivers/vfio/vfio_iommu_type1.c

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ struct vfio_domain {
8080
struct iommu_domain *domain;
8181
struct list_head next;
8282
struct list_head group_list;
83-
bool fgsp : 1; /* Fine-grained super pages */
8483
bool enforce_cache_coherency : 1;
8584
};
8685

@@ -1095,8 +1094,7 @@ static long vfio_unmap_unpin(struct vfio_iommu *iommu, struct vfio_dma *dma,
10951094
* may require hardware cache flushing, try to find the
10961095
* largest contiguous physical memory chunk to unmap.
10971096
*/
1098-
for (len = PAGE_SIZE;
1099-
!domain->fgsp && iova + len < end; len += PAGE_SIZE) {
1097+
for (len = PAGE_SIZE; iova + len < end; len += PAGE_SIZE) {
11001098
next = iommu_iova_to_phys(domain->domain, iova + len);
11011099
if (next != phys + len)
11021100
break;
@@ -1833,49 +1831,6 @@ static int vfio_iommu_replay(struct vfio_iommu *iommu,
18331831
return ret;
18341832
}
18351833

1836-
/*
1837-
* We change our unmap behavior slightly depending on whether the IOMMU
1838-
* supports fine-grained superpages. IOMMUs like AMD-Vi will use a superpage
1839-
* for practically any contiguous power-of-two mapping we give it. This means
1840-
* we don't need to look for contiguous chunks ourselves to make unmapping
1841-
* more efficient. On IOMMUs with coarse-grained super pages, like Intel VT-d
1842-
* with discrete 2M/1G/512G/1T superpages, identifying contiguous chunks
1843-
* significantly boosts non-hugetlbfs mappings and doesn't seem to hurt when
1844-
* hugetlbfs is in use.
1845-
*/
1846-
static void vfio_test_domain_fgsp(struct vfio_domain *domain, struct list_head *regions)
1847-
{
1848-
int ret, order = get_order(PAGE_SIZE * 2);
1849-
struct vfio_iova *region;
1850-
struct page *pages;
1851-
dma_addr_t start;
1852-
1853-
pages = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
1854-
if (!pages)
1855-
return;
1856-
1857-
list_for_each_entry(region, regions, list) {
1858-
start = ALIGN(region->start, PAGE_SIZE * 2);
1859-
if (start >= region->end || (region->end - start < PAGE_SIZE * 2))
1860-
continue;
1861-
1862-
ret = iommu_map(domain->domain, start, page_to_phys(pages), PAGE_SIZE * 2,
1863-
IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE,
1864-
GFP_KERNEL_ACCOUNT);
1865-
if (!ret) {
1866-
size_t unmapped = iommu_unmap(domain->domain, start, PAGE_SIZE);
1867-
1868-
if (unmapped == PAGE_SIZE)
1869-
iommu_unmap(domain->domain, start + PAGE_SIZE, PAGE_SIZE);
1870-
else
1871-
domain->fgsp = true;
1872-
}
1873-
break;
1874-
}
1875-
1876-
__free_pages(pages, order);
1877-
}
1878-
18791834
static struct vfio_iommu_group *find_iommu_group(struct vfio_domain *domain,
18801835
struct iommu_group *iommu_group)
18811836
{
@@ -2314,8 +2269,6 @@ static int vfio_iommu_type1_attach_group(void *iommu_data,
23142269
}
23152270
}
23162271

2317-
vfio_test_domain_fgsp(domain, &iova_copy);
2318-
23192272
/* replay mappings on new domains */
23202273
ret = vfio_iommu_replay(iommu, domain);
23212274
if (ret)

0 commit comments

Comments
 (0)