drm/nouveau: fix GK107 VDPAU regressions
Subsystems (3)
cover drm/nouveau: fix GK107 VDPAU regressions
Hi,
This series fixes two independent Nouveau regressions affecting VDPAU hardware video decoding on NVIDIA GK107 (Kepler).
Patch 1 fixes engine context mappings for the legacy MSVLD, MSPDEC and MSPPP video engines. Since commit 8ab849d6dd4c ("drm/nouveau/fifo: add new engine context handling"), privileged engine context mappings cause FIFO PRIV_VIOLATION faults and kill the channel during VDPAU decoding on GK107.
Patch 2 fixes a fence/progress hang introduced by commit 55e1a5996085 ("drm/nouveau/fifo/ga100-: add per-runlist nonstall intr handling"). Legacy FIFO implementations use a single global nonstall event at index 0, while channel event registration was changed to use runl->id unconditionally. This can leave fence completion waiting for an event that is never signalled.
Tested on NVIDIA GK107 with a Linux 7.3-rc2 based drm-misc tree, Mesa 25.0.7 and mpv using VDPAU_DRIVER=nouveau and vdpau-copy.
With both patches applied:
H.264 1920x1080: PASS
MPEG-2 1920x1080: PASS
VC-1 Advanced Profile: PASS
All three tests completed using VDPAU hardware decoding. No Nouveau faults were reported in dmesg.
Thanks,
Risto
Risto Pajula (2):
drm/nouveau/fifo/gk104: fix legacy video engine context mappings drm/nouveau/fifo: use global nonstall event on legacy FIFO
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c | 14 ++++++++++++++ drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-)
Signature · 1 line
2.47.3
PATCH 1/2 drm/nouveau/fifo/gk104: fix legacy video engine context mappings
Commit 8ab849d6dd4c ("drm/nouveau/fifo: add new engine context handling") made gk104_ectx_ctor() map engine contexts privileged by default.
On GK107, mapping the legacy MSVLD, MSPDEC and MSPPP video engine contexts privileged causes FIFO PRIV_VIOLATION faults and kills the channel during VDPAU decoding.
These engines require non-privileged engine context mappings. Keep privileged mappings for the other engines, but clear the privileged flag for the legacy video engines.
--- drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c +14 -0
@@ -180,6 +180,20 @@ gk104_ectx_ctor(struct nvkm_engn *engn, struct nvkm_vctx *vctx)struct gf100_vmm_map_v0 args = { .priv =1 };int ret; +/* +* Legacy video engines access their engine contexts through +* non-privileged MMU requests. +*/ +switch (engn->engine->subdev.type) { +case NVKM_ENGINE_MSPDEC : +case NVKM_ENGINE_MSPPP : +case NVKM_ENGINE_MSVLD : + args.priv =0 ; +break ; +default : +break ; + } + ret =nvkm_vmm_get (vctx->vmm,12 , vctx->inst->size, &vctx->vma);if (ret)return ret;
Signature · 1 line
2.47.3
PATCH 2/2 drm/nouveau/fifo: use global nonstall event on legacy FIFO
In reply to Risto PajulaThe per-runlist nonstall interrupt handling change made channel nonstall event registration use the runlist ID instead of the global event index 0.
Legacy FIFO implementations do not provide a nonstall constructor. They have a single global nonstall event, and their interrupt handlers signal event index 0. Registering channel events using runl->id can therefore leave fence completion waiting for an event that is never signalled.
Use the runlist ID when per-runlist nonstall interrupts have been constructed, and keep using event index 0 for legacy FIFO implementations.
--- drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c +2 -1
@@ -52,7 +52,8 @@ nvkm_uchan_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_switch (args->v0.type) {case NVIF_CHAN_EVENT_V0_NON_STALL_INTR : -return nvkm_uevent_add (uevent, &runl->fifo->nonstall.event, runl->id, +return nvkm_uevent_add (uevent, &runl->fifo->nonstall.event, + runl->fifo->func->nonstall_ctor ? runl->id :0 ,NVKM_FIFO_NONSTALL_EVENT ,NULL );case NVIF_CHAN_EVENT_V0_KILLED : return nvkm_uevent_add(uevent, &runl->chid->event, chan->id,
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/2] drm/nouveau/fifo: use global nonstall event on legacy FIFO
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] If channel initialization fails early in nvkm_chan_new_(), the cleanup path dereferences a NULL chan->cgrp. --
commit 6a368e9f19db8e6f77b9767f67dd0d51b8625cd8
Author: Risto Pajula <[email protected]>
drm/nouveau/fifo: use global nonstall event on legacy FIFO
This commit changes the nonstall event registration to use the runlist ID only when per-runlist nonstall interrupts are supported, falling back to event index 0 for legacy FIFO implementations. This fixes an issue where fence completion waits for an event that is never signalled.
Quoted 5 lines
drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c +0
-0
drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c nvkm_uchan_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_ · line 59
Quoted 9 lines
drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c +2
-1@@ -52,7 +52,8 @@ nvkm_uchan_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_switch (args->v0.type) {case NVIF_CHAN_EVENT_V0_NON_STALL_INTR : -return nvkm_uevent_add (uevent, &runl->fifo->nonstall.event, runl->id, +return nvkm_uevent_add (uevent, &runl->fifo->nonstall.event, + runl->fifo->func->nonstall_ctor ? runl->id :0 ,NVKM_FIFO_NONSTALL_EVENT ,NULL );case NVIF_CHAN_EVENT_V0_KILLED : return nvkm_uevent_add(uevent, &runl->chid->event, chan->id,
[Severity: Critical]
This is a pre-existing issue, but while reviewing the channel handling code, I noticed a potential NULL pointer dereference if channel initialization fails early.
In drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c:nvkm_chan_new_():
ret = nvkm_cgrp_new(runl, chan->name, vmm, fifo->func->cgrp.force,
&chan->cgrp);
if (ret) {
RUNL_DEBUG(runl, "cgrp %d", ret);
return ret;
}If nvkm_cgrp_new() fails, chan->cgrp remains NULL but the error is returned to the caller while leaving the partially initialized channel allocated.
The cleanup path in nvkm_chan_del() unconditionally executes the RAMFC clear callback on the partially initialized channel object:
drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c:nvkm_chan_del() {
...
if (chan->func->ramfc->clear)
chan->func->ramfc->clear(chan);
...
}For hardware-specific implementations like nv04_chan_ramfc_clear() in drivers/gpu/drm/nouveau/nvkm/engine/fifo/nv04.c, this directly dereferences chan->cgrp:
struct nvkm_memory *ramfc =
chan->cgrp->runl->fifo->engine.subdev.device->imem->ramfc;
Could this lead to a kernel panic when a userspace program invokes the NVIF_IOCTL_NEW ioctl to create a new channel and nvkm_cgrp_new() fails? This seems reachable if a user provides an invalid channel group or during memory pressure.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Quoted 2 lines · Risto Pajula
This series fixes two independent Nouveau regressions affecting VDPAU hardware video decoding on NVIDIA GK107 (Kepler).
I ran into both regressions on a GK208B (GeForce GT 710, NV106) with VA-API and arrived at the same two fixes. Built against the same nouveau source, my versions and this series give identical machine code for gk104.o and uchan.o.
Tested on Ubuntu 26.04 (kernel 7.0.0-38) with the two changes applied to nouveau, video firmware extracted from NVIDIA 340.108, Mesa 26.0.8 with the VA-API fixes from Mesa MR !45340, and ffmpeg -hwaccel vaapi:
H.264 1920x1080: 600/600 frames identical to software decoding, 115 fps MPEG-2 1920x1080: 300 frames, 164 fps
no nouveau messages in dmesg
Without patch 1, MSVLD faults with PRIV_VIOLATION on the first frame and the channel is killed. With only patch 1, decoding blocks for 30 s in DRM_IOCTL_NOUVEAU_GEM_CPU_PREP and then fails with -EBUSY.
Patch 2 also fixes an out-of-bounds access. Without nonstall_ctor, nvkm_fifo_oneinit() creates the non-stall event with a single index, so event->refs[] has one entry, but nvkm_event_get()/nvkm_event_put() are called with index runl->id and don't check it against index_nr. The Kepler video engines are on non-zero runlists, so their channels' non-stall events increment and decrement memory past the end of refs[].
Both regressions are in stable kernels (since 6.2 and 6.6), so it may be worth adding
to both patches.
I used an AI assistant (Claude) to help debug and test this.
[email protected]
maintainerI am going to look at this patch when I have a moment, but I am in the middle of moving right now so it's likely going to take me a bit, however:
Quoted 8 lines · Kush Chandak
Quoted 3 lines · Risto Pajula
This series fixes two independent Nouveau regressions affecting VDPAU
hardware video decoding on NVIDIA GK107 (Kepler).Tested-by Kush Chandak <[email protected]>I used an AI assistant (Claude) to help debug and test this.
Please don't clog up the mailing list with this. I have seen multiple people now going through and 'testing' things with LLMs, and the reality is I'm not going to carry across the tested tags.
If you would like to test, there are plenty of resources available to figure out how to build a kernel against a patch on a mailing list to test changes. LLMs frequently hallucinate and lack an understanding of the tasks they perform. It's already difficult enough keeping up with code submissions, and given that you cannot use LLM output without both vetting it, and having the knowledge required to properly vet it, there really is nothing I can actually establish from "testing" like this. If you weren't able to actually test without using an LLM and we have established we can't trust the output of the LLM - how am I supposed to know it was tested? I can't verify it from what you gave me, and even if I could - that's just doing what is way too commonplace with these tools and offloading the work of verifying anything that it spits to others.
I have tested the patch series on NVIDIA GK104 (Kepler) using a Linux 7.2 based
drm-misc tree:
drm/nouveau/fifo/gk104: fix legacy video engine context mappings drm/nouveau/fifo: use global nonstall event on legacy FIFO
drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c | 14 ++++++++++++++ drivers/gpu/drm/nouveau/nvkm/engine/fifo/uchan.c | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-)
Tested with Mesa (including patches from
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/45340), mpv (with
VA-API), and Clapper.
With both patches applied:
- H.264 1920x1080: PASS
Thanks,
Youssef