tu: Pass real size of prime buffers to allocator
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Thu, 24 Aug 2023 04:48:54 +0000 (07:48 +0300)
committerMarge Bot <emma+marge@anholt.net>
Thu, 24 Aug 2023 16:35:43 +0000 (16:35 +0000)
The msm driver reserves the actual DMABUF size in the memory map, while
TU can request smaller memory chunk to be allocated. This potentially
can lead to a situation when next allocation IOVA will be in the middle
of the address space which is reserved for the DMABUF. Pass the
`real_size' to TU allocator instead, so that kernel and userspace have
the same picture of memory allocations.

Cc: mesa-stable
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24861>

src/freedreno/vulkan/tu_knl_drm_msm.cc

index 2d7f838..4961110 100644 (file)
@@ -580,6 +580,9 @@ msm_bo_init_dmabuf(struct tu_device *dev,
    if (real_size < 0 || (uint64_t) real_size < size)
       return vk_error(dev, VK_ERROR_INVALID_EXTERNAL_HANDLE);
 
+   /* iova allocation needs to consider the object's *real* size: */
+   size = real_size;
+
    /* Importing the same dmabuf several times would yield the same
     * gem_handle. Thus there could be a race when destroying
     * BO and importing the same dmabuf from different threads.