etnaviv: prevent deadlock in error path
PATCH 1/2 etnaviv: prevent deadlock in error path
If drmPrimeFDToHandle fails in etna_bo_from_dmabuf, the function must not return with the table_lock mutex held. There is no reason to call drmPrimeFDToHandle under that lock, so just take the lock after trying to obtain the handle.
Based on ceb70a6b1015 ("freedreno: prevent deadlock in error path").
--- etnaviv/etnaviv_bo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
etnaviv/etnaviv_bo.c +2 -2
@@ -225,13 +225,13 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)int ret, size;uint32_t handle; -pthread_mutex_lock (&table_lock); - ret =drmPrimeFDToHandle (dev->fd, fd, &handle);if (ret) {return NULL ; } +pthread_mutex_lock (&table_lock); + bo =lookup_bo (dev->handle_table, handle);if (bo) goto out_unlock;
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/2 freedreno: simplify locking in fd_bo_from_dmabuf
There should be no reason to call drmPrimeFDToHandle under the table_lock mutex. Instead of taking the lock early and releasing it in two places, just take it after trying to obtain the handle.
--- freedreno/freedreno_bo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
freedreno/freedreno_bo.c +2 -2
@@ -135,13 +135,13 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)uint32_t handle;struct fd_bo *bo; -pthread_mutex_lock (&table_lock); ret =drmPrimeFDToHandle (dev->fd, fd, &handle);if (ret) { -pthread_mutex_unlock (&table_lock);return NULL ; } +pthread_mutex_lock (&table_lock); + bo =lookup_bo (dev->handle_table, handle);if (bo) goto out_unlock;
Signature · 6 lines
2.11.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
2017-08-21 12:57 GMT+02:00 Philipp Zabel <[email protected]>:
Quoted 8 lines
If drmPrimeFDToHandle fails in
etna_bo_from_dmabuf, the function must not return with thetable_lockmutex held. There is no reason to call drmPrimeFDToHandle under that lock, so just take the lock after trying to obtain the handle.Based on
ceb70a6b1015("freedreno: prevent deadlock in error path").Signed-off-by Philipp Zabel <[email protected]>
Quoted 27 lines
--- etnaviv/etnaviv_bo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)etnaviv/etnaviv_bo.c +2
-3@@ -225,13 +225,13 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)int ret, size;uint32_t handle; -pthread_mutex_lock (&table_lock); - ret =drmPrimeFDToHandle (dev->fd, fd, &handle);if (ret) {return NULL ; } +pthread_mutex_lock (&table_lock); + bo =lookup_bo (dev->handle_table, handle);if (bo) goto out_unlock; --2.11.0
Quoted 4 lines
_______________________________________________
etnaviv mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/etnaviv
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 7 lines · Philipp Zabel
If drmPrimeFDToHandle fails in
etna_bo_from_dmabuf, the function must not return with thetable_lockmutex held. There is no reason to call drmPrimeFDToHandle under that lock, so just take the lock after trying to obtain the handle.Based on
ceb70a6b1015("freedreno: prevent deadlock in error path").
Can you skim through cf40cf05a4d7f3945d534790e7768a048adc3ab0 and it's commit message.
Doesn't a similar issue apply here as well?
-Emil
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 6 lines · Emil Velikov
Quoted 6 lines · Philipp Zabel
If drmPrimeFDToHandle fails in
etna_bo_from_dmabuf, the function must not return with thetable_lockmutex held. There is no reason to call drmPrimeFDToHandle under that lock, so just take the lock after trying to obtain the handle.
Quoted 7 lines
Quoted 2 lines
Based on
ceb70a6b1015("freedreno: prevent deadlock in error path").Can you skim through
cf40cf05a4d7f3945d534790e7768a048adc3ab0and it's commit message.Doesn't a similar issue apply here as well?
I think you are right. If fd_bo_del is called at the same time as fd_bo_from_dmabuf with an fd that maps to the same BO, bo_del may call GEM_CLOSE with the same handle that drmPrimeFDToHandle just returned, possibly invalidating it before fd_bo_from_dmabuf can take the lock.
regards
Philipp
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel