Skip to content

Commit cc8d89d

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu/dma: Fix domain init
Despite carefully rewording the kerneldoc to describe the new direct interaction with dma_range_map, it seems I managed to confuse myself in removing the redundant force_aperture check and ended up making the code not do that at all. This led to dma_range_maps inadvertently being able to set iovad->start_pfn = 0, and all the nonsensical chaos which ensues from there. Restore the correct behaviour of constraining base_pfn to the domain aperture regardless of dma_range_map, and not trying to apply dma_range_map constraints to the basic IOVA domain since they will be properly handled with reserved regions later. Reported-by: Jon Hunter <[email protected]> Reported-by: Jerry Snitselaar <[email protected]> Fixes: ad4750b ("iommu/dma: Make limit checks self-contained") Signed-off-by: Robin Murphy <[email protected]> Tested-by: Jerry Snitselaar <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Link: https://lore.kernel.org/r/721fa6baebb0924aa40db0b8fb86bcb4538434af.1716232484.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent a295ec5 commit cc8d89d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,15 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, struct device *dev
686686

687687
/* Check the domain allows at least some access to the device... */
688688
if (map) {
689-
dma_addr_t base = dma_range_map_min(map);
690-
if (base > domain->geometry.aperture_end ||
689+
if (dma_range_map_min(map) > domain->geometry.aperture_end ||
691690
dma_range_map_max(map) < domain->geometry.aperture_start) {
692691
pr_warn("specified DMA range outside IOMMU capability\n");
693692
return -EFAULT;
694693
}
695-
/* ...then finally give it a kicking to make sure it fits */
696-
base_pfn = max(base, domain->geometry.aperture_start) >> order;
697694
}
695+
/* ...then finally give it a kicking to make sure it fits */
696+
base_pfn = max_t(unsigned long, base_pfn,
697+
domain->geometry.aperture_start >> order);
698698

699699
/* start_pfn is always nonzero for an already-initialised domain */
700700
mutex_lock(&cookie->mutex);

0 commit comments

Comments
 (0)