2016-05-23 23:24:40 +00:00
|
|
|
/*
|
|
|
|
* gdb helper commands and functions for Linux kernel debugging
|
|
|
|
*
|
|
|
|
* Kernel constants derived from include files.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016 Linaro Ltd
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Kieran Bingham <kieran.bingham@linaro.org>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL version 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-05-14 22:46:17 +00:00
|
|
|
#include <linux/clk-provider.h>
|
2016-05-23 23:24:59 +00:00
|
|
|
#include <linux/fs.h>
|
2019-05-14 22:45:59 +00:00
|
|
|
#include <linux/hrtimer.h>
|
2023-04-06 22:04:51 +00:00
|
|
|
#include <linux/irq.h>
|
2016-05-23 23:24:59 +00:00
|
|
|
#include <linux/mount.h>
|
2017-07-12 21:34:13 +00:00
|
|
|
#include <linux/of_fdt.h>
|
scripts/gdb/page_owner: add page owner support
This GDB script prints page owner information for user to analyze the
memory usage or memory corruption issue.
Example output from an aarch64 system:
(gdb) lx-dump-page-owner --pfn 655360
page_owner tracks the page as allocated
Page last allocated via order 0, gfp_mask: 0x8, pid: 1, tgid: 1 ("swapper/0\000\000\000\000\000\000"), ts 1295948880 ns, free_ts 1011852016 ns
PFN: 655360, Flags: 0x3fffc0000000000
0xffff8000086ab964 <post_alloc_hook+452>: ldp x19, x20, [sp, #16]
0xffff80000862e4e0 <split_map_pages+344>: cbnz w22, 0xffff80000862e57c <split_map_pages+500>
0xffff8000086370c4 <isolate_freepages_range+556>: mov x0, x27
0xffff8000086bc1cc <alloc_contig_range+808>: mov x24, x0
0xffff80000877d6d8 <cma_alloc+772>: mov w1, w0
0xffff8000082c8d18 <dma_alloc_from_contiguous+104>: ldr x19, [sp, #16]
0xffff8000082ce0e8 <atomic_pool_expand+208>: mov x19, x0
0xffff80000c1e41b4 <__dma_atomic_pool_init+172>: Cannot access memory at address 0xffff80000c1e41b4
0xffff80000c1e4298 <dma_atomic_pool_init+92>: Cannot access memory at address 0xffff80000c1e4298
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
page last free stack trace:
0xffff8000086a6e8c <free_unref_page_prepare+796>: mov w2, w23
0xffff8000086aee1c <free_unref_page+96>: tst w0, #0xff
0xffff8000086af3f8 <__free_pages+292>: ldp x19, x20, [sp, #16]
0xffff80000c1f3214 <init_cma_reserved_pageblock+220>: Cannot access memory at address 0xffff80000c1f3214
0xffff80000c20363c <cma_init_reserved_areas+1284>: Cannot access memory at address 0xffff80000c20363c
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
Link: https://lkml.kernel.org/r/20230808083020.22254-7-Kuan-Ying.Lee@mediatek.com
Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Chinwen Chang <chinwen.chang@mediatek.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-08-08 08:30:16 +00:00
|
|
|
#include <linux/page_ext.h>
|
2023-04-04 21:40:49 +00:00
|
|
|
#include <linux/radix-tree.h>
|
2023-08-08 08:30:17 +00:00
|
|
|
#include <linux/slab.h>
|
2019-05-14 22:45:59 +00:00
|
|
|
#include <linux/threads.h>
|
2023-08-08 08:30:18 +00:00
|
|
|
#include <linux/vmalloc.h>
|
2016-05-23 23:24:59 +00:00
|
|
|
|
2016-05-23 23:24:40 +00:00
|
|
|
/* We need to stringify expanded macros so that they can be parsed */
|
2016-05-23 23:24:59 +00:00
|
|
|
|
2016-05-23 23:24:40 +00:00
|
|
|
#define STRING(x) #x
|
|
|
|
#define XSTRING(x) STRING(x)
|
|
|
|
|
|
|
|
#define LX_VALUE(x) LX_##x = x
|
|
|
|
#define LX_GDBPARSED(x) LX_##x = gdb.parse_and_eval(XSTRING(x))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IS_ENABLED generates (a || b) which is not compatible with python
|
|
|
|
* We can only switch on configuration items we know are available
|
|
|
|
* Therefore - IS_BUILTIN() is more appropriate
|
|
|
|
*/
|
|
|
|
#define LX_CONFIG(x) LX_##x = IS_BUILTIN(x)
|
|
|
|
|
|
|
|
/* The build system will take care of deleting everything above this marker */
|
|
|
|
<!-- end-c-headers -->
|
|
|
|
|
|
|
|
import gdb
|
2016-05-23 23:24:59 +00:00
|
|
|
|
2023-04-06 21:52:51 +00:00
|
|
|
LX_CONFIG(CONFIG_DEBUG_INFO_REDUCED)
|
|
|
|
|
2019-05-14 22:46:17 +00:00
|
|
|
/* linux/clk-provider.h */
|
2019-06-01 05:30:36 +00:00
|
|
|
if IS_BUILTIN(CONFIG_COMMON_CLK):
|
|
|
|
LX_GDBPARSED(CLK_GET_RATE_NOCACHE)
|
2019-05-14 22:46:17 +00:00
|
|
|
|
2016-05-23 23:24:59 +00:00
|
|
|
/* linux/fs.h */
|
2023-06-07 22:13:35 +00:00
|
|
|
LX_GDBPARSED(SB_RDONLY)
|
|
|
|
LX_GDBPARSED(SB_SYNCHRONOUS)
|
|
|
|
LX_GDBPARSED(SB_MANDLOCK)
|
|
|
|
LX_GDBPARSED(SB_DIRSYNC)
|
|
|
|
LX_GDBPARSED(SB_NOATIME)
|
|
|
|
LX_GDBPARSED(SB_NODIRATIME)
|
2016-05-23 23:24:59 +00:00
|
|
|
|
2019-05-14 22:45:59 +00:00
|
|
|
/* linux/htimer.h */
|
|
|
|
LX_GDBPARSED(hrtimer_resolution)
|
|
|
|
|
2023-04-06 22:04:51 +00:00
|
|
|
/* linux/irq.h */
|
|
|
|
LX_GDBPARSED(IRQD_LEVEL)
|
|
|
|
LX_GDBPARSED(IRQ_HIDDEN)
|
|
|
|
|
2023-04-13 21:00:55 +00:00
|
|
|
/* linux/module.h */
|
2023-10-31 13:49:04 +00:00
|
|
|
if IS_BUILTIN(CONFIG_MODULES):
|
|
|
|
LX_GDBPARSED(MOD_TEXT)
|
|
|
|
LX_GDBPARSED(MOD_DATA)
|
|
|
|
LX_GDBPARSED(MOD_RODATA)
|
|
|
|
LX_GDBPARSED(MOD_RO_AFTER_INIT)
|
2023-04-13 21:00:55 +00:00
|
|
|
|
2016-05-23 23:24:59 +00:00
|
|
|
/* linux/mount.h */
|
|
|
|
LX_VALUE(MNT_NOSUID)
|
|
|
|
LX_VALUE(MNT_NODEV)
|
|
|
|
LX_VALUE(MNT_NOEXEC)
|
|
|
|
LX_VALUE(MNT_NOATIME)
|
|
|
|
LX_VALUE(MNT_NODIRATIME)
|
|
|
|
LX_VALUE(MNT_RELATIME)
|
2017-07-12 21:34:13 +00:00
|
|
|
|
2019-05-14 22:45:59 +00:00
|
|
|
/* linux/threads.h */
|
|
|
|
LX_VALUE(NR_CPUS)
|
|
|
|
|
2017-07-12 21:34:13 +00:00
|
|
|
/* linux/of_fdt.h> */
|
|
|
|
LX_VALUE(OF_DT_HEADER)
|
|
|
|
|
2023-04-04 21:40:49 +00:00
|
|
|
/* linux/radix-tree.h */
|
|
|
|
LX_GDBPARSED(RADIX_TREE_ENTRY_MASK)
|
|
|
|
LX_GDBPARSED(RADIX_TREE_INTERNAL_NODE)
|
|
|
|
LX_GDBPARSED(RADIX_TREE_MAP_SIZE)
|
|
|
|
LX_GDBPARSED(RADIX_TREE_MAP_SHIFT)
|
|
|
|
LX_GDBPARSED(RADIX_TREE_MAP_MASK)
|
|
|
|
|
2023-08-08 08:30:18 +00:00
|
|
|
/* linux/vmalloc.h */
|
|
|
|
LX_VALUE(VM_IOREMAP)
|
|
|
|
LX_VALUE(VM_ALLOC)
|
|
|
|
LX_VALUE(VM_MAP)
|
|
|
|
LX_VALUE(VM_USERMAP)
|
|
|
|
LX_VALUE(VM_DMA_COHERENT)
|
|
|
|
|
scripts/gdb/page_owner: add page owner support
This GDB script prints page owner information for user to analyze the
memory usage or memory corruption issue.
Example output from an aarch64 system:
(gdb) lx-dump-page-owner --pfn 655360
page_owner tracks the page as allocated
Page last allocated via order 0, gfp_mask: 0x8, pid: 1, tgid: 1 ("swapper/0\000\000\000\000\000\000"), ts 1295948880 ns, free_ts 1011852016 ns
PFN: 655360, Flags: 0x3fffc0000000000
0xffff8000086ab964 <post_alloc_hook+452>: ldp x19, x20, [sp, #16]
0xffff80000862e4e0 <split_map_pages+344>: cbnz w22, 0xffff80000862e57c <split_map_pages+500>
0xffff8000086370c4 <isolate_freepages_range+556>: mov x0, x27
0xffff8000086bc1cc <alloc_contig_range+808>: mov x24, x0
0xffff80000877d6d8 <cma_alloc+772>: mov w1, w0
0xffff8000082c8d18 <dma_alloc_from_contiguous+104>: ldr x19, [sp, #16]
0xffff8000082ce0e8 <atomic_pool_expand+208>: mov x19, x0
0xffff80000c1e41b4 <__dma_atomic_pool_init+172>: Cannot access memory at address 0xffff80000c1e41b4
0xffff80000c1e4298 <dma_atomic_pool_init+92>: Cannot access memory at address 0xffff80000c1e4298
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
page last free stack trace:
0xffff8000086a6e8c <free_unref_page_prepare+796>: mov w2, w23
0xffff8000086aee1c <free_unref_page+96>: tst w0, #0xff
0xffff8000086af3f8 <__free_pages+292>: ldp x19, x20, [sp, #16]
0xffff80000c1f3214 <init_cma_reserved_pageblock+220>: Cannot access memory at address 0xffff80000c1f3214
0xffff80000c20363c <cma_init_reserved_areas+1284>: Cannot access memory at address 0xffff80000c20363c
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
Link: https://lkml.kernel.org/r/20230808083020.22254-7-Kuan-Ying.Lee@mediatek.com
Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Chinwen Chang <chinwen.chang@mediatek.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-08-08 08:30:16 +00:00
|
|
|
/* linux/page_ext.h */
|
|
|
|
if IS_BUILTIN(CONFIG_PAGE_OWNER):
|
|
|
|
LX_GDBPARSED(PAGE_EXT_OWNER)
|
|
|
|
LX_GDBPARSED(PAGE_EXT_OWNER_ALLOCATED)
|
|
|
|
|
2023-08-08 08:30:17 +00:00
|
|
|
/* linux/slab.h */
|
|
|
|
LX_GDBPARSED(SLAB_RED_ZONE)
|
|
|
|
LX_GDBPARSED(SLAB_POISON)
|
|
|
|
LX_GDBPARSED(SLAB_KMALLOC)
|
|
|
|
LX_GDBPARSED(SLAB_HWCACHE_ALIGN)
|
|
|
|
LX_GDBPARSED(SLAB_CACHE_DMA)
|
|
|
|
LX_GDBPARSED(SLAB_CACHE_DMA32)
|
|
|
|
LX_GDBPARSED(SLAB_STORE_USER)
|
|
|
|
LX_GDBPARSED(SLAB_PANIC)
|
|
|
|
|
2017-07-12 21:34:13 +00:00
|
|
|
/* Kernel Configs */
|
2019-05-14 22:45:59 +00:00
|
|
|
LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS)
|
|
|
|
LX_CONFIG(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)
|
|
|
|
LX_CONFIG(CONFIG_HIGH_RES_TIMERS)
|
|
|
|
LX_CONFIG(CONFIG_NR_CPUS)
|
2017-07-12 21:34:13 +00:00
|
|
|
LX_CONFIG(CONFIG_OF)
|
2019-05-14 22:45:59 +00:00
|
|
|
LX_CONFIG(CONFIG_TICK_ONESHOT)
|
2023-04-06 22:04:51 +00:00
|
|
|
LX_CONFIG(CONFIG_GENERIC_IRQ_SHOW_LEVEL)
|
|
|
|
LX_CONFIG(CONFIG_X86_LOCAL_APIC)
|
|
|
|
LX_CONFIG(CONFIG_SMP)
|
|
|
|
LX_CONFIG(CONFIG_X86_THERMAL_VECTOR)
|
|
|
|
LX_CONFIG(CONFIG_X86_MCE_THRESHOLD)
|
|
|
|
LX_CONFIG(CONFIG_X86_MCE_AMD)
|
|
|
|
LX_CONFIG(CONFIG_X86_MCE)
|
|
|
|
LX_CONFIG(CONFIG_X86_IO_APIC)
|
|
|
|
LX_CONFIG(CONFIG_HAVE_KVM)
|
2023-08-08 08:30:14 +00:00
|
|
|
LX_CONFIG(CONFIG_NUMA)
|
|
|
|
LX_CONFIG(CONFIG_ARM64)
|
|
|
|
LX_CONFIG(CONFIG_ARM64_4K_PAGES)
|
|
|
|
LX_CONFIG(CONFIG_ARM64_16K_PAGES)
|
|
|
|
LX_CONFIG(CONFIG_ARM64_64K_PAGES)
|
|
|
|
if IS_BUILTIN(CONFIG_ARM64):
|
|
|
|
LX_VALUE(CONFIG_ARM64_PA_BITS)
|
|
|
|
LX_VALUE(CONFIG_ARM64_VA_BITS)
|
2024-02-26 16:14:12 +00:00
|
|
|
LX_VALUE(CONFIG_PAGE_SHIFT)
|
2023-08-08 08:30:14 +00:00
|
|
|
LX_VALUE(CONFIG_ARCH_FORCE_MAX_ORDER)
|
|
|
|
LX_CONFIG(CONFIG_SPARSEMEM)
|
|
|
|
LX_CONFIG(CONFIG_SPARSEMEM_EXTREME)
|
|
|
|
LX_CONFIG(CONFIG_SPARSEMEM_VMEMMAP)
|
|
|
|
LX_CONFIG(CONFIG_KASAN)
|
|
|
|
LX_CONFIG(CONFIG_KASAN_GENERIC)
|
|
|
|
LX_CONFIG(CONFIG_KASAN_SW_TAGS)
|
|
|
|
LX_CONFIG(CONFIG_KASAN_HW_TAGS)
|
|
|
|
if IS_BUILTIN(CONFIG_KASAN_GENERIC) or IS_BUILTIN(CONFIG_KASAN_SW_TAGS):
|
|
|
|
LX_VALUE(CONFIG_KASAN_SHADOW_OFFSET)
|
|
|
|
LX_CONFIG(CONFIG_VMAP_STACK)
|
|
|
|
if IS_BUILTIN(CONFIG_NUMA):
|
|
|
|
LX_VALUE(CONFIG_NODES_SHIFT)
|
|
|
|
LX_CONFIG(CONFIG_DEBUG_VIRTUAL)
|
2023-08-08 08:30:15 +00:00
|
|
|
LX_CONFIG(CONFIG_STACKDEPOT)
|
scripts/gdb/page_owner: add page owner support
This GDB script prints page owner information for user to analyze the
memory usage or memory corruption issue.
Example output from an aarch64 system:
(gdb) lx-dump-page-owner --pfn 655360
page_owner tracks the page as allocated
Page last allocated via order 0, gfp_mask: 0x8, pid: 1, tgid: 1 ("swapper/0\000\000\000\000\000\000"), ts 1295948880 ns, free_ts 1011852016 ns
PFN: 655360, Flags: 0x3fffc0000000000
0xffff8000086ab964 <post_alloc_hook+452>: ldp x19, x20, [sp, #16]
0xffff80000862e4e0 <split_map_pages+344>: cbnz w22, 0xffff80000862e57c <split_map_pages+500>
0xffff8000086370c4 <isolate_freepages_range+556>: mov x0, x27
0xffff8000086bc1cc <alloc_contig_range+808>: mov x24, x0
0xffff80000877d6d8 <cma_alloc+772>: mov w1, w0
0xffff8000082c8d18 <dma_alloc_from_contiguous+104>: ldr x19, [sp, #16]
0xffff8000082ce0e8 <atomic_pool_expand+208>: mov x19, x0
0xffff80000c1e41b4 <__dma_atomic_pool_init+172>: Cannot access memory at address 0xffff80000c1e41b4
0xffff80000c1e4298 <dma_atomic_pool_init+92>: Cannot access memory at address 0xffff80000c1e4298
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
page last free stack trace:
0xffff8000086a6e8c <free_unref_page_prepare+796>: mov w2, w23
0xffff8000086aee1c <free_unref_page+96>: tst w0, #0xff
0xffff8000086af3f8 <__free_pages+292>: ldp x19, x20, [sp, #16]
0xffff80000c1f3214 <init_cma_reserved_pageblock+220>: Cannot access memory at address 0xffff80000c1f3214
0xffff80000c20363c <cma_init_reserved_areas+1284>: Cannot access memory at address 0xffff80000c20363c
0xffff8000080161d4 <do_one_initcall+176>: mov w21, w0
0xffff80000c1c1b50 <kernel_init_freeable+952>: Cannot access memory at address 0xffff80000c1c1b50
0xffff80000acf87dc <kernel_init+36>: bl 0xffff8000081ab100 <async_synchronize_full>
0xffff800008018d00 <ret_from_fork+16>: mrs x28, sp_el0
Link: https://lkml.kernel.org/r/20230808083020.22254-7-Kuan-Ying.Lee@mediatek.com
Signed-off-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Cc: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Cc: Chinwen Chang <chinwen.chang@mediatek.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Qun-Wei Lin <qun-wei.lin@mediatek.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-08-08 08:30:16 +00:00
|
|
|
LX_CONFIG(CONFIG_PAGE_OWNER)
|
2023-08-08 08:30:17 +00:00
|
|
|
LX_CONFIG(CONFIG_SLUB_DEBUG)
|
|
|
|
LX_CONFIG(CONFIG_SLAB_FREELIST_HARDENED)
|
2023-10-31 20:22:36 +00:00
|
|
|
LX_CONFIG(CONFIG_MMU)
|