Use high priority scheduler workqueue for high priority rings
Subsystems (2)
v3 cover Use high priority scheduler workqueue for high priority rings
Last patch is the headline item while three preceding ones are hopefully fixes for problems I stumbled upon while adding WQ_HIGHPRI. On those three more eyes are definitely required since the init paths can be tricky.
Smoke tested on the Steam Deck and no explosions.
v2:
* Lets see if I fixed the sashiko bugs.. change log in patch 2.
v3:
* Fixed more sashiko reported issues in patch 2.
Tvrtko Ursulin (4):
drm/amdgpu: Free trail_fence_offs when freeing rings drm/amdgpu: Cleanup on ring failure
drm/amdgpu: Unconfuse amdgpu_ring_init()
drm/amdgpu: Use high priority scheduler workqueue for high priority
rings
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 59 ++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 92 ++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 4 + 4 files changed, 102 insertions(+), 54 deletions(-)
Signature · 1 line
2.56.0
RFC v3 1/4 drm/amdgpu: Free trail_fence_offs when freeing rings
Looks like ring->trail_fence_offs writeback was never freed at ring destruction time. Free it in amdgpu_ring_fini() the same way as other offsets are.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -0
@@ -386,6 +386,7 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)amdgpu_wb_free (ring->adev, ring->wptr_offs);amdgpu_wb_free (ring->adev, ring->cond_exe_offs); +amdgpu_wb_free (ring->adev, ring->trail_fence_offs);amdgpu_wb_free (ring->adev, ring->fence_offs); amdgpu_bo_free_kernel(&ring->ring_obj,
Signature · 1 line
2.56.0
RFC v3 2/4 drm/amdgpu: Cleanup on ring failure
In reply to Tvrtko UrsulinCurrently if ring init fails not all, or to better say not many, objects allocated before the failure point get freed.
amdgpu_ring_fini() already somewhat handles the cleanup of partially constructed rings so lets make it handle it fully and call it when ring init fails.
This involves marking the unallocated writeback slots so only allocated ones can be freed and exporting new amdgpu_fence_driver_fini_ring() as a counterpart to existing amdgpu_fence_driver_init_ring().
---
v2:
* Cleanup the fence driver.
* Do not double free the writeback slots.
* Return -ENOMEM when ring backup allocation fails.
v3:
* Always cleanup fence_drv.
* Mark writeback slots as un-allocated earlier.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 56 +++++++++++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 57 ++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 3 ++ 3 files changed, 76 insertions(+), 40 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +34 -22
@@ -577,31 +577,43 @@ void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop) } } +/** +* 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; + +if (!ring) +return ; + +/* +* 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 (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; +} +void amdgpu_fence_driver_sw_fini (struct amdgpu_device *adev) { -unsigned int i, j; +unsigned int i; -for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { -struct amdgpu_ring *ring = adev->rings[i]; - -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); - -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 <AMDGPU_MAX_RINGS ; i++) +amdgpu_fence_driver_fini_ring (adev->rings[i]); }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +39 -18
130 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -0
@@ -66,6 +66,8 @@ enum amdgpu_ring_priority_level {/* Ensure the execution in case of preemption or reset */ #define AMDGPU_FENCE_FLAG_EXEC (1 << 3) +#define AMDGPU_RING_WB_INVALID (~0u) +#define to_amdgpu_ring (s) container_of((s), struct amdgpu_ring, sched)enum amdgpu_ring_type {
@@ -163,6 +165,7 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring, struct amdgpu_fence *guilty_fence);int amdgpu_fence_driver_init_ring (struct amdgpu_ring *ring); +void amdgpu_fence_driver_fini_ring (struct amdgpu_ring *ring);int amdgpu_fence_driver_start_ring (struct amdgpu_ring *ring,struct amdgpu_irq_src *irq_src,unsigned irq_type);
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC v3 2/4] drm/amdgpu: Cleanup on ring failure
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() --
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 <[email protected]>
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().
Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +20
-17@@ -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]);
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop) · line 609
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +6
-4-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].
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RFC v3 3/4 drm/amdgpu: Unconfuse amdgpu_ring_init()
In reply to Tvrtko UrsulinEver since amdgpu was first added in commitd38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") amdgpu_ring_init() was doing a subset of initialization steps based on the ring->adev being NULL or not.
I am not sure what was the situation back then, but certainly in todays code base I cannot see that any caller sets ring->adev to something before calling amdgpu_ring_init(). Furthermore, I do not see how that would be safe and sensible because it would leak objects which were already initialized.
Lets just remove this special case and as a bonus only "publish" the ring to global struct amdgpu_device once it has been successfully constructed.
References: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Timur Kristóf <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 30 ++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +13 -17
@@ -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
@@ -236,21 +239,13 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->trail_fence_offs =AMDGPU_RING_WB_INVALID ; ring->cond_exe_offs =AMDGPU_RING_WB_INVALID ; -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->adev = adev; - ring->num_hw_submission = sched_hw_submission; - ring->sched_score = sched_score; - - ring->idx = adev->num_rings++; - adev->rings[ring->idx] = ring; - - r =amdgpu_fence_driver_init_ring (ring); -if (r) -return r; - } + r =amdgpu_fence_driver_init_ring (ring); +if (r) +return r; r =amdgpu_wb_get (adev, &ring->rptr_offs);if (r) {
@@ -369,6 +364,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, gpu_sched->sched[gpu_sched->num_scheds++] = &ring->sched; } + ring->idx = adev->num_rings++; + adev->rings[ring->idx] = ring; +return 0 ; err:
@@ -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 ; ring->sched.ready = false;
@@ -417,7 +414,6 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)dma_fence_put (ring->vmid_wait); ring->vmid_wait =NULL ; ring->me =0 ; - ring->adev->rings[ring->idx] =NULL ; ring->adev =NULL ; }
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC v3 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init()
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/amdgpu: double ring fence teardown in amdgpu_ring_fini() - [Medium] drm/amdgpu: NULL deref in…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/amdgpu: double ring fence teardown in amdgpu_ring_fini()
- [Medium] drm/amdgpu: NULL deref in amdgpu_ring_fini() if fence init fails
--
commit 01d7af74f5af72b7ed3ce08e92b4f64ab719695b
Author: Tvrtko Ursulin <[email protected]>
drm/amdgpu: Unconfuse amdgpu_ring_init()
This commit removes the ring->adev == NULL check in amdgpu_ring_init(), defers publishing the ring in adev->rings[] until initialization succeeds, and simplifies the initialization guard and cleanup in amdgpu_ring_fini().
Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +9
-14@@ -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 @@ -236,21 +239,13 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, ring->trail_fence_offs =AMDGPU_RING_WB_INVALID ; ring->cond_exe_offs =AMDGPU_RING_WB_INVALID ; -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; r =amdgpu_wb_get (adev, &ring->rptr_offs);if (r) {
[ ... ]
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 388
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1
-2@@ -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 amdgpu_ring_fini() dereference a NULL ring->fence_drv.fences pointer if amdgpu_fence_driver_init_ring() fails with -ENOMEM?
In amdgpu_fence_driver_init_ring(), ring->fence_drv.num_fences_mask is set to a non-zero mask before allocating ring->fence_drv.fences. When that allocation fails, amdgpu_ring_init() returns early with ring->adev still set and ring->fence_drv.fences == NULL. Because amdgpu_ring_fini() now checks only !ring->adev, a later teardown call (such as amdgpu_device_ip_fini() -> amdgpu_cper_fini() -> amdgpu_ring_fini()) enters amdgpu_fence_driver_fini_ring() and loops up to num_fences_mask, dereferencing ring->fence_drv.fences[0].
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c void amdgpu_ring_fini(struct amdgpu_ring *ring) · line 418
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +0
-1ring->sched.ready = false;@@ -417,7 +414,6 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)dma_fence_put (ring->vmid_wait); ring->vmid_wait =NULL ; ring->me =0 ; - ring->adev->rings[ring->idx] =NULL ; ring->adev =NULL ; }
[Severity: High]
Does leaving ring->adev->rings[ring->idx] populated cause amdgpu_fence_driver_fini_ring() to run a second time on every ring during device teardown?
In amdgpu_device_fini_sw(), amdgpu_device_ip_fini() calls each IP block's sw_fini callback, which invokes amdgpu_ring_fini() -> amdgpu_fence_driver_fini_ring(ring). That destroys ring->sched via drm_sched_fini() and frees ring->fence_drv.fences, setting it to NULL while leaving ring->fence_drv.num_fences_mask non-zero.
Immediately after amdgpu_device_ip_fini(), amdgpu_device_fini_sw() calls amdgpu_fence_driver_sw_fini(), which walks adev->rings[] and calls amdgpu_fence_driver_fini_ring() again on every non-NULL entry, calling drm_sched_fini() a second time and dereferencing NULL at ring->fence_drv.fences[i]:
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:amdgpu_fence_driver_fini_ring() {
...
if (ring->sched.ops)
drm_sched_fini(&ring->sched);
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;
...
}Since amdgpu_ring_init() can also jump to err and call amdgpu_ring_fini() before ring->idx is assigned, amdgpu_ring_fini() could clear the slot only when ring->adev->rings[ring->idx] == ring.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
RFC v3 4/4 drm/amdgpu: Use high priority scheduler workqueue for high priority rings
In reply to Tvrtko UrsulinBack when DRM scheduler was kthread based the submission threads were using SCHED_FIFO to minimize the delays in feeding the GPU. This was lost with the conversion to workqueues but has recently been shown on other drivers (panthor, xe) that modern userspace can still suffer severe submission latencies under CPU load.
Lets convert amdgpu to use own workqueues and make the high priority rings use WQ_HIGHPRI while at it.
This is not expected to be a significant latency improvement, but it paves the way to start using WQ_RT which is queued for 7.5. At that point we can switch to using it with a single line patch and bring submission latencies under CPU load back to what they were in the past.
References: a6149f039369 ("drm/sched: Convert drm scheduler to use a work queue rather than kthread")
References: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/49
References: https://lore.kernel.org/dri-devel/[email protected]/
References: https://lore.kernel.org/dri-devel/[email protected]/
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
Cc: Timur Kristóf <[email protected]>
---
v2:
* Free the workqueue if it has been allocated.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 10 ++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 1 + 4 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -2367,6 +2367,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev) args.credit_limit = ring->num_hw_submission; args.score = ring->sched_score; args.name = ring->name; + args.submit_wq = ring->sched_wq; r =drm_sched_init (&ring->sched, &args);if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3 -0
@@ -601,6 +601,9 @@ void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)if (ring->sched.ops)drm_sched_fini (&ring->sched); +if (ring->sched_wq) +destroy_workqueue (ring->sched_wq); +for (i =0 ; i <= ring->fence_drv.num_fences_mask; ++i)dma_fence_put (ring->fence_drv.fences[i]);kfree (ring->fence_drv.fences);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +10 -0
@@ -360,6 +360,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; }
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
@@ -309,6 +309,7 @@ struct amdgpu_ring {struct amdgpu_fence_driver fence_drv;struct drm_gpu_scheduler sched; +struct workqueue_struct *sched_wq;struct amdgpu_bo *ring_obj;uint32_t *ring;/* backups for resets */
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [RFC v3 4/4] drm/amdgpu: Use high priority scheduler workqueue for high priority rings
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: double destroy of sched_wq in amdgpu_fence_driver_fini_ring() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] drm/amdgpu: double destroy of sched_wq in amdgpu_fence_driver_fini_ring()
--
commit 92ab410b5813a4047dd4abb785b0ad07bf0b8f5d
Author: Tvrtko Ursulin <[email protected]>
drm/amdgpu: Use high priority scheduler workqueue for high priority rings
This commit allocates a dedicated ordered workqueue per ring for the DRM scheduler, setting WQ_HIGHPRI on high-priority rings, and destroys the workqueue in amdgpu_fence_driver_fini_ring().
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring) · line 609
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3
-0@@ -601,6 +601,9 @@ void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)if (ring->sched.ops)drm_sched_fini (&ring->sched); +if (ring->sched_wq) +destroy_workqueue (ring->sched_wq); +for (i =0 ; i <= ring->fence_drv.num_fences_mask; ++i)dma_fence_put (ring->fence_drv.fences[i]);kfree (ring->fence_drv.fences);
[Severity: High]
Can destroy_workqueue(ring->sched_wq) be called twice on the same ring during device teardown?
amdgpu_device_fini_sw() runs amdgpu_device_ip_fini(), where each IP block's sw_fini calls amdgpu_ring_fini() -> amdgpu_fence_driver_fini_ring(ring), and then calls amdgpu_fence_driver_sw_fini(), which iterates over adev->rings[] and calls amdgpu_fence_driver_fini_ring() a second time. Because ring->sched_wq is not cleared (and amdgpu_fence_driver_fini_ring() is not guarded against running twice), the second call passes the already-freed ring->sched_wq to destroy_workqueue().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4