Skip to contentSkip to conversation

iommu/amd: Add missing domain type checks

PATCH In review Jason Gunthorpe 4 participants 4 messages Apr 25, 2023 – May 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/amd: Add missing domain type checks

Drivers are supposed to list the domain types they support in their domain_alloc() ops so when we add new domain types, like BLOCKING or SVA, they don't start breaking.

This ended up providing an empty UNMANAGED domain when the core code asked for a BLOCKING domain, which happens to be the fallback for drivers that don't support it, but this is completely wrong for SVA.

Check for the DMA types AMD supports and reject every other kind.

Fixes 136467962e49 ("iommu: Add IOMMU SVA domain support")
---
 drivers/iommu/amd/iommu.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/amd/iommu.c +5 -1
index c72a0173db2029..17ea44a79c7af9 100644
@@ -2067,7 +2067,7 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 {
 	struct io_pgtable_ops *pgtbl_ops;
 	struct protection_domain *domain;
-	int pgtable = amd_iommu_pgtable;
+	int pgtable;
 	int mode = DEFAULT_PGTABLE_LEVEL;
 	int ret;
 
@@ -2084,6 +2084,10 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
 		mode = PAGE_MODE_NONE;
 	} else if (type == IOMMU_DOMAIN_UNMANAGED) {
 		pgtable = AMD_IOMMU_V1;
+	} else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ) {
+		pgtable = amd_iommu_pgtable;
+	} else {
+		return NULL;
 	}
 
 	switch (pgtable) {

base-commit: 4f933b868392945c9b0e32b499b0bb39beab8a28

Signature · 1 line
2.40.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines

From: Jason Gunthorpe <[email protected]>
Sent: Wednesday, April 26, 2023 3:04 AM

Drivers are supposed to list the domain types they support in their domain_alloc() ops so when we add new domain types, like BLOCKING or SVA,
they don't start breaking.

This ended up providing an empty UNMANAGED domain when the core code asked
for a BLOCKING domain, which happens to be the fallback for drivers that don't support it, but this is completely wrong for SVA.

Quoted 4 lines

Check for the DMA types AMD supports and reject every other kind.

Fixes 136467962e49 ("iommu: Add IOMMU SVA domain support")
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Jason Gunthorpe
Quoted 4 lines · Jason Gunthorpe

Drivers are supposed to list the domain types they support in their domain_alloc() ops so when we add new domain types, like BLOCKING or SVA, they don't start breaking.

Quoted 8 lines

This ended up providing an empty UNMANAGED domain when the core code asked for a BLOCKING domain, which happens to be the fallback for drivers that don't support it, but this is completely wrong for SVA.

Check for the DMA types AMD supports and reject every other kind.

Fixes 136467962e49 ("iommu: Add IOMMU SVA domain support")

Thanks! Patch looks good to me.

-Vasant