Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2915967imm; Mon, 16 Jul 2018 17:11:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdZY85lt0+g/lwhHOYtlqxl/ixl7Y03q21RNuWdpT9M95uh5u9acW7CfLfQ/TC/zQPsq3TV X-Received: by 2002:a63:647:: with SMTP id 68-v6mr17409478pgg.205.1531786288218; Mon, 16 Jul 2018 17:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531786288; cv=none; d=google.com; s=arc-20160816; b=bw6bLgAhnJWOiBS9jWR7Hr7uvcSlSQQNEEdhBUvk24rqkK/K9IKp3g8Q4KHe2Zup3R BNI2NRaVlyPVzUyON1iaeK+ZMzYGlyGdH8wjm7kihTQUfTzgfPK/AM9Fpjbfg8fm9npD 5hu8hqST6WOORhn/e1j5Smeh5ifftciVz8I2cO59vtpi8EHdWgEizhtBGXrjBcYhpTGR f70K7a0fqwfvjd/K/LNVaYQr3tTDdk7jUoBPtVDE2aDXINf7VGS3XpGsAGi2PJ3EG0Fq rtYHH0bUzRI7YE8PO/fO75IWGf9K+Q2StNomuwg6WiQehwxir7tPBJVUDKPvlehdvUFf knpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=RdA05EkEHtL1qWSovDK9fj6Mrj7njXHeqD5oiz9dZfo=; b=G0u2pPM/jBeVkaS/u/KamxdsVJaZk+FJ7BtAw//R8jSNdLEQOvDLSR+RfbcOqRWgw0 bJojpL6iIpjommCCOWiioXJYgCRpU1MoZC/yAvKZ5GHMdSzkjGZB3VoXh+hsq13t6WTn k754YAsGqSN9WJ5gidCXSIfGK4NeipRBJsr9EkGoD+awpmMccZAhSX/x4BzJS0JGAc8M akDAaZe1ZDo3RGmRRB+I5/A8/ZaNOa/I5EbgKBNQUiBFcQpt1Hx2eVhNgJk19TYdfdb4 gfWmjQhgoowGs2sFMIf5iTZzpuLv8KbAGgzRAkFzFMohHswrntzavbP5bWDgAPJLNpaE HHqg== 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 t2-v6si5805025pgs.142.2018.07.16.17.11.13; Mon, 16 Jul 2018 17:11:28 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730094AbeGQAj0 (ORCPT + 99 others); Mon, 16 Jul 2018 20:39:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:60764 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729466AbeGQAjZ (ORCPT ); Mon, 16 Jul 2018 20:39:25 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F36D40122A1; Mon, 16 Jul 2018 23:59:55 +0000 (UTC) Received: from whitewolf.lyude.net.com (ovpn-124-27.rdu2.redhat.com [10.10.124.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB52F2026D65; Mon, 16 Jul 2018 23:59:54 +0000 (UTC) From: Lyude Paul To: nouveau@lists.freedesktop.org Cc: Karol Herbst , stable@vger.kernel.org, Ben Skeggs , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] drm/nouveau: Prevent RPM callback recursion in suspend/resume paths Date: Mon, 16 Jul 2018 19:59:25 -0400 Message-Id: <20180716235936.11268-2-lyude@redhat.com> In-Reply-To: <20180716235936.11268-1-lyude@redhat.com> References: <20180716235936.11268-1-lyude@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 16 Jul 2018 23:59:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 16 Jul 2018 23:59:55 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lyude@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to fix all of the spots that need to have runtime PM get/puts() added, we need to ensure that it's possible for us to call pm_runtime_get/put() in any context, regardless of how deep, since almost all of the spots that are currently missing refs can potentially get called in the runtime suspend/resume path. Otherwise, we'll try to resume the GPU as we're trying to resume the GPU (and vice-versa) and cause the kernel to deadlock. With this, it should be safe to call the pm runtime functions in any context in nouveau with one condition: any point in the driver that calls pm_runtime_get*() cannot hold any locks owned by nouveau that would be acquired anywhere inside nouveau_pmops_runtime_resume(). This includes modesetting locks, i2c bus locks, etc. Signed-off-by: Lyude Paul Cc: Karol Herbst Cc: stable@vger.kernel.org --- drivers/gpu/drm/nouveau/nouveau_drm.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index c7ec86d6c3c9..e851ef7b6373 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -835,6 +835,8 @@ nouveau_pmops_runtime_suspend(struct device *dev) return -EBUSY; } + dev->power.disable_depth++; + drm_kms_helper_poll_disable(drm_dev); nouveau_switcheroo_optimus_dsm(); ret = nouveau_do_suspend(drm_dev, true); @@ -843,6 +845,8 @@ nouveau_pmops_runtime_suspend(struct device *dev) pci_ignore_hotplug(pdev); pci_set_power_state(pdev, PCI_D3cold); drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF; + + dev->power.disable_depth--; return ret; } @@ -859,11 +863,13 @@ nouveau_pmops_runtime_resume(struct device *dev) return -EBUSY; } + dev->power.disable_depth++; + pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); ret = pci_enable_device(pdev); if (ret) - return ret; + goto out; pci_set_master(pdev); ret = nouveau_do_resume(drm_dev, true); @@ -875,6 +881,8 @@ nouveau_pmops_runtime_resume(struct device *dev) /* Monitors may have been connected / disconnected during suspend */ schedule_work(&nouveau_drm(drm_dev)->hpd_work); +out: + dev->power.disable_depth--; return ret; } -- 2.17.1