All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/nouveau: fix crash when DP link training fails
@ 2026-11-23 10:16 ` Frédéric Mahé
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau
  Cc: dri-devel, Lyude Paul, Danilo Krummrich,
	Frédéric Mahé

On a Quadro 600 (GF108), any failed DisplayPort link training during a
modeset crashes the kernel with a divide error in
nv50_disp_super_2_2_dp(), because the supervisor divides by the lane
count that training left at 0. Two ways to get there:

- Xorg (modesetting) builds 3840x2160@60 (533 MHz) from the EDID of a
  4K monitor and sets it on the card's DP 1.1 output, which can carry at
  most 4 x 2.7 Gbit/s even at 6 bpc;
- a connector forced on while the monitor sleeps or is unplugged, then
  any mode set on it.

Patch 1 stops the crash. Patch 2 makes atomic check reject DP modes that
cannot fit the link, so userspace gets -EINVAL instead of a dark screen.

Tested on Ubuntu's 7.0 kernel with a libdrm reproducer (SETCRTC with a
user-defined mode) and with Xorg; the patches apply unchanged on
drm-misc-fixes.

Written with help from Claude (Anthropic); reviewed and tested on
hardware.

Frédéric Mahé (2):
  drm/nouveau/disp/nv50-: don't divide by zero when the DP link is not
    trained
  drm/nouveau/dispnv50: reject DP modes that don't fit the link

 drivers/gpu/drm/nouveau/dispnv50/disp.c         | 15 +++++++++++++++
 drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c | 10 ++++++++++
 2 files changed, 25 insertions(+)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 0/2] drm/nouveau: fix crash when DP link training fails
@ 2026-11-23 10:16 ` Frédéric Mahé
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau; +Cc: dri-devel, Danilo Krummrich, Frédéric Mahé

On a Quadro 600 (GF108), any failed DisplayPort link training during a
modeset crashes the kernel with a divide error in
nv50_disp_super_2_2_dp(), because the supervisor divides by the lane
count that training left at 0. Two ways to get there:

- Xorg (modesetting) builds 3840x2160@60 (533 MHz) from the EDID of a
  4K monitor and sets it on the card's DP 1.1 output, which can carry at
  most 4 x 2.7 Gbit/s even at 6 bpc;
- a connector forced on while the monitor sleeps or is unplugged, then
  any mode set on it.

Patch 1 stops the crash. Patch 2 makes atomic check reject DP modes that
cannot fit the link, so userspace gets -EINVAL instead of a dark screen.

Tested on Ubuntu's 7.0 kernel with a libdrm reproducer (SETCRTC with a
user-defined mode) and with Xorg; the patches apply unchanged on
drm-misc-fixes.

Written with help from Claude (Anthropic); reviewed and tested on
hardware.

Frédéric Mahé (2):
  drm/nouveau/disp/nv50-: don't divide by zero when the DP link is not
    trained
  drm/nouveau/dispnv50: reject DP modes that don't fit the link

 drivers/gpu/drm/nouveau/dispnv50/disp.c         | 15 +++++++++++++++
 drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c | 10 ++++++++++
 2 files changed, 25 insertions(+)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/2] drm/nouveau/disp/nv50-: don't divide by zero when the DP link is not trained
  2026-11-23 10:16 ` Frédéric Mahé
@ 2026-11-23 10:16   ` Frédéric Mahé
  -1 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau
  Cc: dri-devel, Lyude Paul, Danilo Krummrich,
	Frédéric Mahé, stable

Since link training moved out of the supervisor, ior->dp.nr is copied
from the lane count chosen by the DRM side, and it stays 0 when training
fails: no lane/rate combination fits the mode, or the sink does not
answer on AUX.  nouveau_dp_train()'s result is ignored by
nv50_sor_atomic_enable(), so the modeset goes on, and supervisor 2.2
divides by ior->dp.nr in nv50_disp_super_2_2_dp():

  Oops: divide error: 0000 [#1] SMP PTI
  Workqueue: nvkm-disp nv50_disp_super [nouveau]
  RIP: 0010:nv50_disp_super_2_2_dp+0xa4/0x340 [nouveau]
   nv50_disp_super_2_2+0xcc/0x140 [nouveau]
   nv50_disp_super+0x137/0x250 [nouveau]

Seen on a Quadro 600 (GF108) when Xorg set 3840x2160@60 (533 MHz) on a
DP 1.1 output, and when setting 1024x768 on a forced-on DP connector
whose monitor was asleep.

Skip the transfer unit and watermark setup with a warning when the link
has no lanes.  Before the change below, the training loop never left
ior->dp.nr at 0.

Written with help from Claude (Anthropic); reviewed and tested on hardware.

Fixes: 3147ce0d07aa ("drm/nouveau/disp: move link training out of supervisor")
Cc: stable@vger.kernel.org
Signed-off-by: Frédéric Mahé <frederic.mahe@cirad.fr>
---
 drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
index 03a5f88..778559d 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
@@ -1166,6 +1166,16 @@ nv50_disp_super_2_2_dp(struct nvkm_head *head, struct nvkm_ior *ior)
 	u32 best_diff = 64 * symbol;
 	u64 h, v;
 
+	/* Link training failed or was never done (e.g. mode too fast for the
+	 * link, or no sink answering): there is no link to configure, and
+	 * the calculations below would divide by zero.
+	 */
+	if (!ior->dp.nr || !ior->dp.bw) {
+		nvkm_warn(subdev, "head-%d: DP link not trained (nr %d bw %d)\n",
+			  head->id, ior->dp.nr, ior->dp.bw);
+		return;
+	}
+
 	/* symbols/hblank - algorithm taken from comments in tegra driver */
 	h = head->asy.hblanke + head->asy.htotal - head->asy.hblanks - 7;
 	h = h * linkKBps;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 1/2] drm/nouveau/disp/nv50-: don't divide by zero when the DP link is not trained
@ 2026-11-23 10:16   ` Frédéric Mahé
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau; +Cc: dri-devel, Danilo Krummrich, Frédéric Mahé, stable

Since link training moved out of the supervisor, ior->dp.nr is copied
from the lane count chosen by the DRM side, and it stays 0 when training
fails: no lane/rate combination fits the mode, or the sink does not
answer on AUX.  nouveau_dp_train()'s result is ignored by
nv50_sor_atomic_enable(), so the modeset goes on, and supervisor 2.2
divides by ior->dp.nr in nv50_disp_super_2_2_dp():

  Oops: divide error: 0000 [#1] SMP PTI
  Workqueue: nvkm-disp nv50_disp_super [nouveau]
  RIP: 0010:nv50_disp_super_2_2_dp+0xa4/0x340 [nouveau]
   nv50_disp_super_2_2+0xcc/0x140 [nouveau]
   nv50_disp_super+0x137/0x250 [nouveau]

Seen on a Quadro 600 (GF108) when Xorg set 3840x2160@60 (533 MHz) on a
DP 1.1 output, and when setting 1024x768 on a forced-on DP connector
whose monitor was asleep.

Skip the transfer unit and watermark setup with a warning when the link
has no lanes.  Before the change below, the training loop never left
ior->dp.nr at 0.

Written with help from Claude (Anthropic); reviewed and tested on hardware.

Fixes: 3147ce0d07aa ("drm/nouveau/disp: move link training out of supervisor")
Cc: stable@vger.kernel.org
Signed-off-by: Frédéric Mahé <frederic.mahe@cirad.fr>
---
 drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
index 03a5f88..778559d 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
@@ -1166,6 +1166,16 @@ nv50_disp_super_2_2_dp(struct nvkm_head *head, struct nvkm_ior *ior)
 	u32 best_diff = 64 * symbol;
 	u64 h, v;
 
+	/* Link training failed or was never done (e.g. mode too fast for the
+	 * link, or no sink answering): there is no link to configure, and
+	 * the calculations below would divide by zero.
+	 */
+	if (!ior->dp.nr || !ior->dp.bw) {
+		nvkm_warn(subdev, "head-%d: DP link not trained (nr %d bw %d)\n",
+			  head->id, ior->dp.nr, ior->dp.bw);
+		return;
+	}
+
 	/* symbols/hblank - algorithm taken from comments in tegra driver */
 	h = head->asy.hblanke + head->asy.htotal - head->asy.hblanks - 7;
 	h = h * linkKBps;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] drm/nouveau/dispnv50: reject DP modes that don't fit the link
  2026-11-23 10:16 ` Frédéric Mahé
@ 2026-11-23 10:16   ` Frédéric Mahé
  -1 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau
  Cc: dri-devel, Lyude Paul, Danilo Krummrich,
	Frédéric Mahé

nv50_dp_mode_valid() keeps modes that are too fast for the DP link out
of the connector's mode list, but a user-supplied mode only goes through
atomic check, where nv50_outp_atomic_fix_depth() lowers bpc to 6 and
then accepts the mode even if it still does not fit.  Link training
then fails, the display stays dark and, before the previous fix, the
kernel crashed.

This happens with Xorg's modesetting driver, which builds modes from
the EDID itself: on a Quadro 600 (DP 1.1, 4 lanes at 2.7 Gbit/s) with a
4K monitor it sets 3840x2160@60 (533 MHz), which needs 1200 MB/s even
at 18 bpp against 1080 MB/s for the link.

Return -EINVAL from atomic check in that case, so userspace can fall
back to another mode.  Only check when the link capabilities are known,
so that a sink that is asleep or still resuming does not make every
commit fail.

Written with help from Claude (Anthropic); reviewed and tested on hardware.

Signed-off-by: Frédéric Mahé <frederic.mahe@cirad.fr>
---
 drivers/gpu/drm/nouveau/dispnv50/disp.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index e91130f..fbe8528 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -423,6 +423,21 @@ nv50_outp_atomic_check(struct drm_encoder *encoder,
 	/* We might have to reduce the bpc */
 	nv50_outp_atomic_fix_depth(encoder, crtc_state);
 
+	/* Reject a mode that does not fit the DP link even at the lowest bpc:
+	 * link training would fail and the display would stay dark.  Only
+	 * when the link capabilities are known, so that a sink that is
+	 * asleep or still resuming does not make every commit fail.
+	 */
+	if (crtc_state->mode_changed && crtc_state->active) {
+		struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+		if (nv_encoder->dcb->type == DCB_OUTPUT_DP &&
+		    nv_encoder->dp.link_nr && nv_encoder->dp.link_bw &&
+		    nv50_dp_mode_valid(nv_encoder, &crtc_state->adjusted_mode,
+				       NULL) != MODE_OK)
+			return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/2] drm/nouveau/dispnv50: reject DP modes that don't fit the link
@ 2026-11-23 10:16   ` Frédéric Mahé
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 10:16 UTC (permalink / raw)
  To: nouveau; +Cc: dri-devel, Danilo Krummrich, Frédéric Mahé

nv50_dp_mode_valid() keeps modes that are too fast for the DP link out
of the connector's mode list, but a user-supplied mode only goes through
atomic check, where nv50_outp_atomic_fix_depth() lowers bpc to 6 and
then accepts the mode even if it still does not fit.  Link training
then fails, the display stays dark and, before the previous fix, the
kernel crashed.

This happens with Xorg's modesetting driver, which builds modes from
the EDID itself: on a Quadro 600 (DP 1.1, 4 lanes at 2.7 Gbit/s) with a
4K monitor it sets 3840x2160@60 (533 MHz), which needs 1200 MB/s even
at 18 bpp against 1080 MB/s for the link.

Return -EINVAL from atomic check in that case, so userspace can fall
back to another mode.  Only check when the link capabilities are known,
so that a sink that is asleep or still resuming does not make every
commit fail.

Written with help from Claude (Anthropic); reviewed and tested on hardware.

Signed-off-by: Frédéric Mahé <frederic.mahe@cirad.fr>
---
 drivers/gpu/drm/nouveau/dispnv50/disp.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
index e91130f..fbe8528 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
@@ -423,6 +423,21 @@ nv50_outp_atomic_check(struct drm_encoder *encoder,
 	/* We might have to reduce the bpc */
 	nv50_outp_atomic_fix_depth(encoder, crtc_state);
 
+	/* Reject a mode that does not fit the DP link even at the lowest bpc:
+	 * link training would fail and the display would stay dark.  Only
+	 * when the link capabilities are known, so that a sink that is
+	 * asleep or still resuming does not make every commit fail.
+	 */
+	if (crtc_state->mode_changed && crtc_state->active) {
+		struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+		if (nv_encoder->dcb->type == DCB_OUTPUT_DP &&
+		    nv_encoder->dp.link_nr && nv_encoder->dp.link_bw &&
+		    nv50_dp_mode_valid(nv_encoder, &crtc_state->adjusted_mode,
+				       NULL) != MODE_OK)
+			return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/2] drm/nouveau/dispnv50: reject DP modes that don't fit the link
  2026-11-23 10:16   ` Frédéric Mahé
  (?)
@ 2026-11-23 14:30   ` sashiko-bot
  -1 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-23 14:30 UTC (permalink / raw)
  To: Frédéric Mahé; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/nouveau: incomplete DP mode check condition in
  nv50_outp_atomic_check()
--

commit 943220be5958f2da589b892e0f39c0caa93bf128
Author: Frédéric Mahé <frederic.mahe@cirad.fr>

drm/nouveau/dispnv50: reject DP modes that don't fit the link

This commit rejects DisplayPort modes in nv50_outp_atomic_check() when
nv50_dp_mode_valid() indicates that the mode exceeds the link capacity even
after reducing the bpc.

> diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c
> index 98a5188f65234..d7582ed8026b1 100644
> --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c
> +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c
> @@ -423,6 +423,21 @@ nv50_outp_atomic_check(struct drm_encoder *encoder,
>  	/* We might have to reduce the bpc */
>  	nv50_outp_atomic_fix_depth(encoder, crtc_state);
>  
> +	/* Reject a mode that does not fit the DP link even at the lowest bpc:
> +	 * link training would fail and the display would stay dark.  Only
> +	 * when the link capabilities are known, so that a sink that is
> +	 * asleep or still resuming does not make every commit fail.
> +	 */
> +	if (crtc_state->mode_changed && crtc_state->active) {
> +		struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
> +
> +		if (nv_encoder->dcb->type == DCB_OUTPUT_DP &&
> +		    nv_encoder->dp.link_nr && nv_encoder->dp.link_bw &&
> +		    nv50_dp_mode_valid(nv_encoder, &crtc_state->adjusted_mode,
> +				       NULL) != MODE_OK)
> +			return -EINVAL;
> +	}

[Severity: Medium]
Should this condition be (crtc_state->mode_changed ||
crtc_state->connectors_changed), matching the bpc check earlier in
nv50_outp_atomic_check()?

If connector routing or a connector property changes without changing the
CRTC mode, crtc_state->connectors_changed is set while
crtc_state->mode_changed remains false.  This check is then skipped, even
though nv50_disp_outp_atomic_check_set() tests
drm_atomic_crtc_needs_modeset() and still enables the DP output and runs
link training with the out-of-range mode.

Also, struct drm_crtc_state documents that atomic_check callbacks must not
consult crtc_state->active to reject a commit.  Gating on crtc_state->active
allows an out-of-range mode to be committed while active is false; a later
DPMS ON commit only sets active_changed (with mode_changed false), bypassing
this check as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123101659.600247-1-frederic.mahe@cirad.fr?part=2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] drm/nouveau: fix crash when DP link training fails
  2026-11-23 10:16 ` Frédéric Mahé
@ 2026-11-23 16:33   ` Frédéric Mahé
  -1 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 16:33 UTC (permalink / raw)
  To: nouveau; +Cc: dri-devel, Danilo Krummrich, David R . Hedges

Hi,

After sending this I found David Hedges' series "drm/nouveau: recover
DP links the sink drops after waking" (Cc'd). His patch 1/5 does what my
patch 2/2 does, more completely, and touches the same function, so I am
dropping 2/2 in favour of his. That also covers the points the Sashiko
review raised on 2/2 (the check only ran when mode_changed and active
were both set).

Patch 1/2 (divide by zero in nv50_disp_super_2_2_dp() when the DP link
is not trained) is not in his series and still applies: it protects nvkm
itself, whatever the DRM side does, and it is tagged for stable. I can
resend it alone if that is easier.

I tested his series on a Quadro 600 (GF108, no GSP-RM) and will reply
in his thread with the results.

Frédéric

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/2] drm/nouveau: fix crash when DP link training fails
@ 2026-11-23 16:33   ` Frédéric Mahé
  0 siblings, 0 replies; 9+ messages in thread
From: Frédéric Mahé @ 2026-11-23 16:33 UTC (permalink / raw)
  To: nouveau; +Cc: dri-devel, Lyude Paul, Danilo Krummrich, David R . Hedges

Hi,

After sending this I found David Hedges' series "drm/nouveau: recover
DP links the sink drops after waking" (Cc'd). His patch 1/5 does what my
patch 2/2 does, more completely, and touches the same function, so I am
dropping 2/2 in favour of his. That also covers the points the Sashiko
review raised on 2/2 (the check only ran when mode_changed and active
were both set).

Patch 1/2 (divide by zero in nv50_disp_super_2_2_dp() when the DP link
is not trained) is not in his series and still applies: it protects nvkm
itself, whatever the DRM side does, and it is tagged for stable. I can
resend it alone if that is easier.

I tested his series on a Quadro 600 (GF108, no GSP-RM) and will reply
in his thread with the results.

Frédéric

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-24  8:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 10:16 [PATCH 0/2] drm/nouveau: fix crash when DP link training fails Frédéric Mahé
2026-11-23 10:16 ` Frédéric Mahé
2026-11-23 10:16 ` [PATCH 1/2] drm/nouveau/disp/nv50-: don't divide by zero when the DP link is not trained Frédéric Mahé
2026-11-23 10:16   ` Frédéric Mahé
2026-11-23 10:16 ` [PATCH 2/2] drm/nouveau/dispnv50: reject DP modes that don't fit the link Frédéric Mahé
2026-11-23 10:16   ` Frédéric Mahé
2026-11-23 14:30   ` sashiko-bot
2026-11-23 16:33 ` [PATCH 0/2] drm/nouveau: fix crash when DP link training fails Frédéric Mahé
2026-11-23 16:33   ` Frédéric Mahé

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.