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 4/4] drm/amdgpu: Use high priority scheduler workqueue for high priority rings
Date: Mon, 30 Nov 2026 16:26:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-241580@kernel.org> (raw)
In-Reply-To: <20261130161016.64542-5-tvrtko.ursulin@igalia.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/amdgpu: sched_wq workqueue leak when drm_sched_init() is
  not called
- [Medium] drm/amdgpu: leak of ring->fence_drv.fences on
  amdgpu_ring_init() failure
--

commit 9a9b2f95cd45c2fb7c2ee758afeb1983b998825f
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

drm/amdgpu: Use high priority scheduler workqueue for high priority rings

This commit allocates a dedicated ordered submit workqueue per ring in
amdgpu_ring_init() (using WQ_HIGHPRI for high-priority rings), passes it to
drm_sched_init(), and destroys it in amdgpu_fence_driver_sw_fini().

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> index d0a6901532fd6..1984e31627bbc 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c
> @@ -593,8 +593,10 @@ void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev)
>  		 * The natural check would be sched.ready, which is
>  		 * set as drm_sched_init() finishes...
>  		 */
> -		if (ring->sched.ops)
> +		if (ring->sched.ops) {
>  			drm_sched_fini(&ring->sched);
> +			destroy_workqueue(ring->sched_wq);
> +		}
>  
>  		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
>  			dma_fence_put(ring->fence_drv.fences[j]);

[Severity: Medium]
Can gating destroy_workqueue(ring->sched_wq) on ring->sched.ops leak
ring->sched_wq when drm_sched_init() is never called for the ring?

amdgpu_ring_init() allocates ring->sched_wq during IP block sw_init, while
ring->sched.ops is only populated later by amdgpu_device_init_schedulers()
at the end of amdgpu_device_ip_init().  On SR-IOV VFs with VCN 3.0,
vcn_v3_0_hw_init() runs in between and sets ring->no_scheduler = true for
hypervisor-disabled rings:

drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c:vcn_v3_0_hw_init() {
    ...
			if (amdgpu_vcn_is_disabled_vcn(adev, VCN_DECODE_RING, i)) {
				ring->sched.ready = false;
				ring->no_scheduler = true;
				dev_info(adev->dev, "ring %s is disabled by hypervisor\n", ring->name);
			}
    ...
}

amdgpu_device_init_schedulers() then skips the ring, leaving
ring->sched.ops NULL (the same happens if amdgpu_device_ip_init() fails
before amdgpu_device_init_schedulers() finishes), and neither
amdgpu_fence_driver_sw_fini() nor amdgpu_ring_fini() destroys
ring->sched_wq.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> index 2a96cb7d891b5..3fb4b5340ef52 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> @@ -352,6 +352,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
>  	if (!ring->no_scheduler && ring->funcs->type < AMDGPU_HW_IP_NUM) {
>  		struct amdgpu_sched *gpu_sched =
>  			&adev->gpu_sched[ring->funcs->type][hw_prio];
> +		unsigned int flags = WQ_MEM_RECLAIM;
> +
> +		if (hw_prio > AMDGPU_RING_PRIO_DEFAULT)
> +			flags |= WQ_HIGHPRI;
> +
> +		ring->sched_wq = alloc_ordered_workqueue(ring->name, flags);
> +		if (!ring->sched_wq) {
> +			r = -ENOMEM;
> +			goto err;
> +		}
>  
>  		gpu_sched->sched[gpu_sched->num_scheds++] = &ring->sched;
>  	}

[Severity: Medium]
Does jumping to err when alloc_ordered_workqueue() fails leak
ring->fence_drv.fences?

amdgpu_fence_driver_init_ring() allocates ring->fence_drv.fences at the
start of amdgpu_ring_init(), but ring is only added to adev->rings[] after
alloc_ordered_workqueue() succeeds:

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:amdgpu_ring_init() {
    ...
	ring->idx = adev->num_rings++;
	adev->rings[ring->idx] = ring;

	return 0;

err:
	amdgpu_ring_fini(ring);
	return r;
}

amdgpu_ring_fini() does not free ring->fence_drv.fences, and
amdgpu_fence_driver_sw_fini() only walks adev->rings[], so the fences array
is leaked whenever amdgpu_ring_init() fails via err.

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

  reply	other threads:[~2026-11-30 16:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:10 [RFC 0/4] Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin
2026-11-30 16:10 ` [RFC 1/4] drm/amdgpu: Free trail_fence_offs when freeing rings Tvrtko Ursulin
2026-11-30 16:10 ` [RFC 2/4] drm/amdgpu: Cleanup on ring failure Tvrtko Ursulin
2026-11-30 16:32   ` sashiko-bot
2026-11-30 16:10 ` [RFC 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init() Tvrtko Ursulin
2026-11-30 16:28   ` sashiko-bot
2026-11-30 16:10 ` [RFC 4/4] drm/amdgpu: Use high priority scheduler workqueue for high priority rings Tvrtko Ursulin
2026-11-30 16:26   ` sashiko-bot [this message]
2026-11-30 19:50 ` [RFC 0/4] " 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-241580@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