diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 6d5b7d41e7c1..20508110192b 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -65,6 +65,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,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); @@ -620,6 +622,7 @@ struct binder_transaction { * during thread teardown */ spinlock_t lock; + ANDROID_VENDOR_DATA(1); }; /** @@ -1207,6 +1210,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, @@ -3230,6 +3234,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) { @@ -3605,6 +3610,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)) { @@ -3716,6 +3722,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); @@ -4390,6 +4397,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 e2cd9e60f650..87eccccab050 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -11,6 +11,7 @@ #include #include #include +#include /* * Export tracepoints that act as a bare tracehook (ie: have no trace event @@ -26,3 +27,6 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_write_wait_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sched_show_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_ptype_head); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_kfree_skb); +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