Avoid SDRAM access crash
PATCH 1/1 Avoid SDRAM access crash
From: Steve Schefter <[email protected]>
When remapping the SDRAM with the MMU enabled, we need to ensure that the translation tables are not still in cache before invalidating the TLB. Failure to do so will result in the following crash approximately 50% of the time:
booting kernel from /dev/nand0.kernel.bb
Image Name: Linux-3.3.0PD12.0.0
OS: Linux
Architecture: ARM
Type: Kernel Image Compression: uncompressed Data Size: 3384824 Bytes = 3.2 MB Load Address: 80008000 Entry Point: 80008000 unable to handle paging request at address 0x80028000 pc : [<8f01f280>] lr : [<8f005330>]
sp : 8cfff9b0 ip : 0000003f fp : 00000000
r10: 00001000 r9 : 00000000 r8 : 8d2a8f70
r7 : 8f043818 r6 : 0033a5f8 r5 : 8f04381c r4 : 00001000
r3 : 80028000 r2 : 00000fff r1 : 8d2a8f71 r0 : 80028000
Flags: nzCv IRQs off FIQs off Mode SVC_32
[<8f01f280>] (memcpy+0x18/0x20) from [<8f005330>] (uimage_sdram_flush+0x90/0xb8) [<8f005330>] (uimage_sdram_flush+0x90/0xb8) from [<8f0053a4>] (uncompress_copy+0x4c/0x74)
--- arch/arm/cpu/mmu.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
arch/arm/cpu/mmu.c +6 -0
@@ -165,6 +165,12 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank) pte +=256 ; } + asmvolatile ( +"bl __mmu_cache_flush;" + : + : + :"r0" ,"r1" ,"r2" ,"r3" ,"r6" ,"r10" ,"r12" ,"lr" ,"cc" ,"memory" + );tlb_invalidate ();return 0 ;
Signature · 7 lines
1.7.4.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Steve,
Quoted 18 lines · On Mon, Jul 02, 2012 at 01:22:33PM -0400, [email protected] wrote:
From: Steve Schefter <[email protected]>
When remapping the SDRAM with the MMU enabled, we need to ensure that the translation tables are not still in cache before invalidating the TLB. Failure to do so will result in the following crash approximately 50% of the time:
booting kernel from
/dev/nand0.kernel.bb
Image Name: Linux-3.3.0PD12.0.0
OS: Linux
Architecture: ARMType: Kernel Image Compression: uncompressed Data Size: 3384824 Bytes = 3.2 MB Load Address: 80008000 Entry Point: 80008000 unable to handle paging request at address 0x80028000 pc : [<8f01f280>] lr : [<8f005330>]
Quoted 7 lines
sp :
8cfff9b0ip :0000003ffp : 00000000
r10: 00001000 r9 : 00000000 r8 :8d2a8f70
r7 :8f043818r6 :0033a5f8r5 :8f04381cr4 : 00001000
r3 : 80028000 r2 :00000fffr1 :8d2a8f71r0 : 80028000
Flags: nzCv IRQs off FIQs off ModeSVC_32
[<8f01f280>] (memcpy+0x18/0x20) from [<8f005330>] (uimage_sdram_flush+0x90/0xb8) [<8f005330>] (uimage_sdram_flush+0x90/0xb8) from [<8f0053a4>] (uncompress_copy+0x4c/0x74)
I wonder why this has never hit me. On what hardware did you see this?
Does the following patch solve your problem aswell?
8<----------------------------------------------------
ARM mmu: flush page tables in arm_mmu_remap_sdram()
--- arch/arm/cpu/mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm/cpu/mmu.c +4 -1
@@ -147,7 +147,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)if ((phys & (SZ_1M -1 )) || (bank->size & (SZ_1M -1 )))return -EINVAL ; - ptes =memalign (0x400 , num_ptes *sizeof (u32)); + ptes =memalign (PAGE_SIZE , num_ptes *sizeof (u32));debug ("ptes: 0x%p ttb_start: 0x%08lx ttb_end: 0x%08lx\n" , ptes, ttb_start, ttb_end);
@@ -165,6 +165,9 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank) pte +=256 ; } +dma_flush_range ((unsigned long )ttb, (unsigned long )ttb +0x4000 ); +dma_flush_range ((unsigned long )ptes, num_ptes *sizeof (u32)); +tlb_invalidate ();return 0 ;
Signature · 13 lines
1.7.10 -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Sascha.
Quoted 1 line
I wonder why this has never hit me. On what hardware did you see this?
Me too. All I can say is that the timing is tight. I see crashes at various DRAM addresses, all depending on how much was left in cache when the tlb invalidate was done.
I'm using the Phytec phyCORE-OMAP44xx card.
Quoted 1 line
Does the following patch solve your problem aswell?
It does. I see that routine contains a cache flush as well.
Regards,
Steve
Quoted 24 lines
8<----------------------------------------------------
ARM mmu: flush page tables in
arm_mmu_remap_sdram()Signed-off-by Sascha Hauer<[email protected]>--- arch/arm/cpu/mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/arm/cpu/mmu.c +1
-1@@ -147,7 +147,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)if ((phys& (SZ_1M -1 )) || (bank->size& (SZ_1M -1 )))return -EINVAL ; - ptes =memalign (0x400 , num_ptes *sizeof (u32)); + ptes =memalign (PAGE_SIZE , num_ptes *sizeof (u32));debug ("ptes: 0x%p ttb_start: 0x%08lx ttb_end: 0x%08lx\n" , ptes, ttb_start, ttb_end);
arch/arm/cpu/mmu.c static int arm_mmu_remap_sdram(struct memory_bank *bank) · line 173
Quoted 9 lines
arch/arm/cpu/mmu.c +3
-0@@ -165,6 +165,9 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank) pte +=256 ; } +dma_flush_range ((unsigned long )ttb, (unsigned long )ttb +0x4000 ); +dma_flush_range ((unsigned long )ptes, num_ptes *sizeof (u32)); +tlb_invalidate ();return 0 ;
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Quoted 8 lines · Steve Schefter
Hi Sascha.
Quoted 1 line
I wonder why this has never hit me. On what hardware did you see this?
Me too. All I can say is that the timing is tight. I see crashes at various DRAM addresses, all depending on how much was left in cache when the tlb invalidate was done.
Quoted 5 lines
I'm using the Phytec phyCORE-OMAP44xx card.
Quoted 1 line
Does the following patch solve your problem aswell?
It does. I see that routine contains a cache flush as well.
Ok, thanks for testing. I applied my version because it flushes only the relevant parts of the cache and looks more like C ;)
Sascha
Quoted 38 lines
Regards,
SteveQuoted 33 lines
8<----------------------------------------------------
ARM mmu: flush page tables in
arm_mmu_remap_sdram()Signed-off-by Sascha Hauer<[email protected]>--- arch/arm/cpu/mmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/arm/cpu/mmu.c +4
-1@@ -147,7 +147,7 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank)if ((phys& (SZ_1M -1 )) || (bank->size& (SZ_1M -1 )))return -EINVAL ; - ptes =memalign (0x400 , num_ptes *sizeof (u32)); + ptes =memalign (PAGE_SIZE , num_ptes *sizeof (u32));debug ("ptes: 0x%p ttb_start: 0x%08lx ttb_end: 0x%08lx\n" , ptes, ttb_start, ttb_end);@@ -165,6 +165,9 @@ static int arm_mmu_remap_sdram(struct memory_bank *bank) pte +=256 ; } +dma_flush_range ((unsigned long )ttb, (unsigned long )ttb +0x4000 ); +dma_flush_range ((unsigned long )ptes, num_ptes *sizeof (u32)); +tlb_invalidate ();return 0 ;
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 2 lines · Sascha Hauer
I applied my version because it flushes only
the relevant parts of the cache and looks more like C ;)
That's fine by me. Thanks Sascha.
Regards,
Steve
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox