• Russell King's avatar
    ARM: 7785/1: mm: restrict early_alloc to section-aligned memory · c65b7e98
    Russell King authored
    When map_lowmem() runs, and processes a memory bank whose start or end
    is not section-aligned, memory must be allocated to store the 2nd-level
    page tables. Those allocations are made by calling memblock_alloc().
    
    At this point, the only memory that is free *and* mapped is memory which
    has already been mapped by map_lowmem() itself. For this reason, we must
    calculate the first point at which map_lowmem() will need to allocate
    memory, and set the memblock allocation limit to a lower address, so that
    memblock_alloc() is guaranteed to return memory that is already mapped.
    
    This patch enhances sanity_check_meminfo() to calculate that memory
    address, and pass it to memblock_set_current_limit(), rather than just
    assuming the limit is arm_lowmem_limit.
    
    The algorithm applied is:
    
    * Default memblock_limit to arm_lowmem_limit in the absence of any other
      limit; arm_lowmem_limit is the highest memory that is mapped by
      map_lowmem().
    
    * While walking the list of memblocks, if the start of a block is not
      aligned, 2nd-level page tables will need to be allocated to map the
      first few pages of the block. Hence, the memblock_limit must be before
      the start of the block.
    
    * Similarly, if the end of any block is not aligned, 2nd-level page
      tables will need to be allocated to map the last few pages of the
      block. Hence, the memblock_limit must point at the end of the block,
      rounded down to section-alignment.
    
    * The memory blocks are assumed to be sorted in address order, so the
      first unaligned block start or end is used to set the limit.
    
    With this algorithm, the start or end of almost any bank can be non-
    section-aligned. The only exception is that the start of bank 0 must
    be section-aligned, since otherwise memory would need to be allocated
    when mapping the start of bank 0, which occurs before any free memory
    is mapped.
    
    [swarren, wrote commit description, rewrote calculation of memblock_limit]
    Signed-off-by: default avatarStephen Warren <swarren@nvidia.com>
    Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
    c65b7e98
mmu.c 35.2 KB