Skip to content

Commit

Permalink
drm/v3d: Stop active perfmon if it is being destroyed
Browse files Browse the repository at this point in the history
Commit 21f1435 upstream

If the active performance monitor (`v3d->active_perfmon`) is being
destroyed, stop it first. Currently, the active perfmon is not
stopped during destruction, leaving the `v3d->active_perfmon` pointer
stale. This can lead to undefined behavior and instability.

This patch ensures that the active perfmon is stopped before being
destroyed, aligning with the behavior introduced in commit
7d1fd36 ("drm/v3d: Stop the active perfmon before being destroyed").

Cc: [email protected] # v5.15+
Fixes: 26a4dc2 ("drm/v3d: Expose performance counters to userspace")
Signed-off-by: Christian Gmeiner <[email protected]>
Signed-off-by: Maíra Canal <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
Christian Gmeiner authored and 6by9 committed Jan 21, 2025
1 parent dc2770b commit acefb37
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions drivers/gpu/drm/v3d/v3d_perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ int v3d_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
{
struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
struct drm_v3d_perfmon_destroy *req = data;
struct v3d_dev *v3d = v3d_priv->v3d;
struct v3d_perfmon *perfmon;

mutex_lock(&v3d_priv->perfmon.lock);
Expand All @@ -393,6 +394,10 @@ int v3d_perfmon_destroy_ioctl(struct drm_device *dev, void *data,
if (!perfmon)
return -EINVAL;

/* If the active perfmon is being destroyed, stop it first */
if (perfmon == v3d->active_perfmon)
v3d_perfmon_stop(v3d, perfmon, false);

v3d_perfmon_put(perfmon);

return 0;
Expand Down

0 comments on commit acefb37

Please sign in to comment.