[PATCH v4 35/61] arm64: pgtable: Decouple PGDIR size macros from PGD/PUD/PMD levels
Ard Biesheuvel
ardb at kernel.org
Tue Oct 24 23:39:58 PDT 2023
On Tue, 24 Oct 2023 at 19:58, Catalin Marinas <catalin.marinas at arm.com> wrote:
>
> On Thu, Oct 19, 2023 at 05:34:33PM +0100, Catalin Marinas wrote:
> > On Tue, Sep 12, 2023 at 02:16:25PM +0000, Ard Biesheuvel wrote:
> > > diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
> > > index 742a4b2778f7..5000f38ae0c6 100644
> > > --- a/arch/arm64/include/asm/kernel-pgtable.h
> > > +++ b/arch/arm64/include/asm/kernel-pgtable.h
> > > @@ -13,27 +13,22 @@
> > > #include <asm/sparsemem.h>
> > >
> > > /*
> > > - * The linear mapping and the start of memory are both 2M aligned (per
> > > - * the arm64 booting.txt requirements). Hence we can use section mapping
> > > - * with 4K (section size = 2M) but not with 16K (section size = 32M) or
> > > - * 64K (section size = 512M).
> > > + * The physical and virtual addresses of the start of the kernel image are
> > > + * equal modulo 2 MiB (per the arm64 booting.txt requirements). Hence we can
> > > + * use section mapping with 4K (section size = 2M) but not with 16K (section
> > > + * size = 32M) or 64K (section size = 512M).
> > > */
> > > -
> > > -/*
> > > - * The idmap and swapper page tables need some space reserved in the kernel
> > > - * image. Both require pgd, pud (4 levels only) and pmd tables to (section)
> > > - * map the kernel. With the 64K page configuration, swapper and idmap need to
> > > - * map to pte level. The swapper also maps the FDT (see __create_page_tables
> > > - * for more information). Note that the number of ID map translation levels
> > > - * could be increased on the fly if system RAM is out of reach for the default
> > > - * VA range, so pages required to map highest possible PA are reserved in all
> > > - * cases.
> > > - */
> > > -#ifdef CONFIG_ARM64_4K_PAGES
> > > -#define SWAPPER_PGTABLE_LEVELS (CONFIG_PGTABLE_LEVELS - 1)
> > > +#if defined(PMD_SIZE) && PMD_SIZE <= MIN_KIMG_ALIGN
> >
> > Nitpick: we always have PMD_SIZE defined, either directly in the arm64
> > headers if we have more than 2 levels or included from the generic
> > pgtable-nopmd.h. Otherwise the logic is fine.
>
> I pushed a patch removing this defined(PMD_SIZE) but it turns out that
> we include this file in assembly and while the generic PMD_SIZE is only
> defined if !defined(__ASSEMBLY__). Not sure the macro is used or just
> the linker complaining.
>
> I'll revert my patch temporarily on top of for-next/core and think about
> it tomorrow. I don't like that this #if check is only false because some
> other header bracketed it with #ifndef __ASSEMBLY__.
>
I don't remember exactly as it's been a while but I suppose this is
why I added the check in the first place.
I agree that having this conditional is not great, but it is fine for
deciding whether to skip a level, given that we only do so when we
have more than 2 levels of paging.
More information about the linux-arm-kernel
mailing list