Commit ab5ee576 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Clean up evict from list.

First the routine attempted to unlock a mutex it did not own along the
error path.

Secondly the routine should never be called on any list but the inactive
one, since we attempt to unbind those objects, so fix the calling semantics.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
parent 1c5d22f7
...@@ -50,8 +50,7 @@ static int i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, ...@@ -50,8 +50,7 @@ static int i915_gem_object_bind_to_gtt(struct drm_gem_object *obj,
unsigned alignment); unsigned alignment);
static void i915_gem_clear_fence_reg(struct drm_gem_object *obj); static void i915_gem_clear_fence_reg(struct drm_gem_object *obj);
static int i915_gem_evict_something(struct drm_device *dev, int min_size); static int i915_gem_evict_something(struct drm_device *dev, int min_size);
static int i915_gem_evict_from_list(struct drm_device *dev, static int i915_gem_evict_from_inactive_list(struct drm_device *dev);
struct list_head *head);
static int i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj, static int i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
struct drm_i915_gem_pwrite *args, struct drm_i915_gem_pwrite *args,
struct drm_file *file_priv); struct drm_file *file_priv);
...@@ -2095,7 +2094,7 @@ i915_gem_evict_everything(struct drm_device *dev) ...@@ -2095,7 +2094,7 @@ i915_gem_evict_everything(struct drm_device *dev)
if (ret) if (ret)
return ret; return ret;
ret = i915_gem_evict_from_list(dev, &dev_priv->mm.inactive_list); ret = i915_gem_evict_from_inactive_list(dev);
if (ret) if (ret)
return ret; return ret;
...@@ -2195,8 +2194,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size) ...@@ -2195,8 +2194,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size)
*/ */
if (!list_empty (&dev_priv->mm.inactive_list)) { if (!list_empty (&dev_priv->mm.inactive_list)) {
DRM_INFO("GTT full, evicting inactive buffers\n"); DRM_INFO("GTT full, evicting inactive buffers\n");
return i915_gem_evict_from_list(dev, return i915_gem_evict_from_inactive_list(dev);
&dev_priv->mm.inactive_list);
} else } else
return i915_gem_evict_everything(dev); return i915_gem_evict_everything(dev);
} }
...@@ -4155,36 +4153,27 @@ void i915_gem_free_object(struct drm_gem_object *obj) ...@@ -4155,36 +4153,27 @@ void i915_gem_free_object(struct drm_gem_object *obj)
kfree(obj->driver_private); kfree(obj->driver_private);
} }
/** Unbinds all objects that are on the given buffer list. */ /** Unbinds all inactive objects. */
static int static int
i915_gem_evict_from_list(struct drm_device *dev, struct list_head *head) i915_gem_evict_from_inactive_list(struct drm_device *dev)
{ {
struct drm_gem_object *obj; drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_i915_gem_object *obj_priv;
int ret;
while (!list_empty(head)) { while (!list_empty(&dev_priv->mm.inactive_list)) {
obj_priv = list_first_entry(head, struct drm_gem_object *obj;
struct drm_i915_gem_object, int ret;
list);
obj = obj_priv->obj;
if (obj_priv->pin_count != 0) { obj = list_first_entry(&dev_priv->mm.inactive_list,
DRM_ERROR("Pinned object in unbind list\n"); struct drm_i915_gem_object,
mutex_unlock(&dev->struct_mutex); list)->obj;
return -EINVAL;
}
ret = i915_gem_object_unbind(obj); ret = i915_gem_object_unbind(obj);
if (ret != 0) { if (ret != 0) {
DRM_ERROR("Error unbinding object in LeaveVT: %d\n", DRM_ERROR("Error unbinding object: %d\n", ret);
ret);
mutex_unlock(&dev->struct_mutex);
return ret; return ret;
} }
} }
return 0; return 0;
} }
...@@ -4301,7 +4290,7 @@ i915_gem_idle(struct drm_device *dev) ...@@ -4301,7 +4290,7 @@ i915_gem_idle(struct drm_device *dev)
/* Move all inactive buffers out of the GTT. */ /* Move all inactive buffers out of the GTT. */
ret = i915_gem_evict_from_list(dev, &dev_priv->mm.inactive_list); ret = i915_gem_evict_from_inactive_list(dev);
WARN_ON(!list_empty(&dev_priv->mm.inactive_list)); WARN_ON(!list_empty(&dev_priv->mm.inactive_list));
if (ret) { if (ret) {
mutex_unlock(&dev->struct_mutex); mutex_unlock(&dev->struct_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment