xref: /openbmc/linux/scripts/gdb/linux/vmalloc.py (revision 08c52a25)
1852622bfSKuan-Ying Lee# SPDX-License-Identifier: GPL-2.0
2852622bfSKuan-Ying Lee#
3852622bfSKuan-Ying Lee# Copyright (c) 2023 MediaTek Inc.
4852622bfSKuan-Ying Lee#
5852622bfSKuan-Ying Lee# Authors:
6852622bfSKuan-Ying Lee#  Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
7852622bfSKuan-Ying Lee#
8852622bfSKuan-Ying Lee
9852622bfSKuan-Ying Leeimport gdb
10852622bfSKuan-Ying Leeimport re
11852622bfSKuan-Ying Leefrom linux import lists, utils, stackdepot, constants, mm
12852622bfSKuan-Ying Lee
13*08c52a25SBen Wolsiefferif constants.LX_CONFIG_MMU:
14852622bfSKuan-Ying Lee    vmap_area_type = utils.CachedType('struct vmap_area')
15852622bfSKuan-Ying Lee    vmap_area_ptr_type = vmap_area_type.get_type().pointer()
16852622bfSKuan-Ying Lee
17852622bfSKuan-Ying Leedef is_vmalloc_addr(x):
18852622bfSKuan-Ying Lee    pg_ops = mm.page_ops().ops
19852622bfSKuan-Ying Lee    addr = pg_ops.kasan_reset_tag(x)
20852622bfSKuan-Ying Lee    return addr >= pg_ops.VMALLOC_START and addr < pg_ops.VMALLOC_END
21852622bfSKuan-Ying Lee
22852622bfSKuan-Ying Leeclass LxVmallocInfo(gdb.Command):
23852622bfSKuan-Ying Lee    """Show vmallocinfo"""
24852622bfSKuan-Ying Lee
25852622bfSKuan-Ying Lee    def __init__(self):
26852622bfSKuan-Ying Lee        super(LxVmallocInfo, self).__init__("lx-vmallocinfo", gdb.COMMAND_DATA)
27852622bfSKuan-Ying Lee
28852622bfSKuan-Ying Lee    def invoke(self, arg, from_tty):
29*08c52a25SBen Wolsieffer        if not constants.LX_CONFIG_MMU:
30*08c52a25SBen Wolsieffer            raise gdb.GdbError("Requires MMU support")
31*08c52a25SBen Wolsieffer
32852622bfSKuan-Ying Lee        vmap_area_list = gdb.parse_and_eval('vmap_area_list')
33852622bfSKuan-Ying Lee        for vmap_area in lists.list_for_each_entry(vmap_area_list, vmap_area_ptr_type, "list"):
34852622bfSKuan-Ying Lee            if not vmap_area['vm']:
35852622bfSKuan-Ying Lee                gdb.write("0x%x-0x%x %10d vm_map_ram\n" % (vmap_area['va_start'], vmap_area['va_end'],
36852622bfSKuan-Ying Lee                    vmap_area['va_end'] - vmap_area['va_start']))
37852622bfSKuan-Ying Lee                continue
38852622bfSKuan-Ying Lee            v = vmap_area['vm']
39852622bfSKuan-Ying Lee            gdb.write("0x%x-0x%x %10d" % (v['addr'], v['addr'] + v['size'], v['size']))
40852622bfSKuan-Ying Lee            if v['caller']:
41852622bfSKuan-Ying Lee                gdb.write(" %s" % str(v['caller']).split(' ')[-1])
42852622bfSKuan-Ying Lee            if v['nr_pages']:
43852622bfSKuan-Ying Lee                gdb.write(" pages=%d" % v['nr_pages'])
44852622bfSKuan-Ying Lee            if v['phys_addr']:
45852622bfSKuan-Ying Lee                gdb.write(" phys=0x%x" % v['phys_addr'])
46852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_IOREMAP:
47852622bfSKuan-Ying Lee                gdb.write(" ioremap")
48852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_ALLOC:
49852622bfSKuan-Ying Lee                gdb.write(" vmalloc")
50852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_MAP:
51852622bfSKuan-Ying Lee                gdb.write(" vmap")
52852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_USERMAP:
53852622bfSKuan-Ying Lee                gdb.write(" user")
54852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_DMA_COHERENT:
55852622bfSKuan-Ying Lee                gdb.write(" dma-coherent")
56852622bfSKuan-Ying Lee            if is_vmalloc_addr(v['pages']):
57852622bfSKuan-Ying Lee                gdb.write(" vpages")
58852622bfSKuan-Ying Lee            gdb.write("\n")
59852622bfSKuan-Ying Lee
60852622bfSKuan-Ying LeeLxVmallocInfo()
61