From 4952744d12e28679c8627793329d8b7b6c0fc059 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 | 7 +++++++ drivers/android/vendor_hooks.c | 3 +++ include/trace/hooks/binder.h | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index b3a5b79c4bb1..78f210a29b4c 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -1302,6 +1302,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; } @@ -1469,6 +1470,8 @@ err_no_ref: */ static void binder_free_ref(struct binder_ref *ref) { + trace_android_vh_binder_del_ref(ref->proc ? ref->proc->tsk : NULL, + ref->data.desc); if (ref->node) binder_free_node(ref->node); kfree(ref->death); @@ -2972,6 +2975,10 @@ static int binder_proc_transaction(struct binder_transaction *t, if (!thread && !pending_async && !skip) thread = binder_select_thread_ilocked(proc); + trace_android_vh_binder_proc_transaction(current, proc->tsk, + thread ? thread->task : NULL, node->debug_id, t->code, + pending_async); + if (thread) { binder_transaction_priority(thread, t, node); binder_enqueue_thread_work_ilocked(thread, &t->work); diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index b882d9b6c0ab..3fb62914678e 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -265,3 +265,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_exit_signal); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_shrink_node_memcgs); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_modify_thermal_request_freq); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_modify_thermal_target_freq); +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); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 4ae5ef5b3cce..991e9b1271a1 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -82,6 +82,17 @@ DECLARE_HOOK(android_vh_binder_trans, TP_PROTO(struct binder_proc *target_proc, struct binder_proc *proc, struct binder_thread *thread, struct binder_transaction_data *tr), TP_ARGS(target_proc, proc, thread, tr)); +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)); #endif /* _TRACE_HOOK_BINDER_H */ /* This part must be outside protection */