From: sashiko-bot@kernel.org
To: "Marek Czernohous" <mczernohous@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v4 2/3] drm/nouveau: don't kill a fence context that is not ready yet
Date: Fri, 21 Aug 2026 15:35:46 +0000 [thread overview]
Message-ID: <20260821153546.EAA0E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <178732578167.167481.4590474568281802870@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] The newly introduced `ready` flag check can be bypassed because `chan->fence` is published without a release barrier by the backend allocators, allowing a concurrent `nouveau_channel_kill()` to observe pre-initialization garbage.
- [High] A concurrent channel kill event can trigger a Use-After-Free if fence context initialization fails because the kill event is armed prior to full initialization.
--
--- Patch [2]: [PATCH v4 2/3] drm/nouveau: don't kill a fence context that is not ready yet ---
commit 566dba46ab74848a1cc990a88e4d8e18c316f52d
Author: Marek Czernohous <mczernohous@gmail.com>
drm/nouveau: don't kill a fence context that is not ready yet
This commit introduces a ready flag to the fence context to prevent the
kill handler from taking an uninitialized lock. It uses smp_store_release()
and smp_load_acquire() to hand over the context safely once it is fully
built. A channel killed during initialization is recorded and processed
once armed.
> diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouveau/nouveau_chan.c
> --- a/drivers/gpu/drm/nouveau/nouveau_chan.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_chan.c
> @@ -43,9 +43,17 @@ module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400);
> void
> nouveau_channel_kill(struct nouveau_channel *chan)
> {
> + struct nouveau_fence_chan *fctx;
> +
> atomic_set(&chan->killed, 1);
> - if (chan->fence)
> - nouveau_fence_context_kill(chan->fence, -ENODEV);
> +
> + /* Pairs with the smp_mb() in nouveau_fence_context_arm(). */
> + smp_mb();
> +
> + fctx = READ_ONCE(chan->fence);
> + /* Pairs with the smp_store_release() there. */
> + if (fctx && smp_load_acquire(&fctx->ready))
[Severity: High]
This is a pre-existing issue, but can we read pre-initialization garbage
for fctx->ready here?
Because chan->fence is published by backend allocators with a plain store
(e.g., chan->fence = kzalloc_obj(*fctx)), on weakly-ordered architectures,
this READ_ONCE() might observe the pointer before the allocator's zeroing
stores are visible. The smp_load_acquire() on fctx->ready doesn't prevent
reading pre-initialization garbage for the ready flag itself.
If ready is read as non-zero garbage, the kill handler would proceed to
acquire an uninitialized spinlock, potentially causing a kernel panic.
> + nouveau_fence_context_kill(fctx, -ENODEV);
> }
[ ... ]
> @@ -494,7 +502,12 @@ nouveau_channel_init(struct nouveau_channel *chan, u32 vram, u32 gart)
> }
>
> /* initialise synchronisation */
> - return nouveau_fence(drm)->context_new(chan);
> + ret = nouveau_fence(drm)->context_new(chan);
> + if (ret)
> + return ret;
[Severity: High]
This isn't a bug introduced by this patch, but could this error path lead
to a use-after-free if a concurrent channel kill event fires?
Earlier in nouveau_channel_init(), the kill event is armed:
drivers/gpu/drm/nouveau/nouveau_chan.c:nouveau_channel_init() {
...
if (ret == 0)
ret = nvif_event_allow(&chan->kill);
...
}
If context_new() fails (e.g., due to VMA allocation failure), it cleans up
by freeing the fence context. If a hardware kill event fires concurrently,
nouveau_channel_kill() might read chan->fence before the error path clears
it. This would lead to a use-after-free when smp_load_acquire(&fctx->ready)
is evaluated on the freed pointer in the asynchronous kill handler.
> +
> + nouveau_fence_context_arm(chan);
> + return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/178732578167.167481.5619512544301226563@gmail.com?part=2
next prev parent reply other threads:[~2026-08-21 15:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-21 15:23 [PATCH v4 0/3] drm/nouveau: channel-kill event ordering fixes, and lower the gate to NV50 Marek Czernohous
2026-08-21 15:23 ` Marek Czernohous
2026-08-21 15:23 ` [PATCH v4 1/3] drm/nouveau: unsubscribe the channel-kill event before the fence context Marek Czernohous
2026-08-21 15:23 ` Marek Czernohous
2026-08-21 15:35 ` sashiko-bot
2026-08-21 15:23 ` [PATCH v4 2/3] drm/nouveau: don't kill a fence context that is not ready yet Marek Czernohous
2026-08-21 15:23 ` Marek Czernohous
2026-08-21 15:35 ` sashiko-bot [this message]
2026-08-21 15:23 ` [PATCH v4 3/3] drm/nouveau: subscribe to channel-kill events on NV50 and newer Marek Czernohous
2026-08-21 15:23 ` Marek Czernohous
2026-08-21 15:33 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260821153546.EAA0E1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=mczernohous@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.