Skip to content

Commit 11c439a

Browse files
hegdevasantjoergroedel
authored andcommitted
iommu/amd/pgtbl_v2: Fix domain max address
IOMMU v2 page table supports 4 level (47 bit) or 5 level (56 bit) virtual address space. Current code assumes it can support 64bit IOVA address space. If IOVA allocator allocates virtual address > 47/56 bit (depending on page table level) then it will do wrong mapping and cause invalid translation. Hence adjust aperture size to use max address supported by the page table. Reported-by: Jerry Snitselaar <[email protected]> Fixes: aaac38f ("iommu/amd: Initial support for AMD IOMMU v2 page table") Cc: <[email protected]> # v6.0+ Cc: Suravee Suthikulpanit <[email protected]> Signed-off-by: Vasant Hegde <[email protected]> Reviewed-by: Jerry Snitselaar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 2212fc2 commit 11c439a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,6 +2129,15 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
21292129
return NULL;
21302130
}
21312131

2132+
static inline u64 dma_max_address(void)
2133+
{
2134+
if (amd_iommu_pgtable == AMD_IOMMU_V1)
2135+
return ~0ULL;
2136+
2137+
/* V2 with 4/5 level page table */
2138+
return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);
2139+
}
2140+
21322141
static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
21332142
{
21342143
struct protection_domain *domain;
@@ -2145,7 +2154,7 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type)
21452154
return NULL;
21462155

21472156
domain->domain.geometry.aperture_start = 0;
2148-
domain->domain.geometry.aperture_end = ~0ULL;
2157+
domain->domain.geometry.aperture_end = dma_max_address();
21492158
domain->domain.geometry.force_aperture = true;
21502159

21512160
return &domain->domain;

0 commit comments

Comments
 (0)