ANDROID: vendor_hooks: mm: add hook to count the number pages

allocated for each slab

Add the tracing interface on the kmalloc_large allocation path,
which can detect the number of pages allocated by the slab,
and if exceeds a threshold, trigger a panic or other actions.

Bug: 312897430
Change-Id: I5575d0e4f91dab1c6e074f3e907fee8ea9327fd7
Signed-off-by: Fangzheng Zhang <fangzheng.zhang@unisoc.com>
This commit is contained in:
Fangzheng Zhang 2023-11-24 11:05:14 +08:00 committed by Suren Baghdasaryan
parent 4326c78f84
commit aa71a02cf3
3 changed files with 6 additions and 0 deletions

View File

@ -363,3 +363,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_filemap_get_folio);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_blk_mq_rw_recovery);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sd_update_bus_speed_mode);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_folio_alloced);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_kmalloc_large_alloced);

View File

@ -199,6 +199,9 @@ DECLARE_HOOK(android_vh_adjust_kvmalloc_flags,
DECLARE_HOOK(android_vh_slab_folio_alloced,
TP_PROTO(unsigned int order, gfp_t flags),
TP_ARGS(order, flags));
DECLARE_HOOK(android_vh_kmalloc_large_alloced,
TP_PROTO(struct page *page, unsigned int order, gfp_t flags),
TP_ARGS(page, order, flags));
#endif /* _TRACE_HOOK_MM_H */
/* This part must be outside protection */

View File

@ -1102,6 +1102,8 @@ static void *__kmalloc_large_node(size_t size, gfp_t flags, int node)
PAGE_SIZE << order);
}
trace_android_vh_kmalloc_large_alloced(page, order, flags);
ptr = kasan_kmalloc_large(ptr, size, flags);
/* As ptr might get tagged, call kmemleak hook after KASAN. */
kmemleak_alloc(ptr, size, 1, flags);