From 81054a4507e57418d559cafdded4f5086cc7d24a Mon Sep 17 00:00:00 2001 From: Carlos Llamas Date: Tue, 28 May 2024 16:50:12 +0000 Subject: [PATCH] Reapply "ANDROID: vendor_hooks: Add hook for binder_detect_low_async_space" This reverts commit 637c8e0d372f1dfff53337a5db89f772577828d7. Also squash commit db91c5d31a2a ("ANDROID: vendor_hook: rename the the name of hooks"), which fixes the length of the vendor hook's name. Rework the error return for a goto as this has been refactor too. Finally, also fix spaces vs tabs. Change-Id: I22c495eb81237c51c0f9f4d4f9f4f1cf0c8438a8 Signed-off-by: Carlos Llamas --- drivers/android/binder_alloc.c | 10 ++++++++++ drivers/android/vendor_hooks.c | 1 + include/trace/hooks/binder.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index d729129f3f25..ed5ea094c9d2 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -445,9 +445,19 @@ static struct binder_buffer *binder_alloc_new_buf_locked( struct binder_buffer *buffer; unsigned long next_used_page; unsigned long curr_last_page; + bool should_fail = false; size_t buffer_size; trace_android_vh_binder_alloc_new_buf_locked(size, &alloc->free_async_space, is_async); + trace_android_vh_binder_detect_low_async_space(is_async, &alloc->free_async_space, + current->tgid, &should_fail); + if (should_fail) { + binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, + "%d: binder_alloc_buf size %zd failed, not allowed to alloc more async space\n", + alloc->pid, size); + buffer = ERR_PTR(-EPERM); + goto out; + } if (is_async && alloc->free_async_space < size) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 31dde279e279..a45022e569e2 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -391,6 +391,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_ioctl_end); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_looper_exited); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_spawn_new_thread); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_has_special_work_ilocked); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_detect_low_async_space); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_delayacct_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_delayacct_tsk_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_delayacct_tsk_free); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index 77bfa4db10e2..93641ce4ed6e 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -82,6 +82,9 @@ DECLARE_HOOK(android_vh_binder_select_special_worklist, DECLARE_HOOK(android_vh_binder_alloc_new_buf_locked, TP_PROTO(size_t size, size_t *free_async_space, int is_async), TP_ARGS(size, free_async_space, is_async)); +DECLARE_HOOK(android_vh_binder_detect_low_async_space, + TP_PROTO(int is_async, size_t *free_async_space, int pid, bool *should_fail), + TP_ARGS(is_async, free_async_space, pid, should_fail)); struct binder_transaction_data; DECLARE_HOOK(android_vh_binder_reply, TP_PROTO(struct binder_proc *target_proc, struct binder_proc *proc,