Skip to contentSkip to conversation

iommu/amd: Do not identity map v2 capable device when snp is enabled

PATCH In review Vasant Hegde 2 participants 3 messages Feb 7, 2023 – Feb 17, 2023

Subsystems (2)
lore
Share & tools
lore

Vasant Hegde

author maintainer
#0 lore raw

PATCH 1/1 iommu/amd: Do not identity map v2 capable device when snp is enabled

Flow:
- Booted system with SNP enabled, memory encryption off and IOMMU DMA translation mode
- AMD driver detects v2 capable device and amd_iommu_def_domain_type() returns identity mode
- amd_iommu_domain_alloc() returns NULL an SNP is enabled
- System will fail to register device

On SNP enabled system, passthrough mode is not supported. IOMMU default domain is set to translation mode. We need to return zero from amd_iommu_def_domain_type() so that it allocates translation domain.

Fixes fb2accadaa942 (iommu/amd: Introduce function to check and enable SNP)
CC Suravee Suthikulpanit <[email protected]>
---
 drivers/iommu/amd/iommu.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/iommu/amd/iommu.c +9 -4
index 0b011a97e20d..3186e0dd8b2b 100644
@@ -2401,12 +2401,17 @@ static int amd_iommu_def_domain_type(struct device *dev)
 		return 0;
 
 	/*
-	 * Do not identity map IOMMUv2 capable devices when memory encryption is
-	 * active, because some of those devices (AMD GPUs) don't have the
-	 * encryption bit in their DMA-mask and require remapping.
+	 * Do not identity map IOMMUv2 capable devices when:
+	 *  - memory encryption is active, because some of those devices
+	 *    (AMD GPUs) don't have the encryption bit in their DMA-mask
+	 *    and require remapping.
+	 *  - SNP is enabled, because it prohibits DTE[Mode]=0.
 	 */
-	if (!cc_platform_has(CC_ATTR_MEM_ENCRYPT) && dev_data->iommu_v2)
+	if (dev_data->iommu_v2 &&
+	    !cc_platform_has(CC_ATTR_MEM_ENCRYPT) &&
+	    !amd_iommu_snp_en) {
 		return IOMMU_DOMAIN_IDENTITY;
+	}
 
 	return 0;
 }
Signature · 1 line
2.31.1
maintainer
#1 lore raw

Hi Vasant,

Quoted 2 lines · Vasant Hegde
 drivers/iommu/amd/iommu.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Applied and fixed a checkpatch warning. Please use check-patch in the future before submitting.

Regards,

Joerg

author maintainer
#2 lore raw

Joerg,

Quoted 8 lines · Joerg Roedel

Hi Vasant,

Quoted 2 lines · Vasant Hegde
 drivers/iommu/amd/iommu.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Applied and fixed a checkpatch warning. Please use check-patch in the future before submitting.

Sure. Thank you.

-Vasant