dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls
@ 2022-11-08 17:54 Maíra Canal
  2022-11-08 17:54 ` [PATCH v2 1/2] drm/v3d: switch to drmm_mutex_init Maíra Canal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Maíra Canal @ 2022-11-08 17:54 UTC (permalink / raw)
  To: Melissa Wen, Emma Anholt, David Airlie, Daniel Vetter
  Cc: Juan A . Suarez, Maíra Canal, André Almeida,
	linux-kernel, dri-devel

This series introduces some changes to assure the correct resource release on
the V3D driver, especially the mutex. Currently, the V3D has no mutex_destroy()
calls, which means that a mutex is being instantiated, but it is not being
released by the end of its use.

So, use the DRM-managed mutex_init variants when possible to manage the mutex
release and add mutex_destroy() calls when not possible.

Best Regards,
- Maíra Canal

v1 -> v2: https://lore.kernel.org/dri-devel/20221107224656.278135-1-mcanal@igalia.com/T/#m3c23e3f21fe6aaae51138c746c74e94b2a7b3bfc

- Move mutex_destroy() to v3d_perfmon_put() (Daniel Vetter).
- Add mutex_destroy() on error case in v3d_perfmon_create_ioctl() (Daniel Vetter).
- Add Daniel Vetter's tags.

Maíra Canal (2):
  drm/v3d: switch to drmm_mutex_init
  drm/v3d: add missing mutex_destroy

 drivers/gpu/drm/v3d/v3d_gem.c     | 17 +++++++++++++----
 drivers/gpu/drm/v3d/v3d_perfmon.c |  6 +++++-
 2 files changed, 18 insertions(+), 5 deletions(-)

-- 
2.38.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] drm/v3d: switch to drmm_mutex_init
  2022-11-08 17:54 [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Maíra Canal
@ 2022-11-08 17:54 ` Maíra Canal
  2022-11-08 17:54 ` [PATCH v2 2/2] drm/v3d: add missing mutex_destroy Maíra Canal
  2022-11-10 12:59 ` [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Melissa Wen
  2 siblings, 0 replies; 4+ messages in thread
From: Maíra Canal @ 2022-11-08 17:54 UTC (permalink / raw)
  To: Melissa Wen, Emma Anholt, David Airlie, Daniel Vetter
  Cc: André Almeida, Daniel Vetter, Maíra Canal,
	linux-kernel, dri-devel, Juan A . Suarez

mutex_init is supposed to be balanced by a call to mutex_destroy, but
this is not currently happening on the v3d driver.

Considering the introduction of a DRM-managed mutex_init variant, switch
to the drmm_mutex_init.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/v3d/v3d_gem.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c
index b8980440d137..96af1cb5202a 100644
--- a/drivers/gpu/drm/v3d/v3d_gem.c
+++ b/drivers/gpu/drm/v3d/v3d_gem.c
@@ -10,6 +10,7 @@
 #include <linux/sched/signal.h>
 #include <linux/uaccess.h>
 
+#include <drm/drm_managed.h>
 #include <drm/drm_syncobj.h>
 #include <uapi/drm/v3d_drm.h>
 
@@ -1075,10 +1076,18 @@ v3d_gem_init(struct drm_device *dev)
 
 	spin_lock_init(&v3d->mm_lock);
 	spin_lock_init(&v3d->job_lock);
-	mutex_init(&v3d->bo_lock);
-	mutex_init(&v3d->reset_lock);
-	mutex_init(&v3d->sched_lock);
-	mutex_init(&v3d->cache_clean_lock);
+	ret = drmm_mutex_init(dev, &v3d->bo_lock);
+	if (ret)
+		return ret;
+	ret = drmm_mutex_init(dev, &v3d->reset_lock);
+	if (ret)
+		return ret;
+	ret = drmm_mutex_init(dev, &v3d->sched_lock);
+	if (ret)
+		return ret;
+	ret = drmm_mutex_init(dev, &v3d->cache_clean_lock);
+	if (ret)
+		return ret;
 
 	/* Note: We don't allocate address 0.  Various bits of HW
 	 * treat 0 as special, such as the occlusion query counters
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] drm/v3d: add missing mutex_destroy
  2022-11-08 17:54 [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Maíra Canal
  2022-11-08 17:54 ` [PATCH v2 1/2] drm/v3d: switch to drmm_mutex_init Maíra Canal
@ 2022-11-08 17:54 ` Maíra Canal
  2022-11-10 12:59 ` [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Melissa Wen
  2 siblings, 0 replies; 4+ messages in thread
From: Maíra Canal @ 2022-11-08 17:54 UTC (permalink / raw)
  To: Melissa Wen, Emma Anholt, David Airlie, Daniel Vetter
  Cc: André Almeida, Daniel Vetter, Maíra Canal,
	linux-kernel, dri-devel, Juan A . Suarez

v3d_perfmon_open_file() instantiates a mutex for a particular file
instance, but it never destroys it by calling mutex_destroy() in
v3d_perfmon_close_file().

Similarly, v3d_perfmon_create_ioctl() instantiates a mutex for a
particular perfmon, but it never destroys it by calling mutex_destroy()
in v3d_perfmon_destroy_ioctl().

So, add the missing mutex_destroy on both cases.

Signed-off-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/v3d/v3d_perfmon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/v3d/v3d_perfmon.c b/drivers/gpu/drm/v3d/v3d_perfmon.c
index 48aaaa972c49..e1be7368b87d 100644
--- a/drivers/gpu/drm/v3d/v3d_perfmon.c
+++ b/drivers/gpu/drm/v3d/v3d_perfmon.c
@@ -17,8 +17,10 @@ void v3d_perfmon_get(struct v3d_perfmon *perfmon)
 
 void v3d_perfmon_put(struct v3d_perfmon *perfmon)
 {
-	if (perfmon && refcount_dec_and_test(&perfmon->refcnt))
+	if (perfmon && refcount_dec_and_test(&perfmon->refcnt)) {
+		mutex_destroy(&perfmon->lock);
 		kfree(perfmon);
+	}
 }
 
 void v3d_perfmon_start(struct v3d_dev *v3d, struct v3d_perfmon *perfmon)
@@ -113,6 +115,7 @@ void v3d_perfmon_close_file(struct v3d_file_priv *v3d_priv)
 	idr_for_each(&v3d_priv->perfmon.idr, v3d_perfmon_idr_del, NULL);
 	idr_destroy(&v3d_priv->perfmon.idr);
 	mutex_unlock(&v3d_priv->perfmon.lock);
+	mutex_destroy(&v3d_priv->perfmon.lock);
 }
 
 int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data,
@@ -154,6 +157,7 @@ int v3d_perfmon_create_ioctl(struct drm_device *dev, void *data,
 	mutex_unlock(&v3d_priv->perfmon.lock);
 
 	if (ret < 0) {
+		mutex_destroy(&perfmon->lock);
 		kfree(perfmon);
 		return ret;
 	}
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls
  2022-11-08 17:54 [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Maíra Canal
  2022-11-08 17:54 ` [PATCH v2 1/2] drm/v3d: switch to drmm_mutex_init Maíra Canal
  2022-11-08 17:54 ` [PATCH v2 2/2] drm/v3d: add missing mutex_destroy Maíra Canal
@ 2022-11-10 12:59 ` Melissa Wen
  2 siblings, 0 replies; 4+ messages in thread
From: Melissa Wen @ 2022-11-10 12:59 UTC (permalink / raw)
  To: Maíra Canal, Emma Anholt, David Airlie, Daniel Vetter
  Cc: Juan A . Suarez, André Almeida, linux-kernel, dri-devel


On 11/8/22 16:54, Maíra Canal wrote:
> This series introduces some changes to assure the correct resource release on
> the V3D driver, especially the mutex. Currently, the V3D has no mutex_destroy()
> calls, which means that a mutex is being instantiated, but it is not being
> released by the end of its use.
>
> So, use the DRM-managed mutex_init variants when possible to manage the mutex
> release and add mutex_destroy() calls when not possible.
>
> Best Regards,
> - Maíra Canal
>
> v1 -> v2: https://lore.kernel.org/dri-devel/20221107224656.278135-1-mcanal@igalia.com/T/#m3c23e3f21fe6aaae51138c746c74e94b2a7b3bfc
>
> - Move mutex_destroy() to v3d_perfmon_put() (Daniel Vetter).
> - Add mutex_destroy() on error case in v3d_perfmon_create_ioctl() (Daniel Vetter).
> - Add Daniel Vetter's tags.

Applied to drm-misc-next.

Thanks,

Melissa

>
> Maíra Canal (2):
>    drm/v3d: switch to drmm_mutex_init
>    drm/v3d: add missing mutex_destroy
>
>   drivers/gpu/drm/v3d/v3d_gem.c     | 17 +++++++++++++----
>   drivers/gpu/drm/v3d/v3d_perfmon.c |  6 +++++-
>   2 files changed, 18 insertions(+), 5 deletions(-)
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-10 13:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-08 17:54 [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Maíra Canal
2022-11-08 17:54 ` [PATCH v2 1/2] drm/v3d: switch to drmm_mutex_init Maíra Canal
2022-11-08 17:54 ` [PATCH v2 2/2] drm/v3d: add missing mutex_destroy Maíra Canal
2022-11-10 12:59 ` [PATCH v2 0/2] Balance mutex_init and mutex_destroy calls Melissa Wen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).