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

drm/i915: Handle ww locking in init_status_page

Try to pin to ggtt first, and use a full ww loop to handle
eviction correctly.
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-21-maarten.lankhorst@linux.intel.com
parent 83472bb0
...@@ -619,6 +619,7 @@ static void cleanup_status_page(struct intel_engine_cs *engine) ...@@ -619,6 +619,7 @@ static void cleanup_status_page(struct intel_engine_cs *engine)
} }
static int pin_ggtt_status_page(struct intel_engine_cs *engine, static int pin_ggtt_status_page(struct intel_engine_cs *engine,
struct i915_gem_ww_ctx *ww,
struct i915_vma *vma) struct i915_vma *vma)
{ {
unsigned int flags; unsigned int flags;
...@@ -639,12 +640,13 @@ static int pin_ggtt_status_page(struct intel_engine_cs *engine, ...@@ -639,12 +640,13 @@ static int pin_ggtt_status_page(struct intel_engine_cs *engine,
else else
flags = PIN_HIGH; flags = PIN_HIGH;
return i915_ggtt_pin(vma, NULL, 0, flags); return i915_ggtt_pin(vma, ww, 0, flags);
} }
static int init_status_page(struct intel_engine_cs *engine) static int init_status_page(struct intel_engine_cs *engine)
{ {
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
struct i915_gem_ww_ctx ww;
struct i915_vma *vma; struct i915_vma *vma;
void *vaddr; void *vaddr;
int ret; int ret;
...@@ -670,30 +672,39 @@ static int init_status_page(struct intel_engine_cs *engine) ...@@ -670,30 +672,39 @@ static int init_status_page(struct intel_engine_cs *engine)
vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL); vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
if (IS_ERR(vma)) { if (IS_ERR(vma)) {
ret = PTR_ERR(vma); ret = PTR_ERR(vma);
goto err; goto err_put;
} }
i915_gem_ww_ctx_init(&ww, true);
retry:
ret = i915_gem_object_lock(obj, &ww);
if (!ret && !HWS_NEEDS_PHYSICAL(engine->i915))
ret = pin_ggtt_status_page(engine, &ww, vma);
if (ret)
goto err;
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
if (IS_ERR(vaddr)) { if (IS_ERR(vaddr)) {
ret = PTR_ERR(vaddr); ret = PTR_ERR(vaddr);
goto err; goto err_unpin;
} }
engine->status_page.addr = memset(vaddr, 0, PAGE_SIZE); engine->status_page.addr = memset(vaddr, 0, PAGE_SIZE);
engine->status_page.vma = vma; engine->status_page.vma = vma;
if (!HWS_NEEDS_PHYSICAL(engine->i915)) {
ret = pin_ggtt_status_page(engine, vma);
if (ret)
goto err_unpin;
}
return 0;
err_unpin: err_unpin:
i915_gem_object_unpin_map(obj); if (ret)
i915_vma_unpin(vma);
err: err:
i915_gem_object_put(obj); if (ret == -EDEADLK) {
ret = i915_gem_ww_ctx_backoff(&ww);
if (!ret)
goto retry;
}
i915_gem_ww_ctx_fini(&ww);
err_put:
if (ret)
i915_gem_object_put(obj);
return ret; return ret;
} }
......
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