vm-layout.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =====================================
  3. Virtual Memory Layout on RISC-V Linux
  4. =====================================
  5. :Author: Alexandre Ghiti <[email protected]>
  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. ffffffc6fea00000 | -228 GB | ffffffc6feffffff | 6 MB | fixmap
  40. ffffffc6ff000000 | -228 GB | ffffffc6ffffffff | 16 MB | PCI io
  41. ffffffc700000000 | -228 GB | ffffffc7ffffffff | 4 GB | vmemmap
  42. ffffffc800000000 | -224 GB | ffffffd7ffffffff | 64 GB | vmalloc/ioremap space
  43. ffffffd800000000 | -160 GB | fffffff6ffffffff | 124 GB | direct mapping of all physical memory
  44. fffffff700000000 | -36 GB | fffffffeffffffff | 32 GB | kasan
  45. __________________|____________|__________________|_________|____________________________________________________________
  46. |
  47. |
  48. ____________________________________________________________|____________________________________________________________
  49. | | | |
  50. ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
  51. ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
  52. __________________|____________|__________________|_________|____________________________________________________________
  53. RISC-V Linux Kernel SV48
  54. ------------------------
  55. ::
  56. ========================================================================================================================
  57. Start addr | Offset | End addr | Size | VM area description
  58. ========================================================================================================================
  59. | | | |
  60. 0000000000000000 | 0 | 00007fffffffffff | 128 TB | user-space virtual memory, different per mm
  61. __________________|____________|__________________|_________|___________________________________________________________
  62. | | | |
  63. 0000800000000000 | +128 TB | ffff7fffffffffff | ~16M TB | ... huge, almost 64 bits wide hole of non-canonical
  64. | | | | virtual memory addresses up to the -128 TB
  65. | | | | starting offset of kernel mappings.
  66. __________________|____________|__________________|_________|___________________________________________________________
  67. |
  68. | Kernel-space virtual memory, shared between all processes:
  69. ____________________________________________________________|___________________________________________________________
  70. | | | |
  71. ffff8d7ffea00000 | -114.5 TB | ffff8d7ffeffffff | 6 MB | fixmap
  72. ffff8d7fff000000 | -114.5 TB | ffff8d7fffffffff | 16 MB | PCI io
  73. ffff8d8000000000 | -114.5 TB | ffff8f7fffffffff | 2 TB | vmemmap
  74. ffff8f8000000000 | -112.5 TB | ffffaf7fffffffff | 32 TB | vmalloc/ioremap space
  75. ffffaf8000000000 | -80.5 TB | ffffef7fffffffff | 64 TB | direct mapping of all physical memory
  76. ffffef8000000000 | -16.5 TB | fffffffeffffffff | 16.5 TB | kasan
  77. __________________|____________|__________________|_________|____________________________________________________________
  78. |
  79. | Identical layout to the 39-bit one from here on:
  80. ____________________________________________________________|____________________________________________________________
  81. | | | |
  82. ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
  83. ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
  84. __________________|____________|__________________|_________|____________________________________________________________