iommu/arm-smmu: Fixed for 4.6
cover iommu/arm-smmu: Fixed for 4.6
Hi Joerg,
Please can you take these two related arm-smmu fixes for 4.6? They address a regression seem by both Eric and Yang following the partial support for default domains that we added during the merge window.
I can send a pull request if you prefer, but it doesn't seem necessary to me.
Thanks!
Will
--->8
Robin Murphy (1):
iommu/arm-smmu: Don't allocate resources for bypass domains
Will Deacon (1):
iommu/arm-smmu: Fix stream-match conflict with IOMMU_DOMAIN_DMA
drivers/iommu/arm-smmu.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/2 iommu/arm-smmu: Fix stream-match conflict with IOMMU_DOMAIN_DMA
Commit cbf8277ef456 ("iommu/arm-smmu: Treat IOMMU_DOMAIN_DMA as bypass for now") ignores requests to attach a device to the default domain since, without IOMMU-basked DMA ops available everywhere, the default domain will just lead to unexpected transaction faults being reported.
Unfortunately, the way this was implemented on SMMUv2 causes a regression with VFIO PCI device passthrough under KVM on AMD Seattle. On this system, the host controller device is associated with both a pci_dev *and* a platform_device, and can therefore end up with duplicate SMR entries, resulting in a stream-match conflict at runtime.
This patch amends the original fix so that attaching to IOMMU_DOMAIN_DMA is rejected even before configuring the SMRs. This restores the old behaviour for now, but we'll need to look at handing host controllers specially when we come to supporting the default domain fully.
--- drivers/iommu/arm-smmu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/iommu/arm-smmu.c +8 -6
@@ -1089,18 +1089,20 @@ static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,struct arm_smmu_device *smmu = smmu_domain->smmu;void __iomem *gr0_base =ARM_SMMU_GR0 (smmu); -/* Devices in an IOMMU group may already be configured */ - ret =arm_smmu_master_configure_smrs (smmu, cfg); -if (ret) -return ret == -EEXIST ?0 : ret; -/* * FIXME: This won't be needed once we have IOMMU-backed DMA ops -* for all devices behind the SMMU. +* for all devices behind the SMMU. Note that we need to take +* care configuring SMRs for devices both a platform_device and +* and a PCI device (i.e. a PCI host controller) */ if (smmu_domain->domain.type ==IOMMU_DOMAIN_DMA )return 0 ; +/* Devices in an IOMMU group may already be configured */ + ret =arm_smmu_master_configure_smrs (smmu, cfg); +if (ret) +return ret == -EEXIST ?0 : ret; +for (i =0 ; i < cfg->num_streamids; ++i) {u32 idx, s2cr;
Signature · 1 line
2.1.4
PATCH 2/2 iommu/arm-smmu: Don't allocate resources for bypass domains
In reply to Will DeaconFrom: Robin Murphy <[email protected]>
Until we get fully plumbed into of_iommu_configure, our default IOMMU_DOMAIN_DMA domains just bypass translation. Since we achieve that by leaving the stream table entries set to bypass instead of pointing at a translation context, the context bank we allocate for the domain is completely wasted. Context banks are typically a rather limited resource, so don't hog ones we don't need.
--- drivers/iommu/arm-smmu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/iommu/arm-smmu.c +7 -1
@@ -826,6 +826,12 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,if (smmu_domain->smmu) goto out_unlock; +/* We're bypassing these SIDs, so don't allocate an actual context */ +if (domain->type ==IOMMU_DOMAIN_DMA ) { + smmu_domain->smmu = smmu; + goto out_unlock; + } +/* * Mapping the requested stage onto what we support is surprisingly * complicated, mainly because the spec allows S1+S2 SMMUs without
@@ -948,7 +954,7 @@ static void arm_smmu_destroy_domain_context(struct iommu_domain *domain)void __iomem *cb_base;int irq; -if (!smmu) +if (!smmu || domain->type ==IOMMU_DOMAIN_DMA )return ;/*
Signature · 1 line
2.1.4
cover iommu/arm-smmu: Fixed for 4.6
In reply to Will DeaconQuoted 8 lines · Will Deacon
Hi Joerg,
Please can you take these two related arm-smmu fixes for 4.6? They address a regression seem by both Eric and Yang following the partial support for default domains that we added during the merge window.
I can send a pull request if you prefer, but it doesn't seem necessary to me.
Sure, applied both. Thanks Will.
Joerg