Skip to contentSkip to conversation

drm/nouveau/fifo/gf100-: reset the faulting engine even if it switched channels

PATCH Superseded Frédéric Mahé 2 participants 3 messages Nov 26 – Nov 27

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/nouveau/fifo/gf100-: reset the faulting engine even if it switched channels

When an engine reports an MMU fault, recovery flags the faulting channel group and nvkm_runl_rc() resets only the engines whose current context (cxid) belongs to a flagged group. On Fermi the fault can be reported after GR has started switching to another channel: the engine status then reads e.g. 0x01140003 (not busy, chid 3) while channel 4 faulted, so GR is not reset, stays stalled on the fault, and the runlist update never completes:

fifo: fault 01 [WRITE] at 0 engine 00 [PGRAPH] client 0f [GPC0/PROP] reason 02 [PAGE_NOT_PRESENT] on channel 4 object-namespac[1768]: channel 4 killed!
fifo:000000:00[ gr]: 01140003: busy 0 save 1 unk0 0 unk1 0 chid 3
fifo:000000:00[ gr]: cxid not valid

  WARNING: drivers/gpu/drm/nouveau/nvkm/engine/fifo/nv50.c:228 at nv50_runl_wait+0xe8/0x100 [nouveau]
  fifo: SCHED_ERROR 0d []
  WARNING: drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c:251 at nvkm_runl_preempt_wait+0xf7/0x110 [nouveau]

After that no channel makes progress: the whole GPU is dead until a reboot, and processes using it hang in D state.

Remember which engine reported the fault, and reset it during recovery regardless of what its status says. Resetting GR may discard the context being switched in, but that is far better than losing the GPU.

Tested on a Quadro 600 (GF108): a program that faults (piglit "object-namespace-pollution glClearTexSubImage texture") while three other processes keep GR busy hangs the GPU within one to three faults without this patch. With it, 20 of 20 faults recovered (15 of them hit the state above), with no runlist timeouts, and the GPU kept working. On an NVS 315 (GF119) the same test hangs the GPU at the first fault without this patch; with it, 20 of 20 rounds completed, every fault was recovered, and the GPU kept working.

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

Fixes 4d60100a23ec ("drm/nouveau/fifo: add common channel recovery")

---
Tested on GF108 and GF119 only. gf100_fifo_mmu_fault_recover() is also used by gk104, gm107, gv100 and tu102 (non-GSP), so the change applies to those too; feedback from such hardware is welcome.

A small libdrm program reproduces this without Mesa or piglit (nv-mmu-fault.c, available on request):

nv-mmu-fault -e noctx

sends one graphics method on a channel that has no graphics object. PGRAPH's context-switch unit then faults (READ at 0, HUB/CTXCTL) while the engine status no longer names the channel. On an NVS 315 (GF119), without this patch the GPU is dead after the first run; with it, 60 of 60 runs recovered. "nv-mmu-fault -e gr" in a loop with three processes keeping PGRAPH busy gives the WRITE fault of the log above: dead at the 4th fault without the patch, 40 of 40 recovered with it.

 drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c | 11 +++++++++--
 drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c  | 11 ++++++++---
 drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.h  |  1 +
 3 files changed, 18 insertions(+), 5 deletions(-)
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c +9 -2
index e4a4fad..4f221c0 100644
@@ -597,9 +597,16 @@ gf100_fifo_mmu_fault_recover(struct nvkm_fifo *fifo, struct nvkm_fault_data *inf
 		   info->reason, er ? er->name : "",
 		   chan ? chan->id : -1, info->inst, chan ? chan->name : "unknown");
 
-	/* Handle host/engine faults. */
-	if (chan)
+	/* Handle host/engine faults.  The engine that reported the fault must
+	 * be reset even if it has already switched to another channel (its
+	 * status then no longer points at the faulting channel), otherwise it
+	 * stays stalled and the runlist update never completes.
+	 */
+	if (chan) {
+		if (engine)
+			atomic_set(&engn->rc_reset, 1);
 		nvkm_runl_rc_cgrp(chan->cgrp);
+	}
 
 	nvkm_chan_put(&chan, flags);
 }
drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c +8 -3
index 2092521..76fabe8 100644
@@ -99,14 +99,19 @@ nvkm_runl_rc(struct nvkm_runl *runl)
 
 	/* Look for engines that are still on flagged channel groups - reset them. */
 	nvkm_runl_foreach_engn_cond(engn, runl, engn->func->cxid) {
+		bool faulted = atomic_xchg(&engn->rc_reset, 0);
+
 		cgrp = nvkm_engn_cgrp_get(engn, &flags);
-		if (!cgrp) {
+		if (!cgrp && !faulted) {
 			ENGN_DEBUG(engn, "cxid not valid");
 			continue;
 		}
 
-		reset = atomic_read(&cgrp->rc) == NVKM_CGRP_RC_RUNNING;
-		nvkm_cgrp_put(&cgrp, flags);
+		reset = faulted;
+		if (cgrp) {
+			reset |= atomic_read(&cgrp->rc) == NVKM_CGRP_RC_RUNNING;
+			nvkm_cgrp_put(&cgrp, flags);
+		}
 		if (!reset) {
 			ENGN_DEBUG(engn, "cxid not in recovery");
 			continue;
drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.h +1 -0
index 19e6772..08ba44d 100644
@@ -28,6 +28,7 @@ struct nvkm_engn {
 	struct nvkm_engine *engine;
 
 	int fault;
+	atomic_t rc_reset; /* engine reported a fault: reset it during RC */
 
 	struct {
 		u32 desc;
Signature · 1 line
2.53.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/nouveau/fifo: unsynchronized engn->rc_reset in gf100_fifo_mmu_fault_recover() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/nouveau/fifo: unsynchronized engn->rc_reset in gf100_fifo_mmu_fault_recover()
--

commit c25dc87b435d54f44150db91d3c558d0942a3224
Author: Frédéric Mahé <[email protected]>

drm/nouveau/fifo/gf100-: reset the faulting engine even if it switched channels

This commit records when an engine reports an MMU fault in engn->rc_reset and resets that engine during runlist recovery even if its current context no longer points to the faulting channel group.

Quoted 13 lines
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c +3 -2
index e4a4fad2eafce..4f221c0b23fa6 100644
@@ -597,9 +597,16 @@ gf100_fifo_mmu_fault_recover(struct nvkm_fifo *fifo, struct nvkm_fault_data *inf
 		   info->reason, er ? er->name : "",
 		   chan ? chan->id : -1, info->inst, chan ? chan->name : "unknown");
 
-	/* Handle host/engine faults. */
-	if (chan)
+	/* Handle host/engine faults.  The engine that reported the fault must
+	 * be reset even if it has already switched to another channel (its
+	 * status then no longer points at the faulting channel), otherwise it

drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c gf100_fifo_mmu_fault_recover(struct nvkm_fifo *fifo, struct nvkm_fault_data *inf · line 612

Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c +6 -0
+	 * stays stalled and the runlist update never completes.
+	 */
+	if (chan) {
+		if (engine)
+			atomic_set(&engn->rc_reset, 1);
 		nvkm_runl_rc_cgrp(chan->cgrp);
+	}
 
 	nvkm_chan_put(&chan, flags);
 }

[Severity: High]
Can setting engn->rc_reset before nvkm_runl_rc_cgrp() leave a stale rc_reset flag armed when cgrp->rc has already left NVKM_CGRP_RC_NONE?

nvkm_runl_rc_cgrp() only schedules recovery when cgrp->rc transitions from NVKM_CGRP_RC_NONE to NVKM_CGRP_RC_PENDING, and cgrp->rc stays at NVKM_CGRP_RC_RUNNING once recovery starts while the channel remains in runl->chid until userspace closes it. If a faulting channel generates more than one MMU fault entry (for example, multiple fault buffer entries drained by gv100_fault_buffer_process() or a second fault interrupt before the engine is reset), the second call sets engn->rc_reset = 1 while nvkm_runl_rc_cgrp() returns early without scheduling runl->work:

CPU0 (fault handler) CPU1 (runl->work)
gf100_fifo_mmu_fault_recover()
/* fault 1 on chan A */
atomic_set(&engn->rc_reset, 1)
nvkm_runl_rc_cgrp(cgrpA)

    cgrpA->rc: NONE -> PENDING
    nvkm_runl_rc_runl()
                                  nvkm_runl_rc()
                                    cgrpA->rc: PENDING -> RUNNING
                                    ...
                                    atomic_xchg(&engn->rc_reset, 0)
                                    nvkm_engine_reset(engn->engine)

gf100_fifo_mmu_fault_recover()
/* fault 2 on chan A */
atomic_set(&engn->rc_reset, 1)
nvkm_runl_rc_cgrp(cgrpA)

    cmpxchg(cgrpA->rc) != NONE
    return;  <-- engn->rc_reset stays 1

A later recovery on the same runlist (such as a fault on another engine) will then see engn->rc_reset == 1 and reset engn while an unrelated channel is running on it.

Conversely, if a second engine in the same channel group faults after nvkm_runl_rc() has already passed the engine reset loop for the first fault, setting engn2->rc_reset = 1 followed by nvkm_runl_rc_cgrp()'s early return will never schedule another recovery pass to consume engn2->rc_reset, leaving the second engine stalled. And if an unrelated channel group cgrpB faults on engn while nvkm_runl_rc() is already past the cgrp loop (for example, waiting for PBDMA idle), the in-progress pass will consume engn->rc_reset and reset engn before cgrpB's channels have been disabled and removed from the runlist.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 3 lines · On Thu, 26 Nov 2026 18:11:26 +0000, [email protected] wrote:

[Severity: High]
Can setting engn->rc_reset before nvkm_runl_rc_cgrp() leave a stale rc_reset flag armed when cgrp->rc has already left NVKM_CGRP_RC_NONE?

Yes. A second fault for a group that is already in recovery sets the flag, nvkm_runl_rc_cgrp() schedules nothing, and the flag waits for the next recovery on that runlist, which then resets the engine on behalf of a group it is not recovering. A duplicate fault entry for one fault is the likely way to get there (fault buffer on gv100+); on Fermi I only ever saw one fault per channel kill.

Quoted 3 lines

Conversely, if a second engine in the same channel group faults after nvkm_runl_rc() has already passed the engine reset loop for the first fault, [...] leaving the second engine stalled.

That case is not recovered without the patch either: the group is already in recovery, so nothing is scheduled. The patch does not make it worse, but it does not fix it.

Quoted 4 lines

And if an unrelated channel group cgrpB faults on engn while nvkm_runl_rc() is already past the cgrp loop [...] the in-progress pass will consume engn->rc_reset and reset engn before cgrpB's channels have been disabled and removed from the runlist.

Right, the flag is not tied to the pass that recovers the group.

v2 keeps the faulting engines in the channel group (a mask, rc_engm) instead of a per-engine flag. The recovery pass collects the mask of each group it moves from PENDING to RUNNING, after the cmpxchg, and only resets those engines (plus, as before, engines whose context belongs to a group in recovery). So:

- a fault for a group already in recovery only adds to that group's mask, which no later pass reads, as the group never returns to PENDING;
- a pass in progress cannot pick up the mask of a group it did not take into recovery; that group's own pass gets it after removing its channels.

The mask is written before nvkm_runl_rc_cgrp() (atomic_or, then the cmpxchg NONE -> PENDING), and read after the PENDING -> RUNNING cmpxchg, so a pass that takes the group always sees the engines that faulted before it.

v2 has been through the same tests as v1 on a Quadro 600 (GF108), with no failure (numbers in its changelog); I am sending it now.

Analysis done with the help of Claude (AI assistant).

Frédéric Mahé