Skip to contentSkip to conversation

drm/nouveau: don't attempt to schedule hpd_work on headless cards

PATCH Superseded Vasily Khoruzhick 3 participants 4 messages May 28, 2024 – Jun 7, 2024

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau: don't attempt to schedule hpd_work on headless cards

If the card doesn't have display hardware, hpd_work and hpd_lock are left uninitialized which causes BUG when attempting to schedule hpd_work on runtime PM resume.

Fix it by adding headless flag to DRM and skip any hpd if it's set.

Fixes ae1aadb1eb8d ("nouveau: don't fail driver load if no display hw present.")
---
 drivers/gpu/drm/nouveau/dispnv04/disp.c     |  2 +-
 drivers/gpu/drm/nouveau/dispnv50/disp.c     |  2 +-
 drivers/gpu/drm/nouveau/nouveau_connector.c |  3 +++
 drivers/gpu/drm/nouveau/nouveau_display.c   | 11 ++++++++++-
 drivers/gpu/drm/nouveau/nouveau_drv.h       |  1 +
 5 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index 13705c5f1497..4b7497a8755c 100644
@@ -68,7 +68,7 @@ nv04_display_fini(struct drm_device *dev, bool runtime, bool suspend)
 	if (nv_two_heads(dev))
 		NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
 		cancel_work_sync(&drm->hpd_work);
 
 	if (!suspend)
drivers/gpu/drm/nouveau/dispnv50/disp.c +1 -1
index 88728a0b2c25..674dc567e179 100644
@@ -2680,7 +2680,7 @@ nv50_display_fini(struct drm_device *dev, bool runtime, bool suspend)
 			nv50_mstm_fini(nouveau_encoder(encoder));
 	}
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
 		cancel_work_sync(&drm->hpd_work);
 }
 
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
index 856b3ef5edb8..b315a2ef5b28 100644
@@ -1190,6 +1190,9 @@ nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits)
 	u32 mask = drm_connector_mask(&nv_connector->base);
 	unsigned long flags;
 
+	if (drm->headless)
+		return;
+
 	spin_lock_irqsave(&drm->hpd_lock, flags);
 	if (!(drm->hpd_pending & mask)) {
 		nv_connector->hpd_pending |= bits;
drivers/gpu/drm/nouveau/nouveau_display.c +10 -1
index aed5d5b51b43..1961ef665e97 100644
@@ -450,6 +450,9 @@ nouveau_display_hpd_resume(struct drm_device *dev)
 {
 	struct nouveau_drm *drm = nouveau_drm(dev);
 
+	if (drm->headless)
+		return;
+
 	spin_lock_irq(&drm->hpd_lock);
 	drm->hpd_pending = ~0;
 	spin_unlock_irq(&drm->hpd_lock);
@@ -468,6 +471,11 @@ nouveau_display_hpd_work(struct work_struct *work)
 	int changed = 0;
 	struct drm_connector *first_changed_connector = NULL;
 
+	WARN_ON_ONCE(drm->headless);
+
+	if (drm->headless)
+		return;
+
 	pm_runtime_get_sync(dev->dev);
 
 	spin_lock_irq(&drm->hpd_lock);
@@ -635,7 +643,7 @@ nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime)
 	}
 	drm_connector_list_iter_end(&conn_iter);
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
 		cancel_work_sync(&drm->hpd_work);
 
 	drm_kms_helper_poll_disable(dev);
@@ -729,6 +737,7 @@ nouveau_display_create(struct drm_device *dev)
 		/* no display hw */
 		if (ret == -ENODEV) {
 			ret = 0;
+			drm->headless = true;
 			goto disp_create_err;
 		}
 
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index e239c6bf4afa..25fca98a20bc 100644
@@ -276,6 +276,7 @@ struct nouveau_drm {
 	/* modesetting */
 	struct nvbios vbios;
 	struct nouveau_display *display;
+	bool headless;
 	struct work_struct hpd_work;
 	spinlock_t hpd_lock;
 	u32 hpd_pending;
Signature · 1 line
2.45.1
#1 lore raw
Quoted 3 lines · Vasily Khoruzhick

If the card doesn't have display hardware, hpd_work and hpd_lock are left uninitialized which causes BUG when attempting to schedule hpd_work on runtime PM resume.

Hi,

Good catch, thank you for looking at this.  A couple of initial comments below:

Ben.

Quoted 45 lines

Fix it by adding headless flag to DRM and skip any hpd if it's set.

Fixes ae1aadb1eb8d ("nouveau: don't fail driver load if no display hw present.")
---
  drivers/gpu/drm/nouveau/dispnv04/disp.c     |  2 +-
  drivers/gpu/drm/nouveau/dispnv50/disp.c     |  2 +-
  drivers/gpu/drm/nouveau/nouveau_connector.c |  3 +++
  drivers/gpu/drm/nouveau/nouveau_display.c   | 11 ++++++++++-
  drivers/gpu/drm/nouveau/nouveau_drv.h       |  1 +
  5 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index 13705c5f1497..4b7497a8755c 100644
@@ -68,7 +68,7 @@ nv04_display_fini(struct drm_device *dev, bool runtime, bool suspend)
  	if (nv_two_heads(dev))
  		NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
  		cancel_work_sync(&drm->hpd_work);
 
  	if (!suspend)
drivers/gpu/drm/nouveau/dispnv50/disp.c +1 -1
index 88728a0b2c25..674dc567e179 100644
@@ -2680,7 +2680,7 @@ nv50_display_fini(struct drm_device *dev, bool runtime, bool suspend)
  			nv50_mstm_fini(nouveau_encoder(encoder));
  	}
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
  		cancel_work_sync(&drm->hpd_work);
  }
 
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
index 856b3ef5edb8..b315a2ef5b28 100644

drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits) · line 1195

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
@@ -1190,6 +1190,9 @@ nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits)
  	u32 mask = drm_connector_mask(&nv_connector->base);
  	unsigned long flags;
 
+	if (drm->headless)
+		return;
+

You shouldn't need this change, the function can't be called if there's no display.

Quoted 18 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
  	spin_lock_irqsave(&drm->hpd_lock, flags);
  	if (!(drm->hpd_pending & mask)) {
  		nv_connector->hpd_pending |= bits;
drivers/gpu/drm/nouveau/nouveau_display.c +3 -0
index aed5d5b51b43..1961ef665e97 100644
@@ -450,6 +450,9 @@ nouveau_display_hpd_resume(struct drm_device *dev)
  {
  	struct nouveau_drm *drm = nouveau_drm(dev);
 
+	if (drm->headless)
+		return;
+
  	spin_lock_irq(&drm->hpd_lock);
  	drm->hpd_pending = ~0;
  	spin_unlock_irq(&drm->hpd_lock);

drivers/gpu/drm/nouveau/nouveau_display.c nouveau_display_hpd_work(struct work_struct *work) · line 478

Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_display.c +5 -0
@@ -468,6 +471,11 @@ nouveau_display_hpd_work(struct work_struct *work)
  	int changed = 0;
  	struct drm_connector *first_changed_connector = NULL;
 
+	WARN_ON_ONCE(drm->headless);
+
+	if (drm->headless)
+		return;
+

Same here.

Quoted 32 lines
drivers/gpu/drm/nouveau/nouveau_display.c +2 -1
  	pm_runtime_get_sync(dev->dev);
 
  	spin_lock_irq(&drm->hpd_lock);
@@ -635,7 +643,7 @@ nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime)
  	}
  	drm_connector_list_iter_end(&conn_iter);
 
-	if (!runtime)
+	if (!runtime && !drm->headless)
  		cancel_work_sync(&drm->hpd_work);
 
  	drm_kms_helper_poll_disable(dev);
@@ -729,6 +737,7 @@ nouveau_display_create(struct drm_device *dev)
  		/* no display hw */
  		if (ret == -ENODEV) {
  			ret = 0;
+			drm->headless = true;
  			goto disp_create_err;
  		}
 
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index e239c6bf4afa..25fca98a20bc 100644
@@ -276,6 +276,7 @@ struct nouveau_drm {
  	/* modesetting */
  	struct nvbios vbios;
  	struct nouveau_display *display;
+	bool headless;
  	struct work_struct hpd_work;
  	spinlock_t hpd_lock;
  	u32 hpd_pending;
maintainer
#2 lore raw

readding original poster

Quoted 132 lines · Ben Skeggs
Quoted 3 lines · Vasily Khoruzhick

If the card doesn't have display hardware, hpd_work and hpd_lock are left uninitialized which causes BUG when attempting to schedule hpd_work on runtime PM resume.

Hi,

Good catch, thank you for looking at this. A couple of initial comments below:

Ben.

Quoted 45 lines

Fix it by adding headless flag to DRM and skip any hpd if it's set.

Fixes ae1aadb1eb8d ("nouveau: don't fail driver load if no display hw present.")
---
  drivers/gpu/drm/nouveau/dispnv04/disp.c     |  2 +-
  drivers/gpu/drm/nouveau/dispnv50/disp.c     |  2 +-
  drivers/gpu/drm/nouveau/nouveau_connector.c |  3 +++
  drivers/gpu/drm/nouveau/nouveau_display.c   | 11 ++++++++++-
  drivers/gpu/drm/nouveau/nouveau_drv.h       |  1 +
  5 files changed, 16 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/dispnv04/disp.c +1 -1
index 13705c5f1497..4b7497a8755c 100644
@@ -68,7 +68,7 @@ nv04_display_fini(struct drm_device *dev, bool runtime, bool suspend)
      if (nv_two_heads(dev))
              NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
 
-     if (!runtime)
+     if (!runtime && !drm->headless)
              cancel_work_sync(&drm->hpd_work);
 
      if (!suspend)
drivers/gpu/drm/nouveau/dispnv50/disp.c +1 -1
index 88728a0b2c25..674dc567e179 100644
@@ -2680,7 +2680,7 @@ nv50_display_fini(struct drm_device *dev, bool runtime, bool suspend)
                      nv50_mstm_fini(nouveau_encoder(encoder));
      }
 
-     if (!runtime)
+     if (!runtime && !drm->headless)
              cancel_work_sync(&drm->hpd_work);
  }
 
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
index 856b3ef5edb8..b315a2ef5b28 100644

drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits) · line 1195

Quoted 6 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
@@ -1190,6 +1190,9 @@ nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits)
      u32 mask = drm_connector_mask(&nv_connector->base);
      unsigned long flags;
 
+     if (drm->headless)
+             return;
+

You shouldn't need this change, the function can't be called if there's no display.

Quoted 18 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
      spin_lock_irqsave(&drm->hpd_lock, flags);
      if (!(drm->hpd_pending & mask)) {
              nv_connector->hpd_pending |= bits;
drivers/gpu/drm/nouveau/nouveau_display.c +3 -0
index aed5d5b51b43..1961ef665e97 100644
@@ -450,6 +450,9 @@ nouveau_display_hpd_resume(struct drm_device *dev)
  {
      struct nouveau_drm *drm = nouveau_drm(dev);
 
+     if (drm->headless)
+             return;
+
      spin_lock_irq(&drm->hpd_lock);
      drm->hpd_pending = ~0;
      spin_unlock_irq(&drm->hpd_lock);

drivers/gpu/drm/nouveau/nouveau_display.c nouveau_display_hpd_work(struct work_struct *work) · line 478

Quoted 8 lines
drivers/gpu/drm/nouveau/nouveau_display.c +5 -0
@@ -468,6 +471,11 @@ nouveau_display_hpd_work(struct work_struct *work)
      int changed = 0;
      struct drm_connector *first_changed_connector = NULL;
 
+     WARN_ON_ONCE(drm->headless);
+
+     if (drm->headless)
+             return;
+

Same here.

Quoted 32 lines
drivers/gpu/drm/nouveau/nouveau_display.c +2 -1
      pm_runtime_get_sync(dev->dev);
 
      spin_lock_irq(&drm->hpd_lock);
@@ -635,7 +643,7 @@ nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime)
      }
      drm_connector_list_iter_end(&conn_iter);
 
-     if (!runtime)
+     if (!runtime && !drm->headless)
              cancel_work_sync(&drm->hpd_work);
 
      drm_kms_helper_poll_disable(dev);
@@ -729,6 +737,7 @@ nouveau_display_create(struct drm_device *dev)
              /* no display hw */
              if (ret == -ENODEV) {
                      ret = 0;
+                     drm->headless = true;
                      goto disp_create_err;
              }
 
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
index e239c6bf4afa..25fca98a20bc 100644
@@ -276,6 +276,7 @@ struct nouveau_drm {
      /* modesetting */
      struct nvbios vbios;
      struct nouveau_display *display;
+     bool headless;
      struct work_struct hpd_work;
      spinlock_t hpd_lock;
      u32 hpd_pending;
#3 lore raw
Quoted 2 lines · Dave Airlie

readding original poster

Thanks, Dave!

Ben, please keep me on CC, since I'm not subscribed to either nouveau or dri-devel mailing lists.

Quoted 10 lines · Ben Skeggs
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
index 856b3ef5edb8..b315a2ef5b28 100644
@@ -1190,6 +1190,9 @@ nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits)
      u32 mask = drm_connector_mask(&nv_connector->base);
      unsigned long flags;
 
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/nouveau/nouveau_connector.c nouveau_connector_hpd(struct nouveau_connector *nv_connector, u64 bits) · line 1195

Quoted 3 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +3 -0
+     if (drm->headless)
+             return;
+

You shouldn't need this change, the function can't be called if there's no display.

You are right. I added it for extra safety in case if the code changes in future and it somehow gets called, but I don't have a strong preference, so I can drop it in v2.

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
drivers/gpu/drm/nouveau/nouveau_connector.c +0 -0
      spin_lock_irqsave(&drm->hpd_lock, flags);
      if (!(drm->hpd_pending & mask)) {
              nv_connector->hpd_pending |= bits;
drivers/gpu/drm/nouveau/nouveau_display.c +3 -0
index aed5d5b51b43..1961ef665e97 100644
@@ -450,6 +450,9 @@ nouveau_display_hpd_resume(struct drm_device *dev)
  {
      struct nouveau_drm *drm = nouveau_drm(dev);
 
+     if (drm->headless)
+             return;
+
      spin_lock_irq(&drm->hpd_lock);
      drm->hpd_pending = ~0;
      spin_unlock_irq(&drm->hpd_lock);
@@ -468,6 +471,11 @@ nouveau_display_hpd_work(struct work_struct *work)
      int changed = 0;
      struct drm_connector *first_changed_connector = NULL;
 
Quoted 7 lines
Quoted 7 lines

drivers/gpu/drm/nouveau/nouveau_display.c nouveau_display_hpd_work(struct work_struct *work) · line 478

Quoted 5 lines
drivers/gpu/drm/nouveau/nouveau_display.c +5 -0
+     WARN_ON_ONCE(drm->headless);
+
+     if (drm->headless)
+             return;
+

Same here.

Same comment, I'll drop it for v2.

Regards,
Vasily