~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/gdb/linux/mm.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/gdb/linux/mm.py (Version linux-6.12-rc7) and /scripts/gdb/linux/mm.py (Version linux-6.10.14)


  1 # SPDX-License-Identifier: GPL-2.0                  1 # SPDX-License-Identifier: GPL-2.0
  2 #                                                   2 #
  3 # Copyright (c) 2023 MediaTek Inc.                  3 # Copyright (c) 2023 MediaTek Inc.
  4 #                                                   4 #
  5 # Authors:                                          5 # Authors:
  6 #  Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>        6 #  Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
  7 #                                                   7 #
  8                                                     8 
  9 import gdb                                          9 import gdb
 10 import math                                        10 import math
 11 from linux import utils, constants                 11 from linux import utils, constants
 12                                                    12 
 13 def DIV_ROUND_UP(n,d):                             13 def DIV_ROUND_UP(n,d):
 14     return ((n) + (d) - 1) // (d)                  14     return ((n) + (d) - 1) // (d)
 15                                                    15 
 16 def test_bit(nr, addr):                            16 def test_bit(nr, addr):
 17     if addr.dereference() & (0x1 << nr):           17     if addr.dereference() & (0x1 << nr):
 18         return True                                18         return True
 19     else:                                          19     else:
 20         return False                               20         return False
 21                                                    21 
 22 class page_ops():                                  22 class page_ops():
 23     ops = None                                     23     ops = None
 24     def __init__(self):                            24     def __init__(self):
 25         if not constants.LX_CONFIG_SPARSEMEM_V     25         if not constants.LX_CONFIG_SPARSEMEM_VMEMMAP:
 26             raise gdb.GdbError('Only support C     26             raise gdb.GdbError('Only support CONFIG_SPARSEMEM_VMEMMAP now')
 27         if constants.LX_CONFIG_ARM64 and utils     27         if constants.LX_CONFIG_ARM64 and utils.is_target_arch('aarch64'):
 28             self.ops = aarch64_page_ops()          28             self.ops = aarch64_page_ops()
 29         else:                                      29         else:
 30             raise gdb.GdbError('Only support a     30             raise gdb.GdbError('Only support aarch64 now')
 31                                                    31 
 32 class aarch64_page_ops():                          32 class aarch64_page_ops():
 33     def __init__(self):                            33     def __init__(self):
 34         self.SUBSECTION_SHIFT = 21                 34         self.SUBSECTION_SHIFT = 21
 35         self.SEBSECTION_SIZE = 1 << self.SUBSE     35         self.SEBSECTION_SIZE = 1 << self.SUBSECTION_SHIFT
 36         self.MODULES_VSIZE = 2 * 1024 * 1024 * !!  36         self.MODULES_VSIZE = 128 * 1024 * 1024
 37                                                    37 
 38         if constants.LX_CONFIG_ARM64_64K_PAGES     38         if constants.LX_CONFIG_ARM64_64K_PAGES:
 39             self.SECTION_SIZE_BITS = 29            39             self.SECTION_SIZE_BITS = 29
 40         else:                                      40         else:
 41             self.SECTION_SIZE_BITS = 27            41             self.SECTION_SIZE_BITS = 27
 42         self.MAX_PHYSMEM_BITS = constants.LX_C     42         self.MAX_PHYSMEM_BITS = constants.LX_CONFIG_ARM64_VA_BITS
 43                                                    43 
 44         self.PAGE_SHIFT = constants.LX_CONFIG_     44         self.PAGE_SHIFT = constants.LX_CONFIG_PAGE_SHIFT
 45         self.PAGE_SIZE = 1 << self.PAGE_SHIFT      45         self.PAGE_SIZE = 1 << self.PAGE_SHIFT
 46         self.PAGE_MASK = (~(self.PAGE_SIZE - 1     46         self.PAGE_MASK = (~(self.PAGE_SIZE - 1)) & ((1 << 64) - 1)
 47                                                    47 
 48         self.VA_BITS = constants.LX_CONFIG_ARM     48         self.VA_BITS = constants.LX_CONFIG_ARM64_VA_BITS
 49         if self.VA_BITS > 48:                      49         if self.VA_BITS > 48:
 50             if constants.LX_CONFIG_ARM64_16K_P !!  50             self.VA_BITS_MIN = 48
 51                 self.VA_BITS_MIN = 47          !!  51             self.vabits_actual = gdb.parse_and_eval('vabits_actual')
 52             else:                              << 
 53                 self.VA_BITS_MIN = 48          << 
 54             tcr_el1 = gdb.execute("info regist << 
 55             tcr_el1 = int(tcr_el1.split()[1],  << 
 56             self.vabits_actual = 64 - ((tcr_el << 
 57         else:                                      52         else:
 58             self.VA_BITS_MIN = self.VA_BITS        53             self.VA_BITS_MIN = self.VA_BITS
 59             self.vabits_actual = self.VA_BITS      54             self.vabits_actual = self.VA_BITS
 60         self.kimage_voffset = gdb.parse_and_ev     55         self.kimage_voffset = gdb.parse_and_eval('kimage_voffset') & ((1 << 64) - 1)
 61                                                    56 
 62         self.SECTIONS_SHIFT = self.MAX_PHYSMEM     57         self.SECTIONS_SHIFT = self.MAX_PHYSMEM_BITS - self.SECTION_SIZE_BITS
 63                                                    58 
 64         if str(constants.LX_CONFIG_ARCH_FORCE_     59         if str(constants.LX_CONFIG_ARCH_FORCE_MAX_ORDER).isdigit():
 65             self.MAX_ORDER = constants.LX_CONF     60             self.MAX_ORDER = constants.LX_CONFIG_ARCH_FORCE_MAX_ORDER
 66         else:                                      61         else:
 67             self.MAX_ORDER = 10                !!  62             self.MAX_ORDER = 11
 68                                                    63 
 69         self.MAX_ORDER_NR_PAGES = 1 << (self.M !!  64         self.MAX_ORDER_NR_PAGES = 1 << (self.MAX_ORDER - 1)
 70         self.PFN_SECTION_SHIFT = self.SECTION_     65         self.PFN_SECTION_SHIFT = self.SECTION_SIZE_BITS - self.PAGE_SHIFT
 71         self.NR_MEM_SECTIONS = 1 << self.SECTI     66         self.NR_MEM_SECTIONS = 1 << self.SECTIONS_SHIFT
 72         self.PAGES_PER_SECTION = 1 << self.PFN     67         self.PAGES_PER_SECTION = 1 << self.PFN_SECTION_SHIFT
 73         self.PAGE_SECTION_MASK = (~(self.PAGES     68         self.PAGE_SECTION_MASK = (~(self.PAGES_PER_SECTION - 1)) & ((1 << 64) - 1)
 74                                                    69 
 75         if constants.LX_CONFIG_SPARSEMEM_EXTRE     70         if constants.LX_CONFIG_SPARSEMEM_EXTREME:
 76             self.SECTIONS_PER_ROOT = self.PAGE     71             self.SECTIONS_PER_ROOT = self.PAGE_SIZE // gdb.lookup_type("struct mem_section").sizeof
 77         else:                                      72         else:
 78             self.SECTIONS_PER_ROOT = 1             73             self.SECTIONS_PER_ROOT = 1
 79                                                    74 
 80         self.NR_SECTION_ROOTS = DIV_ROUND_UP(s     75         self.NR_SECTION_ROOTS = DIV_ROUND_UP(self.NR_MEM_SECTIONS, self.SECTIONS_PER_ROOT)
 81         self.SECTION_ROOT_MASK = self.SECTIONS     76         self.SECTION_ROOT_MASK = self.SECTIONS_PER_ROOT - 1
 82         self.SUBSECTION_SHIFT = 21                 77         self.SUBSECTION_SHIFT = 21
 83         self.SEBSECTION_SIZE = 1 << self.SUBSE     78         self.SEBSECTION_SIZE = 1 << self.SUBSECTION_SHIFT
 84         self.PFN_SUBSECTION_SHIFT = self.SUBSE     79         self.PFN_SUBSECTION_SHIFT = self.SUBSECTION_SHIFT - self.PAGE_SHIFT
 85         self.PAGES_PER_SUBSECTION = 1 << self.     80         self.PAGES_PER_SUBSECTION = 1 << self.PFN_SUBSECTION_SHIFT
 86                                                    81 
 87         self.SECTION_HAS_MEM_MAP = 1 << int(gd     82         self.SECTION_HAS_MEM_MAP = 1 << int(gdb.parse_and_eval('SECTION_HAS_MEM_MAP_BIT'))
 88         self.SECTION_IS_EARLY = 1 << int(gdb.p     83         self.SECTION_IS_EARLY = 1 << int(gdb.parse_and_eval('SECTION_IS_EARLY_BIT'))
 89                                                    84 
 90         self.struct_page_size = utils.get_page     85         self.struct_page_size = utils.get_page_type().sizeof
 91         self.STRUCT_PAGE_MAX_SHIFT = (int)(mat     86         self.STRUCT_PAGE_MAX_SHIFT = (int)(math.log(self.struct_page_size, 2))
 92                                                    87 
 93         self.PAGE_OFFSET = self._PAGE_OFFSET(s     88         self.PAGE_OFFSET = self._PAGE_OFFSET(self.VA_BITS)
 94         self.MODULES_VADDR = self._PAGE_END(se     89         self.MODULES_VADDR = self._PAGE_END(self.VA_BITS_MIN)
 95         self.MODULES_END = self.MODULES_VADDR      90         self.MODULES_END = self.MODULES_VADDR + self.MODULES_VSIZE
 96                                                    91 
 97         self.VMEMMAP_RANGE = self._PAGE_END(se !!  92         self.VMEMMAP_SHIFT = (self.PAGE_SHIFT - self.STRUCT_PAGE_MAX_SHIFT)
 98         self.VMEMMAP_SIZE = (self.VMEMMAP_RANG !!  93         self.VMEMMAP_SIZE = ((self._PAGE_END(self.VA_BITS_MIN) - self.PAGE_OFFSET) >> self.VMEMMAP_SHIFT)
 99         self.VMEMMAP_END = (-(1 * 1024 * 1024  !!  94         self.VMEMMAP_START = (-(1 << (self.VA_BITS - self.VMEMMAP_SHIFT))) & 0xffffffffffffffff
100         self.VMEMMAP_START = self.VMEMMAP_END  !!  95         self.VMEMMAP_END = self.VMEMMAP_START + self.VMEMMAP_SIZE
101                                                    96 
102         self.VMALLOC_START = self.MODULES_END      97         self.VMALLOC_START = self.MODULES_END
103         self.VMALLOC_END = self.VMEMMAP_START      98         self.VMALLOC_END = self.VMEMMAP_START - 256 * 1024 * 1024
104                                                    99 
105         self.memstart_addr = gdb.parse_and_eva    100         self.memstart_addr = gdb.parse_and_eval("memstart_addr")
106         self.PHYS_OFFSET = self.memstart_addr     101         self.PHYS_OFFSET = self.memstart_addr
107         self.vmemmap = gdb.Value(self.VMEMMAP_    102         self.vmemmap = gdb.Value(self.VMEMMAP_START).cast(utils.get_page_type().pointer()) - (self.memstart_addr >> self.PAGE_SHIFT)
108                                                   103 
109         self.KERNEL_START = gdb.parse_and_eval    104         self.KERNEL_START = gdb.parse_and_eval("_text")
110         self.KERNEL_END = gdb.parse_and_eval("    105         self.KERNEL_END = gdb.parse_and_eval("_end")
111                                                   106 
112         if constants.LX_CONFIG_KASAN_GENERIC o    107         if constants.LX_CONFIG_KASAN_GENERIC or constants.LX_CONFIG_KASAN_SW_TAGS:
113             if constants.LX_CONFIG_KASAN_GENER    108             if constants.LX_CONFIG_KASAN_GENERIC:
114                 self.KASAN_SHADOW_SCALE_SHIFT     109                 self.KASAN_SHADOW_SCALE_SHIFT = 3
115             else:                                 110             else:
116                 self.KASAN_SHADOW_SCALE_SHIFT     111                 self.KASAN_SHADOW_SCALE_SHIFT = 4
117             self.KASAN_SHADOW_OFFSET = constan    112             self.KASAN_SHADOW_OFFSET = constants.LX_CONFIG_KASAN_SHADOW_OFFSET
118             self.KASAN_SHADOW_END = (1 << (64     113             self.KASAN_SHADOW_END = (1 << (64 - self.KASAN_SHADOW_SCALE_SHIFT)) + self.KASAN_SHADOW_OFFSET
119             self.PAGE_END = self.KASAN_SHADOW_    114             self.PAGE_END = self.KASAN_SHADOW_END - (1 << (self.vabits_actual - self.KASAN_SHADOW_SCALE_SHIFT))
120         else:                                     115         else:
121             self.PAGE_END = self._PAGE_END(sel    116             self.PAGE_END = self._PAGE_END(self.VA_BITS_MIN)
122                                                   117 
123         if constants.LX_CONFIG_NUMA and consta    118         if constants.LX_CONFIG_NUMA and constants.LX_CONFIG_NODES_SHIFT:
124             self.NODE_SHIFT = constants.LX_CON    119             self.NODE_SHIFT = constants.LX_CONFIG_NODES_SHIFT
125         else:                                     120         else:
126             self.NODE_SHIFT = 0                   121             self.NODE_SHIFT = 0
127                                                   122 
128         self.MAX_NUMNODES = 1 << self.NODE_SHI    123         self.MAX_NUMNODES = 1 << self.NODE_SHIFT
129                                                   124 
130     def SECTION_NR_TO_ROOT(self, sec):            125     def SECTION_NR_TO_ROOT(self, sec):
131         return sec // self.SECTIONS_PER_ROOT      126         return sec // self.SECTIONS_PER_ROOT
132                                                   127 
133     def __nr_to_section(self, nr):                128     def __nr_to_section(self, nr):
134         root = self.SECTION_NR_TO_ROOT(nr)        129         root = self.SECTION_NR_TO_ROOT(nr)
135         mem_section = gdb.parse_and_eval("mem_    130         mem_section = gdb.parse_and_eval("mem_section")
136         return mem_section[root][nr & self.SEC    131         return mem_section[root][nr & self.SECTION_ROOT_MASK]
137                                                   132 
138     def pfn_to_section_nr(self, pfn):             133     def pfn_to_section_nr(self, pfn):
139         return pfn >> self.PFN_SECTION_SHIFT      134         return pfn >> self.PFN_SECTION_SHIFT
140                                                   135 
141     def section_nr_to_pfn(self, sec):             136     def section_nr_to_pfn(self, sec):
142         return sec << self.PFN_SECTION_SHIFT      137         return sec << self.PFN_SECTION_SHIFT
143                                                   138 
144     def __pfn_to_section(self, pfn):              139     def __pfn_to_section(self, pfn):
145         return self.__nr_to_section(self.pfn_t    140         return self.__nr_to_section(self.pfn_to_section_nr(pfn))
146                                                   141 
147     def pfn_to_section(self, pfn):                142     def pfn_to_section(self, pfn):
148         return self.__pfn_to_section(pfn)         143         return self.__pfn_to_section(pfn)
149                                                   144 
150     def subsection_map_index(self, pfn):          145     def subsection_map_index(self, pfn):
151         return (pfn & ~(self.PAGE_SECTION_MASK    146         return (pfn & ~(self.PAGE_SECTION_MASK)) // self.PAGES_PER_SUBSECTION
152                                                   147 
153     def pfn_section_valid(self, ms, pfn):         148     def pfn_section_valid(self, ms, pfn):
154         if constants.LX_CONFIG_SPARSEMEM_VMEMM    149         if constants.LX_CONFIG_SPARSEMEM_VMEMMAP:
155             idx = self.subsection_map_index(pf    150             idx = self.subsection_map_index(pfn)
156             return test_bit(idx, ms['usage']['    151             return test_bit(idx, ms['usage']['subsection_map'])
157         else:                                     152         else:
158             return True                           153             return True
159                                                   154 
160     def valid_section(self, mem_section):         155     def valid_section(self, mem_section):
161         if mem_section != None and (mem_sectio    156         if mem_section != None and (mem_section['section_mem_map'] & self.SECTION_HAS_MEM_MAP):
162             return True                           157             return True
163         return False                              158         return False
164                                                   159 
165     def early_section(self, mem_section):         160     def early_section(self, mem_section):
166         if mem_section != None and (mem_sectio    161         if mem_section != None and (mem_section['section_mem_map'] & self.SECTION_IS_EARLY):
167             return True                           162             return True
168         return False                              163         return False
169                                                   164 
170     def pfn_valid(self, pfn):                     165     def pfn_valid(self, pfn):
171         ms = None                                 166         ms = None
172         if self.PHYS_PFN(self.PFN_PHYS(pfn)) !    167         if self.PHYS_PFN(self.PFN_PHYS(pfn)) != pfn:
173             return False                          168             return False
174         if self.pfn_to_section_nr(pfn) >= self    169         if self.pfn_to_section_nr(pfn) >= self.NR_MEM_SECTIONS:
175             return False                          170             return False
176         ms = self.__pfn_to_section(pfn)           171         ms = self.__pfn_to_section(pfn)
177                                                   172 
178         if not self.valid_section(ms):            173         if not self.valid_section(ms):
179             return False                          174             return False
180         return self.early_section(ms) or self.    175         return self.early_section(ms) or self.pfn_section_valid(ms, pfn)
181                                                   176 
182     def _PAGE_OFFSET(self, va):                   177     def _PAGE_OFFSET(self, va):
183         return (-(1 << (va))) & 0xffffffffffff    178         return (-(1 << (va))) & 0xffffffffffffffff
184                                                   179 
185     def _PAGE_END(self, va):                      180     def _PAGE_END(self, va):
186         return (-(1 << (va - 1))) & 0xffffffff    181         return (-(1 << (va - 1))) & 0xffffffffffffffff
187                                                   182 
188     def kasan_reset_tag(self, addr):              183     def kasan_reset_tag(self, addr):
189         if constants.LX_CONFIG_KASAN_SW_TAGS o    184         if constants.LX_CONFIG_KASAN_SW_TAGS or constants.LX_CONFIG_KASAN_HW_TAGS:
190             return int(addr) | (0xff << 56)       185             return int(addr) | (0xff << 56)
191         else:                                     186         else:
192             return addr                           187             return addr
193                                                   188 
194     def __is_lm_address(self, addr):              189     def __is_lm_address(self, addr):
195         if (addr - self.PAGE_OFFSET) < (self.P    190         if (addr - self.PAGE_OFFSET) < (self.PAGE_END - self.PAGE_OFFSET):
196             return True                           191             return True
197         else:                                     192         else:
198             return False                          193             return False
199     def __lm_to_phys(self, addr):                 194     def __lm_to_phys(self, addr):
200         return addr - self.PAGE_OFFSET + self.    195         return addr - self.PAGE_OFFSET + self.PHYS_OFFSET
201                                                   196 
202     def __kimg_to_phys(self, addr):               197     def __kimg_to_phys(self, addr):
203         return addr - self.kimage_voffset         198         return addr - self.kimage_voffset
204                                                   199 
205     def __virt_to_phys_nodebug(self, va):         200     def __virt_to_phys_nodebug(self, va):
206         untagged_va = self.kasan_reset_tag(va)    201         untagged_va = self.kasan_reset_tag(va)
207         if self.__is_lm_address(untagged_va):     202         if self.__is_lm_address(untagged_va):
208             return self.__lm_to_phys(untagged_    203             return self.__lm_to_phys(untagged_va)
209         else:                                     204         else:
210             return self.__kimg_to_phys(untagge    205             return self.__kimg_to_phys(untagged_va)
211                                                   206 
212     def __virt_to_phys(self, va):                 207     def __virt_to_phys(self, va):
213         if constants.LX_CONFIG_DEBUG_VIRTUAL:     208         if constants.LX_CONFIG_DEBUG_VIRTUAL:
214             if not self.__is_lm_address(self.k    209             if not self.__is_lm_address(self.kasan_reset_tag(va)):
215                 raise gdb.GdbError("Warning: v    210                 raise gdb.GdbError("Warning: virt_to_phys used for non-linear address: 0x%lx\n" % va)
216         return self.__virt_to_phys_nodebug(va)    211         return self.__virt_to_phys_nodebug(va)
217                                                   212 
218     def virt_to_phys(self, va):                   213     def virt_to_phys(self, va):
219         return self.__virt_to_phys(va)            214         return self.__virt_to_phys(va)
220                                                   215 
221     def PFN_PHYS(self, pfn):                      216     def PFN_PHYS(self, pfn):
222         return pfn << self.PAGE_SHIFT             217         return pfn << self.PAGE_SHIFT
223                                                   218 
224     def PHYS_PFN(self, phys):                     219     def PHYS_PFN(self, phys):
225         return phys >> self.PAGE_SHIFT            220         return phys >> self.PAGE_SHIFT
226                                                   221 
227     def __phys_to_virt(self, pa):                 222     def __phys_to_virt(self, pa):
228         return (pa - self.PHYS_OFFSET) | self.    223         return (pa - self.PHYS_OFFSET) | self.PAGE_OFFSET
229                                                   224 
230     def __phys_to_pfn(self, pa):                  225     def __phys_to_pfn(self, pa):
231         return self.PHYS_PFN(pa)                  226         return self.PHYS_PFN(pa)
232                                                   227 
233     def __pfn_to_phys(self, pfn):                 228     def __pfn_to_phys(self, pfn):
234         return self.PFN_PHYS(pfn)                 229         return self.PFN_PHYS(pfn)
235                                                   230 
236     def __pa_symbol_nodebug(self, x):             231     def __pa_symbol_nodebug(self, x):
237         return self.__kimg_to_phys(x)             232         return self.__kimg_to_phys(x)
238                                                   233 
239     def __phys_addr_symbol(self, x):              234     def __phys_addr_symbol(self, x):
240         if constants.LX_CONFIG_DEBUG_VIRTUAL:     235         if constants.LX_CONFIG_DEBUG_VIRTUAL:
241             if x < self.KERNEL_START or x > se    236             if x < self.KERNEL_START or x > self.KERNEL_END:
242                 raise gdb.GdbError("0x%x excee    237                 raise gdb.GdbError("0x%x exceed kernel range" % x)
243         return self.__pa_symbol_nodebug(x)        238         return self.__pa_symbol_nodebug(x)
244                                                   239 
245     def __pa_symbol(self, x):                     240     def __pa_symbol(self, x):
246         return self.__phys_addr_symbol(x)         241         return self.__phys_addr_symbol(x)
247                                                   242 
248     def __va(self, pa):                           243     def __va(self, pa):
249         return self.__phys_to_virt(pa)            244         return self.__phys_to_virt(pa)
250                                                   245 
251     def pfn_to_kaddr(self, pfn):                  246     def pfn_to_kaddr(self, pfn):
252         return self.__va(pfn << self.PAGE_SHIF    247         return self.__va(pfn << self.PAGE_SHIFT)
253                                                   248 
254     def virt_to_pfn(self, va):                    249     def virt_to_pfn(self, va):
255         return self.__phys_to_pfn(self.__virt_    250         return self.__phys_to_pfn(self.__virt_to_phys(va))
256                                                   251 
257     def sym_to_pfn(self, x):                      252     def sym_to_pfn(self, x):
258         return self.__phys_to_pfn(self.__pa_sy    253         return self.__phys_to_pfn(self.__pa_symbol(x))
259                                                   254 
260     def page_to_pfn(self, page):                  255     def page_to_pfn(self, page):
261         return int(page.cast(utils.get_page_ty    256         return int(page.cast(utils.get_page_type().pointer()) - self.vmemmap.cast(utils.get_page_type().pointer()))
262                                                   257 
263     def page_to_phys(self, page):                 258     def page_to_phys(self, page):
264         return self.__pfn_to_phys(self.page_to    259         return self.__pfn_to_phys(self.page_to_pfn(page))
265                                                   260 
266     def pfn_to_page(self, pfn):                   261     def pfn_to_page(self, pfn):
267         return (self.vmemmap + pfn).cast(utils    262         return (self.vmemmap + pfn).cast(utils.get_page_type().pointer())
268                                                   263 
269     def page_to_virt(self, page):                 264     def page_to_virt(self, page):
270         if constants.LX_CONFIG_DEBUG_VIRTUAL:     265         if constants.LX_CONFIG_DEBUG_VIRTUAL:
271             return self.__va(self.page_to_phys    266             return self.__va(self.page_to_phys(page))
272         else:                                     267         else:
273             __idx = int((page.cast(gdb.lookup_    268             __idx = int((page.cast(gdb.lookup_type("unsigned long")) - self.VMEMMAP_START).cast(utils.get_ulong_type())) // self.struct_page_size
274             return self.PAGE_OFFSET + (__idx *    269             return self.PAGE_OFFSET + (__idx * self.PAGE_SIZE)
275                                                   270 
276     def virt_to_page(self, va):                   271     def virt_to_page(self, va):
277         if constants.LX_CONFIG_DEBUG_VIRTUAL:     272         if constants.LX_CONFIG_DEBUG_VIRTUAL:
278             return self.pfn_to_page(self.virt_    273             return self.pfn_to_page(self.virt_to_pfn(va))
279         else:                                     274         else:
280             __idx = int(self.kasan_reset_tag(v    275             __idx = int(self.kasan_reset_tag(va) - self.PAGE_OFFSET) // self.PAGE_SIZE
281             addr = self.VMEMMAP_START + (__idx    276             addr = self.VMEMMAP_START + (__idx * self.struct_page_size)
282             return gdb.Value(addr).cast(utils.    277             return gdb.Value(addr).cast(utils.get_page_type().pointer())
283                                                   278 
284     def page_address(self, page):                 279     def page_address(self, page):
285         return self.page_to_virt(page)            280         return self.page_to_virt(page)
286                                                   281 
287     def folio_address(self, folio):               282     def folio_address(self, folio):
288         return self.page_address(folio['page']    283         return self.page_address(folio['page'].address)
289                                                   284 
290 class LxPFN2Page(gdb.Command):                    285 class LxPFN2Page(gdb.Command):
291     """PFN to struct page"""                      286     """PFN to struct page"""
292                                                   287 
293     def __init__(self):                           288     def __init__(self):
294         super(LxPFN2Page, self).__init__("lx-p    289         super(LxPFN2Page, self).__init__("lx-pfn_to_page", gdb.COMMAND_USER)
295                                                   290 
296     def invoke(self, arg, from_tty):              291     def invoke(self, arg, from_tty):
297         argv = gdb.string_to_argv(arg)            292         argv = gdb.string_to_argv(arg)
298         pfn = int(argv[0])                        293         pfn = int(argv[0])
299         page = page_ops().ops.pfn_to_page(pfn)    294         page = page_ops().ops.pfn_to_page(pfn)
300         gdb.write("pfn_to_page(0x%x) = 0x%x\n"    295         gdb.write("pfn_to_page(0x%x) = 0x%x\n" % (pfn, page))
301                                                   296 
302 LxPFN2Page()                                      297 LxPFN2Page()
303                                                   298 
304 class LxPage2PFN(gdb.Command):                    299 class LxPage2PFN(gdb.Command):
305     """struct page to PFN"""                      300     """struct page to PFN"""
306                                                   301 
307     def __init__(self):                           302     def __init__(self):
308         super(LxPage2PFN, self).__init__("lx-p    303         super(LxPage2PFN, self).__init__("lx-page_to_pfn", gdb.COMMAND_USER)
309                                                   304 
310     def invoke(self, arg, from_tty):              305     def invoke(self, arg, from_tty):
311         argv = gdb.string_to_argv(arg)            306         argv = gdb.string_to_argv(arg)
312         struct_page_addr = int(argv[0], 16)       307         struct_page_addr = int(argv[0], 16)
313         page = gdb.Value(struct_page_addr).cas    308         page = gdb.Value(struct_page_addr).cast(utils.get_page_type().pointer())
314         pfn = page_ops().ops.page_to_pfn(page)    309         pfn = page_ops().ops.page_to_pfn(page)
315         gdb.write("page_to_pfn(0x%x) = 0x%x\n"    310         gdb.write("page_to_pfn(0x%x) = 0x%x\n" % (page, pfn))
316                                                   311 
317 LxPage2PFN()                                      312 LxPage2PFN()
318                                                   313 
319 class LxPageAddress(gdb.Command):                 314 class LxPageAddress(gdb.Command):
320     """struct page to linear mapping address""    315     """struct page to linear mapping address"""
321                                                   316 
322     def __init__(self):                           317     def __init__(self):
323         super(LxPageAddress, self).__init__("l    318         super(LxPageAddress, self).__init__("lx-page_address", gdb.COMMAND_USER)
324                                                   319 
325     def invoke(self, arg, from_tty):              320     def invoke(self, arg, from_tty):
326         argv = gdb.string_to_argv(arg)            321         argv = gdb.string_to_argv(arg)
327         struct_page_addr = int(argv[0], 16)       322         struct_page_addr = int(argv[0], 16)
328         page = gdb.Value(struct_page_addr).cas    323         page = gdb.Value(struct_page_addr).cast(utils.get_page_type().pointer())
329         addr = page_ops().ops.page_address(pag    324         addr = page_ops().ops.page_address(page)
330         gdb.write("page_address(0x%x) = 0x%x\n    325         gdb.write("page_address(0x%x) = 0x%x\n" % (page, addr))
331                                                   326 
332 LxPageAddress()                                   327 LxPageAddress()
333                                                   328 
334 class LxPage2Phys(gdb.Command):                   329 class LxPage2Phys(gdb.Command):
335     """struct page to physical address"""         330     """struct page to physical address"""
336                                                   331 
337     def __init__(self):                           332     def __init__(self):
338         super(LxPage2Phys, self).__init__("lx-    333         super(LxPage2Phys, self).__init__("lx-page_to_phys", gdb.COMMAND_USER)
339                                                   334 
340     def invoke(self, arg, from_tty):              335     def invoke(self, arg, from_tty):
341         argv = gdb.string_to_argv(arg)            336         argv = gdb.string_to_argv(arg)
342         struct_page_addr = int(argv[0], 16)       337         struct_page_addr = int(argv[0], 16)
343         page = gdb.Value(struct_page_addr).cas    338         page = gdb.Value(struct_page_addr).cast(utils.get_page_type().pointer())
344         phys_addr = page_ops().ops.page_to_phy    339         phys_addr = page_ops().ops.page_to_phys(page)
345         gdb.write("page_to_phys(0x%x) = 0x%x\n    340         gdb.write("page_to_phys(0x%x) = 0x%x\n" % (page, phys_addr))
346                                                   341 
347 LxPage2Phys()                                     342 LxPage2Phys()
348                                                   343 
349 class LxVirt2Phys(gdb.Command):                   344 class LxVirt2Phys(gdb.Command):
350     """virtual address to physical address"""     345     """virtual address to physical address"""
351                                                   346 
352     def __init__(self):                           347     def __init__(self):
353         super(LxVirt2Phys, self).__init__("lx-    348         super(LxVirt2Phys, self).__init__("lx-virt_to_phys", gdb.COMMAND_USER)
354                                                   349 
355     def invoke(self, arg, from_tty):              350     def invoke(self, arg, from_tty):
356         argv = gdb.string_to_argv(arg)            351         argv = gdb.string_to_argv(arg)
357         linear_addr = int(argv[0], 16)            352         linear_addr = int(argv[0], 16)
358         phys_addr = page_ops().ops.virt_to_phy    353         phys_addr = page_ops().ops.virt_to_phys(linear_addr)
359         gdb.write("virt_to_phys(0x%x) = 0x%x\n    354         gdb.write("virt_to_phys(0x%x) = 0x%x\n" % (linear_addr, phys_addr))
360                                                   355 
361 LxVirt2Phys()                                     356 LxVirt2Phys()
362                                                   357 
363 class LxVirt2Page(gdb.Command):                   358 class LxVirt2Page(gdb.Command):
364     """virtual address to struct page"""          359     """virtual address to struct page"""
365                                                   360 
366     def __init__(self):                           361     def __init__(self):
367         super(LxVirt2Page, self).__init__("lx-    362         super(LxVirt2Page, self).__init__("lx-virt_to_page", gdb.COMMAND_USER)
368                                                   363 
369     def invoke(self, arg, from_tty):              364     def invoke(self, arg, from_tty):
370         argv = gdb.string_to_argv(arg)            365         argv = gdb.string_to_argv(arg)
371         linear_addr = int(argv[0], 16)            366         linear_addr = int(argv[0], 16)
372         page = page_ops().ops.virt_to_page(lin    367         page = page_ops().ops.virt_to_page(linear_addr)
373         gdb.write("virt_to_page(0x%x) = 0x%x\n    368         gdb.write("virt_to_page(0x%x) = 0x%x\n" % (linear_addr, page))
374                                                   369 
375 LxVirt2Page()                                     370 LxVirt2Page()
376                                                   371 
377 class LxSym2PFN(gdb.Command):                     372 class LxSym2PFN(gdb.Command):
378     """symbol address to PFN"""                   373     """symbol address to PFN"""
379                                                   374 
380     def __init__(self):                           375     def __init__(self):
381         super(LxSym2PFN, self).__init__("lx-sy    376         super(LxSym2PFN, self).__init__("lx-sym_to_pfn", gdb.COMMAND_USER)
382                                                   377 
383     def invoke(self, arg, from_tty):              378     def invoke(self, arg, from_tty):
384         argv = gdb.string_to_argv(arg)            379         argv = gdb.string_to_argv(arg)
385         sym_addr = int(argv[0], 16)               380         sym_addr = int(argv[0], 16)
386         pfn = page_ops().ops.sym_to_pfn(sym_ad    381         pfn = page_ops().ops.sym_to_pfn(sym_addr)
387         gdb.write("sym_to_pfn(0x%x) = %d\n" %     382         gdb.write("sym_to_pfn(0x%x) = %d\n" % (sym_addr, pfn))
388                                                   383 
389 LxSym2PFN()                                       384 LxSym2PFN()
390                                                   385 
391 class LxPFN2Kaddr(gdb.Command):                   386 class LxPFN2Kaddr(gdb.Command):
392     """PFN to kernel address"""                   387     """PFN to kernel address"""
393                                                   388 
394     def __init__(self):                           389     def __init__(self):
395         super(LxPFN2Kaddr, self).__init__("lx-    390         super(LxPFN2Kaddr, self).__init__("lx-pfn_to_kaddr", gdb.COMMAND_USER)
396                                                   391 
397     def invoke(self, arg, from_tty):              392     def invoke(self, arg, from_tty):
398         argv = gdb.string_to_argv(arg)            393         argv = gdb.string_to_argv(arg)
399         pfn = int(argv[0])                        394         pfn = int(argv[0])
400         kaddr = page_ops().ops.pfn_to_kaddr(pf    395         kaddr = page_ops().ops.pfn_to_kaddr(pfn)
401         gdb.write("pfn_to_kaddr(%d) = 0x%x\n"     396         gdb.write("pfn_to_kaddr(%d) = 0x%x\n" % (pfn, kaddr))
402                                                   397 
403 LxPFN2Kaddr()                                     398 LxPFN2Kaddr()
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php