Received: by 10.213.65.68 with SMTP id h4csp436043imn; Tue, 13 Mar 2018 09:00:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELuGUpMZ7t6mialrtCm7e1KG8CHeNIimrGKCim7sSL7l3odqhqnAZtWbAMzNYCXdCIN7DEl4 X-Received: by 10.99.106.68 with SMTP id f65mr874561pgc.343.1520956844823; Tue, 13 Mar 2018 09:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520956844; cv=none; d=google.com; s=arc-20160816; b=mQXdXEgvgCSFpX/9S5niwtLHQvKOuWmHlBi3iG4mKney2aOC1yS4rsPanMqLXz0bIY 8qHaQ9Ya7MfC+ilwmxd4l/HqZNdZt0otR99SLzv8wMMRqpCvfgN1oWKUFl0rzTA367MW XKnY1kB6WrOBlrpXIx9SeHKOJmNQbbSUdUidsBANIztNegWk3nbO4LpcY2TeGMQ47Lfg zHbRayY6lXqfavpfAek389g5HBhawhelr3CBLHniOfvxLV3NPSN+CQEH4ydKMbzmkdHi ozT6fV9j2gdVxqmGBFNaXE/SrSQnc4Kh1zanaYcZ6dqlArrxYsKDX73nqmU+FEZCc1lg nh7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Ph4cQRAlhHymM1mK4vbzQm7c22AA0G/W3pWGIW+QaR4=; b=q4ZJL0tZEQS/R/MWTYXtk/6t92FFa0S0hDidIsNN/bwsgUbGQxAoLlYZJxZ8eGskBx zDZofg98BXLH/oNuTRDbPRYekm7Px2NjMZFyqXTiBl2E0LFdLM81MrfJFgvPdxuybJtR lamTN4tkuBPDR+t4Jj1+b39tRqp5VZAov66Ln6NTPyJFj1fFBgRRDoUWVdia8i8XF3kj Knr8RHPcmpEn+DDppB0YIbGGvj0qi+VogJ2ghsRHmXKE3xsWlYlkcmq1nuiGuTqzMO0W WYpApDUP73CDr7D3RzY6o8LClzXXDOkQKksH3P4c1Rb0+QCzm1CQhPXlhY7b77QkctAD 5Clw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1-v6si289465pls.673.2018.03.13.09.00.30; Tue, 13 Mar 2018 09:00:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934483AbeCMPh6 (ORCPT + 99 others); Tue, 13 Mar 2018 11:37:58 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34148 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934468AbeCMPhy (ORCPT ); Tue, 13 Mar 2018 11:37:54 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C11CB125F; Tue, 13 Mar 2018 15:37:53 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Airlie , Ben Skeggs , Alex Deucher , Lyude Paul , Lukas Wunner Subject: [PATCH 4.14 062/140] drm: Allow determining if current task is output poll worker Date: Tue, 13 Mar 2018 16:24:25 +0100 Message-Id: <20180313152502.407258743@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit 25c058ccaf2ebbc3e250ec1e199e161f91fe27d4 upstream. 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 Cc: Ben Skeggs Cc: Alex Deucher Reviewed-by: Lyude Paul Signed-off-by: Lukas Wunner Link: https://patchwork.freedesktop.org/patch/msgid/3549ce32e7f1467102e70d3e9cbf70c46bfe108e.1518593424.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_probe_helper.c | 20 ++++++++++++++++++++ include/drm/drm_crtc_helper.h | 1 + 2 files changed, 21 insertions(+) --- a/drivers/gpu/drm/drm_probe_helper.c +++ b/drivers/gpu/drm/drm_probe_helper.c @@ -672,6 +672,26 @@ out: } /** + * drm_kms_helper_is_poll_worker - is %current task an output poll worker? + * + * Determine if %current task is an output poll worker. This can be used + * to select distinct code paths for output polling versus other contexts. + * + * One use case is to avoid a deadlock between the output poll worker and + * the autosuspend worker wherein the latter waits for polling to finish + * upon calling drm_kms_helper_poll_disable(), while the former waits for + * runtime suspend to finish upon calling pm_runtime_get_sync() in a + * connector ->detect hook. + */ +bool drm_kms_helper_is_poll_worker(void) +{ + struct work_struct *work = current_work(); + + return work && work->func == output_poll_execute; +} +EXPORT_SYMBOL(drm_kms_helper_is_poll_worker); + +/** * drm_kms_helper_poll_disable - disable output polling * @dev: drm_device * --- a/include/drm/drm_crtc_helper.h +++ b/include/drm/drm_crtc_helper.h @@ -77,5 +77,6 @@ void drm_kms_helper_hotplug_event(struct void drm_kms_helper_poll_disable(struct drm_device *dev); void drm_kms_helper_poll_enable(struct drm_device *dev); +bool drm_kms_helper_is_poll_worker(void); #endif