All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lyude Paul <lyude@redhat.com>
To: nouveau@lists.freedesktop.org
Cc: David Airlie <airlied@linux.ie>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Karol Herbst <karolherbst@gmail.com>,
	stable@vger.kernel.org, Ben Skeggs <bskeggs@redhat.com>
Subject: [PATCH 1/5] drm/nouveau: Prevent RPM callback recursion in suspend/resume paths
Date: Mon, 16 Jul 2018 19:59:25 -0400	[thread overview]
Message-ID: <20180716235936.11268-2-lyude@redhat.com> (raw)
In-Reply-To: <20180716235936.11268-1-lyude@redhat.com>

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 <lyude@redhat.com>
Cc: Karol Herbst <karolherbst@gmail.com>
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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

WARNING: multiple messages have this Message-ID (diff)
From: Lyude Paul <lyude@redhat.com>
To: nouveau@lists.freedesktop.org
Cc: Karol Herbst <karolherbst@gmail.com>,
	stable@vger.kernel.org, Ben Skeggs <bskeggs@redhat.com>,
	David Airlie <airlied@linux.ie>,
	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	[thread overview]
Message-ID: <20180716235936.11268-2-lyude@redhat.com> (raw)
In-Reply-To: <20180716235936.11268-1-lyude@redhat.com>

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 <lyude@redhat.com>
Cc: Karol Herbst <karolherbst@gmail.com>
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


  reply	other threads:[~2018-07-16 23:59 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 23:59 [PATCH 0/5] drm/nouveau: Fix a lot of nasty RPM bugs and deadlocks Lyude Paul
2018-07-16 23:59 ` Lyude Paul
2018-07-16 23:59 ` Lyude Paul [this message]
2018-07-16 23:59   ` [PATCH 1/5] drm/nouveau: Prevent RPM callback recursion in suspend/resume paths Lyude Paul
2018-07-17  7:16   ` [Nouveau] " Lukas Wunner
     [not found]     ` <20180717071641.GA5411-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-17  7:39       ` Rafael J. Wysocki
2018-07-17  7:39         ` [Nouveau] " Rafael J. Wysocki
2018-07-17 16:53     ` Lyude Paul
     [not found]       ` <d7c25a7f41df70685c0c4726315592d1d9b561ff.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-17 18:20         ` Lukas Wunner
2018-07-17 18:20           ` [Nouveau] " Lukas Wunner
     [not found]           ` <20180717182041.GA18363-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-17 18:24             ` Lyude Paul
2018-07-17 18:24               ` [Nouveau] " Lyude Paul
2018-07-17 18:32               ` Lukas Wunner
2018-07-17 18:34                 ` Lyude Paul
2018-07-17 18:34                   ` Lyude Paul
     [not found]                   ` <2dbe75b1a83c025b9cddc229dbca9af6fb30111e.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-18  7:40                     ` Rafael J. Wysocki
2018-07-18  7:40                       ` [Nouveau] " Rafael J. Wysocki
2018-07-18  7:47                     ` Lukas Wunner
2018-07-18  7:47                       ` [Nouveau] " Lukas Wunner
2018-07-18  7:38             ` Rafael J. Wysocki
2018-07-18  7:38               ` [Nouveau] " Rafael J. Wysocki
     [not found]               ` <CAJZ5v0g8O8J0U8V-gLMe+NnTd3xgZ5_pjr9p2oci7yAfW54B-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-07-18  8:25                 ` Lukas Wunner
2018-07-18  8:25                   ` [Nouveau] " Lukas Wunner
     [not found]                   ` <20180718082505.GB16072-JFq808J9C/izQB+pC5nmwQ@public.gmane.org>
2018-07-18  8:35                     ` Rafael J. Wysocki
2018-07-18  8:35                       ` [Nouveau] " Rafael J. Wysocki
2018-07-18  8:36                   ` Lukas Wunner
2018-07-18  8:36                     ` Lukas Wunner
2018-07-18 20:11                     ` Lyude Paul
     [not found]                       ` <2724dd5eee8a1e4e523e43915fa184ad5afe1c59.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-18 21:49                         ` Rafael J. Wysocki
2018-07-18 21:49                           ` [Nouveau] " Rafael J. Wysocki
     [not found] ` <20180716235936.11268-1-lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-07-16 23:59   ` [PATCH 2/5] drm/nouveau: Grab RPM ref while probing outputs Lyude Paul
2018-07-16 23:59     ` Lyude Paul
2018-07-17  7:21     ` [Nouveau] " Lukas Wunner
2018-07-17  7:21       ` Lukas Wunner
2018-07-17 10:12       ` Karol Herbst
2018-07-17 10:12         ` Karol Herbst
2018-07-16 23:59   ` [PATCH 3/5] drm/nouveau: Add missing RPM get/put() when probing connectors Lyude Paul
2018-07-16 23:59     ` Lyude Paul
2018-07-17 10:11     ` [Nouveau] " Karol Herbst
2018-07-16 23:59   ` [PATCH 4/5] drm/nouveau: Grab RPM ref when i2c bus is in use Lyude Paul
2018-07-16 23:59     ` Lyude Paul
2018-07-17 10:17     ` [Nouveau] " Karol Herbst
2018-07-17 11:54       ` Ben Skeggs
2018-07-17 11:54         ` Ben Skeggs
2018-07-17 12:10         ` Karol Herbst
2018-07-16 23:59 ` [PATCH 5/5] drm/nouveau: Grab RPM ref when aux " Lyude Paul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180716235936.11268-2-lyude@redhat.com \
    --to=lyude@redhat.com \
    --cc=airlied@linux.ie \
    --cc=bskeggs@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karolherbst@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.