All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] arm: Round the dma_alloc_coherent memory size to cache line aligned
@ 2019-01-04  9:24 Ye Li
  2019-01-10  2:31 ` [U-Boot] " Tom Rini
  0 siblings, 1 reply; 2+ messages in thread
From: Ye Li @ 2019-01-04  9:24 UTC (permalink / raw)
  To: u-boot

When running usb dwc3 gadget driver, we meet random USB enumeration failure in fastboot.
The root cause is a cache coherence issue. When it happens, the ctrl_req in
gadget driver is allocated at 0xfe932f40, and the usb_composite_dev (cdev)
is allocated at 0xfe932f60. So after we submit the setup request (cache flushed) to USB
controller, any accessing to usb_composite_dev variable will cause the cache line refill, then
when setup transfer is completed, reading the setup data in ctrl_req will gets old value from
cache not from memory.

The ctrl_req is allocated by API dma_alloc_coherent, but u-boot don't have cohernet memory.
so it still needs cache maintain operations before/after HW accessing. Since the cache flush or
invalidate bases on cache line, so when the allocated memory size is not cache line aligned,
potentially it may meet such issue.

This patch modifies the dma_alloc_coherent API to round the size to cache line aligned.

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
---
 arch/arm/include/asm/dma-mapping.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 0883b7e..fc5b8f6 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -13,7 +13,7 @@
 
 static inline void *dma_alloc_coherent(size_t len, unsigned long *handle)
 {
-	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, len);
+	*handle = (unsigned long)memalign(ARCH_DMA_MINALIGN, ROUND(len, ARCH_DMA_MINALIGN));
 	return (void *)*handle;
 }
 
-- 
2.7.4

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

* [U-Boot] arm: Round the dma_alloc_coherent memory size to cache line aligned
  2019-01-04  9:24 [U-Boot] [PATCH] arm: Round the dma_alloc_coherent memory size to cache line aligned Ye Li
@ 2019-01-10  2:31 ` Tom Rini
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2019-01-10  2:31 UTC (permalink / raw)
  To: u-boot

On Fri, Jan 04, 2019 at 09:24:14AM +0000, Ye Li wrote:

> When running usb dwc3 gadget driver, we meet random USB enumeration failure in fastboot.
> The root cause is a cache coherence issue. When it happens, the ctrl_req in
> gadget driver is allocated at 0xfe932f40, and the usb_composite_dev (cdev)
> is allocated at 0xfe932f60. So after we submit the setup request (cache flushed) to USB
> controller, any accessing to usb_composite_dev variable will cause the cache line refill, then
> when setup transfer is completed, reading the setup data in ctrl_req will gets old value from
> cache not from memory.
> 
> The ctrl_req is allocated by API dma_alloc_coherent, but u-boot don't have cohernet memory.
> so it still needs cache maintain operations before/after HW accessing. Since the cache flush or
> invalidate bases on cache line, so when the allocated memory size is not cache line aligned,
> potentially it may meet such issue.
> 
> This patch modifies the dma_alloc_coherent API to round the size to cache line aligned.
> 
> Signed-off-by: Ye Li <ye.li@nxp.com>
> Reviewed-by: Peng Fan <peng.fan@nxp.com>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190109/f06f92b7/attachment.sig>

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

end of thread, other threads:[~2019-01-10  2:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04  9:24 [U-Boot] [PATCH] arm: Round the dma_alloc_coherent memory size to cache line aligned Ye Li
2019-01-10  2:31 ` [U-Boot] " Tom Rini

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.