From: sashiko-bot@kernel.org
To: "Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
amd-gfx@lists.freedesktop.org
Subject: Re: [RFC v3 2/4] drm/amdgpu: Cleanup on ring failure
Date: Tue, 01 Dec 2026 16:02:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-243632@kernel.org> (raw)
In-Reply-To: <20261201154232.78320-3-tvrtko.ursulin@igalia.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: NULL deref and double fini in
amdgpu_fence_driver_fini_ring()
--
commit 189f0a18b562d59559b39f2a462dcfb86a6bfab5
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
drm/amdgpu: Cleanup on ring failure
This commit updates amdgpu_ring_init() and amdgpu_ring_fini() to clean up
allocated writeback slots, buffer objects, and the fence driver when ring
initialization fails, introducing amdgpu_fence_driver_fini_ring().
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index d0a6901532fd6..1f1c28b200ffa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -577,31 +577,43 @@ void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop)
> }
> }
>
> -void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev)
> +/**
> + * amdgpu_fence_driver_fini_ring - fini the fence driver
> + * for the requested ring.
> + *
> + * @ring: ring to fini the fence driver on
> + *
> + * Cleanup the fence driver for the requested ring (all asics).
> + */
> +void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)
> {
> - unsigned int i, j;
> + unsigned int i;
>
> - for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
> - struct amdgpu_ring *ring = adev->rings[i];
> + if (!ring)
> + return;
>
> - if (!ring || !ring->fence_drv.initialized)
> - continue;
> + /*
> + * Notice we check for sched.ops since there's some
> + * override on the meaning of sched.ready by amdgpu.
> + * The natural check would be sched.ready, which is
> + * set as drm_sched_init() finishes...
> + */
> + if (ring->sched.ops)
> + drm_sched_fini(&ring->sched);
>
> - /*
> - * Notice we check for sched.ops since there's some
> - * override on the meaning of sched.ready by amdgpu.
> - * The natural check would be sched.ready, which is
> - * set as drm_sched_init() finishes...
> - */
> - if (ring->sched.ops)
> - drm_sched_fini(&ring->sched);
> -
> - for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
> - dma_fence_put(ring->fence_drv.fences[j]);
> - kfree(ring->fence_drv.fences);
> - ring->fence_drv.fences = NULL;
> - ring->fence_drv.initialized = false;
> - }
> + for (i = 0; i <= ring->fence_drv.num_fences_mask; ++i)
> + dma_fence_put(ring->fence_drv.fences[i]);
> + kfree(ring->fence_drv.fences);
> + ring->fence_drv.fences = NULL;
> + ring->fence_drv.initialized = false;
> +}
[Severity: High]
Can amdgpu_fence_driver_fini_ring() dereference a NULL
ring->fence_drv.fences pointer?
In amdgpu_ring_init(), ring->adev and adev->rings[ring->idx] are populated
before calling amdgpu_fence_driver_init_ring(), which sets
ring->fence_drv.num_fences_mask before allocating ring->fence_drv.fences:
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:amdgpu_fence_driver_init_ring() {
...
ring->fence_drv.num_fences_mask = ring->num_hw_submission * 2 - 1;
spin_lock_init(&ring->fence_drv.lock);
ring->fence_drv.fences = kzalloc_objs(*ring->fence_drv.fences,
ring->num_hw_submission * 2);
if (!ring->fence_drv.fences)
return -ENOMEM;
...
}
Because amdgpu_fence_driver_fini_ring() drops the
!ring->fence_drv.initialized check and loops with i <= num_fences_mask
without checking whether ring->fence_drv.fences is non-NULL, an allocation
failure in amdgpu_fence_driver_init_ring() leaves the ring registered in
adev->rings[] with fences == NULL, causing a NULL pointer dereference at
ring->fence_drv.fences[0] during subsequent teardown.
In addition, amdgpu_fence_driver_fini_ring() leaves num_fences_mask and
ring->sched.ops set after freeing ring->fence_drv.fences, so calling it a
second time on the same ring (for instance, when both amdgpu_ring_fini()
and amdgpu_fence_driver_sw_fini() run on a ring) will call drm_sched_fini()
twice and dereference NULL at ring->fence_drv.fences[0].
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201154232.78320-1-tvrtko.ursulin@igalia.com?part=2
next prev parent reply other threads:[~2026-12-01 16:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:42 [RFC v3 0/4] Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin
2026-12-01 15:42 ` [RFC v3 1/4] drm/amdgpu: Free trail_fence_offs when freeing rings Tvrtko Ursulin
2026-12-01 15:42 ` [RFC v3 2/4] drm/amdgpu: Cleanup on ring failure Tvrtko Ursulin
2026-12-01 16:02 ` sashiko-bot [this message]
2026-12-01 15:42 ` [RFC v3 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init() Tvrtko Ursulin
2026-12-01 15:57 ` sashiko-bot
2026-12-01 15:42 ` [RFC v3 4/4] drm/amdgpu: Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin
2026-12-01 15:56 ` 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=sashiko-outbox-243632@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tvrtko.ursulin@igalia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox