vm-layout.rst 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =====================================
  3. Virtual Memory Layout on RISC-V Linux
  4. =====================================
  5. :Author: Alexandre Ghiti <alex@ghiti.fr>
  6. :Date: 12 February 2021
  7. This document describes the virtual memory layout used by the RISC-V Linux
  8. Kernel.
  9. RISC-V Linux Kernel 32bit
  10. =========================
  11. RISC-V Linux Kernel SV32
  12. ------------------------
  13. TODO
  14. RISC-V Linux Kernel 64bit
  15. =========================
  16. The RISC-V privileged architecture document states that the 64bit addresses
  17. "must have bits 63–48 all equal to bit 47, or else a page-fault exception will
  18. occur.": that splits the virtual address space into 2 halves separated by a very
  19. big hole, the lower half is where the userspace resides, the upper half is where
  20. the RISC-V Linux Kernel resides.
  21. RISC-V Linux Kernel SV39
  22. ------------------------
  23. ::
  24. ========================================================================================================================
  25. Start addr | Offset | End addr | Size | VM area description
  26. ========================================================================================================================
  27. | | | |
  28. 0000000000000000 | 0 | 0000003fffffffff | 256 GB | user-space virtual memory, different per mm
  29. __________________|____________|__________________|_________|___________________________________________________________
  30. | | | |
  31. 0000004000000000 | +256 GB | ffffffbfffffffff | ~16M TB | ... huge, almost 64 bits wide hole of non-canonical
  32. | | | | virtual memory addresses up to the -256 GB
  33. | | | | starting offset of kernel mappings.
  34. __________________|____________|__________________|_________|___________________________________________________________
  35. |
  36. | Kernel-space virtual memory, shared between all processes:
  37. ____________________________________________________________|___________________________________________________________
  38. | | | |
  39. ffffffc4fea00000 | -236 GB | ffffffc4feffffff | 6 MB | fixmap
  40. ffffffc4ff000000 | -236 GB | ffffffc4ffffffff | 16 MB | PCI io
  41. ffffffc500000000 | -236 GB | ffffffc5ffffffff | 4 GB | vmemmap
  42. ffffffc600000000 | -232 GB | ffffffd5ffffffff | 64 GB | vmalloc/ioremap space
  43. ffffffd600000000 | -168 GB | fffffff5ffffffff | 128 GB | direct mapping of all physical memory
  44. | | | |
  45. fffffff700000000 | -36 GB | fffffffeffffffff | 32 GB | kasan
  46. __________________|____________|__________________|_________|____________________________________________________________
  47. |
  48. |
  49. ____________________________________________________________|____________________________________________________________
  50. | | | |
  51. ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
  52. ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
  53. __________________|____________|__________________|_________|____________________________________________________________
  54. RISC-V Linux Kernel SV48
  55. ------------------------
  56. ::
  57. ========================================================================================================================
  58. Start addr | Offset | End addr | Size | VM area description
  59. ========================================================================================================================
  60. | | | |
  61. 0000000000000000 | 0 | 00007fffffffffff | 128 TB | user-space virtual memory, different per mm
  62. __________________|____________|__________________|_________|___________________________________________________________
  63. | | | |
  64. 0000800000000000 | +128 TB | ffff7fffffffffff | ~16M TB | ... huge, almost 64 bits wide hole of non-canonical
  65. | | | | virtual memory addresses up to the -128 TB
  66. | | | | starting offset of kernel mappings.
  67. __________________|____________|__________________|_________|___________________________________________________________
  68. |
  69. | Kernel-space virtual memory, shared between all processes:
  70. ____________________________________________________________|___________________________________________________________
  71. | | | |
  72. ffff8d7ffea00000 | -114.5 TB | ffff8d7ffeffffff | 6 MB | fixmap
  73. ffff8d7fff000000 | -114.5 TB | ffff8d7fffffffff | 16 MB | PCI io
  74. ffff8d8000000000 | -114.5 TB | ffff8f7fffffffff | 2 TB | vmemmap
  75. ffff8f8000000000 | -112.5 TB | ffffaf7fffffffff | 32 TB | vmalloc/ioremap space
  76. ffffaf8000000000 | -80.5 TB | ffffef7fffffffff | 64 TB | direct mapping of all physical memory
  77. ffffef8000000000 | -16.5 TB | fffffffeffffffff | 16.5 TB | kasan
  78. __________________|____________|__________________|_________|____________________________________________________________
  79. |
  80. | Identical layout to the 39-bit one from here on:
  81. ____________________________________________________________|____________________________________________________________
  82. | | | |
  83. ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
  84. ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
  85. __________________|____________|__________________|_________|____________________________________________________________
  86. RISC-V Linux Kernel SV57
  87. ------------------------
  88. ::
  89. ========================================================================================================================
  90. Start addr | Offset | End addr | Size | VM area description
  91. ========================================================================================================================
  92. | | | |
  93. 0000000000000000 | 0 | 00ffffffffffffff | 64 PB | user-space virtual memory, different per mm
  94. __________________|____________|__________________|_________|___________________________________________________________
  95. | | | |
  96. 0100000000000000 | +64 PB | feffffffffffffff | ~16K PB | ... huge, almost 64 bits wide hole of non-canonical
  97. | | | | virtual memory addresses up to the -64 PB
  98. | | | | starting offset of kernel mappings.
  99. __________________|____________|__________________|_________|___________________________________________________________
  100. |
  101. | Kernel-space virtual memory, shared between all processes:
  102. ____________________________________________________________|___________________________________________________________
  103. | | | |
  104. ff1bfffffea00000 | -57 PB | ff1bfffffeffffff | 6 MB | fixmap
  105. ff1bffffff000000 | -57 PB | ff1bffffffffffff | 16 MB | PCI io
  106. ff1c000000000000 | -57 PB | ff1fffffffffffff | 1 PB | vmemmap
  107. ff20000000000000 | -56 PB | ff5fffffffffffff | 16 PB | vmalloc/ioremap space
  108. ff60000000000000 | -40 PB | ffdeffffffffffff | 32 PB | direct mapping of all physical memory
  109. ffdf000000000000 | -8 PB | fffffffeffffffff | 8 PB | kasan
  110. __________________|____________|__________________|_________|____________________________________________________________
  111. |
  112. | Identical layout to the 39-bit one from here on:
  113. ____________________________________________________________|____________________________________________________________
  114. | | | |
  115. ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
  116. ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
  117. __________________|____________|__________________|_________|____________________________________________________________