Skip to contentSkip to conversation

etnaviv: prevent deadlock in error path

PATCH Superseded Philipp Zabel 3 participants 5 messages Aug 21, 2017 – Sep 14, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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").

---
v2: keep lock around drmPrimeFDToHandle call

---
 etnaviv/etnaviv_bo.c | 5 +++++
 1 file changed, 5 insertions(+)
etnaviv/etnaviv_bo.c +5 -0
index 0cc3ab97..86fb894b 100644
@@ -225,10 +225,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 	int ret, size;
 	uint32_t handle;
 
+	/* take the lock before calling drmPrimeFDToHandle to avoid
+	 * racing against etna_bo_del, which might invalidate the
+	 * returned handle.
+	 */
 	pthread_mutex_lock(&table_lock);
 
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 	if (ret) {
+		pthread_mutex_unlock(&table_lock);
 		return NULL;
 	}
 
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Philipp Zabel

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").

Quoted 29 lines

---
v2: keep lock around drmPrimeFDToHandle call

---
 etnaviv/etnaviv_bo.c | 5 +++++
 1 file changed, 5 insertions(+)
etnaviv/etnaviv_bo.c +5 -0
index 0cc3ab97..86fb894b 100644
@@ -225,10 +225,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 	int ret, size;
 	uint32_t handle;
 
+	/* take the lock before calling drmPrimeFDToHandle to avoid
+	 * racing against etna_bo_del, which might invalidate the
+	 * returned handle.
+	 */
 	pthread_mutex_lock(&table_lock);
 
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 	if (ret) {
+		pthread_mutex_unlock(&table_lock);
 		return NULL;
 	}
 
Signature · 1 line
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 5 lines · Eric Engestrom
Quoted 4 lines · Philipp Zabel

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.

I was about to merge this, when I noticed the commit message doesn't apply to v2 of this patch.
Can you re-spin it with this fixed, and I'll merge it for you?

Cheers,
Eric

Quoted 33 lines
Quoted 4 lines

Based on ceb70a6b1015 ("freedreno: prevent deadlock in error path").

Quoted 26 lines

---
v2: keep lock around drmPrimeFDToHandle call

---
 etnaviv/etnaviv_bo.c | 5 +++++
 1 file changed, 5 insertions(+)
etnaviv/etnaviv_bo.c +5 -0
index 0cc3ab97..86fb894b 100644
@@ -225,10 +225,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 	int ret, size;
 	uint32_t handle;
 
+	/* take the lock before calling drmPrimeFDToHandle to avoid
+	 * racing against etna_bo_del, which might invalidate the
+	 * returned handle.
+	 */
 	pthread_mutex_lock(&table_lock);
 
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 	if (ret) {
+		pthread_mutex_unlock(&table_lock);
 		return NULL;
 	}
 
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

PATCH v3 1/1 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. Unlock the mutex in the error path.

Based on ceb70a6b1015 ("freedreno: prevent deadlock in error path").

---
v3: fix the commit message to correspond to the code in v2/v3

---
 etnaviv/etnaviv_bo.c | 5 +++++
 1 file changed, 5 insertions(+)
etnaviv/etnaviv_bo.c +5 -0
index 4fe877f1..78b9cd27 100644
@@ -206,10 +206,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 	int ret, size;
 	uint32_t handle;
 
+	/* take the lock before calling drmPrimeFDToHandle to avoid
+	 * racing against etna_bo_del, which might invalidate the
+	 * returned handle.
+	 */
 	pthread_mutex_lock(&table_lock);
 
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 	if (ret) {
+		pthread_mutex_unlock(&table_lock);
 		return NULL;
 	}
 
Signature · 6 lines
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 10 lines · Philipp Zabel

If drmPrimeFDToHandle fails in etna_bo_from_dmabuf, the function must not return with the table_lock mutex held. Unlock the mutex in the error path.

Based on ceb70a6b1015 ("freedreno: prevent deadlock in error path").

---
v3: fix the commit message to correspond to the code in v2/v3

Thanks, pushed now :)

Quoted 27 lines
---
 etnaviv/etnaviv_bo.c | 5 +++++
 1 file changed, 5 insertions(+)
etnaviv/etnaviv_bo.c +5 -0
index 4fe877f1..78b9cd27 100644
@@ -206,10 +206,15 @@ struct etna_bo *etna_bo_from_dmabuf(struct etna_device *dev, int fd)
 	int ret, size;
 	uint32_t handle;
 
+	/* take the lock before calling drmPrimeFDToHandle to avoid
+	 * racing against etna_bo_del, which might invalidate the
+	 * returned handle.
+	 */
 	pthread_mutex_lock(&table_lock);
 
 	ret = drmPrimeFDToHandle(dev->fd, fd, &handle);
 	if (ret) {
+		pthread_mutex_unlock(&table_lock);
 		return NULL;
 	}
 
Signature · 1 line
2.11.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel