• Lorenzo Stoakes's avatar
    x86/mm: Increase pgt_buf size for 5-level page tables · 167dcfc0
    Lorenzo Stoakes authored
    pgt_buf is used to allocate page tables on initial direct page mapping
    which bootstraps the kernel into being able to allocate these before the
    direct mapping makes further pages available.
    
    INIT_PGD_PAGE_COUNT is set to 6 pages (doubled for KASLR) - 3 (PUD, PMD,
    PTE) for the 1 MiB ISA mapping and 3 more for the first direct mapping
    assignment in each case providing 2 MiB of address space.
    
    This has not been updated for 5-level page tables which has an
    additional P4D page table level above PUD.
    
    In most instances, this will not have a material impact as the first
    4 page levels allocated for the ISA mapping will provide sufficient
    address space to encompass all further address mappings.
    
    If the first direct mapping is within 512 GiB of the ISA mapping, only
    a PMD and PTE needs to be added in the instance the kernel is using 4
    KiB page tables (e.g. CONFIG_DEBUG_PAGEALLOC is enabled) and only a PMD
    if the kernel can use 2 MiB pages (the first allocation is limited to
    PMD_SIZE so a GiB page cannot be used there).
    
    However, if the machine has more than 512 GiB of RAM and the kernel is
    allocating 4 KiB page size, 3 further page tables are required.
    
    If the machine has more than 256 TiB of RAM at 4 KiB or 2 MiB page size,
    further 3 or 4 page tables are required respectively.
    
    Update INIT_PGD_PAGE_COUNT to reflect this.
    
     [ bp: Sanitize text into passive voice without ambiguous personal pronouns. ]
    Signed-off-by: default avatarLorenzo Stoakes <lstoakes@gmail.com>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Acked-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
    Acked-by: default avatarDave Hansen <dave.hansen@intel.com>
    Link: https://lkml.kernel.org/r/20201215205641.34096-1-lstoakes@gmail.com
    167dcfc0
init.c 30.3 KB