Skip to content

Commit 8f880d1

Browse files
snitsjoergroedel
authored andcommitted
iommu/amd: Set page size bitmap during V2 domain allocation
With the addition of the V2 page table support, the domain page size bitmap needs to be set prior to iommu core setting up direct mappings for reserved regions. When reserved regions are mapped, if this is not done, it will be looking at the V1 page size bitmap when determining the page size to use in iommu_pgsize(). When it gets into the actual amd mapping code, a check of see if the page size is supported can fail, because at that point it is checking it against the V2 page size bitmap which only supports 4K, 2M, and 1G. Add a check to __iommu_domain_alloc() to not override the bitmap if it was already set by the iommu ops domain_alloc() code path. Cc: Vasant Hegde <vasant.hegde@amd.com> Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Cc: Robin Murphy <robin.murphy@arm.com> Cc: Will Deacon <will@kernel.org> Cc: Joerg Roedel <joro@8bytes.org> Fixes: 4db6c41 ("iommu/amd: Add support for using AMD IOMMU v2 page table for DMA-API") Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Link: https://lore.kernel.org/r/20230404072742.1895252-1-jsnitsel@redhat.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 09a9639 commit 8f880d1

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

drivers/iommu/amd/iommu.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,10 +1666,6 @@ static void do_attach(struct iommu_dev_data *dev_data,
16661666
domain->dev_iommu[iommu->index] += 1;
16671667
domain->dev_cnt += 1;
16681668

1669-
/* Override supported page sizes */
1670-
if (domain->flags & PD_GIOV_MASK)
1671-
domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
1672-
16731669
/* Update device table */
16741670
set_dte_entry(iommu, dev_data->devid, domain,
16751671
ats, dev_data->iommu_v2);
@@ -2048,6 +2044,8 @@ static int protection_domain_init_v2(struct protection_domain *domain)
20482044

20492045
domain->flags |= PD_GIOV_MASK;
20502046

2047+
domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
2048+
20512049
if (domain_enable_v2(domain, 1)) {
20522050
domain_id_free(domain->id);
20532051
return -ENOMEM;

drivers/iommu/iommu.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,8 +1964,13 @@ static struct iommu_domain *__iommu_domain_alloc(struct bus_type *bus,
19641964
return NULL;
19651965

19661966
domain->type = type;
1967-
/* Assume all sizes by default; the driver may override this later */
1968-
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
1967+
/*
1968+
* If not already set, assume all sizes by default; the driver
1969+
* may override this later
1970+
*/
1971+
if (!domain->pgsize_bitmap)
1972+
domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap;
1973+
19691974
if (!domain->ops)
19701975
domain->ops = bus->iommu_ops->default_domain_ops;
19711976

0 commit comments

Comments
 (0)