Commit a85fffe3 authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Daniel Vetter

drm/i915: Convert i915_gem_object_attach_phys() to ww locking, v2.

Simple adding of i915_gem_object_lock, we may start to pass ww to
get_pages() in the future, but that won't be the case here;
We override shmem's get_pages() handling by calling
i915_gem_object_get_pages_phys(), no ww is needed.

Changes since v1:
- Call shmem put pages directly, the callback would
  go down the phys free path.
Signed-off-by: default avatarMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20210323155059.628690-10-maarten.lankhorst@linux.intel.com
parent a6117097
...@@ -43,10 +43,11 @@ int i915_gem_object_pread_phys(struct drm_i915_gem_object *obj, ...@@ -43,10 +43,11 @@ int i915_gem_object_pread_phys(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_pread *args); const struct drm_i915_gem_pread *args);
int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align); int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align);
void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj,
struct sg_table *pages);
void i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj, void i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
struct sg_table *pages); struct sg_table *pages);
void i915_gem_flush_free_objects(struct drm_i915_private *i915); void i915_gem_flush_free_objects(struct drm_i915_private *i915);
struct sg_table * struct sg_table *
......
...@@ -201,7 +201,7 @@ static int i915_gem_object_shmem_to_phys(struct drm_i915_gem_object *obj) ...@@ -201,7 +201,7 @@ static int i915_gem_object_shmem_to_phys(struct drm_i915_gem_object *obj)
__i915_gem_object_pin_pages(obj); __i915_gem_object_pin_pages(obj);
if (!IS_ERR_OR_NULL(pages)) if (!IS_ERR_OR_NULL(pages))
i915_gem_shmem_ops.put_pages(obj, pages); i915_gem_object_put_pages_shmem(obj, pages);
i915_gem_object_release_memory_region(obj); i915_gem_object_release_memory_region(obj);
return 0; return 0;
...@@ -232,7 +232,13 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) ...@@ -232,7 +232,13 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)
if (err) if (err)
return err; return err;
mutex_lock_nested(&obj->mm.lock, I915_MM_GET_PAGES); err = i915_gem_object_lock_interruptible(obj, NULL);
if (err)
return err;
err = mutex_lock_interruptible_nested(&obj->mm.lock, I915_MM_GET_PAGES);
if (err)
goto err_unlock;
if (unlikely(!i915_gem_object_has_struct_page(obj))) if (unlikely(!i915_gem_object_has_struct_page(obj)))
goto out; goto out;
...@@ -263,6 +269,8 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align) ...@@ -263,6 +269,8 @@ int i915_gem_object_attach_phys(struct drm_i915_gem_object *obj, int align)
out: out:
mutex_unlock(&obj->mm.lock); mutex_unlock(&obj->mm.lock);
err_unlock:
i915_gem_object_unlock(obj);
return err; return err;
} }
......
...@@ -296,18 +296,12 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj, ...@@ -296,18 +296,12 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
__start_cpu_write(obj); __start_cpu_write(obj);
} }
static void void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj, struct sg_table *pages)
shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages)
{ {
struct sgt_iter sgt_iter; struct sgt_iter sgt_iter;
struct pagevec pvec; struct pagevec pvec;
struct page *page; struct page *page;
if (unlikely(!i915_gem_object_has_struct_page(obj))) {
i915_gem_object_put_pages_phys(obj, pages);
return;
}
__i915_gem_object_release_shmem(obj, pages, true); __i915_gem_object_release_shmem(obj, pages, true);
i915_gem_gtt_finish_pages(obj, pages); i915_gem_gtt_finish_pages(obj, pages);
...@@ -336,6 +330,15 @@ shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages) ...@@ -336,6 +330,15 @@ shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages)
kfree(pages); kfree(pages);
} }
static void
shmem_put_pages(struct drm_i915_gem_object *obj, struct sg_table *pages)
{
if (likely(i915_gem_object_has_struct_page(obj)))
i915_gem_object_put_pages_shmem(obj, pages);
else
i915_gem_object_put_pages_phys(obj, pages);
}
static int static int
shmem_pwrite(struct drm_i915_gem_object *obj, shmem_pwrite(struct drm_i915_gem_object *obj,
const struct drm_i915_gem_pwrite *arg) const struct drm_i915_gem_pwrite *arg)
......
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