[PATCH 4.4 069/138] iommu/amd: Init unity mappings only for dma_ops domains

From: Greg Kroah-Hartman
Date: Thu Aug 18 2016 - 10:03:44 EST


4.4-stable review patch. If anyone has any objections, please let me know.

------------------

From: Joerg Roedel <jroedel@xxxxxxx>

commit b548e786ce47017107765bbeb0f100202525ea83 upstream.

The default domain for a device might also be
identity-mapped. In this case the kernel would crash when
unity mappings are defined for the device. Fix that by
making sure the domain is a dma_ops domain.

Fixes: 0bb6e243d7fb ('iommu/amd: Support IOMMU_DOMAIN_DMA type allocation')
Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/iommu/amd_iommu.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -352,9 +352,11 @@ static void init_iommu_group(struct devi
if (!domain)
goto out;

- dma_domain = to_pdomain(domain)->priv;
+ if (to_pdomain(domain)->flags == PD_DMA_OPS_MASK) {
+ dma_domain = to_pdomain(domain)->priv;
+ init_unity_mappings_for_device(dev, dma_domain);
+ }

- init_unity_mappings_for_device(dev, dma_domain);
out:
iommu_group_put(group);
}