drm/prime: fix lifetime issue with storing dma_buf on import list for exports
Subsystems (2)
Dave Airlie
maintainerPATCH 1/1 drm/prime: fix lifetime issue with storing dma_buf on import list for exports
From: Dave Airlie <[email protected]>
So when we export an dma buf we store it on the import list for that file priv, so we can trap later imports of a buffer we exported from ourselves.
However there is nothing to clean that pointer up if the dma-buf gets released internally, since we don't hold a reference to it. Holding a reference to it could cause circular references so is probably best avoided.
However if we store the gem objects in the file priv, and when we clean up the gem object handles we clean up these references as well, then it should be safe. We can then search for dma bufs referenced from the gem objects themselves.
This seems to point out that obj->export_dma_buf and obj->import_attach may need a bit of a lock safety review.
This fixes some intel/radeon tests from ages ago that started to fail along with appearing to fix prime on my GM45/r600 laptop in F18.
--- drivers/gpu/drm/drm_gem.c | 9 +-------- drivers/gpu/drm/drm_prime.c | 48 +++++++++++++++++++++++++++++++++++---------- include/drm/drmP.h | 7 ++++--- 3 files changed, 43 insertions(+), 21 deletions(-)
drivers/gpu/drm/drm_gem.c +1 -8
@@ -204,14 +204,7 @@ EXPORT_SYMBOL(drm_gem_object_alloc);static void drm_gem_remove_prime_handles (struct drm_gem_object *obj,struct drm_file *filp) { -if (obj->import_attach) { -drm_prime_remove_imported_buf_handle (&filp->prime, - obj->import_attach->dmabuf); - } -if (obj->export_dma_buf) { -drm_prime_remove_imported_buf_handle (&filp->prime, - obj->export_dma_buf); - } +drm_prime_remove_imported_buf_handle (&filp->prime, obj); }/**
drivers/gpu/drm/drm_prime.c +38 -10
102 lines not on this page · raw message
include/drm/drmP.h +4 -3
@@ -1559,9 +1559,10 @@ extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *svoid drm_prime_init_file_private (struct drm_prime_file_private *prime_fpriv);void drm_prime_destroy_file_private (struct drm_prime_file_private *prime_fpriv); -int drm_prime_add_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct dma_buf *dma_buf,uint32_t handle); -int drm_prime_lookup_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct dma_buf *dma_buf,uint32_t *handle); -void drm_prime_remove_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct dma_buf *dma_buf); +int drm_prime_add_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct drm_gem_object *obj,uint32_t handle); +int drm_prime_add_exported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct drm_gem_object *obj,uint32_t handle); +int drm_prime_lookup_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct dma_buf *,uint32_t *handle); +void drm_prime_remove_imported_buf_handle (struct drm_prime_file_private *prime_fpriv,struct drm_gem_object *obj);int drm_prime_add_dma_buf (struct drm_device *dev,struct drm_gem_object *obj); int drm_prime_lookup_obj(struct drm_device *dev, struct dma_buf *buf,
Signature · 1 line
1.8.0.2