linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] DMA teardown fixes
@ 2015-01-14 19:13 Will Deacon
  2015-01-14 19:13 ` [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction Will Deacon
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Will Deacon @ 2015-01-14 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

Hi again,

Here's v2 of the DMA teardown fixes I posted on Monday:

  http://lists.infradead.org/pipermail/linux-arm-kernel/2015-January/315366.html

The only change since v1 is that I've moved the conversion to using
to_dma_iommu_mapping into a separate patch and converted the whole of
dma-mapping.c in the process (suggested by Laurent).

I plan to send patches 2 and 3 via rmk and I hope that arm-soc can pick
up the first one.

Will

--->8

Will Deacon (3):
  of/platform: teardown DMA mappings on device destruction
  ARM: dma-mapping: don't detach devices without an IOMMU during
    teardown
  ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing
    archdata

 arch/arm/mm/dma-mapping.c | 25 ++++++++++++++-----------
 drivers/of/platform.c     |  1 +
 2 files changed, 15 insertions(+), 11 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction
  2015-01-14 19:13 [PATCH v2 0/3] DMA teardown fixes Will Deacon
@ 2015-01-14 19:13 ` Will Deacon
  2015-01-14 19:53   ` Rob Herring
  2015-01-14 19:13 ` [PATCH v2 2/3] ARM: dma-mapping: don't detach devices without an IOMMU during teardown Will Deacon
  2015-01-14 19:13 ` [PATCH v2 3/3] ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing archdata Will Deacon
  2 siblings, 1 reply; 5+ messages in thread
From: Will Deacon @ 2015-01-14 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

Now that we can create and attach to IOMMU domains via of_dma_configure,
make sure we give the architecture a chance to tear them down when a
platform or amba device is destroyed.

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 drivers/of/platform.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 5b33c6a21807..3f61d668ded7 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -526,6 +526,7 @@ static int of_platform_device_destroy(struct device *dev, void *data)
 		amba_device_unregister(to_amba_device(dev));
 #endif
 
+	of_dma_deconfigure(dev);
 	of_node_clear_flag(dev->of_node, OF_POPULATED);
 	of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
 	return 0;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] ARM: dma-mapping: don't detach devices without an IOMMU during teardown
  2015-01-14 19:13 [PATCH v2 0/3] DMA teardown fixes Will Deacon
  2015-01-14 19:13 ` [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction Will Deacon
@ 2015-01-14 19:13 ` Will Deacon
  2015-01-14 19:13 ` [PATCH v2 3/3] ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing archdata Will Deacon
  2 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2015-01-14 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

When tearing down the DMA ops for a device via of_dma_deconfigure, we
unconditionally detach the device from its IOMMU domain. For devices
that aren't actually behind an IOMMU, this produces a "Not attached"
warning message on the console.

This patch changes the teardown code so that we don't detach from the
IOMMU domain when there isn't an IOMMU dma mapping to start with.

Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/mm/dma-mapping.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 7864797609b3..f142ddd6c40a 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -2025,6 +2025,9 @@ static void arm_teardown_iommu_dma_ops(struct device *dev)
 {
 	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
 
+	if (!mapping)
+		return;
+
 	arm_iommu_detach_device(dev);
 	arm_iommu_release_mapping(mapping);
 }
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing archdata
  2015-01-14 19:13 [PATCH v2 0/3] DMA teardown fixes Will Deacon
  2015-01-14 19:13 ` [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction Will Deacon
  2015-01-14 19:13 ` [PATCH v2 2/3] ARM: dma-mapping: don't detach devices without an IOMMU during teardown Will Deacon
@ 2015-01-14 19:13 ` Will Deacon
  2 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2015-01-14 19:13 UTC (permalink / raw)
  To: linux-arm-kernel

When using the IOMMU-backed DMA ops for a device, we store a pointer to
the dma_iommu_mapping structure (used to keep track of the address
space) in the archdata.mapping field of the struct device.

Rather than access this field directly, use the to_dma_iommu_mapping
helper in dma-mapping, so that we don't really care where the mapping
information is held.

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
---
 arch/arm/mm/dma-mapping.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index f142ddd6c40a..4dab38fea608 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1206,7 +1206,7 @@ __iommu_alloc_remap(struct page **pages, size_t size, gfp_t gfp, pgprot_t prot,
 static dma_addr_t
 __iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
 	dma_addr_t dma_addr, iova;
 	int i, ret = DMA_ERROR_CODE;
@@ -1242,7 +1242,7 @@ fail:
 
 static int __iommu_remove_mapping(struct device *dev, dma_addr_t iova, size_t size)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 
 	/*
 	 * add optional in-page offset from iova to size and align
@@ -1457,7 +1457,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
 			  enum dma_data_direction dir, struct dma_attrs *attrs,
 			  bool is_coherent)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t iova, iova_base;
 	int ret = 0;
 	unsigned int count;
@@ -1678,7 +1678,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
 	     unsigned long offset, size_t size, enum dma_data_direction dir,
 	     struct dma_attrs *attrs)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t dma_addr;
 	int ret, prot, len = PAGE_ALIGN(size + offset);
 
@@ -1731,7 +1731,7 @@ static void arm_coherent_iommu_unmap_page(struct device *dev, dma_addr_t handle,
 		size_t size, enum dma_data_direction dir,
 		struct dma_attrs *attrs)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t iova = handle & PAGE_MASK;
 	int offset = handle & ~PAGE_MASK;
 	int len = PAGE_ALIGN(size + offset);
@@ -1756,7 +1756,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle,
 		size_t size, enum dma_data_direction dir,
 		struct dma_attrs *attrs)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t iova = handle & PAGE_MASK;
 	struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova));
 	int offset = handle & ~PAGE_MASK;
@@ -1775,7 +1775,7 @@ static void arm_iommu_unmap_page(struct device *dev, dma_addr_t handle,
 static void arm_iommu_sync_single_for_cpu(struct device *dev,
 		dma_addr_t handle, size_t size, enum dma_data_direction dir)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t iova = handle & PAGE_MASK;
 	struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova));
 	unsigned int offset = handle & ~PAGE_MASK;
@@ -1789,7 +1789,7 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev,
 static void arm_iommu_sync_single_for_device(struct device *dev,
 		dma_addr_t handle, size_t size, enum dma_data_direction dir)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 	dma_addr_t iova = handle & PAGE_MASK;
 	struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova));
 	unsigned int offset = handle & ~PAGE_MASK;
@@ -1960,7 +1960,7 @@ int arm_iommu_attach_device(struct device *dev,
 		return err;
 
 	kref_get(&mapping->kref);
-	dev->archdata.mapping = mapping;
+	to_dma_iommu_mapping(dev) = mapping;
 
 	pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev));
 	return 0;
@@ -1985,7 +1985,7 @@ void arm_iommu_detach_device(struct device *dev)
 
 	iommu_detach_device(mapping->domain, dev);
 	kref_put(&mapping->kref, release_iommu_mapping);
-	dev->archdata.mapping = NULL;
+	to_dma_iommu_mapping(dev) = NULL;
 
 	pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev));
 }
@@ -2023,7 +2023,7 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
 
 static void arm_teardown_iommu_dma_ops(struct device *dev)
 {
-	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
+	struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
 
 	if (!mapping)
 		return;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction
  2015-01-14 19:13 ` [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction Will Deacon
@ 2015-01-14 19:53   ` Rob Herring
  0 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2015-01-14 19:53 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jan 14, 2015 at 1:13 PM, Will Deacon <will.deacon@arm.com> wrote:
> Now that we can create and attach to IOMMU domains via of_dma_configure,
> make sure we give the architecture a chance to tear them down when a
> platform or amba device is destroyed.
>
> Reported-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Will Deacon <will.deacon@arm.com>

Acked-by: Rob Herring <robh@kernel.org>

> ---
>  drivers/of/platform.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 5b33c6a21807..3f61d668ded7 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -526,6 +526,7 @@ static int of_platform_device_destroy(struct device *dev, void *data)
>                 amba_device_unregister(to_amba_device(dev));
>  #endif
>
> +       of_dma_deconfigure(dev);
>         of_node_clear_flag(dev->of_node, OF_POPULATED);
>         of_node_clear_flag(dev->of_node, OF_POPULATED_BUS);
>         return 0;
> --
> 2.1.4
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-01-14 19:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-14 19:13 [PATCH v2 0/3] DMA teardown fixes Will Deacon
2015-01-14 19:13 ` [PATCH v2 1/3] of/platform: teardown DMA mappings on device destruction Will Deacon
2015-01-14 19:53   ` Rob Herring
2015-01-14 19:13 ` [PATCH v2 2/3] ARM: dma-mapping: don't detach devices without an IOMMU during teardown Will Deacon
2015-01-14 19:13 ` [PATCH v2 3/3] ARM: dma-mapping: use to_dma_iommu_mapping instead of accessing archdata Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).