Skip to content

Commit 33729a5

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/io-pgtable-arm: Remove split on unmap behavior
A minority of page table implementations (arm_lpae, armv7) are unique in how they handle partial unmap of large IOPTEs. Other implementations will unmap the large IOPTE and return it's length. For example if a 2M IOPTE is present and the first 4K is requested to be unmapped then unmap will remove the whole 2M and report 2M as the result. arm_lpae instead replaces the IOPTE with a table of smaller IOPTEs, unmaps the 4K and returns 4k. This is actually an illegal/non-hitless operation on at least SMMUv3 because of the BBM level 0 rules. Will says this was done to support VFIO, but upon deeper analysis this was never strictly necessary: https://lore.kernel.org/all/20241024134411.GA6956@nvidia.com/ In summary, historical VFIO supported the AMD behavior of unmapping the whole large IOPTE and returning the size, even if asked to unmap a portion. The driver would see this as a request to split a large IOPTE. Modern VFIO always unmaps entire large IOPTEs (except on AMD) and drivers don't see an IOPTE split. Given it doesn't work fully correctly on SMMUv3 and relying on ARM unique behavior would create portability problems across IOMMU drivers, retire this functionality. Outside the iommu users, this will potentially effect io_pgtable users of ARM_32_LPAE_S1, ARM_32_LPAE_S2, ARM_64_LPAE_S1, ARM_64_LPAE_S2, and ARM_MALI_LPAE formats. Cc: Boris Brezillon <boris.brezillon@collabora.com> Cc: Steven Price <steven.price@arm.com> Cc: Liviu Dudau <liviu.dudau@arm.com> Cc: dri-devel@lists.freedesktop.org Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/1-v3-b3a5b5937f56+7bb-arm_no_split_jgg@nvidia.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 896de2a commit 33729a5

File tree

1 file changed

+2
-79
lines changed

1 file changed

+2
-79
lines changed

drivers/iommu/io-pgtable-arm.c

Lines changed: 2 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -581,66 +581,6 @@ static void arm_lpae_free_pgtable(struct io_pgtable *iop)
581581
kfree(data);
582582
}
583583

584-
static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data,
585-
struct iommu_iotlb_gather *gather,
586-
unsigned long iova, size_t size,
587-
arm_lpae_iopte blk_pte, int lvl,
588-
arm_lpae_iopte *ptep, size_t pgcount)
589-
{
590-
struct io_pgtable_cfg *cfg = &data->iop.cfg;
591-
arm_lpae_iopte pte, *tablep;
592-
phys_addr_t blk_paddr;
593-
size_t tablesz = ARM_LPAE_GRANULE(data);
594-
size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data);
595-
int ptes_per_table = ARM_LPAE_PTES_PER_TABLE(data);
596-
int i, unmap_idx_start = -1, num_entries = 0, max_entries;
597-
598-
if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS))
599-
return 0;
600-
601-
tablep = __arm_lpae_alloc_pages(tablesz, GFP_ATOMIC, cfg, data->iop.cookie);
602-
if (!tablep)
603-
return 0; /* Bytes unmapped */
604-
605-
if (size == split_sz) {
606-
unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data);
607-
max_entries = arm_lpae_max_entries(unmap_idx_start, data);
608-
num_entries = min_t(int, pgcount, max_entries);
609-
}
610-
611-
blk_paddr = iopte_to_paddr(blk_pte, data);
612-
pte = iopte_prot(blk_pte);
613-
614-
for (i = 0; i < ptes_per_table; i++, blk_paddr += split_sz) {
615-
/* Unmap! */
616-
if (i >= unmap_idx_start && i < (unmap_idx_start + num_entries))
617-
continue;
618-
619-
__arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i]);
620-
}
621-
622-
pte = arm_lpae_install_table(tablep, ptep, blk_pte, data);
623-
if (pte != blk_pte) {
624-
__arm_lpae_free_pages(tablep, tablesz, cfg, data->iop.cookie);
625-
/*
626-
* We may race against someone unmapping another part of this
627-
* block, but anything else is invalid. We can't misinterpret
628-
* a page entry here since we're never at the last level.
629-
*/
630-
if (iopte_type(pte) != ARM_LPAE_PTE_TYPE_TABLE)
631-
return 0;
632-
633-
tablep = iopte_deref(pte, data);
634-
} else if (unmap_idx_start >= 0) {
635-
for (i = 0; i < num_entries; i++)
636-
io_pgtable_tlb_add_page(&data->iop, gather, iova + i * size, size);
637-
638-
return num_entries * size;
639-
}
640-
641-
return __arm_lpae_unmap(data, gather, iova, size, pgcount, lvl, tablep);
642-
}
643-
644584
static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
645585
struct iommu_iotlb_gather *gather,
646586
unsigned long iova, size_t size, size_t pgcount,
@@ -690,12 +630,8 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data,
690630

691631
return i * size;
692632
} else if (iopte_leaf(pte, lvl, iop->fmt)) {
693-
/*
694-
* Insert a table at the next level to map the old region,
695-
* minus the part we want to unmap
696-
*/
697-
return arm_lpae_split_blk_unmap(data, gather, iova, size, pte,
698-
lvl + 1, ptep, pgcount);
633+
WARN_ONCE(true, "Unmap of a partial large IOPTE is not allowed");
634+
return 0;
699635
}
700636

701637
/* Keep on walkin' */
@@ -1359,19 +1295,6 @@ static int __init arm_lpae_run_tests(struct io_pgtable_cfg *cfg)
13591295
iova += SZ_1G;
13601296
}
13611297

1362-
/* Partial unmap */
1363-
size = 1UL << __ffs(cfg->pgsize_bitmap);
1364-
if (ops->unmap_pages(ops, SZ_1G + size, size, 1, NULL) != size)
1365-
return __FAIL(ops, i);
1366-
1367-
/* Remap of partial unmap */
1368-
if (ops->map_pages(ops, SZ_1G + size, size, size, 1,
1369-
IOMMU_READ, GFP_KERNEL, &mapped))
1370-
return __FAIL(ops, i);
1371-
1372-
if (ops->iova_to_phys(ops, SZ_1G + size + 42) != (size + 42))
1373-
return __FAIL(ops, i);
1374-
13751298
/* Full unmap */
13761299
iova = 0;
13771300
for_each_set_bit(j, &cfg->pgsize_bitmap, BITS_PER_LONG) {

0 commit comments

Comments
 (0)