drm/scheduler: Fix lockup in drm_sched_entity_kill()
authorDmitry Osipenko <dmitry.osipenko@collabora.com>
Wed, 23 Nov 2022 00:13:03 +0000 (03:13 +0300)
committerDmitry Osipenko <dmitry.osipenko@collabora.com>
Wed, 23 Nov 2022 13:16:08 +0000 (16:16 +0300)
commit9f1ecfc5dcb47a7ca37be47b0eaca0f37f1ae93d
tree73672c48c0a6c50ddbc3320fc993157890dadfcf
parent834c23e4f798dcdc8af251b3c428ceef94741991
drm/scheduler: Fix lockup in drm_sched_entity_kill()

The drm_sched_entity_kill() is invoked twice by drm_sched_entity_destroy()
while userspace process is exiting or being killed. First time it's invoked
when sched entity is flushed and second time when entity is released. This
causes a lockup within wait_for_completion(entity_idle) due to how completion
API works.

Calling wait_for_completion() more times than complete() was invoked is a
error condition that causes lockup because completion internally uses
counter for complete/wait calls. The complete_all() must be used instead
in such cases.

This patch fixes lockup of Panfrost driver that is reproducible by killing
any application in a middle of 3d drawing operation.

Fixes: 2fdb8a8f07c2 ("drm/scheduler: rework entity flush, kill and fini")
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221123001303.533968-1-dmitry.osipenko@collabora.com
drivers/gpu/drm/scheduler/sched_entity.c
drivers/gpu/drm/scheduler/sched_main.c