Skip to content

Commit fd995a3

Browse files
mlankhorstdanvet
authored andcommitted
drm/i915: Keep userpointer bindings if seqcount is unchanged, v2.
Instead of force unbinding and rebinding every time, we try to check if our notifier seqcount is still correct when pages are bound. This way we only rebind userptr when we need to, and prevent stalls. Changes since v1: - Missing mutex_unlock, reported by kbuild. Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Signed-off-by: Maarten Lankhorst <[email protected]> Signed-off-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent cf41a8f commit fd995a3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

drivers/gpu/drm/i915/gem/i915_gem_userptr.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,33 @@ int i915_gem_object_userptr_submit_init(struct drm_i915_gem_object *obj)
281281
if (ret)
282282
return ret;
283283

284-
/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */
285-
ret = i915_gem_object_userptr_unbind(obj, false);
284+
/* optimistically try to preserve current pages while unlocked */
285+
if (i915_gem_object_has_pages(obj) &&
286+
!mmu_interval_check_retry(&obj->userptr.notifier,
287+
obj->userptr.notifier_seq)) {
288+
spin_lock(&i915->mm.notifier_lock);
289+
if (obj->userptr.pvec &&
290+
!mmu_interval_read_retry(&obj->userptr.notifier,
291+
obj->userptr.notifier_seq)) {
292+
obj->userptr.page_ref++;
293+
294+
/* We can keep using the current binding, this is the fastpath */
295+
ret = 1;
296+
}
297+
spin_unlock(&i915->mm.notifier_lock);
298+
}
299+
300+
if (!ret) {
301+
/* Make sure userptr is unbound for next attempt, so we don't use stale pages. */
302+
ret = i915_gem_object_userptr_unbind(obj, false);
303+
}
286304
i915_gem_object_unlock(obj);
287-
if (ret)
305+
if (ret < 0)
288306
return ret;
289307

308+
if (ret > 0)
309+
return 0;
310+
290311
notifier_seq = mmu_interval_read_begin(&obj->userptr.notifier);
291312

292313
pvec = kvmalloc_array(num_pages, sizeof(struct page *), GFP_KERNEL);

0 commit comments

Comments
 (0)