From 443ff5cf3b0af2425b2967d05d2a77c543f43966 Mon Sep 17 00:00:00 2001 From: davidwang Date: Mon, 8 Aug 2022 16:57:01 +0800 Subject: [PATCH] ANDROID: vendor_hooks: add vendor hook for dma_heap_buffer_alloc Add android_vh_dmabuf_heap_flags_validation vh for heap flags with vendor valid check. Bug: 241733930 Signed-off-by: davidwang Change-Id: I5c1c111b8231a05f733bc56bda34bc408e708554 (cherry picked from commit fc9630b3cb24f5c0dd111cb49b462268a343f66c) --- drivers/android/vendor_hooks.c | 1 + drivers/dma-buf/dma-heap.c | 9 ++++++++- include/trace/hooks/dmabuf.h | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 355da57ae386..1a277f068248 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -274,6 +274,7 @@ 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_rwsem_wake_finish); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dma_buf_release); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_dmabuf_heap_flags_validation); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_pass_input_event); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_check_status); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_blk_alloc_rqs); diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index 53d8ee80a26d..c372cb9f24df 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -20,6 +20,8 @@ #include #include +#include + #define DEVNAME "dma_heap" #define NUM_HEAP_MINORS 128 @@ -80,10 +82,15 @@ struct dma_buf *dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, unsigned int fd_flags, unsigned int heap_flags) { + bool vh_valid = false; + + trace_android_vh_dmabuf_heap_flags_validation(heap, + len, fd_flags, heap_flags, &vh_valid); + if (fd_flags & ~DMA_HEAP_VALID_FD_FLAGS) return ERR_PTR(-EINVAL); - if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS) + if (heap_flags & ~DMA_HEAP_VALID_HEAP_FLAGS && !vh_valid) return ERR_PTR(-EINVAL); /* * Allocations from all heaps have to begin diff --git a/include/trace/hooks/dmabuf.h b/include/trace/hooks/dmabuf.h index 31ac68577522..666aa5abe11d 100644 --- a/include/trace/hooks/dmabuf.h +++ b/include/trace/hooks/dmabuf.h @@ -16,6 +16,12 @@ struct dma_buf; DECLARE_HOOK(android_vh_dma_buf_release, TP_PROTO(struct dma_buf *data), TP_ARGS(data)); + +struct dma_heap; +DECLARE_HOOK(android_vh_dmabuf_heap_flags_validation, + TP_PROTO(struct dma_heap *heap, size_t len, + unsigned int fd_flags, unsigned int heap_flags, bool *skip), + TP_ARGS(heap, len, fd_flags, heap_flags, skip)); #endif /* _TRACE_HOOK_DMABUF_H */ /* This part must be outside protection */ #include