Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2298039imm; Thu, 7 Jun 2018 08:22:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJs9GpbxWNAmnneNbYnv/TktWLlAmA/C/lQvaMYDySMDE8r9/cNr7PHsVDmErYTYKvjCqQb X-Received: by 2002:a63:6485:: with SMTP id y127-v6mr1960664pgb.126.1528384970945; Thu, 07 Jun 2018 08:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528384970; cv=none; d=google.com; s=arc-20160816; b=S5O9/3xX3aC22uThwV4+Tx1k2ts8sx42k4gGAfGM0JHHz9bvwWZ/Bsa1WCHSlnrF6P 7k+DT3Y6nfLV9BkKFLazGG2hYEgAeXWloFIj6PE2LVQGOpDAqdhGsTIIUj6cq58+r0fL GZuo/kBnQg19R0r3bza2vPA/2k6n4JqF2YocMr9N+OazkAq9d7srEe7Efi4RhfRl+2Sl +37/bM37QYJbrEIyNk1cLU9N8YuFxHQNC8fQ9+JwA/dHRY3KFwIEM+F1/cPpVGOznL7r tvBLkgKdbFS3HGj2vJlkPbFnIUdJ1orlRNP1ZwltCDkdrtb1M6F3n9YlZi8GzHUKIu42 8fjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=TX53s6NMinlE5pdVNpn8hHHNxoaIKsNsyvxwNZS24iQ=; b=p/WfEYodInYDFQicGcJbbfMcM3tp7TuFcV9Fnka0dYQ9hJ7rTkkdw1ZL7Ox7z+5SkE yIb66LlLaJO5ybj7+Z2Td+yveqqSXkYX3nQIy+BVqFZXQ4OTyVwHnP/F5JoheiH/rDhk JFTkE4iJZtNvPvxvGzPw+1T/KqXhBDY5sjHZuLlTd5Fy1mazajkctJ04Y5C8Kp8Rp7Dx O1PFMekInFDNCU7uxhLrlLZubXsIrgKUlvUVTo06ofOTr+h94HrOm7HgBJrpuiBmnyCg 59mDKMLZQ6YJL34titCZg1uAb8DaXSTirzvvrakQsehnpOsDxvFRo8qp1h0ZgkNLj5hR 4p8A== 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 r1-v6si21917773plb.172.2018.06.07.08.22.36; Thu, 07 Jun 2018 08:22:50 -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 S935621AbeFGO7I (ORCPT + 99 others); Thu, 7 Jun 2018 10:59:08 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41244 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935607AbeFGO7E (ORCPT ); Thu, 7 Jun 2018 10:59:04 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvba-0005Zn-IA; Thu, 07 Jun 2018 15:09:34 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb8-000354-E4; Thu, 07 Jun 2018 15:09:06 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Alex Deucher" , "Lyude Paul" , "Lukas Wunner" , "Dave Airlie" , "Ben Skeggs" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 255/410] drm: Allow determining if current task is output poll worker In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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 [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- 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 @@ -303,6 +303,26 @@ static void output_poll_execute(struct w } /** + * 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 @@ -176,5 +176,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); +bool drm_kms_helper_is_poll_worker(void); #endif