xref: /linux-6.15/scripts/gdb/linux/vmalloc.py (revision 852622bf)
1*852622bfSKuan-Ying Lee# SPDX-License-Identifier: GPL-2.0
2*852622bfSKuan-Ying Lee#
3*852622bfSKuan-Ying Lee# Copyright (c) 2023 MediaTek Inc.
4*852622bfSKuan-Ying Lee#
5*852622bfSKuan-Ying Lee# Authors:
6*852622bfSKuan-Ying Lee#  Kuan-Ying Lee <[email protected]>
7*852622bfSKuan-Ying Lee#
8*852622bfSKuan-Ying Lee
9*852622bfSKuan-Ying Leeimport gdb
10*852622bfSKuan-Ying Leeimport re
11*852622bfSKuan-Ying Leefrom linux import lists, utils, stackdepot, constants, mm
12*852622bfSKuan-Ying Lee
13*852622bfSKuan-Ying Leevmap_area_type = utils.CachedType('struct vmap_area')
14*852622bfSKuan-Ying Leevmap_area_ptr_type = vmap_area_type.get_type().pointer()
15*852622bfSKuan-Ying Lee
16*852622bfSKuan-Ying Leedef is_vmalloc_addr(x):
17*852622bfSKuan-Ying Lee    pg_ops = mm.page_ops().ops
18*852622bfSKuan-Ying Lee    addr = pg_ops.kasan_reset_tag(x)
19*852622bfSKuan-Ying Lee    return addr >= pg_ops.VMALLOC_START and addr < pg_ops.VMALLOC_END
20*852622bfSKuan-Ying Lee
21*852622bfSKuan-Ying Leeclass LxVmallocInfo(gdb.Command):
22*852622bfSKuan-Ying Lee    """Show vmallocinfo"""
23*852622bfSKuan-Ying Lee
24*852622bfSKuan-Ying Lee    def __init__(self):
25*852622bfSKuan-Ying Lee        super(LxVmallocInfo, self).__init__("lx-vmallocinfo", gdb.COMMAND_DATA)
26*852622bfSKuan-Ying Lee
27*852622bfSKuan-Ying Lee    def invoke(self, arg, from_tty):
28*852622bfSKuan-Ying Lee        vmap_area_list = gdb.parse_and_eval('vmap_area_list')
29*852622bfSKuan-Ying Lee        for vmap_area in lists.list_for_each_entry(vmap_area_list, vmap_area_ptr_type, "list"):
30*852622bfSKuan-Ying Lee            if not vmap_area['vm']:
31*852622bfSKuan-Ying Lee                gdb.write("0x%x-0x%x %10d vm_map_ram\n" % (vmap_area['va_start'], vmap_area['va_end'],
32*852622bfSKuan-Ying Lee                    vmap_area['va_end'] - vmap_area['va_start']))
33*852622bfSKuan-Ying Lee                continue
34*852622bfSKuan-Ying Lee            v = vmap_area['vm']
35*852622bfSKuan-Ying Lee            gdb.write("0x%x-0x%x %10d" % (v['addr'], v['addr'] + v['size'], v['size']))
36*852622bfSKuan-Ying Lee            if v['caller']:
37*852622bfSKuan-Ying Lee                gdb.write(" %s" % str(v['caller']).split(' ')[-1])
38*852622bfSKuan-Ying Lee            if v['nr_pages']:
39*852622bfSKuan-Ying Lee                gdb.write(" pages=%d" % v['nr_pages'])
40*852622bfSKuan-Ying Lee            if v['phys_addr']:
41*852622bfSKuan-Ying Lee                gdb.write(" phys=0x%x" % v['phys_addr'])
42*852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_IOREMAP:
43*852622bfSKuan-Ying Lee                gdb.write(" ioremap")
44*852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_ALLOC:
45*852622bfSKuan-Ying Lee                gdb.write(" vmalloc")
46*852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_MAP:
47*852622bfSKuan-Ying Lee                gdb.write(" vmap")
48*852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_USERMAP:
49*852622bfSKuan-Ying Lee                gdb.write(" user")
50*852622bfSKuan-Ying Lee            if v['flags'] & constants.LX_VM_DMA_COHERENT:
51*852622bfSKuan-Ying Lee                gdb.write(" dma-coherent")
52*852622bfSKuan-Ying Lee            if is_vmalloc_addr(v['pages']):
53*852622bfSKuan-Ying Lee                gdb.write(" vpages")
54*852622bfSKuan-Ying Lee            gdb.write("\n")
55*852622bfSKuan-Ying Lee
56*852622bfSKuan-Ying LeeLxVmallocInfo()
57