From c75073626f3df79bafa5f90824e7dde0b9049584 Mon Sep 17 00:00:00 2001 From: Jing Xia Date: Tue, 9 Jan 2024 13:50:22 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add android_vh_rwsem_downgrade_wake_finish to rwsem_downgrade_wake The commit d4528a28cb5b ("ANDROID: vendor_hooks: Add hooks for rwsem and mutex") adds the android_vh_rwsem_wake_finish hook to rwsem_wake().It can get the point when a [write/read]_owner releases the rwsem and wakes up other waiters of the rwsem. However, it cannot cover a scenario that a task acquires the write-lock first, then downgrades to the read-lock and wakes up other waiters in list. In order to avoid breaking other partner handlers that don't expect to be called from rwsem_downgrade_wake,this patch adds a new vendor hook named android_vh_rwsem_downgrade_wake_finish to rwsem_downgrade_wake() as Todd Kjos suggested. Bug: 319178409 Change-Id: I73f677d2aa813777f21f13fafc17b1f912f6ef7e Signed-off-by: Jing Xia (cherry picked from commit 6ac0a2682b5f958c7204506e58b67ffebb06ad85) --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/rwsem.h | 3 +++ kernel/locking/rwsem.c | 2 ++ 3 files changed, 6 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 332cf53f5577..0049f7526def 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -146,3 +146,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_wake); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_write_finished); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alter_rwsem_list_add); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rwsem_downgrade_wake_finish); diff --git a/include/trace/hooks/rwsem.h b/include/trace/hooks/rwsem.h index 71215dfd5eff..40d960d4e29f 100644 --- a/include/trace/hooks/rwsem.h +++ b/include/trace/hooks/rwsem.h @@ -25,6 +25,9 @@ DECLARE_HOOK(android_vh_alter_rwsem_list_add, struct rw_semaphore *sem, bool *already_on_list), TP_ARGS(waiter, sem, already_on_list)); +DECLARE_HOOK(android_vh_rwsem_downgrade_wake_finish, + TP_PROTO(struct rw_semaphore *sem), + TP_ARGS(sem)); #endif /* _TRACE_HOOK_RWSEM_H */ /* This part must be outside protection */ #include diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 909b96da7802..4c6524464fdd 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1250,6 +1250,8 @@ static struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) if (!list_empty(&sem->wait_list)) rwsem_mark_wake(sem, RWSEM_WAKE_READ_OWNED, &wake_q); + trace_android_vh_rwsem_downgrade_wake_finish(sem); + raw_spin_unlock_irqrestore(&sem->wait_lock, flags); wake_up_q(&wake_q);