From 35014985c266face161f6d107f8d8338e02a0b2d Mon Sep 17 00:00:00 2001 From: zhengding chen Date: Wed, 28 Apr 2021 19:24:57 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks for binder proc transaction When servicemanager process added service proxy from other process register the service, we want to know the matching relation between handle in the process and service name. When binder transaction happened, We want to know what process calls what method on what service. Bug: 186604985 Signed-off-by: zhengding chen Change-Id: I813d1cde10294d8665f899f7fef0d444ec1f1f5e --- drivers/android/binder.c | 5 +++++ drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/binder.h | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index e0b36c9af117..a6ebc3056b6b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -1202,6 +1202,7 @@ static struct binder_ref *binder_get_ref_for_node_olocked( "%d new ref %d desc %d for node %d\n", proc->pid, new_ref->data.debug_id, new_ref->data.desc, node->debug_id); + trace_android_vh_binder_new_ref(proc->tsk, new_ref->data.desc, new_ref->node->debug_id); binder_node_unlock(node); return new_ref; } @@ -1369,6 +1370,7 @@ static struct binder_node *binder_get_node_from_ref( */ static void binder_free_ref(struct binder_ref *ref) { + trace_android_vh_binder_del_ref(ref->proc ? ref->proc->tsk : 0, ref->data.desc); if (ref->node) binder_free_node(ref->node); kfree(ref->death); @@ -2502,6 +2504,9 @@ static int binder_proc_transaction(struct binder_transaction *t, if (!thread && !pending_async) thread = binder_select_thread_ilocked(proc); + trace_android_vh_binder_proc_transaction(current, proc->tsk, + thread ? thread->task : 0, node->debug_id, t->code, pending_async); + if (thread) { binder_transaction_priority(thread->task, t, node_prio, node->inherit_rt); diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index a7608d1f39ac..80018a261550 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -240,6 +240,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_alloc_new_buf_locked); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_reply); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_trans); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_preset); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_proc_transaction); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_new_ref); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_del_ref); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_post_init_entity_util_avg); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_get_timer); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_adj_current_limit); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index b00018dab116..ddeb936e8945 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -54,6 +54,17 @@ DECLARE_HOOK(android_vh_binder_trans, DECLARE_HOOK(android_vh_binder_preset, TP_PROTO(struct hlist_head *hhead, struct mutex *lock), TP_ARGS(hhead, lock)); +DECLARE_HOOK(android_vh_binder_proc_transaction, + TP_PROTO(struct task_struct *caller_task, struct task_struct *binder_proc_task, + struct task_struct *binder_th_task, int node_debug_id, + unsigned int code, bool pending_async), + TP_ARGS(caller_task, binder_proc_task, binder_th_task, node_debug_id, code, pending_async)); +DECLARE_HOOK(android_vh_binder_new_ref, + TP_PROTO(struct task_struct *proc, uint32_t ref_desc, int node_debug_id), + TP_ARGS(proc, ref_desc, node_debug_id)); +DECLARE_HOOK(android_vh_binder_del_ref, + TP_PROTO(struct task_struct *proc, uint32_t ref_desc), + TP_ARGS(proc, ref_desc)); /* macro versions of hooks are no longer required */