Skip to content

Commit e0e6b41

Browse files
jkrzyszt-inteljnikula
authored andcommitted
drm/i915/active: Fix misuse of non-idle barriers as fence trackers
Users reported oopses on list corruptions when using i915 perf with a number of concurrently running graphics applications. Root cause analysis pointed at an issue in barrier processing code -- a race among perf open / close replacing active barriers with perf requests on kernel context and concurrent barrier preallocate / acquire operations performed during user context first pin / last unpin. When adding a request to a composite tracker, we try to reuse an existing fence tracker, already allocated and registered with that composite. The tracker we obtain may already track another fence, may be an idle barrier, or an active barrier. If the tracker we get occurs a non-idle barrier then we try to delete that barrier from a list of barrier tasks it belongs to. However, while doing that we don't respect return value from a function that performs the barrier deletion. Should the deletion ever fail, we would end up reusing the tracker still registered as a barrier task. Since the same structure field is reused with both fence callback lists and barrier tasks list, list corruptions would likely occur. Barriers are now deleted from a barrier tasks list by temporarily removing the list content, traversing that content with skip over the node to be deleted, then populating the list back with the modified content. Should that intentionally racy concurrent deletion attempts be not serialized, one or more of those may fail because of the list being temporary empty. Related code that ignores the results of barrier deletion was initially introduced in v5.4 by commit d8af05f ("drm/i915: Allow sharing the idle-barrier from other kernel requests"). However, all users of the barrier deletion routine were apparently serialized at that time, then the issue didn't exhibit itself. Results of git bisect with help of a newly developed igt@gem_barrier_race@remote-request IGT test indicate that list corruptions might start to appear after commit 3117701 ("drm/i915/gt: Schedule request retirement when timeline idles"), introduced in v5.5. Respect results of barrier deletion attempts -- mark the barrier as idle only if successfully deleted from the list. Then, before proceeding with setting our fence as the one currently tracked, make sure that the tracker we've got is not a non-idle barrier. If that check fails then don't use that tracker but go back and try to acquire a new, usable one. v3: use unlikely() to document what outcome we expect (Andi), - fix bad grammar in commit description. v2: no code changes, - blame commit 3117701 ("drm/i915/gt: Schedule request retirement when timeline idles"), v5.5, not commit d8af05f ("drm/i915: Allow sharing the idle-barrier from other kernel requests"), v5.4, - reword commit description. Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/6333 Fixes: 3117701 ("drm/i915/gt: Schedule request retirement when timeline idles") Cc: Chris Wilson <[email protected]> Cc: [email protected] # v5.5 Cc: Andi Shyti <[email protected]> Signed-off-by: Janusz Krzysztofik <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andi Shyti <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] (cherry picked from commit 5060060) Signed-off-by: Jani Nikula <[email protected]>
1 parent 193c419 commit e0e6b41

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

drivers/gpu/drm/i915/i915_active.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,12 @@ replace_barrier(struct i915_active *ref, struct i915_active_fence *active)
422422
* we can use it to substitute for the pending idle-barrer
423423
* request that we want to emit on the kernel_context.
424424
*/
425-
__active_del_barrier(ref, node_from_active(active));
426-
return true;
425+
return __active_del_barrier(ref, node_from_active(active));
427426
}
428427

429428
int i915_active_add_request(struct i915_active *ref, struct i915_request *rq)
430429
{
430+
u64 idx = i915_request_timeline(rq)->fence_context;
431431
struct dma_fence *fence = &rq->fence;
432432
struct i915_active_fence *active;
433433
int err;
@@ -437,16 +437,19 @@ int i915_active_add_request(struct i915_active *ref, struct i915_request *rq)
437437
if (err)
438438
return err;
439439

440-
active = active_instance(ref, i915_request_timeline(rq)->fence_context);
441-
if (!active) {
442-
err = -ENOMEM;
443-
goto out;
444-
}
440+
do {
441+
active = active_instance(ref, idx);
442+
if (!active) {
443+
err = -ENOMEM;
444+
goto out;
445+
}
446+
447+
if (replace_barrier(ref, active)) {
448+
RCU_INIT_POINTER(active->fence, NULL);
449+
atomic_dec(&ref->count);
450+
}
451+
} while (unlikely(is_barrier(active)));
445452

446-
if (replace_barrier(ref, active)) {
447-
RCU_INIT_POINTER(active->fence, NULL);
448-
atomic_dec(&ref->count);
449-
}
450453
if (!__i915_active_fence_set(active, fence))
451454
__i915_active_acquire(ref);
452455

0 commit comments

Comments
 (0)