Skip to contentSkip to conversation

drm/nouveau/clk: fix RAM error handling and pstate desync in nvkm_pstate_prog

PATCH In review Francesco Magazzu 2 participants 8 messages Jul 27 – Oct 26

lore
Share & tools
lore
#0 lore raw

cover drm/nouveau/clk: fix RAM error handling and pstate desync in nvkm_pstate_prog

Follow-up to "[PATCH v2 0/4] drm/nouveau: fix list cursor use after loop in the clk pstate paths" ([email protected]). Sashiko AI review flagged three pre-existing issues while reviewing patch 2/4 of that series; the third (clk->func->prog()'s error being clobbered by nvkm_volt_set_id() in nvkm_cstate_prog()) is already fixed by patch 4/4 of that series. These two patches address the other two:

1. nvkm_pstate_prog() drops the RAM reclock error and falls through to core clock programming anyway.
2. nvkm_pstate_prog() commits clk->pstate to the new state before the hardware transition has actually succeeded.

Francesco Magazzu (2):
drm/nouveau/clk: don't ignore RAM clock programming errors in
nvkm_pstate_prog
drm/nouveau/clk: only update clk->pstate after hardware programming
succeeds

 nvkm/subdev/clk/base.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/2 drm/nouveau/clk: don't ignore RAM clock programming errors in nvkm_pstate_prog

The RAM reclock loop discards its own return value: once the do-while exits, ram->func->tidy() runs and the function falls straight into nvkm_cstate_prog(), whose result becomes the return value regardless of whether ram->func->calc()/prog() failed. A negative ret from RAM programming is silently dropped, so a failed memory clock transition is never reported and the core clock still gets reprogrammed on top of it.

Return the RAM error (after tidy() has still run) instead of falling through to the core clock path.

Found by Sashiko AI review (https://sashiko.dev) while reviewing "[PATCH v2 2/4] drm/nouveau/clk: don't use the pstate cursor after the loop" ([email protected]) as a pre-existing issue.

---
 nvkm/subdev/clk/base.c | 2 ++
 1 file changed, 2 insertions(+)
nvkm/subdev/clk/base.c +2 -0
index 44dc86b..737bec8 100644
@@ -298,6 +298,8 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 				ret = ram->func->prog(ram);
 		} while (ret > 0);
 		ram->func->tidy(ram);
+		if (ret < 0)
+			return ret;
 	}
 
 	return nvkm_cstate_prog(clk, pstate, NVKM_CLK_CSTATE_HIGHEST);
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 drm/nouveau/clk: only update clk->pstate after hardware programming succeeds

In reply to Francesco Magazzu

nvkm_pstate_prog() wrote clk->pstate = pstatei before attempting the RAM and core clock reprogramming. If either step failed, the software state tracker had already committed to the new pstate even though the hardware transition never completed, and a later re-request for that same state could be skipped (pstate != clk->pstate would be false), leaving the hardware stuck out of sync with what the driver believes it's running.

Move the assignment to after nvkm_cstate_prog() returns, and only commit it on success.

Found by Sashiko AI review (https://sashiko.dev) while reviewing "[PATCH v2 2/4] drm/nouveau/clk: don't use the pstate cursor after the loop" ([email protected]) as a pre-existing issue.

---
 nvkm/subdev/clk/base.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
nvkm/subdev/clk/base.c +5 -2
index 737bec8..91c51d4 100644
@@ -285,7 +285,6 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 		return -EINVAL;
 
 	nvkm_debug(subdev, "setting performance state %d\n", pstatei);
-	clk->pstate = pstatei;
 
 	nvkm_pcie_set_link(pci, pstate->pcie_speed, pstate->pcie_width);
 
@@ -302,7 +301,11 @@ nvkm_pstate_prog(struct nvkm_clk *clk, int pstatei)
 			return ret;
 	}
 
-	return nvkm_cstate_prog(clk, pstate, NVKM_CLK_CSTATE_HIGHEST);
+	ret = nvkm_cstate_prog(clk, pstate, NVKM_CLK_CSTATE_HIGHEST);
+	if (ret == 0)
+		clk->pstate = pstatei;
+
+	return ret;
 }
 
 static void
Signature · 1 line
2.55.0
#3 lore raw
In reply to Francesco Magazzu

Note: this series applies on top of my earlier "[PATCH v2 0/4] drm/nouveau: fix list cursor use after loop in the clk pstate paths" ([email protected], sent 2026-07-12), not on a clean tree -- patch 2/2 here touches the same nvkm_pstate_prog() that v2's patch 2/4 modifies.

Both patches fix pre-existing issues an automated review (Sashiko) found in v2's patch 2/4 while reviewing it: nvkm_pstate_prog() silently discarding RAM clock programming errors, and clk->pstate being updated before hardware programming actually succeeds. Neither bug was introduced by v2 itself.

If it's easier to review as one unit, happy to resend as a v3 of the original series with these two folded in -- let me know what you'd prefer.

Francesco

Reviewed-by on the v1 series
#4 lore raw
In reply to Francesco Magazzu

For the whole series:

Will push to drm-misc-fixes in just a moment

Quoted 27 lines · Francesco Magazzu

Follow-up to "[PATCH v2 0/4] drm/nouveau: fix list cursor use after loop
in the clk pstate paths" ([email protected]). Sashiko AI review flagged three pre-existing issues while reviewing patch
2/4 of that series; the third (clk->func->prog()'s error being clobbered
by nvkm_volt_set_id() in nvkm_cstate_prog()) is already fixed by patch 4/4
of that series. These two patches address the other two:

  1. nvkm_pstate_prog() drops the RAM reclock error and falls through to
     core clock programming anyway.
  2. nvkm_pstate_prog() commits clk->pstate to the new state before the
     hardware transition has actually succeeded.

Francesco Magazzu (2):
  drm/nouveau/clk: don't ignore RAM clock programming errors in nvkm_pstate_prog
  drm/nouveau/clk: only update clk->pstate after hardware programming succeeds

 nvkm/subdev/clk/base.c | 9 +++++++--

 1 file changed, 7 insertions(+), 2 deletions(-)
#5 lore raw

Well, I -would- have pushed it but then I quickly realized I reviewed these patches in the wrong order, whoops :).

Just consider these reviewed, will push once the series this depends on is all good to go

Quoted 36 lines · On Thu, 2026-09-17 at 16:51 -0400, [email protected] wrote:

For the whole series:

Will push to drm-misc-fixes in just a moment

Quoted 29 lines · Francesco Magazzu

Follow-up to "[PATCH v2 0/4] drm/nouveau: fix list cursor use after loop
in the clk pstate paths" ([email protected]). Sashiko AI review flagged three pre-existing issues while reviewing patch
2/4 of that series; the third (clk->func->prog()'s error being clobbered
by nvkm_volt_set_id() in nvkm_cstate_prog()) is already fixed by patch 4/4
of that series. These two patches address the other two:

  1. nvkm_pstate_prog() drops the RAM reclock error and falls through
to
     core clock programming anyway.
  2. nvkm_pstate_prog() commits clk->pstate to the new state before the
     hardware transition has actually succeeded.

Francesco Magazzu (2):
  drm/nouveau/clk: don't ignore RAM clock programming errors in nvkm_pstate_prog
  drm/nouveau/clk: only update clk->pstate after hardware programming
    succeeds

 nvkm/subdev/clk/base.c | 9 +++++++--

 1 file changed, 7 insertions(+), 2 deletions(-)
#6 lore raw

Re: [PATCH 1/2] drm/nouveau/clk: don't ignore RAM clock programming errors in nvkm_pstate_prog

In reply to Francesco Magazzu

Hi Lyude,

Gentle ping on these two. The v3 of the cursor series is in v7.3 now, thanks for picking it up - but these two don't show up in mainline or in drm-misc-next, so I suspect they got lost after your review.

Both still apply on current mainline (one line of offset). On drm-misc-next 2/2 needs the v3 series to be there first, since its context comes from "drm/nouveau/clk: don't use the pstate cursor after the loop" - so either after the next backmerge, or I can rebase and resend, whichever is less work for you.

Thanks,
Francesco

#7 lore raw

Re: [PATCH 1/2] drm/nouveau/clk: don't ignore RAM clock programming errors in nvkm_pstate_prog

In reply to Francesco Magazzu

Hi Lyude,

Gentle ping on these two. The v3 of the cursor series is in v7.3 now, thanks for picking it up - but these two don't show up in mainline or in drm-misc-next, so I suspect they got lost after your review.

Both still apply on current mainline (one line of offset). On drm-misc-next 2/2 needs the v3 series to be there first, since its context comes from "drm/nouveau/clk: don't use the pstate cursor after the loop" - so either after the next backmerge, or I can rebase and resend, whichever is less work for you.

Thanks,
Francesco