[PATCH v6 08/41] arm64: vmemmap: Avoid base2 order of struct page size to dimension region

Ard Biesheuvel ardb at kernel.org
Tue Dec 12 13:34:31 PST 2023


On Mon, 11 Dec 2023 at 15:35, Mark Rutland <mark.rutland at arm.com> wrote:
>
> On Wed, Nov 29, 2023 at 12:16:04PM +0100, Ard Biesheuvel wrote:
> > From: Ard Biesheuvel <ardb at kernel.org>
> >
> > The placement and size of the vmemmap region in the kernel virtual
> > address space is currently derived from the base2 order of the size of a
> > struct page. This makes for nicely aligned constants with lots of
> > leading 0xf and trailing 0x0 digits, but given that the actual struct
> > pages are indexed as an ordinary array, this resulting region is
> > severely overdimensioned when the size of a struct page is just over a
> > power of 2.
> >
> > This doesn't matter today, but once we enable 52-bit virtual addressing
> > for 4k pages configurations, the vmemmap region may take up almost half
> > of the upper VA region with the current struct page upper bound at 64
> > bytes. And once we enable KMSAN or other features that push the size of
> > a struct page over 64 bytes, we will run out of VMALLOC space entirely.
> >
> > So instead, let's derive the region size from the actual size of a
> > struct page, and place the entire region 1 GB from the top of the VA
> > space, where it still doesn't share any lower level translation table
> > entries with the fixmap.
> >
> > Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
>
> This is nice, and largely addresses the fear I mentioned on the earlier patches
> move the PCI_IO_* and FIXMAP_* regions. I'd still like to ensure that we have
> assertions that those don't overlap with the VMEMMAP region, but assuming those
> get added to the earlier patches, this looks good as-is:
>
> Acked-by: Mark Rutland <mark.rutland at arm.com>
>

Thanks.

But actually, the only meaningful assert here is that the fixmap does
not grow down into the PCI I/O region. Everything else is hard coded
to unambiguous numeric constants, i.e.

#define VMEMMAP_END             (-UL(SZ_1G))
#define PCI_IO_START            (VMEMMAP_END + SZ_8M)
#define PCI_IO_END              (PCI_IO_START + PCI_IO_SIZE)
#define FIXADDR_TOP             (-UL(SZ_8M))

So I will add the hunk below to

arm64: mm: Move fixmap region above vmemmap region

but adding a static assert that a region that starts at VMEMMAP_END+8M
does not overlap with the VMEMMAP region seems rather futile to me.


--- a/arch/arm64/mm/fixmap.c
+++ b/arch/arm64/mm/fixmap.c
@@ -16,6 +16,9 @@
 #include <asm/pgalloc.h>
 #include <asm/tlbflush.h>

+/* ensure that the fixmap region does not grow down into the PCI I/O region */
+static_assert(FIXADDR_TOT_START > PCI_IO_END);
+
 #define NR_BM_PTE_TABLES \
        SPAN_NR_ENTRIES(FIXADDR_TOT_START, FIXADDR_TOP, PMD_SHIFT)
 #define NR_BM_PMD_TABLES \



More information about the linux-arm-kernel mailing list