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.

Record in the channel group which engines reported a fault for it.  The
recovery pass that takes the group from pending to running collects
that mask, and resets those engines regardless of what their status
says.  Resetting GR may discard the context being switched in, but that
is far better than losing the GPU.

Faults reported for a group whose recovery is already running are
recorded but never acted on: as before, such a group is not recovered
again, and keeping the mask with the group means a later recovery of
another group cannot reset an engine on its behalf.

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 (17 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")
Cc: [email protected]
Signed-off-by: Frédéric Mahé <[email protected]>
---
v2: keep the faulting engines in the channel group (cgrp->rc_engm)
instead of a per-engine flag, and consume them only in the recovery
pass that takes that group into recovery.  v1 could leave the flag set
when a second fault arrived for a group already in recovery, so that a
later recovery of another group would reset the engine; it could also
let a pass already in progress reset an engine for a group whose
channels it had not removed yet.  Both reported by the Sashiko review of
v1.  rc_engm is initialised explicitly, as nvkm_cgrp_new() uses kmalloc.
v2 was tested again on the Quadro 600 (GF108): the piglit test above
recovered 20 of 20 faults (17 in the state above); "nv-mmu-fault -e
noctx" (below) recovered 60 of 60 runs, plus 20 of 20 with fifo debug
output, where GR was reset every time through the new mask (its status
held no valid context); "-e gr" under load recovered 2 x 40 of 40.  No
runlist timeouts.  The NVS 315 numbers are from v1.
v1: 
https://lore.kernel.org/nouveau/[email protected]/

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/cgrp.c  |  1 +
 drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h  |  1 +
 drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c | 11 +++++++++--
 drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c  | 15 ++++++++++++---
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.c
index 7e2d5711a..93b79bcaf 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.c
@@ -241,6 +241,7 @@ nvkm_cgrp_new(struct nvkm_runl *runl, const char *name, 
struct nvkm_vmm *vmm, bo
        INIT_LIST_HEAD(&cgrp->vctxs);
        mutex_init(&cgrp->mutex);
        atomic_set(&cgrp->rc, NVKM_CGRP_RC_NONE);
+       atomic_set(&cgrp->rc_engm, 0);
 
        if (runl->cgid) {
                cgrp->id = nvkm_chid_get(runl->cgid, cgrp);
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h 
b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h
index 5f6abd59a..e7e6abe9e 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h
@@ -50,6 +50,7 @@ struct nvkm_cgrp {
 #define NVKM_CGRP_RC_PENDING 1
 #define NVKM_CGRP_RC_RUNNING 2
        atomic_t rc;
+       atomic_t rc_engm; /* engines that faulted on the group, reset during 
its RC */
 
        struct list_head head;
 };
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c
index e4a4fad2e..b12f7d396 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c
@@ -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 && engn->runl == chan->cgrp->runl && 
!WARN_ON(engn->id >= 32))
+                       atomic_or(BIT(engn->id), &chan->cgrp->rc_engm);
                nvkm_runl_rc_cgrp(chan->cgrp);
+       }
 
        nvkm_chan_put(&chan, flags);
 }
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c 
b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c
index 209252105..daddc2080 100644
--- a/drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c
+++ b/drivers/gpu/drm/nouveau/nvkm/engine/fifo/runl.c
@@ -63,6 +63,7 @@ nvkm_runl_rc(struct nvkm_runl *runl)
        struct nvkm_engn *engn;
        unsigned long flags;
        int rc, state, i;
+       u32 engm = 0;
        bool reset;
 
        /* Runlist is blocked before scheduling recovery - fetch count. */
@@ -75,6 +76,9 @@ nvkm_runl_rc(struct nvkm_runl *runl)
        nvkm_runl_foreach_cgrp_safe(cgrp, gtmp, runl) {
                state = atomic_cmpxchg(&cgrp->rc, NVKM_CGRP_RC_PENDING, 
NVKM_CGRP_RC_RUNNING);
                if (state == NVKM_CGRP_RC_PENDING) {
+                       /* Collect the engines that reported a fault for the 
group. */
+                       engm |= atomic_xchg(&cgrp->rc_engm, 0);
+
                        /* Disable all channels in them, and remove from 
runlist. */
                        nvkm_cgrp_foreach_chan_safe(chan, ctmp, cgrp) {
                                nvkm_chan_error(chan, false);
@@ -99,14 +103,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 = engn->id < 32 && (engm & BIT(engn->id));
+
                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;
-- 
2.53.0

Reply via email to