Skip to content

Commit 3aef9ca

Browse files
Jacob Panjoergroedel
authored andcommitted
iommu/vt-d: Use a helper function to skip agaw for SL
An Intel iommu domain uses 5-level page table by default. If the iommu that the domain tries to attach supports less page levels, the top level page tables should be skipped. Add a helper to do this so that it could be used in other places. Signed-off-by: Jacob Pan <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Eric Auger <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 3db9983 commit 3aef9ca

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

drivers/iommu/intel-pasid.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,25 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu,
499499
return 0;
500500
}
501501

502+
/*
503+
* Skip top levels of page tables for iommu which has less agaw
504+
* than default. Unnecessary for PT mode.
505+
*/
506+
static inline int iommu_skip_agaw(struct dmar_domain *domain,
507+
struct intel_iommu *iommu,
508+
struct dma_pte **pgd)
509+
{
510+
int agaw;
511+
512+
for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) {
513+
*pgd = phys_to_virt(dma_pte_addr(*pgd));
514+
if (!dma_pte_present(*pgd))
515+
return -EINVAL;
516+
}
517+
518+
return agaw;
519+
}
520+
502521
/*
503522
* Set up the scalable mode pasid entry for second only translation type.
504523
*/
@@ -522,17 +541,11 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu,
522541
return -EINVAL;
523542
}
524543

525-
/*
526-
* Skip top levels of page tables for iommu which has less agaw
527-
* than default. Unnecessary for PT mode.
528-
*/
529544
pgd = domain->pgd;
530-
for (agaw = domain->agaw; agaw > iommu->agaw; agaw--) {
531-
pgd = phys_to_virt(dma_pte_addr(pgd));
532-
if (!dma_pte_present(pgd)) {
533-
dev_err(dev, "Invalid domain page table\n");
534-
return -EINVAL;
535-
}
545+
agaw = iommu_skip_agaw(domain, iommu, &pgd);
546+
if (agaw < 0) {
547+
dev_err(dev, "Invalid domain page table\n");
548+
return -EINVAL;
536549
}
537550

538551
pgd_val = virt_to_phys(pgd);

0 commit comments

Comments
 (0)