Module kspace

Source
Expand description

Kernel memory space management.

The kernel memory space is currently managed as follows, if the address width is 48 bits (with 47 bits kernel space).

TODO: the cap of linear mapping (the start of vm alloc) are raised to workaround for high IO in TDX. We need actual vm alloc API to have a proper fix.

+-+ <- the highest used address (0xffff_ffff_ffff_0000)
| |         For the kernel code, 1 GiB.
+-+ <- 0xffff_ffff_8000_0000
| |
| |         Unused hole.
+-+ <- 0xffff_e100_0000_0000
| |         For frame metadata, 1 TiB.
+-+ <- 0xffff_e000_0000_0000
| |         For [`KVirtArea`], 32 TiB.
+-+ <- the middle of the higher half (0xffff_c000_0000_0000)
| |
| |
| |
| |         For linear mappings, 64 TiB.
| |         Mapped physical addresses are untracked.
| |
| |
| |
+-+ <- the base of high canonical address (0xffff_8000_0000_0000)

If the address width is (according to crate::arch::mm::PagingConsts) 39 bits or 57 bits, the memory space just adjust proportionally.

Modulesยง

kvirt_area ๐Ÿ”’
Kernel virtual memory allocation

Structsยง

KernelPtConfig ๐Ÿ”’

Enumsยง

MappedItem ๐Ÿ”’

Constantsยง

ADDR_WIDTH_SHIFT ๐Ÿ”’
The shortest supported address width is 39 bits. And the literal values are written for 48 bits address width. Adjust the values by arithmetic left shift.
FRAME_METADATA_BASE_VADDR ๐Ÿ”’
FRAME_METADATA_CAP_VADDR ๐Ÿ”’
FRAME_METADATA_RANGE ๐Ÿ”’
KERNEL_BASE_VADDR
Start of the kernel address space. This is the lowest address of the x86-64โ€™s high canonical addresses.
KERNEL_CODE_BASE_VADDR ๐Ÿ”’
KERNEL_END_VADDR
End of the kernel address space (non inclusive).
LINEAR_MAPPING_BASE_VADDR
The base address of the linear mapping of all physical memory in the kernel address space.
LINEAR_MAPPING_VADDR_RANGE
VMALLOC_BASE_VADDR ๐Ÿ”’
VMALLOC_VADDR_RANGE

Staticsยง

KERNEL_PAGE_TABLE
The kernel page table instance.

Functionsยง

activate_kernel_page_tableโš 
Activates the kernel page table.
init_kernel_page_table
Initializes the kernel page table.
kernel_loaded_offset
The kernel code is linear mapped to this address.
paddr_to_vaddr
Convert physical address to virtual address using offset, only available inside ostd