Skip to content

Commit afad94a

Browse files
rmurphy-armjoergroedel
authored andcommitted
iommu: Improve map/unmap sanity checks
The current checks for the __IOMMU_DOMAIN_PAGING capability seem a bit stifled, since it is quite likely now that a non-paging domain won't have a pgsize_bitmap and/or mapping ops, and thus get caught by the earlier condition anyway. Swap them around to test the more fundamental condition first, then we can reasonably also upgrade the other to a WARN_ON, since if a driver does ever expose a paging domain without the means to actually page, it's clearly very broken. Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/524db1ec0139c964d26928a6a264945aa66d010c.1694525662.git.robin.murphy@arm.com Signed-off-by: Joerg Roedel <[email protected]>
1 parent bd111e9 commit afad94a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/iommu/iommu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,12 +2519,12 @@ static int __iommu_map(struct iommu_domain *domain, unsigned long iova,
25192519
phys_addr_t orig_paddr = paddr;
25202520
int ret = 0;
25212521

2522-
if (unlikely(!ops->map_pages || domain->pgsize_bitmap == 0UL))
2523-
return -ENODEV;
2524-
25252522
if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
25262523
return -EINVAL;
25272524

2525+
if (WARN_ON(!ops->map_pages || domain->pgsize_bitmap == 0UL))
2526+
return -ENODEV;
2527+
25282528
/* find out the minimum page size supported */
25292529
min_pagesz = 1 << __ffs(domain->pgsize_bitmap);
25302530

@@ -2602,10 +2602,10 @@ static size_t __iommu_unmap(struct iommu_domain *domain,
26022602
unsigned long orig_iova = iova;
26032603
unsigned int min_pagesz;
26042604

2605-
if (unlikely(!ops->unmap_pages || domain->pgsize_bitmap == 0UL))
2605+
if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
26062606
return 0;
26072607

2608-
if (unlikely(!(domain->type & __IOMMU_DOMAIN_PAGING)))
2608+
if (WARN_ON(!ops->unmap_pages || domain->pgsize_bitmap == 0UL))
26092609
return 0;
26102610

26112611
/* find out the minimum page size supported */

0 commit comments

Comments
 (0)