From 4ec2a921d3437cfd6dc01c63b3cac180e308188e Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 5 Nov 2025 14:23:00 -0800 Subject: [PATCH] panvk: fix mem alloc size for VkBuffer backed by imported blob AHB For AHB VkBuffer import, the allocationSize comes from the raw external AHB props query and it can be larger than the underlying buffer memory requirement. So we must respect the allocationSize for the actual mem import to support mapping the whole AHB size, and the dedicated buffer info has to be stripped to obey the spec. Test: CtsNativeHardwareTestCases no longer crashes on debug build panvk Fixes: 66bbd9eec83 ("panvk: implement AHB image deferred init and memory alloc") Tested-by: Valentine Burley Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Christoph Pillmayer Part-of: --- src/panfrost/vulkan/panvk_android.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/panfrost/vulkan/panvk_android.c b/src/panfrost/vulkan/panvk_android.c index 63e196dcef7..82e30c61139 100644 --- a/src/panfrost/vulkan/panvk_android.c +++ b/src/panfrost/vulkan/panvk_android.c @@ -436,6 +436,17 @@ panvk_android_import_ahb_memory(VkDevice device, buf_handle = dedicated_info->buffer; result = panvk_android_get_buffer_mem_reqs(device, buf_handle, dma_buf_fd, &mem_reqs); + if (result == VK_SUCCESS && + pAllocateInfo->allocationSize > mem_reqs.size) { + /* For AHB VkBuffer import, the allocationSize comes from the raw + * external AHB props query and it can be larger than the underlying + * buffer memory requirement. So we must respect the allocationSize + * for the actual mem import to support mapping the whole AHB size, + * and the dedicated buffer info has to be stripped to obey the spec. + */ + mem_reqs.size = pAllocateInfo->allocationSize; + buf_handle = VK_NULL_HANDLE; + } } else { mem_reqs.size = pAllocateInfo->allocationSize; mem_reqs.memoryTypeBits =