Re: [PATCH] efi/arm: fix allocation failure when reserving the kernel base

From: Ard Biesheuvel
Date: Wed Aug 21 2019 - 05:43:12 EST


On Wed, 21 Aug 2019 at 11:29, Mike Rapoport <rppt@xxxxxxxxxxxxx> wrote:
>
> On Wed, Aug 21, 2019 at 10:29:37AM +0300, Ard Biesheuvel wrote:
> > On Wed, 21 Aug 2019 at 10:11, Mike Rapoport <rppt@xxxxxxxxxxxxx> wrote:
> > >
...
> > > I think the only missing part here is to ensure that non-reserved memory in
> > > bank 0 starts from a PMD-aligned address. I believe this could be done if
> > > EFI stub, but I'm not really familiar with it so this just a semi-educated
> > > guess :)
> > >
> >
> > Given that it is the ARM arch code that imposes this requirement, how
> > about adding something like this to adjust_lowmem_bounds():
> >
> > if (memblock_start_of_DRAM() % PMD_SIZE)
> > memblock_mark_nomap(memblock_start_of_DRAM(),
> > PMD_SIZE - (memblock_start_of_DRAM() % PMD_SIZE));
>
> memblock_start_of_DRAM() won't work here, as it returns the actual start of
> the DRAM including NOMAP regions. Moreover, as we cannot mark a region
> NOMAP inside for_each_memblock() this should be done beforehand.
>
> I think something like this could work:
>
> diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
> index 2f0f07e..f2b635b 100644
> --- a/arch/arm/mm/mmu.c
> +++ b/arch/arm/mm/mmu.c
> @@ -1178,6 +1178,19 @@ void __init adjust_lowmem_bounds(void)
> */
> vmalloc_limit = (u64)(uintptr_t)vmalloc_min - PAGE_OFFSET + PHYS_OFFSET;
>
> + /*
> + * The first usable region must be PMD aligned. Mark its start
> + * as MEMBLOCK_NOMAP if it isn't
> + */
> + for_each_memblock(memory, reg) {
> + if (!memblock_is_nomap(reg) && (reg->base % PMD_SIZE)) {
> + phys_addr_t size = PMD_SIZE - (reg->base % PMD_SIZE);
> +
> + memblock_mark_nomap(reg->base, size);
> + break;

We should break on the first !NOMAP memblock, even if it is already
PMD aligned, but beyond that, this looks ok to me.