0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 =====================================
0004 Virtual Memory Layout on RISC-V Linux
0005 =====================================
0006
0007 :Author: Alexandre Ghiti <alex@ghiti.fr>
0008 :Date: 12 February 2021
0009
0010 This document describes the virtual memory layout used by the RISC-V Linux
0011 Kernel.
0012
0013 RISC-V Linux Kernel 32bit
0014 =========================
0015
0016 RISC-V Linux Kernel SV32
0017 ------------------------
0018
0019 TODO
0020
0021 RISC-V Linux Kernel 64bit
0022 =========================
0023
0024 The RISC-V privileged architecture document states that the 64bit addresses
0025 "must have bits 63–48 all equal to bit 47, or else a page-fault exception will
0026 occur.": that splits the virtual address space into 2 halves separated by a very
0027 big hole, the lower half is where the userspace resides, the upper half is where
0028 the RISC-V Linux Kernel resides.
0029
0030 RISC-V Linux Kernel SV39
0031 ------------------------
0032
0033 ::
0034
0035 ========================================================================================================================
0036 Start addr | Offset | End addr | Size | VM area description
0037 ========================================================================================================================
0038 | | | |
0039 0000000000000000 | 0 | 0000003fffffffff | 256 GB | user-space virtual memory, different per mm
0040 __________________|____________|__________________|_________|___________________________________________________________
0041 | | | |
0042 0000004000000000 | +256 GB | ffffffbfffffffff | ~16M TB | ... huge, almost 64 bits wide hole of non-canonical
0043 | | | | virtual memory addresses up to the -256 GB
0044 | | | | starting offset of kernel mappings.
0045 __________________|____________|__________________|_________|___________________________________________________________
0046 |
0047 | Kernel-space virtual memory, shared between all processes:
0048 ____________________________________________________________|___________________________________________________________
0049 | | | |
0050 ffffffc6fee00000 | -228 GB | ffffffc6feffffff | 2 MB | fixmap
0051 ffffffc6ff000000 | -228 GB | ffffffc6ffffffff | 16 MB | PCI io
0052 ffffffc700000000 | -228 GB | ffffffc7ffffffff | 4 GB | vmemmap
0053 ffffffc800000000 | -224 GB | ffffffd7ffffffff | 64 GB | vmalloc/ioremap space
0054 ffffffd800000000 | -160 GB | fffffff6ffffffff | 124 GB | direct mapping of all physical memory
0055 fffffff700000000 | -36 GB | fffffffeffffffff | 32 GB | kasan
0056 __________________|____________|__________________|_________|____________________________________________________________
0057 |
0058 |
0059 ____________________________________________________________|____________________________________________________________
0060 | | | |
0061 ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
0062 ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
0063 __________________|____________|__________________|_________|____________________________________________________________
0064
0065
0066 RISC-V Linux Kernel SV48
0067 ------------------------
0068
0069 ::
0070
0071 ========================================================================================================================
0072 Start addr | Offset | End addr | Size | VM area description
0073 ========================================================================================================================
0074 | | | |
0075 0000000000000000 | 0 | 00007fffffffffff | 128 TB | user-space virtual memory, different per mm
0076 __________________|____________|__________________|_________|___________________________________________________________
0077 | | | |
0078 0000800000000000 | +128 TB | ffff7fffffffffff | ~16M TB | ... huge, almost 64 bits wide hole of non-canonical
0079 | | | | virtual memory addresses up to the -128 TB
0080 | | | | starting offset of kernel mappings.
0081 __________________|____________|__________________|_________|___________________________________________________________
0082 |
0083 | Kernel-space virtual memory, shared between all processes:
0084 ____________________________________________________________|___________________________________________________________
0085 | | | |
0086 ffff8d7ffee00000 | -114.5 TB | ffff8d7ffeffffff | 2 MB | fixmap
0087 ffff8d7fff000000 | -114.5 TB | ffff8d7fffffffff | 16 MB | PCI io
0088 ffff8d8000000000 | -114.5 TB | ffff8f7fffffffff | 2 TB | vmemmap
0089 ffff8f8000000000 | -112.5 TB | ffffaf7fffffffff | 32 TB | vmalloc/ioremap space
0090 ffffaf8000000000 | -80.5 TB | ffffef7fffffffff | 64 TB | direct mapping of all physical memory
0091 ffffef8000000000 | -16.5 TB | fffffffeffffffff | 16.5 TB | kasan
0092 __________________|____________|__________________|_________|____________________________________________________________
0093 |
0094 | Identical layout to the 39-bit one from here on:
0095 ____________________________________________________________|____________________________________________________________
0096 | | | |
0097 ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
0098 ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
0099 __________________|____________|__________________|_________|____________________________________________________________