All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
@ 2020-10-26 15:27 ` Geert Uytterhoeven
  0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2020-10-26 15:27 UTC (permalink / raw)
  To: Jim Quinlan, Christoph Hellwig, Rob Herring, Frank Rowand
  Cc: devicetree, linux-pci, linux-renesas-soc, linux-arm-kernel,
	linux-kernel, Geert Uytterhoeven

On r8a7791/koelsch and shmobile_defconfig, PCIe probing fails with:

    rcar-pcie fe000000.pcie: Adjusted size 0x0 invalid
    rcar-pcie: probe of fe000000.pcie failed with error -22

of_dma_get_range() returns the following map:

    cpu_start 0x40000000 dma_start 0x40000000 size 0x080000000 offset 0
    cpu_start 0x00000000 dma_start 0x00000000 size 0x100000000 offset 0

If CONFIG_ARM_LPAE=n, dma_addr_t is 32-bit.  Hence when assigning
r->dma_start + r->size to dma_end, this value will be truncated to
32-bit, yielding zero when processing the second table entry.
Consequently, both dma_start and dma_end will be zero, leading to a zero
size.

Fix this by changing the dma_start and dma_end variables from dma_addr_t
to u64.

Fixes: e0d072782c734d27 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/of/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 655dee422563f05f..3a469c79e6b05de4 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -93,7 +93,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 {
 	const struct iommu_ops *iommu;
 	const struct bus_dma_region *map = NULL;
-	dma_addr_t dma_start = 0;
+	u64 dma_start = 0;
 	u64 mask, end, size = 0;
 	bool coherent;
 	int ret;
@@ -109,10 +109,10 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 			return ret == -ENODEV ? 0 : ret;
 	} else {
 		const struct bus_dma_region *r = map;
-		dma_addr_t dma_end = 0;
+		u64 dma_end = 0;
 
 		/* Determine the overall bounds of all DMA regions */
-		for (dma_start = ~(dma_addr_t)0; r->size; r++) {
+		for (dma_start = ~0ULL; r->size; r++) {
 			/* Take lower and upper limits */
 			if (r->dma_start < dma_start)
 				dma_start = r->dma_start;
-- 
2.25.1


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

* [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
@ 2020-10-26 15:27 ` Geert Uytterhoeven
  0 siblings, 0 replies; 8+ messages in thread
From: Geert Uytterhoeven @ 2020-10-26 15:27 UTC (permalink / raw)
  To: Jim Quinlan, Christoph Hellwig, Rob Herring, Frank Rowand
  Cc: devicetree, Geert Uytterhoeven, linux-pci, linux-kernel,
	linux-renesas-soc, linux-arm-kernel

On r8a7791/koelsch and shmobile_defconfig, PCIe probing fails with:

    rcar-pcie fe000000.pcie: Adjusted size 0x0 invalid
    rcar-pcie: probe of fe000000.pcie failed with error -22

of_dma_get_range() returns the following map:

    cpu_start 0x40000000 dma_start 0x40000000 size 0x080000000 offset 0
    cpu_start 0x00000000 dma_start 0x00000000 size 0x100000000 offset 0

If CONFIG_ARM_LPAE=n, dma_addr_t is 32-bit.  Hence when assigning
r->dma_start + r->size to dma_end, this value will be truncated to
32-bit, yielding zero when processing the second table entry.
Consequently, both dma_start and dma_end will be zero, leading to a zero
size.

Fix this by changing the dma_start and dma_end variables from dma_addr_t
to u64.

Fixes: e0d072782c734d27 ("dma-mapping: introduce DMA range map, supplanting dma_pfn_offset")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 drivers/of/device.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/of/device.c b/drivers/of/device.c
index 655dee422563f05f..3a469c79e6b05de4 100644
--- a/drivers/of/device.c
+++ b/drivers/of/device.c
@@ -93,7 +93,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 {
 	const struct iommu_ops *iommu;
 	const struct bus_dma_region *map = NULL;
-	dma_addr_t dma_start = 0;
+	u64 dma_start = 0;
 	u64 mask, end, size = 0;
 	bool coherent;
 	int ret;
@@ -109,10 +109,10 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
 			return ret == -ENODEV ? 0 : ret;
 	} else {
 		const struct bus_dma_region *r = map;
-		dma_addr_t dma_end = 0;
+		u64 dma_end = 0;
 
 		/* Determine the overall bounds of all DMA regions */
-		for (dma_start = ~(dma_addr_t)0; r->size; r++) {
+		for (dma_start = ~0ULL; r->size; r++) {
 			/* Take lower and upper limits */
 			if (r->dma_start < dma_start)
 				dma_start = r->dma_start;
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
  2020-10-26 15:27 ` Geert Uytterhoeven
@ 2020-10-27  7:55   ` Christoph Hellwig
  -1 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2020-10-27  7:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jim Quinlan, Christoph Hellwig, Rob Herring, Frank Rowand,
	devicetree, linux-pci, linux-renesas-soc, linux-arm-kernel,
	linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Rob and Frank: do you want to take this through the OF tree, or should
I queue it up in the dma-mapping tree that caused the problem?

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
@ 2020-10-27  7:55   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2020-10-27  7:55 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: devicetree, linux-pci, linux-kernel, linux-renesas-soc,
	Rob Herring, Jim Quinlan, Frank Rowand, Christoph Hellwig,
	linux-arm-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Rob and Frank: do you want to take this through the OF tree, or should
I queue it up in the dma-mapping tree that caused the problem?

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
  2020-10-27  7:55   ` Christoph Hellwig
@ 2020-10-29 15:59     ` Christoph Hellwig
  -1 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2020-10-29 15:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Jim Quinlan, Christoph Hellwig, Rob Herring, Frank Rowand,
	devicetree, linux-pci, linux-renesas-soc, linux-arm-kernel,
	linux-kernel

On Tue, Oct 27, 2020 at 08:55:51AM +0100, Christoph Hellwig wrote:
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Rob and Frank: do you want to take this through the OF tree, or should
> I queue it up in the dma-mapping tree that caused the problem?

I've picked this up in the dma-mapping tree so that we don't miss
rc2.

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
@ 2020-10-29 15:59     ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2020-10-29 15:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: devicetree, linux-pci, linux-kernel, linux-renesas-soc,
	Rob Herring, Jim Quinlan, Frank Rowand, Christoph Hellwig,
	linux-arm-kernel

On Tue, Oct 27, 2020 at 08:55:51AM +0100, Christoph Hellwig wrote:
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Rob and Frank: do you want to take this through the OF tree, or should
> I queue it up in the dma-mapping tree that caused the problem?

I've picked this up in the dma-mapping tree so that we don't miss
rc2.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
  2020-10-29 15:59     ` Christoph Hellwig
@ 2020-10-30 18:44       ` Rob Herring
  -1 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-10-30 18:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Geert Uytterhoeven, Jim Quinlan, Frank Rowand, devicetree,
	linux-pci, linux-renesas-soc, linux-arm-kernel, linux-kernel

On Thu, Oct 29, 2020 at 04:59:18PM +0100, Christoph Hellwig wrote:
> On Tue, Oct 27, 2020 at 08:55:51AM +0100, Christoph Hellwig wrote:
> > Looks good:
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Rob and Frank: do you want to take this through the OF tree, or should
> > I queue it up in the dma-mapping tree that caused the problem?
> 
> I've picked this up in the dma-mapping tree so that we don't miss
> rc2.

Thanks.

Rob

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

* Re: [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n
@ 2020-10-30 18:44       ` Rob Herring
  0 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-10-30 18:44 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: devicetree, Geert Uytterhoeven, linux-pci, linux-kernel,
	linux-renesas-soc, Jim Quinlan, Frank Rowand, linux-arm-kernel

On Thu, Oct 29, 2020 at 04:59:18PM +0100, Christoph Hellwig wrote:
> On Tue, Oct 27, 2020 at 08:55:51AM +0100, Christoph Hellwig wrote:
> > Looks good:
> > 
> > Reviewed-by: Christoph Hellwig <hch@lst.de>
> > 
> > Rob and Frank: do you want to take this through the OF tree, or should
> > I queue it up in the dma-mapping tree that caused the problem?
> 
> I've picked this up in the dma-mapping tree so that we don't miss
> rc2.

Thanks.

Rob

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-10-30 18:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-26 15:27 [PATCH] dma-mapping: Fix 32-bit overflow with CONFIG_ARM_LPAE=n Geert Uytterhoeven
2020-10-26 15:27 ` Geert Uytterhoeven
2020-10-27  7:55 ` Christoph Hellwig
2020-10-27  7:55   ` Christoph Hellwig
2020-10-29 15:59   ` Christoph Hellwig
2020-10-29 15:59     ` Christoph Hellwig
2020-10-30 18:44     ` Rob Herring
2020-10-30 18:44       ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.