Received: by 10.213.65.68 with SMTP id h4csp532345imn; Fri, 16 Mar 2018 10:36:09 -0700 (PDT) X-Google-Smtp-Source: AG47ELtWYW0OjJAxTV/YFP1rNaRYWVPyqACM04zSijia15kzrWgOTXdJAZkmrdWsjeWXPFbXfoMp X-Received: by 10.98.68.154 with SMTP id m26mr2185282pfi.171.1521221768957; Fri, 16 Mar 2018 10:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521221768; cv=none; d=google.com; s=arc-20160816; b=UwjWmU8NVimqCIA117CFKyM45IQ8j6aWCtJyS1bAw40kiM3sdGqIGBng1j/Hd3f12Q Qk/eDu6ckuc/uNw13YTv5op7Vd02wmfKK+vdevP2V7Mf6Mkvh6m6ECCQ++DGEtAeKBzP t2tKmaonTxZgwo8tHBwtsR6/qJWx3WbP10b5ze7QuLZguJIngMhU7oZDVfqt9CZkGVlh T4W8koTZBCLkzpr5N/5LS2tmYlLgF4OJu6hzViqwE8qMoBuWQRuic3i28HO1KhPgyWY8 JSA5oc5hDI1uPk6oZMd9ON9zpjf4u8oSuIAmQW+Xo6tFWZ4EEc9YN7huhtdUR3/HBdA0 ZFLw== 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=kkVYLl3ybmgwHvzrGsYeGhrKAJ/7oQXiTCVgMLYtNtk=; b=FKZsgBnvcoH83DBkRTrMLr8GcZF2X4pZno/jMI0Q4WWGnbpIwX+8ozp93IzKCbzvLi 3KlNxVwVbXP43rmJChQ6r+AIJGWJEPpiY2N3NNz2Wv+sKrVkI+fLEukdaRK1a3L/8LET hXZg8NVT5oezVyI/AvMA+V24bGQWYb7DbwZKnB7UAvizODlMmM/Z4cOcPS27ejGkrMg7 eRt6r0cSeiggpj+kSpQD1s9U8+PnPub5BsQ7DaPrGhspYjP1ws04KXlpfLuDMGtIuZqH DUgohm07K/+agRTqFsdR5ZZqdmPZ4f0L+iCa/AbcjRNHJSeIAGqO+Unxv1yjd6QKdaDZ 549g== 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 k80si3039690pfh.137.2018.03.16.10.35.54; Fri, 16 Mar 2018 10:36:08 -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 S932641AbeCPRek (ORCPT + 99 others); Fri, 16 Mar 2018 13:34:40 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34050 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754188AbeCPP1C (ORCPT ); Fri, 16 Mar 2018 11:27:02 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0CDB51239; Fri, 16 Mar 2018 15:27:01 +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.4 06/63] drm: Allow determining if current task is output poll worker Date: Fri, 16 Mar 2018 16:22:38 +0100 Message-Id: <20180316152300.761879094@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152259.964532775@linuxfoundation.org> References: <20180316152259.964532775@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.4-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 @@ -412,6 +412,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 @@ -241,5 +241,6 @@ extern void drm_kms_helper_hotplug_event extern void drm_kms_helper_poll_disable(struct drm_device *dev); extern void drm_kms_helper_poll_enable(struct drm_device *dev); extern void drm_kms_helper_poll_enable_locked(struct drm_device *dev); +extern bool drm_kms_helper_is_poll_worker(void); #endif