68 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3==============45-level paging5==============6 7Overview8========9Original x86-64 was limited by 4-level paging to 256 TiB of virtual address10space and 64 TiB of physical address space. We are already bumping into11this limit: some vendors offer servers with 64 TiB of memory today.12 13To overcome the limitation upcoming hardware will introduce support for145-level paging. It is a straight-forward extension of the current page15table structure adding one more layer of translation.16 17It bumps the limits to 128 PiB of virtual address space and 4 PiB of18physical address space. This "ought to be enough for anybody" ©.19 20QEMU 2.9 and later support 5-level paging.21 22Virtual memory layout for 5-level paging is described in23Documentation/arch/x86/x86_64/mm.rst24 25 26Enabling 5-level paging27=======================28CONFIG_X86_5LEVEL=y enables the feature.29 30Kernel with CONFIG_X86_5LEVEL=y still able to boot on 4-level hardware.31In this case additional page table level -- p4d -- will be folded at32runtime.33 34User-space and large virtual address space35==========================================36On x86, 5-level paging enables 56-bit userspace virtual address space.37Not all user space is ready to handle wide addresses. It's known that38at least some JIT compilers use higher bits in pointers to encode their39information. It collides with valid pointers with 5-level paging and40leads to crashes.41 42To mitigate this, we are not going to allocate virtual address space43above 47-bit by default.44 45But userspace can ask for allocation from full address space by46specifying hint address (with or without MAP_FIXED) above 47-bits.47 48If hint address set above 47-bit, but MAP_FIXED is not specified, we try49to look for unmapped area by specified address. If it's already50occupied, we look for unmapped area in *full* address space, rather than51from 47-bit window.52 53A high hint address would only affect the allocation in question, but not54any future mmap()s.55 56Specifying high hint address on older kernel or on machine without 5-level57paging support is safe. The hint will be ignored and kernel will fall back58to allocation from 47-bit address space.59 60This approach helps to easily make application's memory allocator aware61about large address space without manually tracking allocated virtual62address space.63 64One important case we need to handle here is interaction with MPX.65MPX (without MAWA extension) cannot handle addresses above 47-bit, so we66need to make sure that MPX cannot be enabled we already have VMA above67the boundary and forbid creating such VMAs once MPX is enabled.68