From fbcda4a3138517cccc56136ac7d5109f8fea9ee1 Mon Sep 17 00:00:00 2001 From: Wanwei Jiang Date: Thu, 7 Sep 2023 17:39:59 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add vendor hook in cma_alloc() By this vh, so that we can reimplement the function cma_alloc() Bug: 299425220 Change-Id: I7068915c3c38784dba25d130434abe595b06b996 Signed-off-by: Wanwei Jiang --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 5 ++++- mm/cma.c | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index ca34ae9a2a09..1d146a268df3 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -102,3 +102,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sched_show_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ftrace_format_check); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_free); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mem_cgroup_alloc); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cma_alloc_bypass); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 2dcce0029af4..49c4356b0d8e 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -19,7 +19,6 @@ DECLARE_RESTRICTED_HOOK(android_rvh_set_gfp_zone_flags, DECLARE_RESTRICTED_HOOK(android_rvh_set_readahead_gfp_mask, TP_PROTO(gfp_t *flags), TP_ARGS(flags), 1); - */ struct mem_cgroup; DECLARE_HOOK(android_vh_mem_cgroup_alloc, @@ -29,6 +28,10 @@ DECLARE_HOOK(android_vh_mem_cgroup_free, TP_PROTO(struct mem_cgroup *memcg), TP_ARGS(memcg)); +DECLARE_HOOK(android_vh_cma_alloc_bypass, + TP_PROTO(struct cma *cma, unsigned long count, unsigned int align, + gfp_t gfp_mask, struct page **page, bool *bypass), + TP_ARGS(cma, count, align, gfp_mask, page, bypass)); #endif /* _TRACE_HOOK_MM_H */ /* This part must be outside protection */ diff --git a/mm/cma.c b/mm/cma.c index 956b10f6e1f3..1f5e64a5ed91 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -30,6 +30,8 @@ #include #include #include +#undef CREATE_TRACE_POINTS +#include #include "internal.h" #include "cma.h" @@ -420,11 +422,17 @@ struct page *__cma_alloc(struct cma *cma, unsigned long count, const char *name = cma ? cma->name : NULL; int num_attempts = 0; int max_retries = 5; + bool bypass = false; if (WARN_ON_ONCE((gfp & GFP_KERNEL) == 0 || (gfp & ~(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY)) != 0)) return page; + trace_android_vh_cma_alloc_bypass(cma, count, align, gfp, + &page, &bypass); + if (bypass) + return page; + trace_cma_alloc_start(name, count, align); if (!cma || !cma->count || !cma->bitmap)