Skip to contentSkip to conversation

ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

PATCH Superseded Vladimir Murzin 3 participants 5 messages Nov 19, 2018 – Nov 21, 2018 Arm (32-bit)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

Chris has discovered and reported that v7_dma_inv_range() may corrupt memory if address range is not aligned to cache line size.

Since the whole cache-v7m.S was lifted form cache-v7.S the same observation applies to v7m_dma_inv_range(). So the fix just mirrors what has been done for v7 with a little specific of M-class.

---
 arch/arm/mm/cache-v7m.S | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/mm/cache-v7m.S +8 -5
index 788486e8..1059d5e 100644
@@ -73,9 +73,11 @@
 /*
  * dcimvac: Invalidate data cache line by MVA to PoC
  */
-.macro dcimvac, rt, tmp
-	v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
+.irp    c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+.macro dcimvac\c, rt, tmp
+	v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC, \c
 .endm
+.endr
 
 /*
  * dccmvau: Clean data cache line by MVA to PoU
@@ -369,14 +371,15 @@ v7m_dma_inv_range:
 	tst	r0, r3
 	bic	r0, r0, r3
 	dccimvacne r0, r3
+	addne	r0, r0, r2
 	subne	r3, r2, #1	@ restore r3, corrupted by v7m's dccimvac
 	tst	r1, r3
 	bic	r1, r1, r3
 	dccimvacne r1, r3
 1:
-	dcimvac r0, r3
-	add	r0, r0, r2
-	cmp	r0, r1
+	dcimvaclo r0, r3
+	addlo	r0, r0, r2
+	cmplo	r0, r1
 	blo	1b
 	dsb	st
 	ret	lr
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

Hi Vladimir,

Quoted 52 lines · Vladimir Murzin

Chris has discovered and reported that v7_dma_inv_range() may corrupt memory if address range is not aligned to cache line size.

Since the whole cache-v7m.S was lifted form cache-v7.S the same observation applies to v7m_dma_inv_range(). So the fix just mirrors what has been done for v7 with a little specific of M-class.

---
 arch/arm/mm/cache-v7m.S | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/mm/cache-v7m.S +8 -6
index 788486e8..1059d5e 100644
@@ -73,9 +73,11 @@
 /*
  * dcimvac: Invalidate data cache line by MVA to PoC
  */
-.macro dcimvac, rt, tmp
-       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
+.irp    c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+.macro dcimvac\c, rt, tmp
+       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC, \c
 .endm
+.endr
 
 /*
  * dccmvau: Clean data cache line by MVA to PoU
@@ -369,14 +371,15 @@ v7m_dma_inv_range:
        tst     r0, r3
        bic     r0, r0, r3
        dccimvacne r0, r3
+       addne   r0, r0, r2
        subne   r3, r2, #1      @ restore r3, corrupted by v7m's dccimvac
        tst     r1, r3
        bic     r1, r1, r3
        dccimvacne r1, r3
 1:
-       dcimvac r0, r3
-       add     r0, r0, r2
-       cmp     r0, r1
+       dcimvaclo r0, r3
+       addlo   r0, r0, r2
+       cmplo   r0, r1
        blo     1b
        dsb     st
        ret     lr
--
Quoted 2 lines

1.9.1

There needs to be "cmp r0, r1" added after "1:" label.

Thanks,
Chris

#2 lore raw

PATCH 1/1 ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

Hi Chris,

Quoted 51 lines · Chris Cole

Hi Vladimir,

Quoted 48 lines · Vladimir Murzin

Chris has discovered and reported that v7_dma_inv_range() may corrupt memory if address range is not aligned to cache line size.

Since the whole cache-v7m.S was lifted form cache-v7.S the same observation applies to v7m_dma_inv_range(). So the fix just mirrors what has been done for v7 with a little specific of M-class.

---
 arch/arm/mm/cache-v7m.S | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/mm/cache-v7m.S +8 -5
index 788486e8..1059d5e 100644
@@ -73,9 +73,11 @@
 /*
  * dcimvac: Invalidate data cache line by MVA to PoC
  */
-.macro dcimvac, rt, tmp
-       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
+.irp    c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+.macro dcimvac\c, rt, tmp
+       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC, \c
 .endm
+.endr
 
 /*
  * dccmvau: Clean data cache line by MVA to PoU
@@ -369,14 +371,15 @@ v7m_dma_inv_range:
        tst     r0, r3
        bic     r0, r0, r3
        dccimvacne r0, r3
+       addne   r0, r0, r2
        subne   r3, r2, #1      @ restore r3, corrupted by v7m's dccimvac
        tst     r1, r3
        bic     r1, r1, r3
        dccimvacne r1, r3
 1:
-       dcimvac r0, r3
-       add     r0, r0, r2
-       cmp     r0, r1
+       dcimvaclo r0, r3
+       addlo   r0, r0, r2
+       cmplo   r0, r1
Quoted 8 lines
Quoted 6 lines
arch/arm/mm/cache-v7m.S +0 -1
        blo     1b
        dsb     st
        ret     lr
--

1.9.1

There needs to be "cmp r0, r1" added after "1:" label.

Nice catch! I'll send update shortly.

Thanks
Vladimir

Quoted 4 lines

Thanks,
Chris

#3 lore raw

PATCH 1/1 ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

Quoted 63 lines · Vladimir Murzin

Hi Chris,

Quoted 51 lines · Chris Cole

Hi Vladimir,

Quoted 48 lines · Vladimir Murzin

Chris has discovered and reported that v7_dma_inv_range() may corrupt memory if address range is not aligned to cache line size.

Since the whole cache-v7m.S was lifted form cache-v7.S the same observation applies to v7m_dma_inv_range(). So the fix just mirrors what has been done for v7 with a little specific of M-class.

---
 arch/arm/mm/cache-v7m.S | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/mm/cache-v7m.S +8 -5
index 788486e8..1059d5e 100644
@@ -73,9 +73,11 @@
 /*
  * dcimvac: Invalidate data cache line by MVA to PoC
  */
-.macro dcimvac, rt, tmp
-       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
+.irp    c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+.macro dcimvac\c, rt, tmp
+       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC, \c
 .endm
+.endr
 
 /*
  * dccmvau: Clean data cache line by MVA to PoU
@@ -369,14 +371,15 @@ v7m_dma_inv_range:
        tst     r0, r3
        bic     r0, r0, r3
        dccimvacne r0, r3
+       addne   r0, r0, r2
        subne   r3, r2, #1      @ restore r3, corrupted by v7m's dccimvac
        tst     r1, r3
        bic     r1, r1, r3
        dccimvacne r1, r3
 1:
-       dcimvac r0, r3
-       add     r0, r0, r2
-       cmp     r0, r1
+       dcimvaclo r0, r3
+       addlo   r0, r0, r2
+       cmplo   r0, r1
Quoted 8 lines
Quoted 6 lines
arch/arm/mm/cache-v7m.S +0 -1
        blo     1b
        dsb     st
        ret     lr
--

1.9.1

There needs to be "cmp r0, r1" added after "1:" label.

Quoted 1 line

Nice catch! I'll send update shortly.

No, actually, the cmp needs to be _before_ the label, as per the v7 version.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#4 lore raw

PATCH 1/1 ARM: V7M: align v7m_dma_inv_range() with v7 counterpart

Quoted 64 lines · Russell King - ARM Linux
Quoted 63 lines · Vladimir Murzin

Hi Chris,

Quoted 59 lines · Chris Cole

Hi Vladimir,

Quoted 52 lines · Vladimir Murzin

Chris has discovered and reported that v7_dma_inv_range() may corrupt memory if address range is not aligned to cache line size.

Since the whole cache-v7m.S was lifted form cache-v7.S the same observation applies to v7m_dma_inv_range(). So the fix just mirrors what has been done for v7 with a little specific of M-class.

---
 arch/arm/mm/cache-v7m.S | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
arch/arm/mm/cache-v7m.S +8 -6
index 788486e8..1059d5e 100644
@@ -73,9 +73,11 @@
 /*
  * dcimvac: Invalidate data cache line by MVA to PoC
  */
-.macro dcimvac, rt, tmp
-       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
+.irp    c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
+.macro dcimvac\c, rt, tmp
+       v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC, \c
 .endm
+.endr
 
 /*
  * dccmvau: Clean data cache line by MVA to PoU
@@ -369,14 +371,15 @@ v7m_dma_inv_range:
        tst     r0, r3
        bic     r0, r0, r3
        dccimvacne r0, r3
+       addne   r0, r0, r2
        subne   r3, r2, #1      @ restore r3, corrupted by v7m's dccimvac
        tst     r1, r3
        bic     r1, r1, r3
        dccimvacne r1, r3
 1:
-       dcimvac r0, r3
-       add     r0, r0, r2
-       cmp     r0, r1
+       dcimvaclo r0, r3
+       addlo   r0, r0, r2
+       cmplo   r0, r1
        blo     1b
        dsb     st
        ret     lr
--
Quoted 2 lines

1.9.1

There needs to be "cmp r0, r1" added after "1:" label.

Quoted 5 lines
Quoted 1 line

Nice catch! I'll send update shortly.

No, actually, the cmp needs to be _before_ the label, as per the v7 version.

Yup, I also noticed that, so v2 already have cmp before the label.

Since you in thread, are you happy if both patches go into your patch system?

Thanks
Vladimir