Received: by 10.213.65.68 with SMTP id h4csp524621imn; Fri, 16 Mar 2018 10:21:53 -0700 (PDT) X-Google-Smtp-Source: AG47ELsFGwlnqJbpkHCEouo4/kQA8lo1eq5j79c4/qWY5onqFmwfLyZ5gBYS2J6EKQGvoQrRmPAt X-Received: by 10.98.26.85 with SMTP id a82mr2213912pfa.37.1521220913039; Fri, 16 Mar 2018 10:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521220912; cv=none; d=google.com; s=arc-20160816; b=eNEslrDpIn5lwftC96rBee7X3HmX/NomxKkmLn35KCFDnzvSoOu1BpKAl5lRBe5bUg 2JzZBEYI4GZMOy20JJpENVCDZR6qf9DALLu9fQRid2riHz7zTt7ppeT9QpoFvNghga/q NjNAiOAoF+tx7B7yC8JVICjS9Gh5sr3x9G7jb1n7wL4MetxB8osx0Ig+oPQosy9t2t5i RigIWm9Tf3ND2cUUTYTqKJlsXj2NG44a/VhfG4bzLH+upScYC9JiD0DddyUvuXJgwTFS IMXWG6NIcwBZ9L4iGzOiEzTGQFs9sSrisBmhAPPqkwJYw2oh+xKBlsERXXcwESFEhRU3 I9wA== 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=yN2s38K6JIydtqO4ZatNa9gzKvgL5GoVczVjmxw4Wrc=; b=w4z4ahtJZ20ShkBTlOXQFhtmW/jym8ck/U8jYJr4ynzIgvghjvIXld2CpJLVF6Bz06 EGtncjped/f43gh4zlpp691TNKXYwLCuGxFMG8CfffFrjL3R0SEqmw6wP02SPLIZl5/h qC90tqr9dJnm4oz6HHki1Qu6ndyLkTosUygFEtmOUC/95SoC6NwUeLbqXBZNJ1BFjOlI 4LgH9+VgUP7UIfxzHipRxd2NbB9u+wgEIPCNlSOfnpVUWM8EnT9+Z7s09jRTPvGWV1vD 2AP4fQyBLUUgipB2tE9Qah3GGRgPkPeTHfPUefTUu8gSQV/tJPKl5CHjagUNJUjAG+IA 2jQA== 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 q7si5302413pgn.559.2018.03.16.10.21.38; Fri, 16 Mar 2018 10:21:52 -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 S1754253AbeCPPaY (ORCPT + 99 others); Fri, 16 Mar 2018 11:30:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:36402 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932240AbeCPPaQ (ORCPT ); Fri, 16 Mar 2018 11:30:16 -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 0114E110B; Fri, 16 Mar 2018 15:30:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ben Skeggs , Dave Airlie , Lyude Paul , Lukas Wunner Subject: [PATCH 4.9 09/86] drm/nouveau: Fix deadlock on runtime suspend Date: Fri, 16 Mar 2018 16:22:32 +0100 Message-Id: <20180316152317.885130071@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lukas Wunner commit d61a5c1063515e855bedb1b81e20e50b0ac3541e upstream. nouveau's ->runtime_suspend hook calls drm_kms_helper_poll_disable(), which waits for the output poll worker to finish if it's running. The output poll worker meanwhile calls pm_runtime_get_sync() in nouveau_connector_detect() which waits for the ongoing suspend to finish, causing a deadlock. Fix by not acquiring a runtime PM ref if nouveau_connector_detect() is called in the output poll worker's context. This is safe because the poll worker is only enabled while runtime active and we know that ->runtime_suspend waits for it to finish. Other contexts calling nouveau_connector_detect() do require a runtime PM ref, these comprise: status_store() drm sysfs interface ->fill_modes drm callback drm_fb_helper_probe_connector_modes() drm_mode_getconnector() nouveau_connector_hotplug() nouveau_display_hpd_work() nv17_tv_set_property() Stack trace for posterity: INFO: task kworker/0:1:58 blocked for more than 120 seconds. Workqueue: events output_poll_execute [drm_kms_helper] Call Trace: schedule+0x28/0x80 rpm_resume+0x107/0x6e0 __pm_runtime_resume+0x47/0x70 nouveau_connector_detect+0x7e/0x4a0 [nouveau] nouveau_connector_detect_lvds+0x132/0x180 [nouveau] drm_helper_probe_detect_ctx+0x85/0xd0 [drm_kms_helper] output_poll_execute+0x11e/0x1c0 [drm_kms_helper] process_one_work+0x184/0x380 worker_thread+0x2e/0x390 INFO: task kworker/0:2:252 blocked for more than 120 seconds. Workqueue: pm pm_runtime_work Call Trace: schedule+0x28/0x80 schedule_timeout+0x1e3/0x370 wait_for_completion+0x123/0x190 flush_work+0x142/0x1c0 nouveau_pmops_runtime_suspend+0x7e/0xd0 [nouveau] pci_pm_runtime_suspend+0x5c/0x180 vga_switcheroo_runtime_suspend+0x1e/0xa0 __rpm_callback+0xc1/0x200 rpm_callback+0x1f/0x70 rpm_suspend+0x13c/0x640 pm_runtime_work+0x6e/0x90 process_one_work+0x184/0x380 worker_thread+0x2e/0x390 Bugzilla: https://bugs.archlinux.org/task/53497 Bugzilla: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=870523 Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=70388#c33 Fixes: 5addcf0a5f0f ("nouveau: add runtime PM support (v0.9)") Cc: stable@vger.kernel.org # v3.12+: 27d4ee03078a: workqueue: Allow retrieval of current task's work struct Cc: stable@vger.kernel.org # v3.12+: 25c058ccaf2e: drm: Allow determining if current task is output poll worker Cc: Ben Skeggs Cc: Dave Airlie Reviewed-by: Lyude Paul Signed-off-by: Lukas Wunner Link: https://patchwork.freedesktop.org/patch/msgid/b7d2cbb609a80f59ccabfdf479b9d5907c603ea1.1518338789.git.lukas@wunner.de Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/nouveau/nouveau_connector.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/nouveau/nouveau_connector.c +++ b/drivers/gpu/drm/nouveau/nouveau_connector.c @@ -271,9 +271,15 @@ nouveau_connector_detect(struct drm_conn nv_connector->edid = NULL; } - ret = pm_runtime_get_sync(connector->dev->dev); - if (ret < 0 && ret != -EACCES) - return conn_status; + /* Outputs are only polled while runtime active, so acquiring a + * runtime PM ref here is unnecessary (and would deadlock upon + * runtime suspend because it waits for polling to finish). + */ + if (!drm_kms_helper_is_poll_worker()) { + ret = pm_runtime_get_sync(connector->dev->dev); + if (ret < 0 && ret != -EACCES) + return conn_status; + } nv_encoder = nouveau_connector_ddc_detect(connector); if (nv_encoder && (i2c = nv_encoder->i2c) != NULL) { @@ -348,8 +354,10 @@ detect_analog: out: - pm_runtime_mark_last_busy(connector->dev->dev); - pm_runtime_put_autosuspend(connector->dev->dev); + if (!drm_kms_helper_is_poll_worker()) { + pm_runtime_mark_last_busy(connector->dev->dev); + pm_runtime_put_autosuspend(connector->dev->dev); + } return conn_status; }