Received: by 10.223.185.116 with SMTP id b49csp2454690wrg; Mon, 12 Feb 2018 09:47:24 -0800 (PST) X-Google-Smtp-Source: AH8x227k0nDGEnH8gloFfCfK/76Gk6VqK0+ZksGrmOX3kjTrlQ1X0vs82s8FS6V8cbqMD2YM0Nuq X-Received: by 10.98.172.21 with SMTP id v21mr12531388pfe.66.1518457644424; Mon, 12 Feb 2018 09:47:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518457644; cv=none; d=google.com; s=arc-20160816; b=b2k9h9OegQkdsUZc/5JdUSPZxAVcoeMg0wNOu+csVeE9M1hxvDoT1AXtg8XMysLiHg NxeGZCMDiC/4/TiRQwI6XSlONZMequZp+/Wa13UqnRJjZrb0Lqy1x+MtQZk9CJgrAENH WJ15Y+5FX30RgfQsoD23joHLjDYrLe7wqSA8HFEqsB04rVn89f90EXo2Erz0tBxWcgSE eUVe1arT7cVUV1Q6adblUc9ANUkJ40KrympbkxGFe7/yG/ekrS/RXfCUC4wLnE0Z5NLp P8NYtNq42Pm5HK2i/Lf9f5mXGABZV7dh491LpFWpS0iIj/ctbThEy7YEYUgeeJHB7ltE DRag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=0xDRCtIRA/h3jEyQaqUDPEehLKJnoWf38ozImIwtufo=; b=ti5/wjuJKRWpC5yqTDw0ZsaHEBXcuZPogUN7StdlAPxGdevfQ2yk9X5Lr08dEGUQ8s nRdfR/o3iVG452kxIMOqOGmH6pOs45ENJJRLgs/GQScmFCsCKZANYyN5kpjYoO0DS9Q6 a5JahfoIxV7Cb5fl3Dp9gaEvA1nbgEbSlo9ayPLT/+NUlWFQTDI6n0TPaYhYfupijY6F HMPyRwrdb7yorKyJx7LymKsC7bki7risFrjBqPoKppLl7PRUrtA3Bj3LLGm9E2lQDOXc XBvUobnkEa7wTFb7RdSP0MC6IVLo5gdZJghbiJ2X/HTzx4Wq/DGR+CAnhwrYwsElAvZ9 MpUw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 23si6557657pfm.48.2018.02.12.09.47.09; Mon, 12 Feb 2018 09:47:24 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932250AbeBLRqQ (ORCPT + 99 others); Mon, 12 Feb 2018 12:46:16 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:34261 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753643AbeBLRqO (ORCPT ); Mon, 12 Feb 2018 12:46:14 -0500 Received: by mail-qk0-f193.google.com with SMTP id o7so4936580qkc.1 for ; Mon, 12 Feb 2018 09:46:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:organization:mime-version:content-transfer-encoding; bh=0xDRCtIRA/h3jEyQaqUDPEehLKJnoWf38ozImIwtufo=; b=kutzCTDjbstJca7I4F7jqqIO6TUp82/9SHvm+prWM4nkxN9pSehcA4pR4ukNpmOBPI 1C0VOYIYOhiobDxHn7oukiVMsryRlN2+JSJO94QMoGSC1hPatsU69z8vQWZRA417PcB+ wNV80TSE3HJBBbW0YG3seRgKaWDN9N4HUEhwwXbRnuN3CXIOGJtP0I1E7aon3UP62AnP MbSvGVlDi+rUzCPkBxNB3toON3nRhBRgjGgT3VR5z9LRAqqQwAquD+WPNgMaEfxX++Fr fNGCWo6SWF/6S2w4Pv3jXLytH94OWvua/9o/bni2U7CUasy80PB5pS7OV0wXBg4hJVJt 7dkg== X-Gm-Message-State: APf1xPC0Ze6BlLWSY54s0btiQvQSSXIUmkwbtABffySRIH+L59UqrhBI DuH6ZFPHY7XzhpLWGTA34lWzXA== X-Received: by 10.55.33.129 with SMTP id f1mr19026211qki.158.1518457573989; Mon, 12 Feb 2018 09:46:13 -0800 (PST) Received: from dhcp-10-20-1-30.bss.redhat.com ([144.121.20.162]) by smtp.gmail.com with ESMTPSA id v185sm6125856qkd.44.2018.02.12.09.46.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Feb 2018 09:46:13 -0800 (PST) Message-ID: <1518457571.5319.7.camel@redhat.com> Subject: Re: [PATCH 2/5] drm: Allow determining if current task is output poll worker From: Lyude Paul To: Lukas Wunner , Tejun Heo , Lai Jiangshan , Alex Deucher , Dave Airlie , Ben Skeggs Cc: dri-devel@lists.freedesktop.org, Peter Wu , nouveau@lists.freedesktop.org, Hans de Goede , Pierre Moreau , linux-kernel@vger.kernel.org, Ismo Toijala , intel-gfx@lists.freedesktop.org, Liviu Dudau , Archit Taneja Date: Mon, 12 Feb 2018 12:46:11 -0500 In-Reply-To: <7831d4f21dde8cd0b1659e393854598995dfb249.1518338788.git.lukas@wunner.de> References: <7831d4f21dde8cd0b1659e393854598995dfb249.1518338788.git.lukas@wunner.de> Organization: Red Hat Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.4 (3.26.4-1.fc27) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2018-02-11 at 10:38 +0100, Lukas Wunner wrote: > 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. > > Cc: Dave Airlie > Cc: Ben Skeggs > Cc: Alex Deucher > Signed-off-by: Lukas Wunner > --- > drivers/gpu/drm/drm_probe_helper.c | 14 ++++++++++++++ > include/drm/drm_crtc_helper.h | 1 + > 2 files changed, 15 insertions(+) > > diff --git a/drivers/gpu/drm/drm_probe_helper.c > b/drivers/gpu/drm/drm_probe_helper.c > index 555fbe54d6e2..019881d15ce1 100644 > --- a/drivers/gpu/drm/drm_probe_helper.c > +++ b/drivers/gpu/drm/drm_probe_helper.c > @@ -653,6 +653,20 @@ static void output_poll_execute(struct work_struct > *work) > schedule_delayed_work(delayed_work, > DRM_OUTPUT_POLL_PERIOD); > } > > +/** > + * 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. > + */ For this, it would be worth explicitly noting in the comments herethat this should be called by DRM drivers in order to prevent racing with hotplug polling workers, so that new drivers in the future can avoid implementing this race condition in their driver. > +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 > diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h > index 76e237bd989b..6914633037a5 100644 > --- 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 drm_device *dev); > > 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 -- Cheers, Lyude Paul