Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1======================
2Kernel page table dump
3======================
4
5ptdump is a debugfs interface that provides a detailed dump of the
6kernel page tables. It offers a comprehensive overview of the kernel
7virtual memory layout as well as the attributes associated with the
8various regions in a human-readable format. It is useful to dump the
9kernel page tables to verify permissions and memory types. Examining the
10page table entries and permissions helps identify potential security
11vulnerabilities such as mappings with overly permissive access rights or
12improper memory protections.
13
14Memory hotplug allows dynamic expansion or contraction of available
15memory without requiring a system reboot. To maintain the consistency
16and integrity of the memory management data structures, arm64 makes use
17of the ``mem_hotplug_lock`` semaphore in write mode. Additionally, in
18read mode, ``mem_hotplug_lock`` supports an efficient implementation of
19``get_online_mems()`` and ``put_online_mems()``. These protect the
20offlining of memory being accessed by the ptdump code.
21
22In order to dump the kernel page tables, enable the following
23configurations and mount debugfs::
24
25 CONFIG_PTDUMP_DEBUGFS=y
26
27 mount -t debugfs nodev /sys/kernel/debug
28 cat /sys/kernel/debug/kernel_page_tables
29
30On analysing the output of ``cat /sys/kernel/debug/kernel_page_tables``
31one can derive information about the virtual address range of the entry,
32followed by size of the memory region covered by this entry, the
33hierarchical structure of the page tables and finally the attributes
34associated with each page. The page attributes provide information about
35access permissions, execution capability, type of mapping such as leaf
36level PTE or block level PGD, PMD and PUD, and access status of a page
37within the kernel memory. Assessing these attributes can assist in
38understanding the memory layout, access patterns and security
39characteristics of the kernel pages.
40
41Kernel virtual memory layout example::
42
43 start address end address size attributes
44 +---------------------------------------------------------------------------------------+
45 | ---[ Linear Mapping start ]---------------------------------------------------------- |
46 | .................. |
47 | 0xfff0000000000000-0xfff0000000210000 2112K PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED |
48 | 0xfff0000000210000-0xfff0000001c00000 26560K PTE ro NX SHD AF UXN MEM/NORMAL |
49 | .................. |
50 | ---[ Linear Mapping end ]------------------------------------------------------------ |
51 +---------------------------------------------------------------------------------------+
52 | ---[ Modules start ]----------------------------------------------------------------- |
53 | .................. |
54 | 0xffff800000000000-0xffff800008000000 128M PTE |
55 | .................. |
56 | ---[ Modules end ]------------------------------------------------------------------- |
57 +---------------------------------------------------------------------------------------+
58 | ---[ vmalloc() area ]---------------------------------------------------------------- |
59 | .................. |
60 | 0xffff800008010000-0xffff800008200000 1984K PTE ro x SHD AF UXN MEM/NORMAL |
61 | 0xffff800008200000-0xffff800008e00000 12M PTE ro x SHD AF CON UXN MEM/NORMAL |
62 | .................. |
63 | ---[ vmalloc() end ]----------------------------------------------------------------- |
64 +---------------------------------------------------------------------------------------+
65 | ---[ Fixmap start ]------------------------------------------------------------------ |
66 | .................. |
67 | 0xfffffbfffdb80000-0xfffffbfffdb90000 64K PTE ro x SHD AF UXN MEM/NORMAL |
68 | 0xfffffbfffdb90000-0xfffffbfffdba0000 64K PTE ro NX SHD AF UXN MEM/NORMAL |
69 | .................. |
70 | ---[ Fixmap end ]-------------------------------------------------------------------- |
71 +---------------------------------------------------------------------------------------+
72 | ---[ PCI I/O start ]----------------------------------------------------------------- |
73 | .................. |
74 | 0xfffffbfffe800000-0xfffffbffff800000 16M PTE |
75 | .................. |
76 | ---[ PCI I/O end ]------------------------------------------------------------------- |
77 +---------------------------------------------------------------------------------------+
78 | ---[ vmemmap start ]----------------------------------------------------------------- |
79 | .................. |
80 | 0xfffffc0002000000-0xfffffc0002200000 2M PTE RW NX SHD AF UXN MEM/NORMAL |
81 | 0xfffffc0002200000-0xfffffc0020000000 478M PTE |
82 | .................. |
83 | ---[ vmemmap end ]------------------------------------------------------------------- |
84 +---------------------------------------------------------------------------------------+
85
86``cat /sys/kernel/debug/kernel_page_tables`` output::
87
88 0xfff0000001c00000-0xfff0000080000000 2020M PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
89 0xfff0000080000000-0xfff0000800000000 30G PMD
90 0xfff0000800000000-0xfff0000800700000 7M PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
91 0xfff0000800700000-0xfff0000800710000 64K PTE ro NX SHD AF UXN MEM/NORMAL-TAGGED
92 0xfff0000800710000-0xfff0000880000000 2089920K PTE RW NX SHD AF UXN MEM/NORMAL-TAGGED
93 0xfff0000880000000-0xfff0040000000000 4062G PMD
94 0xfff0040000000000-0xffff800000000000 3964T PGD