Skip to contentSkip to conversation

armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

PATCH New Jamie Iles 4 participants 9 messages Dec 21, 2009 – Jan 14, 2010 Arm (32-bit)

lore
Share & tools
lore

Jamie Iles

author
#0 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Some ARMv6 cores will use speculative prefetching. This can be a problem when devices DMA to memory and the core prefetches data before the device has written it. This can result in stale data being stored in the cache. The DMA API will request the invalidation but this is currently a no-op on v6. Use the same dma_unmap_area implementation as for v7.

---
 arch/arm/mm/cache-v6.S |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/arm/mm/cache-v6.S +3 -0
index a11934e..a4da9d2 100644
@@ -284,6 +284,9 @@ ENDPROC(v6_dma_map_area)
  *	- dir	- DMA direction
  */
 ENTRY(v6_dma_unmap_area)
+	add	r1, r1, r0
+	teq	r2, #DMA_TO_DEVICE
+	bne	v6_dma_inv_range
 	mov	pc, lr
 ENDPROC(v6_dma_unmap_area)
 
Signature · 1 line
1.6.5.4
author
#1 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

I've just noticed that we can also defer the invalidation from the v6_dma_map_area to v6_dma_unmap_area. The following patch cleans the cache for DMA_TO_DEVICE and DMA_BIDIRECTIONAL on mapping but does no invalidation.

author
#2 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Some ARMv6 cores will use speculative prefetching. This can be a problem when devices DMA to memory and the core prefetches data before the device has written it. This can result in stale data being stored in the cache. The DMA API will request the invalidation but this is currently a no-op on v6. Use the same dma_unmap_area implementation as for v7.

Additionally, simplify v6_dma_map_area() so that we clean the cache lines for DMA_TO_DEVICE and DMA_FROM_DEVICE but don't do any invalidation. This will be done when we unmap.

---
 arch/arm/mm/cache-v6.S |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
arch/arm/mm/cache-v6.S +6 -4
index a11934e..1dd9e0e 100644
@@ -271,10 +271,9 @@ ENTRY(v6_dma_flush_range)
  */
 ENTRY(v6_dma_map_area)
 	add	r1, r1, r0
-	cmp	r2, #DMA_TO_DEVICE
-	beq	v6_dma_clean_range
-	bcs	v6_dma_inv_range
-	b	v6_dma_flush_range
+	teq	r2, #DMA_FROM_DEVICE
+	bne	v6_dma_clean_range
+	mov	pc, lr
 ENDPROC(v6_dma_map_area)
 
 /*
@@ -284,6 +283,9 @@ ENDPROC(v6_dma_map_area)
  *	- dir	- DMA direction
  */
 ENTRY(v6_dma_unmap_area)
+	add	r1, r1, r0
+	teq	r2, #DMA_TO_DEVICE
+	bne	v6_dma_inv_range
 	mov	pc, lr
 ENDPROC(v6_dma_unmap_area)
 
Signature · 1 line
1.6.5.4
#3 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Quoted 9 lines · Jamie Iles

Some ARMv6 cores will use speculative prefetching. This can be a problem when devices DMA to memory and the core prefetches data before the device has written it. This can result in stale data being stored in the cache. The DMA API will request the invalidation but this is currently a no-op on v6. Use the same dma_unmap_area implementation as for v7.

Additionally, simplify v6_dma_map_area() so that we clean the cache lines for DMA_TO_DEVICE and DMA_FROM_DEVICE but don't do any invalidation. This will be done when we unmap.

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

Nevertheless, the patch is fine, can I just combine it with the other DMA patches - it is after all just a copy of the ARMv7 code.

author
#4 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Quoted 7 lines · Russell King - ARM Linux
Quoted 6 lines · Jamie Iles

Some ARMv6 cores will use speculative prefetching. This can be a problem when devices DMA to memory and the core prefetches data before the device has written it. This can result in stale data being stored in the cache. The DMA API will request the invalidation but this is currently a no-op on v6. Use the same dma_unmap_area implementation as for v7.

Quoted 6 lines
Quoted 3 lines

Additionally, simplify v6_dma_map_area() so that we clean the cache lines for DMA_TO_DEVICE and DMA_FROM_DEVICE but don't do any invalidation. This will be done when we unmap.

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

I couldn't find the words in the TRM that categorically stated it either way, but on the 1176JZ-S platform that I'm using this definitely needs to be done.

Quoted 3 lines

Nevertheless, the patch is fine, can I just combine it with the other DMA patches - it is after all just a copy of the ARMv7 code.

Sure, fine with me.

Jamie

#5 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Quoted 12 lines · Jamie Iles
Quoted 11 lines · Russell King - ARM Linux
Quoted 9 lines · Jamie Iles

Some ARMv6 cores will use speculative prefetching. This can be a problem when devices DMA to memory and the core prefetches data before the device has written it. This can result in stale data being stored in the cache. The DMA API will request the invalidation but this is currently a no-op on v6. Use the same dma_unmap_area implementation as for v7.

Additionally, simplify v6_dma_map_area() so that we clean the cache lines for DMA_TO_DEVICE and DMA_FROM_DEVICE but don't do any invalidation. This will be done when we unmap.

Quoted 8 lines
Quoted 2 lines

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

I couldn't find the words in the TRM that categorically stated it either way, but on the 1176JZ-S platform that I'm using this definitely needs to be done.

Quoted 3 lines

Nevertheless, the patch is fine, can I just combine it with the other DMA patches - it is after all just a copy of the ARMv7 code.

Sure, fine with me.

Actually, it isn't - on map, you don't invalidate at all for DMA_FROM_DEVICE which means dirty writebacks can corrupt DMA.

I'll copy what I did for ARMv7 to ARMv6.

#6 lore raw

PATCH 1/1 armv6: invalidate cache on DMA_FROM_DEVICE/DMA_BIDIRECTIONAL

In reply to Russell King - ARM Linux
Quoted 7 lines

From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel- bounces at lists.infradead.org] On Behalf Of Russell King - ARM Linux
Sent: Monday, December 21, 2009 6:45 AM

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

If you bolt on a unified L2 cache won't normal branch prediction result in some possible erroneous data in L2 cache range (assume mmu execution flag is set I suppose)?

Regards,
Richard W.

#7 lore raw

PATCH 1/1 armv6: invalidate cache onDMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Quoted 11 lines · Richard
Quoted 7 lines

From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel- bounces at lists.infradead.org] On Behalf Of Russell King - ARM Linux
Sent: Monday, December 21, 2009 6:45 AM

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

If you bolt on a unified L2 cache won't normal branch prediction result in some possible erroneous data in L2 cache range (assume mmu execution flag is set I suppose)?

I think that's possible, in which case we should treat ARMv6 in a similar way to ARMv7, in case we have an external L2 cache.

Signature · 1 line
Catalin
#8 lore raw

PATCH 1/1 armv6: invalidate cache onDMA_FROM_DEVICE/DMA_BIDIRECTIONAL

Quoted 9 lines · Catalin Marinas
Quoted 8 lines · Richard
Quoted 7 lines

From: linux-arm-kernel-bounces at lists.infradead.org [mailto:linux-arm-kernel- bounces at lists.infradead.org] On Behalf Of Russell King - ARM Linux
Sent: Monday, December 21, 2009 6:45 AM

I was thinking about doing this for ARMv6, but I thought the concensus was that ARMv6 didn't have speculative prefetching.

Quoted 6 lines
Quoted 3 lines

If you bolt on a unified L2 cache won't normal branch prediction result in some possible erroneous data in L2 cache range (assume mmu execution flag is set I suppose)?

I think that's possible, in which case we should treat ARMv6 in a similar way to ARMv7, in case we have an external L2 cache.

My patches already do.