Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3765894imm; Sat, 21 Jul 2018 02:42:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdga6+bG8050DMMJk3lAf+k8SSdwK7RVBCIiGaoYZzc+d23OWnK3I4IOOSFoHnpm1aQzHM+ X-Received: by 2002:a17:902:9f81:: with SMTP id g1-v6mr5227973plq.304.1532166156960; Sat, 21 Jul 2018 02:42:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532166156; cv=none; d=google.com; s=arc-20160816; b=L+bOwEnbQ/fdEi7nMktGei8AnloTxpL+u3TaAvSfNDM6XTU4dy7q8fMSeWTg9DXNYt gvyzWWbQ4Cn9WJJreRvcQTOYirMp725Njhcw7sbEf1Pm2DvJ61X3H/w9AR5MmAs3inYF pYNLl7yKS/vqK0LaxQ7B64F3ieX5RRraUYL51YIONzCrEfbpDLMGXTGGEsfmArYt7VWr ibE91NzbOYPVteG1RFRPc1u31GugFN7W2v3UeMwvbPqDdWVv5FND0Dc7MUrW+8xLzPtZ sF3I5ytpXKYVyi7vNZm1oUrrAWOcyVQ1nP2Thbmw/ErZrTfRp841hxeP0SvikIDnbe0G XtEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=thyZ+BuEq1+yXrrmAFI2AzdAwRoaU6+L5CKoZG8de4s=; b=SY8XQnGe7UWJLv0pDodI3tYlGlHH2U5Pb/Q5GEkH48C4T3k4+/MPfwZUNivmgwwuUt 5MZer1aC/iYipwcMZf3WZ1qUiH87eKb4As2/Bu8a+Y4U3PsodDqcRTUmq6pXhvwxJ7oi Mwd5H6IEHoXbK/4KkPNcTMZzo9Gl0MWhQEKFENbvA3+yk94GJkw3vp83vkimXsTsVVuB GYfewTgBPEFIzU6TCoI0qTD13BA0qIBYhDh9pMWZImdAIxACiEwZvQqLBtdJPxcfTFmT 88014vxQI4HqX45ngleFu6VD/jw1KNObapRTBto9tiH351Y5gqgduAFv2CJnrVqwItyM TRrA== 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 a5-v6si4178918pll.412.2018.07.21.02.41.58; Sat, 21 Jul 2018 02:42:36 -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 S1727542AbeGUKcG (ORCPT + 99 others); Sat, 21 Jul 2018 06:32:06 -0400 Received: from bmailout3.hostsharing.net ([176.9.242.62]:40683 "EHLO bmailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727140AbeGUKcG (ORCPT ); Sat, 21 Jul 2018 06:32:06 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id 7B6F6102C4C3D; Sat, 21 Jul 2018 11:39:56 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 0D9D46F3AA; Sat, 21 Jul 2018 11:39:55 +0200 (CEST) Date: Sat, 21 Jul 2018 11:39:55 +0200 From: Lukas Wunner To: Lyude Paul Cc: nouveau@lists.freedesktop.org, Gustavo Padovan , Maarten Lankhorst , Sean Paul , David Airlie , Ben Skeggs , Daniel Vetter , Ville =?iso-8859-1?Q?Syrj=E4l=E4?= , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] drm/fb_helper: Add drm_fb_helper_output_poll_changed_with_rpm() Message-ID: <20180721093955.GA32572@wunner.de> References: <20180718205645.25924-1-lyude@redhat.com> <20180718205645.25924-2-lyude@redhat.com> <20180719074926.GA14303@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 19, 2018 at 08:08:15PM -0400, Lyude Paul wrote: > On Thu, 2018-07-19 at 09:49 +0200, Lukas Wunner wrote: > > On Wed, Jul 18, 2018 at 04:56:39PM -0400, Lyude Paul wrote: > > > When DP MST hubs get confused, they can occasionally stop responding for > > > a good bit of time up until the point where the DRM driver manages to > > > do the right DPCD accesses to get it to start responding again. In a > > > worst case scenario however, this process can take upwards of 10+ > > > seconds. > > > > > > Currently we use the default output_poll_changed handler > > > drm_fb_helper_output_poll_changed() to handle output polling, which > > > doesn't happen to grab any power references on the device when polling. > > > If we're unlucky enough to have a hub (such as Lenovo's infamous laptop > > > docks for the P5x/P7x series) that's easily startled and confused, this > > > can lead to a pretty nasty deadlock situation that looks like this: > > > > > > - Hotplug event from hub happens, we enter > > > drm_fb_helper_output_poll_changed() and start communicating with the > > > hub > > > - While we're in drm_fb_helper_output_poll_changed() and attempting to > > > communicate with the hub, we end up confusing it and cause it to stop > > > responding for at least 10 seconds > > > - After 5 seconds of being in drm_fb_helper_output_poll_changed(), the > > > pm core attempts to put the GPU into autosuspend, which ends up > > > calling drm_kms_helper_poll_disable() > > > - While the runtime PM core is waiting in drm_kms_helper_poll_disable() > > > for the output poll to finish, we end up finally detecting an MST > > > display > > > - We notice the new display and tries to enable it, which triggers > > > an atomic commit which triggers a call to pm_runtime_get_sync() > > > - the output poll thread deadlocks the pm core waiting for the pm core > > > to finish the autosuspend request while the pm core waits for the > > > output poll thread to finish > > > > The correct fix is to call pm_runtime_get_sync() *conditionally* in > > the atomic commit which enables the display, using the same conditional > > as d61a5c106351, i.e. if (!drm_kms_helper_is_poll_worker()). First of all, I was mistaken when I wrote above that a check for !drm_kms_helper_is_poll_worker() would solve the problem. Sorry! It doesn't because the call to pm_runtime_get_sync() is not happening in output_poll_execute() but in drm_dp_mst_link_probe_work(). Looking once more at the three stack traces you've provided, we've got: - output_poll_execute() stuck waiting for fb_helper->lock which is held by drm_dp_mst_link_probe_work() - rpm_suspend() stuck waiting for output_poll_execute() to finish - drm_dp_mst_link_probe_work() stuck waiting in rpm_resume() For the moment we can ignore the first task, i.e. output_poll_execute(), and focus on the latter two. As said I'm unfamiliar with MST but browsing through drm_dp_mst_topology.c I notice that drm_dp_mst_link_probe_work() is the ->work element in drm_dp_mst_topology_mgr() and is queued on HPD. I further notice that the work item is flushed on ->runtime_suspend: nouveau_pmops_runtime_suspend() nouveau_do_suspend() nouveau_display_suspend() nouveau_display_fini() disp->fini() == nv50_display_fini() nv50_mstm_fini() drm_dp_mst_topology_mgr_suspend() flush_work(&mgr->work); And before the work item is flushed, the HPD source is quiesced. So it looks like drm_dp_mst_link_probe_work() can only ever run while the GPU is runtime resumed, it never runs while the GPU is runtime suspended. This means that you don't have to acquire any runtime PM references in or below drm_dp_mst_link_probe_work(). Au contraire, you must not acquire any because it will deadlock while the GPU is runtime suspending. If there are functions which are called from drm_dp_mst_link_probe_work() as well as from other contexts, and those other contexts need a runtime PM ref to be acquired, you need to acquire the runtime PM ref conditionally on not being drm_dp_mst_link_probe_work() (using the current_work() technique). Alternatively, move acquisition of the runtime PM ref further up in the call chain to those other contexts. > Anyway-that's why your explanation doesn't make sense: the deadlock is > happening because we're calling pm_runtime_get_sync(). If we were to > make that call conditional (e.g. drm_kms_helper_is_poll_worker()), > all that would mean is that we wouldn't grab any runtime power reference > and the GPU would immediately suspend once the atomic commit finished, > as the suspend request in Thread 5 would finally get unblocked and thus > ----suspend. Right, that seems to be a bug nouveau_pmops_runtime_suspend(): If a display is plugged in while the GPU is about to runtime suspend, the display may be lit up by output_poll_execute() but the GPU will then nevertheless be powered off. I guess after calling drm_kms_helper_poll_disable() we should re-check if a crtc has been activated. This should have bumped the runtime PM refcount and have_disp_power_ref should be true. In that case, the nouveau_pmops_runtime_suspend() should return -EBUSY to abort the runtime_suspend. The same check seems necessary after flushing drm_dp_mst_link_probe_work(): If the work item lit up a new display, all previous suspend steps need to be unwound and -EBUSY needs to be returned to the PM core. Communication with an MST hub exceeding the autosuspend timeout is just one scenario where this bug manifests itself. BTW, drm_kms_helper_poll_disable() seems to be called twice in the runtime_suspend code path, once in nouveau_pmops_runtime_suspend() and a second time in nouveau_display_fini(). A stupid question, I notice that nv50_display_fini() calls nv50_mstm_fini() only if encoder_type != DRM_MODE_ENCODER_DPMST. Why isn't that == ? Thanks, Lukas