Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Allow determining if current task is output poll worker

Introduce a helper to determine if the current task is an output poll
worker.

This allows us to fix a long-standing deadlock in several DRM drivers
wherein the ->runtime_suspend callback waits for the output poll worker
to finish and the worker in turn calls a ->detect callback which waits
for runtime suspend to finish. The ->detect callback is invoked from
multiple call sites and waiting for runtime suspend to finish is the
correct thing to do except if it's executing in the context of the
worker.

v2: Expand kerneldoc to specifically mention deadlock between
output poll worker and autosuspend worker as use case. (Lyude)

Cc: Dave Airlie <airlied@redhat.com>
Cc: Ben Skeggs <bskeggs@redhat.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://patchwork.freedesktop.org/patch/msgid/3549ce32e7f1467102e70d3e9cbf70c46bfe108e.1518593424.git.lukas@wunner.de

+21
+20
drivers/gpu/drm/drm_probe_helper.c
··· 655 655 } 656 656 657 657 /** 658 + * drm_kms_helper_is_poll_worker - is %current task an output poll worker? 659 + * 660 + * Determine if %current task is an output poll worker. This can be used 661 + * to select distinct code paths for output polling versus other contexts. 662 + * 663 + * One use case is to avoid a deadlock between the output poll worker and 664 + * the autosuspend worker wherein the latter waits for polling to finish 665 + * upon calling drm_kms_helper_poll_disable(), while the former waits for 666 + * runtime suspend to finish upon calling pm_runtime_get_sync() in a 667 + * connector ->detect hook. 668 + */ 669 + bool drm_kms_helper_is_poll_worker(void) 670 + { 671 + struct work_struct *work = current_work(); 672 + 673 + return work && work->func == output_poll_execute; 674 + } 675 + EXPORT_SYMBOL(drm_kms_helper_is_poll_worker); 676 + 677 + /** 658 678 * drm_kms_helper_poll_disable - disable output polling 659 679 * @dev: drm_device 660 680 *
+1
include/drm/drm_crtc_helper.h
··· 77 77 78 78 void drm_kms_helper_poll_disable(struct drm_device *dev); 79 79 void drm_kms_helper_poll_enable(struct drm_device *dev); 80 + bool drm_kms_helper_is_poll_worker(void); 80 81 81 82 #endif