AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [RFC v2 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init()
Date: Tue, 01 Dec 2026 11:01:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-243111@kernel.org> (raw)
In-Reply-To: <20261201103953.74817-4-tvrtko.ursulin@igalia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: invalid writeback slot 0 free after
  amdgpu_ring_init() failure
--

commit 2f4b28cebbd5fafa9eaae6b7dedcf51f49d518ac
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

drm/amdgpu: Unconfuse amdgpu_ring_init()

This commit removes the ring->adev == NULL check in amdgpu_ring_init() and
defers registering the ring in adev->rings[] until initialization succeeds.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> index 2a2b4c39c2892..f82352078646b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> @@ -217,6 +217,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
>  	unsigned int max_ibs_dw;
>  	int r;
>  
> +	if (adev->num_rings >= AMDGPU_MAX_RINGS)
> +		return -EINVAL;
> +
>  	/* Set the hw submission limit higher for KIQ because
>  	 * it's used for a number of gfx/compute tasks by both
>  	 * KFD and KGD which may have outstanding fences and
> @@ -230,21 +233,13 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
>  	else if (ring == &adev->sdma.instance[0].page)
>  		sched_hw_submission = 256;
>  
> -	if (ring->adev == NULL) {
> -		if (adev->num_rings >= AMDGPU_MAX_RINGS)
> -			return -EINVAL;
> -
> -		ring->adev = adev;
> -		ring->num_hw_submission = sched_hw_submission;
> -		ring->sched_score = sched_score;
> -
> -		ring->idx = adev->num_rings++;
> -		adev->rings[ring->idx] = ring;
> +	ring->adev = adev;
> +	ring->num_hw_submission = sched_hw_submission;
> +	ring->sched_score = sched_score;
>  
> -		r = amdgpu_fence_driver_init_ring(ring);
> -		if (r)
> -			return r;
> -	}
> +	r = amdgpu_fence_driver_init_ring(ring);
> +	if (r)
> +		return r;
>  
>  	ring->rptr_offs = AMDGPU_RING_WB_INVALID;
>  	ring->wptr_offs = AMDGPU_RING_WB_INVALID;

[ ... ]

> @@ -386,8 +384,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
>  void amdgpu_ring_fini(struct amdgpu_ring *ring)
>  {
>  
> -	/* Not to finish a ring which is not initialized */
> -	if (!(ring->adev) || !(ring->adev->rings[ring->idx]))
> +	if (!ring->adev)
>  		return;

[Severity: Medium]
Can this free writeback slot 0 belonging to another ring when
amdgpu_fence_driver_init_ring() fails?

If amdgpu_fence_driver_init_ring() returns an error, amdgpu_ring_init()
returns early with ring->adev set and the five writeback offsets
(rptr_offs, wptr_offs, fence_offs, trail_fence_offs, and cond_exe_offs)
still zero-initialized rather than set to AMDGPU_RING_WB_INVALID.  When
teardown later calls amdgpu_ring_fini() (for example via
amdgpu_device_ip_fini() -> amdgpu_cper_fini()), it now passes the
!ring->adev check and calls amdgpu_wb_free(ring->adev, 0) for each offset.

Resetting ring->adev = NULL before returning on
amdgpu_fence_driver_init_ring() failure would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201103953.74817-1-tvrtko.ursulin@igalia.com?part=3

  reply	other threads:[~2026-12-01 11:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 10:39 [RFC v2 0/4] Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin
2026-12-01 10:39 ` [RFC v2 1/4] drm/amdgpu: Free trail_fence_offs when freeing rings Tvrtko Ursulin
2026-12-01 10:39 ` [RFC v2 2/4] drm/amdgpu: Cleanup on ring failure Tvrtko Ursulin
2026-12-01 10:57   ` sashiko-bot
2026-12-01 10:39 ` [RFC v2 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init() Tvrtko Ursulin
2026-12-01 11:01   ` sashiko-bot [this message]
2026-12-01 10:39 ` [RFC v2 4/4] drm/amdgpu: Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin

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-243111@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