Skip to contentSkip to conversation

pm: prevent freeing the wrong engine context

PATCH In review Samuel Pitoiset 1 participant 3 messages Apr 14, 2015 – May 10, 2015 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pm: prevent freeing the wrong engine context

This fixes a crash when multiple PM engine contexts are created.

---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drm/nouveau/nvkm/engine/pm/base.c +5 -2
index 2006c44..274457c 100644
@@ -332,9 +332,12 @@ static void
 nvkm_perfctx_dtor(struct nvkm_object *object)
 {
 	struct nvkm_pm *ppm = (void *)object->engine;
+	struct nvkm_perfctx *ctx = (void *)object;
+
 	mutex_lock(&nv_subdev(ppm)->mutex);
-	nvkm_engctx_destroy(&ppm->context->base);
-	ppm->context = NULL;
+	nvkm_engctx_destroy(&ctx->base);
+	if (ppm->context == ctx)
+		ppm->context = NULL;
 	mutex_unlock(&nv_subdev(ppm)->mutex);
 }
 
Signature · 6 lines
2.3.5

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 1429044239-2223-1-git-send-email-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 2/2 pm: fix a potential race condition when creating an engine context

There is always the possiblity that the ppm->context pointer would get partially updated and accidentally would equal ctx. This would allow two contexts to co-exist, which is not acceptable. Moving the test to the critical section takes care of this problem.

---
 drm/nouveau/nvkm/engine/pm/base.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drm/nouveau/nvkm/engine/pm/base.c +3 -4
index 274457c..4cf36a3 100644
@@ -358,12 +358,11 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
 	mutex_lock(&nv_subdev(ppm)->mutex);
 	if (ppm->context == NULL)
 		ppm->context = ctx;
-	mutex_unlock(&nv_subdev(ppm)->mutex);
-
 	if (ctx != ppm->context)
-		return -EBUSY;
+		ret = -EBUSY;
+	mutex_unlock(&nv_subdev(ppm)->mutex);
 
-	return 0;
+	return ret;
 }
 
 struct nvkm_oclass
Signature · 6 lines
2.3.5

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau

A message that is not in the archive (sent off-list or not yet received): 1429044239-2223-2-git-send-email-samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] pm: fix a potential race condition when creating an engine context

* bump *

Ben, could you take a look at the series ?

Quoted 21 lines · Samuel Pitoiset

There is always the possiblity that the ppm->context pointer would get partially updated and accidentally would equal ctx. This would allow two contexts to co-exist, which is not acceptable. Moving the test to the critical section takes care of this problem.

---
  drm/nouveau/nvkm/engine/pm/base.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drm/nouveau/nvkm/engine/pm/base.c +0 -2
index 274457c..4cf36a3 100644
@@ -358,12 +358,11 @@ nvkm_perfctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
  	mutex_lock(&nv_subdev(ppm)->mutex);
  	if (ppm->context == NULL)
  		ppm->context = ctx;
-	mutex_unlock(&nv_subdev(ppm)->mutex);
-

drm/nouveau/nvkm/engine/pm/base.c nvkm_perfctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine, · line 368

Quoted 10 lines
drm/nouveau/nvkm/engine/pm/base.c +3 -2
  	if (ctx != ppm->context)
-		return -EBUSY;
+		ret = -EBUSY;
+	mutex_unlock(&nv_subdev(ppm)->mutex);
 
-	return 0;
+	return ret;
  }
 
  struct nvkm_oclass

_______________________________________________
Nouveau mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau