Skip to contentSkip to conversation

drm/gma500: fix double freeing

PATCH Superseded Sudip Mukherjee 2 participants 7 messages Sep 9, 2015 – Oct 5, 2015

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/gma500: fix double freeing

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---
 drivers/gpu/drm/gma500/framebuffer.c | 3 ++-
 drivers/gpu/drm/gma500/gtt.c         | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/gma500/framebuffer.c +2 -1
index 2eaf1b3..381d7af 100644
@@ -474,7 +474,8 @@ out_unref:
 	drm_fb_helper_release_fbi(&fbdev->psb_fb_helper);
 out_err1:
 	mutex_unlock(&dev->struct_mutex);
-	psb_gtt_free_range(dev, backing);
+	if (backing)
+		psb_gtt_free_range(dev, backing);
 	return ret;
 }
 
drivers/gpu/drm/gma500/gtt.c +1 -0
index ce015db..8130fa8 100644
@@ -385,6 +385,7 @@ void psb_gtt_free_range(struct drm_device *dev, struct gtt_range *gt)
 	WARN_ON(gt->in_gart && !gt->stolen);
 	release_resource(&gt->resource);
 	kfree(gt);
+	gt = NULL;
 }
 
 static void psb_gtt_alloc(struct drm_device *dev)
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 7 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---

Hi Patrik,
A gentle ping.

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

maintainer
#2 lore raw
Quoted 6 lines · Sudip Mukherjee
Quoted 5 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

Quoted 7 lines
Quoted 2 lines

---

Hi Patrik,
A gentle ping.

regards
sudip

Hi, sorry for the late reply.

Why are we freeing the range twice in the first case?

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

#3 lore raw
Quoted 13 lines · Patrik Jakobsson
Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---

Hi Patrik,
A gentle ping.

Quoted 6 lines
Quoted 2 lines

regards
sudip

Hi, sorry for the late reply.

Why are we freeing the range twice in the first case?

I think,
if backing->stolen is true then backing is released using psb_gtt_free_range() but if backing->stolen is false then the gem object is freed but the backing is not yet freed. To free that backing psb_gtt_free_range() has been called second time. My patch tried to fix the possibility of backing->stolen being true and backing being freed 2 times.

regards
sudip

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

maintainer
#4 lore raw
Quoted 28 lines · Sudip Mukherjee
Quoted 13 lines · Patrik Jakobsson
Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---

Hi Patrik,
A gentle ping.

Quoted 6 lines
Quoted 2 lines

regards
sudip

Hi, sorry for the late reply.

Why are we freeing the range twice in the first case?

I think,
if backing->stolen is true then backing is released using psb_gtt_free_range() but if backing->stolen is false then the gem object is freed but the backing is not yet freed. To free that backing psb_gtt_free_range() has been called second time. My patch tried to fix the possibility of backing->stolen being true and backing being freed 2 times.

Quoted 2 lines

regards
sudip

There are some special handling of the stolen framebuffer that I don't remember entirely but the basic concept is that we free the backing when we drop the last reference on a gem object. That will trigger a psb_gtt_free_range(). So in this case it looks to me that the extra free is not needed at all. That's my quick reasoning, feel free to prove me wrong :)

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

#5 lore raw
Quoted 33 lines · Patrik Jakobsson
Quoted 28 lines · Sudip Mukherjee
Quoted 13 lines · Patrik Jakobsson
Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---

Hi Patrik,
A gentle ping.

Quoted 6 lines
Quoted 2 lines

regards
sudip

Hi, sorry for the late reply.

Why are we freeing the range twice in the first case?

I think,
if backing->stolen is true then backing is released using psb_gtt_free_range() but if backing->stolen is false then the gem object is freed but the backing is not yet freed. To free that backing psb_gtt_free_range() has been called second time. My patch tried to fix the possibility of backing->stolen being true and backing being freed 2 times.

Quoted 2 lines

regards
sudip

Quoted 6 lines

There are some special handling of the stolen framebuffer that I don't remember entirely but the basic concept is that we free the backing when we drop the last reference on a gem object. That will trigger a psb_gtt_free_range(). So in this case it looks to me that the extra free is not needed at all. That's my quick reasoning, feel free to prove me wrong :)

In this case we are allocating backing using psbfb_alloc() and so backing->stolen is always true. So we can remove the backing->stolen condition. And if drm_fb_helper_alloc_fbi() fails then we are jumping to out_err1. So the fitst free will not be needed.

drivers/gpu/drm/gma500/framebuffer.c +0 -5
index 2eaf1b3..932f07b 100644
@@ -466,11 +466,6 @@ static int psbfb_create(struct psb_fbdev *fbdev,
 	mutex_unlock(&dev->struct_mutex);
 	return 0;
 out_unref:
-	if (backing->stolen)
-		psb_gtt_free_range(dev, backing);
-	else
-		drm_gem_object_unreference(&backing->gem);
-
 	drm_fb_helper_release_fbi(&fbdev->psb_fb_helper);
 out_err1:
 	mutex_unlock(&dev->struct_mutex);

If it is ok, I can submit the v2.

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

maintainer
#6 lore raw
Quoted 41 lines · Sudip Mukherjee
Quoted 33 lines · Patrik Jakobsson
Quoted 28 lines · Sudip Mukherjee
Quoted 13 lines · Patrik Jakobsson
Quoted 11 lines · Sudip Mukherjee
Quoted 7 lines · Sudip Mukherjee

If backing->stolen is true then we were freeing backing by calling psb_gtt_free_range() but we called it again after unlocking the mutex. Lets make it NULL after freeing in psb_gtt_free_range() and check for NULL before calling the function for the second time.

---

Hi Patrik,
A gentle ping.

Quoted 6 lines
Quoted 2 lines

regards
sudip

Hi, sorry for the late reply.

Why are we freeing the range twice in the first case?

I think,
if backing->stolen is true then backing is released using psb_gtt_free_range() but if backing->stolen is false then the gem object is freed but the backing is not yet freed. To free that backing psb_gtt_free_range() has been called second time. My patch tried to fix the possibility of backing->stolen being true and backing being freed 2 times.

Quoted 2 lines

regards
sudip

Quoted 6 lines

There are some special handling of the stolen framebuffer that I don't remember entirely but the basic concept is that we free the backing when we drop the last reference on a gem object. That will trigger a psb_gtt_free_range(). So in this case it looks to me that the extra free is not needed at all. That's my quick reasoning, feel free to prove me wrong :)

Quoted 4 lines

In this case we are allocating backing using psbfb_alloc() and so backing->stolen is always true. So we can remove the backing->stolen condition. And if drm_fb_helper_alloc_fbi() fails then we are jumping to out_err1. So the fitst free will not be needed.

Sounds good, could you also rename the labels to what they're doing now. I'm thinking out_release and out_unlock or something you feel is suitable.

Thanks
Patrik

Quoted 22 lines
drivers/gpu/drm/gma500/framebuffer.c +0 -5
index 2eaf1b3..932f07b 100644
@@ -466,11 +466,6 @@ static int psbfb_create(struct psb_fbdev *fbdev,
        mutex_unlock(&dev->struct_mutex);
        return 0;
 out_unref:
-       if (backing->stolen)
-               psb_gtt_free_range(dev, backing);
-       else
-               drm_gem_object_unreference(&backing->gem);
-
        drm_fb_helper_release_fbi(&fbdev->psb_fb_helper);
 out_err1:
        mutex_unlock(&dev->struct_mutex);

If it is ok, I can submit the v2.

regards
sudip