summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/msm/msm_gem.c
diff options
context:
space:
mode:
authorRob Clark <robdclark@chromium.org>2020-11-16 20:48:49 +0300
committerRob Clark <robdclark@chromium.org>2020-11-21 20:50:23 +0300
commitab5c54cb88350e224632e5b0fcd7f86ece06beb9 (patch)
tree01cc4f34f02dd7815eb6cdb96ead692b569b793a /drivers/gpu/drm/msm/msm_gem.c
parente8c765811b1064c200829eacf237ac8c25e79cd0 (diff)
downloadlinux-ab5c54cb88350e224632e5b0fcd7f86ece06beb9.tar.xz
drm/msm: Protect obj->active_count under obj lock
Previously we only held obj lock in the _active_get() path, and relied on atomic_dec_return() to not be racy in the _active_put() path where obj lock was not held. But this is a false sense of security. Unlike obj lifetime refcnt, where you do not expect to *increase* the refcnt after the last put (which would mean that something has gone horribly wrong with the object liveness reference counting), the active_count can increase again from zero. Racing _active_put()s and _active_get()s could leave the obj on the wrong mm list. But in the retire path, immediately after the _active_put(), the _unpin_iova() would acquire obj lock. So just move the locking earlier and rely on that to protect obj->active_count. Fixes: c5c1643cef7a ("drm/msm: Drop struct_mutex from the retire path") Signed-off-by: Rob Clark <robdclark@chromium.org>
Diffstat (limited to 'drivers/gpu/drm/msm/msm_gem.c')
-rw-r--r--drivers/gpu/drm/msm/msm_gem.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 0319e0ad07f5..562db92aa631 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -769,7 +769,7 @@ void msm_gem_active_get(struct drm_gem_object *obj, struct msm_gpu *gpu)
WARN_ON(!msm_gem_is_locked(obj));
WARN_ON(msm_obj->madv != MSM_MADV_WILLNEED);
- if (!atomic_fetch_inc(&msm_obj->active_count)) {
+ if (msm_obj->active_count++ == 0) {
mutex_lock(&priv->mm_lock);
list_del_init(&msm_obj->mm_list);
list_add_tail(&msm_obj->mm_list, &gpu->active_list);
@@ -783,8 +783,9 @@ void msm_gem_active_put(struct drm_gem_object *obj)
struct msm_drm_private *priv = obj->dev->dev_private;
might_sleep();
+ WARN_ON(!msm_gem_is_locked(obj));
- if (!atomic_dec_return(&msm_obj->active_count)) {
+ if (--msm_obj->active_count == 0) {
mutex_lock(&priv->mm_lock);
list_del_init(&msm_obj->mm_list);
list_add_tail(&msm_obj->mm_list, &priv->inactive_list);
@@ -935,15 +936,15 @@ void msm_gem_free_object(struct drm_gem_object *obj)
struct drm_device *dev = obj->dev;
struct msm_drm_private *priv = dev->dev_private;
- /* object should not be on active list: */
- WARN_ON(is_active(msm_obj));
-
mutex_lock(&priv->mm_lock);
list_del(&msm_obj->mm_list);
mutex_unlock(&priv->mm_lock);
msm_gem_lock(obj);
+ /* object should not be on active list: */
+ WARN_ON(is_active(msm_obj));
+
put_iova(obj);
if (obj->import_attach) {