Skip to content

turnip: Add a refcount mechanism to BOs

Danylo Piliaiev requested to merge Danil/mesa:fix/turnip/bo-refcount into main

Until now we have lived without a refcount mechanism in the driver because in Vulkan the user is responsible for handling the life span of memory allocations for all Vulkan objects, however, imported BOs are tricky because the kernel doesn't refcount so user-space needs to make sure that:

  1. When importing a BO into the same device used to create it (self-importing) it does not double free the same BO.
  2. Frees imported BOs that were not allocated through the same device.

Our initial implementation always freed BOs when requested, so we handled 2) correctly but not 1) on drm and we would double-free self-imported BOs because kernel doesn't return a unique gem_handle on each import.

Beside this the submit ioctl checks for duplicates in the BO list and returns an error if there is one.

This fixes the problem for good by adding refcounts to BOs so that self-imported BOs have a refcnt > 1 and are only freed when all references are freed.

KGSL on the other hand does not have the same problems, at least not with ION buffers which are used for exportable BOs on pre 5.10 android kernels.

Closes: #5936 (closed)
Fixes CTS tests: dEQP-VK.drm_format_modifiers.export_import.*

Merge request reports

Loading