Commit 4b356a85 authored by Christian Gmeiner's avatar Christian Gmeiner Committed by Wentao Guan
Browse files

drm/v3d: Stop active perfmon if it is being destroyed

stable inclusion
from stable-v6.6.79
commit eb0e0eca0eab93f310c6c37b8564049366704691
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBXANC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=eb0e0eca0eab93f310c6c37b8564049366704691



--------------------------------

commit 21f1435b1e6b012a07c42f36b206d2b66fc8f13b 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
7d1fd3638ee3 ("drm/v3d: Stop the active perfmon before being destroyed").

Cc: stable@vger.kernel.org # v5.15+
Fixes: 26a4dc29 ("drm/v3d: Expose performance counters to userspace")
Signed-off-by: default avatarChristian Gmeiner <cgmeiner@igalia.com>
Signed-off-by: default avatarMaíra Canal <mcanal@igalia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241118221948.1758130-1-christian.gmeiner@gmail.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit eb0e0eca0eab93f310c6c37b8564049366704691)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent ef372911
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -179,6 +179,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);
@@ -188,6 +189,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;