From 7e57c2b1155def3cfc311ce2fab7839cdaede96d Mon Sep 17 00:00:00 2001 From: zhujingpeng Date: Wed, 28 Aug 2024 21:50:56 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add hook in __mutex_unlock_slowpath() This hook is used to modify the variables in mutex oemdata when the task releases mutex lock. This code cannot be done in existing hook trace_android_vh_mutex_unlock_slowpath(), because it is executed after wake_up_q, and there is a risk that the mutex object has been freed. Bug: 362700382 Bug: 363173652 Change-Id: I7787c0ea51959642a010891606b2bc39fe056dd2 Signed-off-by: zhujingpeng Signed-off-by: renchenghan (cherry picked from commit 9f6bd03727ea509b05d49f4203d8de3585469a6c) --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/dtask.h | 3 +++ kernel/locking/mutex.c | 1 + 3 files changed, 5 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 7135a5e45490..c3465bfc1c61 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -297,6 +297,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_downgrade_wake_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_wake_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_mutex_list_add); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_unlock_slowpath); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mutex_unlock_slowpath_before_wakeq); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_hibernation_swap); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_cpu_resume); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_hib_resume_bdev); diff --git a/include/trace/hooks/dtask.h b/include/trace/hooks/dtask.h index 0aae26ffd5a6..942241510d03 100644 --- a/include/trace/hooks/dtask.h +++ b/include/trace/hooks/dtask.h @@ -117,6 +117,9 @@ DECLARE_HOOK(android_vh_alter_mutex_list_add, DECLARE_HOOK(android_vh_mutex_unlock_slowpath, TP_PROTO(struct mutex *lock), TP_ARGS(lock)); +DECLARE_HOOK(android_vh_mutex_unlock_slowpath_before_wakeq, + TP_PROTO(struct mutex *lock), + TP_ARGS(lock)); DECLARE_HOOK(android_vh_record_mutex_lock_starttime, TP_PROTO(struct mutex *lock, unsigned long settime_jiffies), diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c index 85cba7ef8595..478d4dcb7558 100644 --- a/kernel/locking/mutex.c +++ b/kernel/locking/mutex.c @@ -1025,6 +1025,7 @@ static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigne if (sched_proxy_exec()) raw_spin_unlock(¤t->blocked_lock); + trace_android_vh_mutex_unlock_slowpath_before_wakeq(lock); preempt_disable(); raw_spin_unlock_irqrestore(&lock->wait_lock, flags); wake_up_q(&wake_q);