Re: [PATCH] [RESEND] arm: limit memblock base address for early_pte_alloc

From: Minchan Kim
Date: Tue Jun 19 2012 - 04:38:10 EST


Resend.

Could you please see this problem?

Thanks.

On Tue, Jun 5, 2012 at 4:11 PM, Minchan Kim <minchan@xxxxxxxxxx> wrote:
> If we do arm_memblock_steal with a page which is not aligned with section size,
> panic can happen during boot by page fault in map_lowmem.
>
> Detail:
>
> 1) mdesc->reserve can steal a page which is allocated at 0x1ffff000 by memblock
> Â which prefers tail pages of regions.
> 2) map_lowmem maps 0x00000000 - 0x1fe00000
> 3) map_lowmem try to map 0x1fe00000 but it's not aligned by section due to 1.
> 4) calling alloc_init_pte allocates a new page for new pte by memblock_alloc
> 5) allocated memory for pte is 0x1fffe000 -> it's not mapped yet.
> 6) memset(ptr, 0, sz) in early_alloc_aligned got PANICed!
>
> This patch fix it by limiting memblock to mapped memory range.
>
> Reported-by: Jongsung Kim <neidhard.kim@xxxxxxx>
> Suggested-by: Chanho Min <chanho.min@xxxxxxx>
> Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
> ---
> Âarch/arm/mm/mmu.c | Â 37 ++++++++++++++++++++++---------------
> Â1 file changed, 22 insertions(+), 15 deletions(-)
>
> diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
> index e5dad60..a15aafe 100644
> --- a/arch/arm/mm/mmu.c
> +++ b/arch/arm/mm/mmu.c
> @@ -594,7 +594,7 @@ static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
>
> Âstatic void __init alloc_init_section(pud_t *pud, unsigned long addr,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned long end, phys_addr_t phys,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const struct mem_type *type)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const struct mem_type *type, bool lowmem)
> Â{
> Â Â Â Âpmd_t *pmd = pmd_offset(pud, addr);
>
> @@ -619,6 +619,8 @@ static void __init alloc_init_section(pud_t *pud, unsigned long addr,
>
> Â Â Â Â Â Â Â Âflush_pmd_entry(p);
> Â Â Â Â} else {
> + Â Â Â Â Â Â Â if (lowmem)
> + Â Â Â Â Â Â Â Â Â Â Â memblock_set_current_limit(__pa(addr));
> Â Â Â Â Â Â Â Â/*
> Â Â Â Â Â Â Â Â * No need to loop; pte's aren't interested in the
> Â Â Â Â Â Â Â Â * individual L1 entries.
> @@ -628,14 +630,15 @@ static void __init alloc_init_section(pud_t *pud, unsigned long addr,
> Â}
>
> Âstatic void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
> - Â Â Â unsigned long end, unsigned long phys, const struct mem_type *type)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned long end, unsigned long phys,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â const struct mem_type *type, bool lowmem)
> Â{
> Â Â Â Âpud_t *pud = pud_offset(pgd, addr);
> Â Â Â Âunsigned long next;
>
> Â Â Â Âdo {
> Â Â Â Â Â Â Â Ânext = pud_addr_end(addr, end);
> - Â Â Â Â Â Â Â alloc_init_section(pud, addr, next, phys, type);
> + Â Â Â Â Â Â Â alloc_init_section(pud, addr, next, phys, type, lowmem);
> Â Â Â Â Â Â Â Âphys += next - addr;
> Â Â Â Â} while (pud++, addr = next, addr != end);
> Â}
> @@ -702,14 +705,7 @@ static void __init create_36bit_mapping(struct map_desc *md,
> Â}
> Â#endif /* !CONFIG_ARM_LPAE */
>
> -/*
> - * Create the page directory entries and any necessary
> - * page tables for the mapping specified by `md'. ÂWe
> - * are able to cope here with varying sizes and address
> - * offsets, and we take full advantage of sections and
> - * supersections.
> - */
> -static void __init create_mapping(struct map_desc *md)
> +static inline void __create_mapping(struct map_desc *md, bool lowmem)
> Â{
> Â Â Â Âunsigned long addr, length, end;
> Â Â Â Âphys_addr_t phys;
> @@ -759,7 +755,7 @@ static void __init create_mapping(struct map_desc *md)
> Â Â Â Âdo {
> Â Â Â Â Â Â Â Âunsigned long next = pgd_addr_end(addr, end);
>
> - Â Â Â Â Â Â Â alloc_init_pud(pgd, addr, next, phys, type);
> + Â Â Â Â Â Â Â alloc_init_pud(pgd, addr, next, phys, type, lowmem);
>
> Â Â Â Â Â Â Â Âphys += next - addr;
> Â Â Â Â Â Â Â Âaddr = next;
> @@ -767,6 +763,18 @@ static void __init create_mapping(struct map_desc *md)
> Â}
>
> Â/*
> + * Create the page directory entries and any necessary
> + * page tables for the mapping specified by `md'. ÂWe
> + * are able to cope here with varying sizes and address
> + * offsets, and we take full advantage of sections and
> + * supersections.
> + */
> +static void __init create_mapping(struct map_desc *md)
> +{
> + Â Â Â __create_mapping(md, false);
> +}
> +
> +/*
> Â* Create the architecture specific mappings
> Â*/
> Âvoid __init iotable_init(struct map_desc *io_desc, int nr)
> @@ -1111,7 +1119,7 @@ static void __init map_lowmem(void)
> Â Â Â Â Â Â Â Âmap.length = end - start;
> Â Â Â Â Â Â Â Âmap.type = MT_MEMORY;
>
> - Â Â Â Â Â Â Â create_mapping(&map);
> + Â Â Â Â Â Â Â __create_mapping(&map, true);
> Â Â Â Â}
> Â}
>
> @@ -1123,11 +1131,10 @@ void __init paging_init(struct machine_desc *mdesc)
> Â{
> Â Â Â Âvoid *zero_page;
>
> - Â Â Â memblock_set_current_limit(arm_lowmem_limit);
> -
> Â Â Â Âbuild_mem_type_table();
> Â Â Â Âprepare_page_table();
> Â Â Â Âmap_lowmem();
> + Â Â Â memblock_set_current_limit(arm_lowmem_limit);
> Â Â Â Âdma_contiguous_remap();
> Â Â Â Âdevicemaps_init(mdesc);
> Â Â Â Âkmap_init();
> --
> 1.7.9.5
>



--
Kind regards,
Minchan Kim
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/