ARM: map_init_section flushes incorrect pmd
PATCH 1/1 ARM: map_init_section flushes incorrect pmd
This bug was introduced in commit e651eab0.
Some v4/v5 platforms failed to boot due to this.
--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mm/mmu.c +3 -1
@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to
@@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end); -flush_pmd_entry (pmd); +flush_pmd_entry (p); } static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
Signature · 1 line
1.7.9.5
Quoted 22 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to
arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 5 lines
arch/arm/mm/mmu.c +1
-1@@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end); -flush_pmd_entry (pmd); +flush_pmd_entry (p);
Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
Will
Quoted 26 lines · Will Deacon
Quoted 25 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to @@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end);
Quoted 5 lines
arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 2 lines
arch/arm/mm/mmu.c +1
-1-flush_pmd_entry (pmd); +flush_pmd_entry (p);Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
I think in LPAE this loop iterates once and non LPAE twice. So both the entries should be contained in same cache line right ?
Regards,
Sricharan
Quoted 27 lines · Sricharan R
Quoted 26 lines · Will Deacon
Quoted 25 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to @@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end);
Quoted 7 lines
Quoted 5 lines
arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 2 lines
arch/arm/mm/mmu.c +1
-1-flush_pmd_entry (pmd); +flush_pmd_entry (p);Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
I think in LPAE this loop iterates once and non LPAE twice. So both the entries should be contained in same cache line right ?
Dunno, are there any guarantees about alignment of the starting pmd? Even so, the function takes the range as parameters, so I don't think we should tailor it to the caller. It may explain why this hasn't come up sooner though.
Will
Quoted 33 lines · Will Deacon
Quoted 32 lines · Sricharan R
Quoted 31 lines · Will Deacon
Quoted 22 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 5 lines
arch/arm/mm/mmu.c +1
-1@@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end); -flush_pmd_entry (pmd); +flush_pmd_entry (p);Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
Quoted 8 lines
Quoted 2 lines
I think in LPAE this loop iterates once and non LPAE twice. So both the entries should be contained in same cache line right ?
Dunno, are there any guarantees about alignment of the starting pmd? Even so, the function takes the range as parameters, so I don't think we should tailor it to the caller. It may explain why this hasn't come up sooner though.
Will
This function is not exposed outside. And the ranges passed to this is going
to not more than 2 entries in any case. If we put the flush inside the loop, then we will end up doing an extra flush for the same line. Regarding the alignment, I think if the pgd base is aligned, then rest should be fine. Will have to check this.
Regards,
Sricharan
Quoted 44 lines · Sricharan R
Quoted 33 lines · Will Deacon
Quoted 32 lines · Sricharan R
Quoted 31 lines · Will Deacon
Quoted 22 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 5 lines
arch/arm/mm/mmu.c +1
-1@@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end); -flush_pmd_entry (pmd); +flush_pmd_entry (p);Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
Quoted 8 lines
Quoted 2 lines
I think in LPAE this loop iterates once and non LPAE twice. So both the entries should be contained in same cache line right ?
Dunno, are there any guarantees about alignment of the starting pmd? Even so, the function takes the range as parameters, so I don't think we should tailor it to the caller. It may explain why this hasn't come up sooner though.
Will
Quoted 9 lines
This function is not exposed outside. And the ranges passed to this is going
to not more than 2 entries in any case. If we put the flush inside the loop, then we will end up doing an extra flush for the same line. Regarding the alignment, I think if the pgd base is aligned, then rest should be fine. Will have to check this.Regards,
Sricharan
Hi ,
Catalin and Sricharan,
Thanks for your explanation.
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.
Regards,
Po-Yu
Quoted 4 lines · Po-Yu Chuang
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.
It does if it's UP. The walker is only guaranteed to read from L1 if you have the multiprocessing extensions.
As for this function, looks like it's ok because it has precisely one caller, so it might be worth prefixing it with some underscores to make it clear that nobody else should be calling it!
Will
Hi Will,
Quoted 8 lines · Will Deacon
Quoted 4 lines · Po-Yu Chuang
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.It does if it's UP. The walker is only guaranteed to read from L1 if you have the multiprocessing extensions.
Ya, I see.
Quoted 4 lines
As for this function, looks like it's ok because it has precisely one caller, so it might be worth prefixing it with some underscores to make it clear that nobody else should be calling it!
I am fine with that.
Should I create a new patch?
Regards,
Po-Yu
Quoted 12 lines · Po-Yu Chuang
Hi Will,
Quoted 8 lines · Will Deacon
Quoted 4 lines · Po-Yu Chuang
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.It does if it's UP. The walker is only guaranteed to read from L1 if you have the multiprocessing extensions.
Quoted 8 lines
Ya, I see.
Quoted 4 lines
As for this function, looks like it's ok because it has precisely one caller, so it might be worth prefixing it with some underscores to make it clear that nobody else should be calling it!
I am fine with that.
Should I create a new patch?
Hi,
Does anyone have more comment about this?
Regards,
Po-Yu
Quoted 19 lines · Po-Yu Chuang
Quoted 18 lines · Po-Yu Chuang
Hi Will,
Quoted 8 lines · Will Deacon
Quoted 4 lines · Po-Yu Chuang
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.It does if it's UP. The walker is only guaranteed to read from L1 if you have the multiprocessing extensions.
Ya, I see.
Quoted 4 lines
As for this function, looks like it's ok because it has precisely one caller, so it might be worth prefixing it with some underscores to make it clear that nobody else should be calling it!
Quoted 6 lines
Quoted 2 lines
I am fine with that.
Should I create a new patch?Hi,
Does anyone have more comment about this?
Sorry, I was snowed under yesterday. If you fancy adding the underscores to __map_init_section, that would help preserve what little remains of my sanity.
Your existing patch looks technically correct.
Will
Quoted 20 lines · Will Deacon
Quoted 19 lines · Po-Yu Chuang
Quoted 18 lines · Po-Yu Chuang
Hi Will,
Quoted 8 lines · Will Deacon
Quoted 4 lines · Po-Yu Chuang
Will,
I guess nobody noticed this because the MMU of later v7 processors fetches page table
from D-cache. It even doesn't need to clean pmd to PoU.It does if it's UP. The walker is only guaranteed to read from L1 if you have the multiprocessing extensions.
Ya, I see.
Quoted 4 lines
As for this function, looks like it's ok because it has precisely one caller, so it might be worth prefixing it with some underscores to make it clear that nobody else should be calling it!
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
I am fine with that.
Should I create a new patch?Hi,
Does anyone have more comment about this?
Hi Will,
Quoted 3 lines
Sorry, I was snowed under yesterday. If you fancy adding the underscores to
__map_init_section, that would help preserve what little remains of my sanity.
Although I recognize each word above, I am not quite sure what do you mean. :-p I assume that the sentences mean you prefer adding underscores, so I will submit a new patch.
Quoted 2 lines
Your existing patch looks technically correct.
Regards,
Po-Yu
PATCH v2 1/1 ARM: map_init_section flushes incorrect pmd
This bug was introduced in commit e651eab0.
Some v4/v5 platforms failed to boot due to this.
---
v2:
prefix underscores to map_init_section to emphasize that it should never be called by some random function.
arch/arm/mm/mmu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/arm/mm/mmu.c +5 -3
@@ -616,10 +616,12 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr, }while (pte++, addr +=PAGE_SIZE , addr != end); } -static void __init map_init_section (pmd_t *pmd,unsigned long addr, +static void __init __map_init_section (pmd_t *pmd,unsigned long addr,unsigned long end,phys_addr_t phys,const struct mem_type *type) { +pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to
@@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end); -flush_pmd_entry (pmd); +flush_pmd_entry (p); } static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
@@ -661,7 +663,7 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,*/ if (type->prot_sect && ((addr | next | phys) & ~SECTION_MASK ) ==0 ) { -map_init_section (pmd, addr, next, phys, type); +__map_init_section (pmd, addr, next, phys, type); }else {alloc_init_pte (pmd, addr, next,__phys_to_pfn (phys), type);
Signature · 1 line
1.7.9.5
Quoted 2 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.
Thanks!
Confirming that this fixes boot on MOXA ART (FA526).
Best regards,
Jonas
Quoted 26 lines · Will Deacon
Quoted 25 lines · Po-Yu Chuang
This bug was introduced in commit
e651eab0.
Some v4/v5 platforms failed to boot due to this.Signed-off-by Po-Yu Chuang <[email protected]>--- arch/arm/mm/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)arch/arm/mm/mmu.c +2
-0@@ -620,6 +620,8 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, unsigned long end, phys_addr_t phys, const struct mem_type *type) { + pmd_t *p = pmd; +#ifndef CONFIG_ARM_LPAE /* * In classic MMU format, puds and pmds are folded in to @@ -638,7 +640,7 @@ static void __init map_init_section(pmd_t *pmd, unsigned long addr, phys +=SECTION_SIZE ; }while (pmd++, addr +=SECTION_SIZE , addr != end);
Quoted 6 lines
arch/arm/mm/mmu.c static void __init map_init_section(pmd_t *pmd, unsigned long addr, · line 643
Quoted 2 lines
arch/arm/mm/mmu.c +1
-1-flush_pmd_entry (pmd); +flush_pmd_entry (p);Wait, shouldn't this flush be *inside* the loop anyway? Otherwise we just flush the cacheline containing the first pmd. The flushing code could also flush to PoU instead of PoC for UP ARMv7, but that's an unrelated optimisation.
With LPAE, map_init_section() is called once per section from alloc_init_pmd(). The loop is there for classic MMU to allow setting two pmd entries (maximum) and flush_pmd_entry() takes care of both (it flushes a full cache line anyway).
Signature · 1 line
Catalin