diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 9803f62d092e..0d56738b6a34 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -76,6 +77,7 @@ #include "binder_alloc.h" #include "binder_internal.h" #include "binder_trace.h" +#include static HLIST_HEAD(binder_deferred_list); static DEFINE_MUTEX(binder_deferred_lock); @@ -616,6 +618,7 @@ struct binder_transaction { * during thread teardown */ spinlock_t lock; + ANDROID_VENDOR_DATA(1); }; /** @@ -1203,6 +1206,7 @@ static void binder_transaction_priority(struct task_struct *task, } binder_set_priority(task, desired_prio); + trace_android_vh_binder_set_priority(t, task); } static struct binder_node *binder_get_node_ilocked(struct binder_proc *proc, @@ -3222,6 +3226,7 @@ static void binder_transaction(struct binder_proc *proc, INIT_LIST_HEAD(&t->fd_fixups); binder_stats_created(BINDER_STAT_TRANSACTION); spin_lock_init(&t->lock); + trace_android_vh_binder_transaction_init(t); tcomplete = kzalloc(sizeof(*tcomplete), GFP_KERNEL); if (tcomplete == NULL) { @@ -3597,6 +3602,7 @@ static void binder_transaction(struct binder_proc *proc, binder_enqueue_thread_work_ilocked(target_thread, &t->work); binder_inner_proc_unlock(target_proc); wake_up_interruptible_sync(&target_thread->wait); + trace_android_vh_binder_restore_priority(in_reply_to, current); binder_restore_priority(current, in_reply_to->saved_priority); binder_free_transaction(in_reply_to); } else if (!(t->flags & TF_ONE_WAY)) { @@ -3708,6 +3714,7 @@ err_invalid_target_handle: BUG_ON(thread->return_error.cmd != BR_OK); if (in_reply_to) { + trace_android_vh_binder_restore_priority(in_reply_to, current); binder_restore_priority(current, in_reply_to->saved_priority); thread->return_error.cmd = BR_TRANSACTION_COMPLETE; binder_enqueue_thread_work(thread, &thread->return_error.work); @@ -4375,6 +4382,7 @@ retry: wait_event_interruptible(binder_user_error_wait, binder_stop_on_user_error < 2); } + trace_android_vh_binder_restore_priority(NULL, current); binder_restore_priority(current, proc->default_priority); } diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 80129eff606f..db00a798a4bf 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -10,6 +10,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -24,3 +25,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dequeue_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_can_migrate_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_find_lowest_rq); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_is_fpsimd_save); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_init); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_set_priority); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_restore_priority); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h new file mode 100644 index 000000000000..48ef1ebb65ba --- /dev/null +++ b/include/trace/hooks/binder.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#undef TRACE_SYSTEM +#define TRACE_SYSTEM binder +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH trace/hooks +#if !defined(_TRACE_HOOK_BINDER_H) || defined(TRACE_HEADER_MULTI_READ) +#define _TRACE_HOOK_BINDER_H +#include +#include +/* + * Following tracepoints are not exported in tracefs and provide a + * mechanism for vendor modules to hook and extend functionality + */ +#if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_ANDROID_VENDOR_HOOKS) +struct binder_transaction; +struct task_struct; +DECLARE_HOOK(android_vh_binder_transaction_init, + TP_PROTO(struct binder_transaction *t), + TP_ARGS(t)); +DECLARE_HOOK(android_vh_binder_set_priority, + TP_PROTO(struct binder_transaction *t, struct task_struct *task), + TP_ARGS(t, task)); +DECLARE_HOOK(android_vh_binder_restore_priority, + TP_PROTO(struct binder_transaction *t, struct task_struct *task), + TP_ARGS(t, task)); +#else +#define trace_android_vh_binder_transaction_init(t) +#define trace_android_vh_binder_set_priority(t, task) +#define trace_android_vh_binder_restore_priority(t, task) +#endif +#endif /* _TRACE_HOOK_BINDER_H */ +/* This part must be outside protection */ +#include