diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index c07c82dee039..bd3ec829be63 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -25,6 +25,7 @@ #include #include "binder_alloc.h" #include "binder_trace.h" +#include struct list_lru binder_freelist; @@ -444,8 +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, + &should_fail); + if (should_fail) { + binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, + "%d: binder_alloc_buf failed, not allowed to alloc more async space\n", + alloc->pid); + buffer = ERR_PTR(-EPERM); + goto out; + } + if (is_async && alloc->free_async_space < size) { binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, "%d: binder_alloc_buf size %zd failed, no async space left\n", diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f87996190add..ec3f2ccc37fa 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -382,6 +382,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_alloc_new_buf_locked); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_preset); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_reply); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_trans); diff --git a/include/trace/hooks/binder.h b/include/trace/hooks/binder.h index c5b8409df24d..07e856e7fd7c 100644 --- a/include/trace/hooks/binder.h +++ b/include/trace/hooks/binder.h @@ -26,6 +26,9 @@ DECLARE_HOOK(android_vh_binder_set_priority, DECLARE_HOOK(android_vh_binder_restore_priority, TP_PROTO(struct binder_transaction *t, struct task_struct *task), TP_ARGS(t, task)); +DECLARE_HOOK(android_vh_binder_alloc_new_buf_locked, + TP_PROTO(size_t size, size_t *free_async_space, int is_async, bool *should_fail), + TP_ARGS(size, free_async_space, is_async, should_fail)); DECLARE_HOOK(android_vh_binder_wait_for_work, TP_PROTO(bool do_proc_work, struct binder_thread *tsk, struct binder_proc *proc), TP_ARGS(do_proc_work, tsk, proc));