Skip to contentSkip to conversation

of/device: Update dma_range_map only when dev has valid dma-ranges

PATCH In review Yong Wu 5 participants 8 messages Jan 19, 2021 – Jan 27, 2021

Subsystems (2)
lore
Share & tools
lore

Yong Wu

author
#0 lore raw

PATCH v2 1/1 of/device: Update dma_range_map only when dev has valid dma-ranges

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
---
 drivers/of/device.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/of/device.c +7 -3
index aedfaaafd3e7..1122daa8e273 100644
@@ -162,9 +162,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 	mask = DMA_BIT_MASK(ilog2(end) + 1);
 	dev->coherent_dma_mask &= mask;
 	*dev->dma_mask &= mask;
-	/* ...but only set bus limit if we found valid dma-ranges earlier */
-	if (!ret)
+	/* ...but only set bus limit and range map if we found valid dma-ranges earlier */
+	if (!ret) {
 		dev->bus_dma_limit = end;
+		dev->dma_range_map = map;
+	}
 
 	coherent = of_dma_is_coherent(np);
 	dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	iommu = of_iommu_configure(dev, np, id);
 	if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+		/* Don't touch range map if it wasn't set from a valid dma-ranges */
+		if (!ret)
+			dev->dma_range_map = NULL;
 		kfree(map);
 		return -EPROBE_DEFER;
 	}
@@ -181,7 +186,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
-	dev->dma_range_map = map;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
Signature · 6 lines
2.18.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#1 lore raw

Hi,

Quoted 9 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

Just a gentle ping on this issue, it would be nice to have this fix merged ASAP, in the next RC :)

Cheers,

Paul

Quoted 52 lines

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
---
 drivers/of/device.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/of/device.c +7 -3
index aedfaaafd3e7..1122daa8e273 100644
@@ -162,9 +162,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 	mask = DMA_BIT_MASK(ilog2(end) + 1);
 	dev->coherent_dma_mask &= mask;
 	*dev->dma_mask &= mask;
-	/* ...but only set bus limit if we found valid dma-ranges earlier */
-	if (!ret)
+	/* ...but only set bus limit and range map if we found valid dma-ranges earlier */
+	if (!ret) {
 		dev->bus_dma_limit = end;
+		dev->dma_range_map = map;
+	}
 
 	coherent = of_dma_is_coherent(np);
 	dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	iommu = of_iommu_configure(dev, np, id);
 	if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+		/* Don't touch range map if it wasn't set from a valid dma-ranges */
+		if (!ret)
+			dev->dma_range_map = NULL;
 		kfree(map);
 		return -EPROBE_DEFER;
 	}
@@ -181,7 +186,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
 	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
-	dev->dma_range_map = map;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
Signature · 1 line
2.18.0
Signature · 3 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#2 lore raw

[ + Christoph, Marek ]

Quoted 8 lines · Paul Kocialkowski

Hi,

Quoted 5 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Quoted 7 lines
Quoted 4 lines

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

Just a gentle ping on this issue, it would be nice to have this fix merged ASAP, in the next RC :)

Ack to that - Rob, Frank, do you want to take this through the OF tree, or shall we take it through the DMA-mapping tree like the original culprit?

Thanks,
Robin.

Quoted 50 lines

Cheers,

Paul

Quoted 45 lines

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
---
  drivers/of/device.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/of/device.c +7 -2
index aedfaaafd3e7..1122daa8e273 100644
@@ -162,9 +162,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
  	mask = DMA_BIT_MASK(ilog2(end) + 1);
  	dev->coherent_dma_mask &= mask;
  	*dev->dma_mask &= mask;
-	/* ...but only set bus limit if we found valid dma-ranges earlier */
-	if (!ret)
+	/* ...but only set bus limit and range map if we found valid dma-ranges earlier */
+	if (!ret) {
  		dev->bus_dma_limit = end;
+		dev->dma_range_map = map;
+	}
 
  	coherent = of_dma_is_coherent(np);
  	dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
  	iommu = of_iommu_configure(dev, np, id);
  	if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+		/* Don't touch range map if it wasn't set from a valid dma-ranges */
+		if (!ret)
+			dev->dma_range_map = NULL;
  		kfree(map);
  		return -EPROBE_DEFER;
  	}
@@ -181,7 +186,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
  	arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
Quoted 8 lines
Quoted 7 lines
drivers/of/device.c +0 -1
-	dev->dma_range_map = map;
  	return 0;
  }
  EXPORT_SYMBOL_GPL(of_dma_configure_id);
Signature · 1 line
2.18.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#3 lore raw
Quoted 17 lines · Robin Murphy

[ + Christoph, Marek ]

Quoted 13 lines · Paul Kocialkowski

Hi,

Quoted 9 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

Quoted 5 lines
Quoted 2 lines

Just a gentle ping on this issue, it would be nice to have this fix merged ASAP, in the next RC :)

Ack to that - Rob, Frank, do you want to take this through the OF tree, or shall we take it through the DMA-mapping tree like the original culprit?

I've already got some fixes queued up and can take it.

Suggested-by doesn't mean you are happy with the implementation. So Acked-by or Reviewed-by?

Rob
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reviewed-by
#4 lore raw
Quoted 18 lines · Rob Herring
Quoted 17 lines · Robin Murphy

[ + Christoph, Marek ]

Quoted 13 lines · Paul Kocialkowski

Hi,

Quoted 9 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Just a gentle ping on this issue, it would be nice to have this fix merged ASAP, in the next RC :)

Ack to that - Rob, Frank, do you want to take this through the OF tree, or shall we take it through the DMA-mapping tree like the original culprit?

I've already got some fixes queued up and can take it.

Brilliant, thanks!

Quoted 2 lines

Suggested-by doesn't mean you are happy with the implementation. So Acked-by or Reviewed-by?

It still feels slightly awkward to give a tag to say "yes, this is exactly what I suggested", but for the avoidance of doubt,

Cheers,
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#5 lore raw
In reply to Yong Wu
Quoted 5 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

only when dev *doesn't* have valid dma-ranges?

Quoted 55 lines

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
---
 drivers/of/device.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/of/device.c +7 -4
index aedfaaafd3e7..1122daa8e273 100644
@@ -162,9 +162,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
        mask = DMA_BIT_MASK(ilog2(end) + 1);
        dev->coherent_dma_mask &= mask;
        *dev->dma_mask &= mask;
-       /* ...but only set bus limit if we found valid dma-ranges earlier */
-       if (!ret)
+       /* ...but only set bus limit and range map if we found valid dma-ranges earlier */
+       if (!ret) {
                dev->bus_dma_limit = end;
+               dev->dma_range_map = map;
+       }
 
        coherent = of_dma_is_coherent(np);
        dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
        iommu = of_iommu_configure(dev, np, id);
        if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+               /* Don't touch range map if it wasn't set from a valid dma-ranges */
+               if (!ret)
+                       dev->dma_range_map = NULL;
                kfree(map);
                return -EPROBE_DEFER;
        }
@@ -181,7 +186,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
        arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
-       dev->dma_range_map = map;
        return 0;
 }
 EXPORT_SYMBOL_GPL(of_dma_configure_id);
--
Quoted 2 lines

2.18.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#6 lore raw
Quoted 8 lines · Rob Herring
Quoted 5 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

only when dev *doesn't* have valid dma-ranges?

I believe the intent is to mean when a valid "dma-ranges" property is specified in DT. The implementation allows DT to take precedence even if platform code *has* already installed a dma_range_map, although we shouldn't expect that to ever happen (except perhaps in the wild early days of platform bringup).

Robin.

Quoted 50 lines
Quoted 50 lines

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
---
  drivers/of/device.c | 10 +++++++---
  1 file changed, 7 insertions(+), 3 deletions(-)
drivers/of/device.c +7 -2
index aedfaaafd3e7..1122daa8e273 100644
@@ -162,9 +162,11 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
         mask = DMA_BIT_MASK(ilog2(end) + 1);
         dev->coherent_dma_mask &= mask;
         *dev->dma_mask &= mask;
-       /* ...but only set bus limit if we found valid dma-ranges earlier */
-       if (!ret)
+       /* ...but only set bus limit and range map if we found valid dma-ranges earlier */
+       if (!ret) {
                 dev->bus_dma_limit = end;
+               dev->dma_range_map = map;
+       }
 
         coherent = of_dma_is_coherent(np);
         dev_dbg(dev, "device is%sdma coherent\n",
@@ -172,6 +174,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
         iommu = of_iommu_configure(dev, np, id);
         if (PTR_ERR(iommu) == -EPROBE_DEFER) {
+               /* Don't touch range map if it wasn't set from a valid dma-ranges */
+               if (!ret)
+                       dev->dma_range_map = NULL;
                 kfree(map);
                 return -EPROBE_DEFER;
         }
@@ -181,7 +186,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 
         arch_setup_dma_ops(dev, dma_start, size, iommu, coherent);
 
Quoted 12 lines
Quoted 7 lines
drivers/of/device.c +0 -2
-       dev->dma_range_map = map;
         return 0;
  }
  EXPORT_SYMBOL_GPL(of_dma_configure_id);
--

2.18.0

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#7 lore raw
In reply to Yong Wu
Quoted 19 lines · Yong Wu

The commit e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset") always update dma_range_map even though it was already set, like in the sunxi_mbus driver. the issue is reported at [1]. This patch avoid this(Updating it only when dev has valid dma-ranges).

Meanwhile, dma_range_map contains the devices' dma_ranges information, This patch moves dma_range_map before of_iommu_configure. The iommu driver may need to know the dma_address requirements of its iommu consumer devices.

[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

CC Rob Herring <[email protected]>
CC Frank Rowand <[email protected]>
Fixes e0d072782c73 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset"),
Quoted 4 lines
---
 drivers/of/device.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Applied, thanks!
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu