| From e6378f334e411675a80aaa4cbea7ee5c9309d1a9 Mon Sep 17 00:00:00 2001 |
| From: Robin Murphy <robin.murphy@arm.com> |
| Date: Fri, 13 Oct 2017 19:23:40 +0100 |
| Subject: [PATCH 0096/1795] iommu/ipmmu-vmsa: Simplify group allocation |
| |
| We go through quite the merry dance in order to find masters behind the |
| same IPMMU instance, so that we can ensure they are grouped together. |
| None of which is really necessary, since the master's private data |
| already points to the particular IPMMU it is associated with, and that |
| IPMMU instance data is the perfect place to keep track of a per-instance |
| group directly. |
| |
| Signed-off-by: Robin Murphy <robin.murphy@arm.com> |
| Signed-off-by: Alex Williamson <alex.williamson@redhat.com> |
| (cherry picked from commit b354c73edc7eb8d6ee643866e9e4de7842213b06) |
| Signed-off-by: Simon Horman <horms+renesas@verge.net.au> |
| Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> |
| --- |
| drivers/iommu/ipmmu-vmsa.c | 53 +++++++------------------------------- |
| 1 file changed, 9 insertions(+), 44 deletions(-) |
| |
| diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c |
| index 1f4df07eda06..6ef16b7d803c 100644 |
| --- a/drivers/iommu/ipmmu-vmsa.c |
| +++ b/drivers/iommu/ipmmu-vmsa.c |
| @@ -43,6 +43,7 @@ struct ipmmu_vmsa_device { |
| DECLARE_BITMAP(ctx, IPMMU_CTX_MAX); |
| struct ipmmu_vmsa_domain *domains[IPMMU_CTX_MAX]; |
| |
| + struct iommu_group *group; |
| struct dma_iommu_mapping *mapping; |
| }; |
| |
| @@ -59,8 +60,6 @@ struct ipmmu_vmsa_domain { |
| |
| struct ipmmu_vmsa_iommu_priv { |
| struct ipmmu_vmsa_device *mmu; |
| - struct device *dev; |
| - struct list_head list; |
| }; |
| |
| static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) |
| @@ -673,7 +672,6 @@ static int ipmmu_init_platform_device(struct device *dev, |
| return -ENOMEM; |
| |
| priv->mmu = platform_get_drvdata(ipmmu_pdev); |
| - priv->dev = dev; |
| dev->iommu_fwspec->iommu_priv = priv; |
| return 0; |
| } |
| @@ -789,9 +787,6 @@ static const struct iommu_ops ipmmu_ops = { |
| |
| #ifdef CONFIG_IOMMU_DMA |
| |
| -static DEFINE_SPINLOCK(ipmmu_slave_devices_lock); |
| -static LIST_HEAD(ipmmu_slave_devices); |
| - |
| static int ipmmu_add_device_dma(struct device *dev) |
| { |
| struct iommu_group *group; |
| @@ -806,55 +801,25 @@ static int ipmmu_add_device_dma(struct device *dev) |
| if (IS_ERR(group)) |
| return PTR_ERR(group); |
| |
| - spin_lock(&ipmmu_slave_devices_lock); |
| - list_add(&to_priv(dev)->list, &ipmmu_slave_devices); |
| - spin_unlock(&ipmmu_slave_devices_lock); |
| return 0; |
| } |
| |
| static void ipmmu_remove_device_dma(struct device *dev) |
| { |
| - struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); |
| - |
| - spin_lock(&ipmmu_slave_devices_lock); |
| - list_del(&priv->list); |
| - spin_unlock(&ipmmu_slave_devices_lock); |
| - |
| iommu_group_remove_device(dev); |
| } |
| |
| -static struct device *ipmmu_find_sibling_device(struct device *dev) |
| +static struct iommu_group *ipmmu_find_group(struct device *dev) |
| { |
| struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); |
| - struct ipmmu_vmsa_iommu_priv *sibling_priv = NULL; |
| - bool found = false; |
| - |
| - spin_lock(&ipmmu_slave_devices_lock); |
| - |
| - list_for_each_entry(sibling_priv, &ipmmu_slave_devices, list) { |
| - if (priv == sibling_priv) |
| - continue; |
| - if (sibling_priv->mmu == priv->mmu) { |
| - found = true; |
| - break; |
| - } |
| - } |
| - |
| - spin_unlock(&ipmmu_slave_devices_lock); |
| - |
| - return found ? sibling_priv->dev : NULL; |
| -} |
| - |
| -static struct iommu_group *ipmmu_find_group_dma(struct device *dev) |
| -{ |
| struct iommu_group *group; |
| - struct device *sibling; |
| |
| - sibling = ipmmu_find_sibling_device(dev); |
| - if (sibling) |
| - group = iommu_group_get(sibling); |
| - if (!sibling || !group) |
| - group = generic_device_group(dev); |
| + if (priv->mmu->group) |
| + return iommu_group_ref_get(priv->mmu->group); |
| + |
| + group = iommu_group_alloc(); |
| + if (!IS_ERR(group)) |
| + priv->mmu->group = group; |
| |
| return group; |
| } |
| @@ -872,7 +837,7 @@ static const struct iommu_ops ipmmu_ops = { |
| .iova_to_phys = ipmmu_iova_to_phys, |
| .add_device = ipmmu_add_device_dma, |
| .remove_device = ipmmu_remove_device_dma, |
| - .device_group = ipmmu_find_group_dma, |
| + .device_group = ipmmu_find_group, |
| .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, |
| .of_xlate = ipmmu_of_xlate, |
| }; |
| -- |
| 2.19.0 |
| |