AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path
@ 2026-02-06 14:24 Srinivasan Shanmugam
  2026-02-06 15:29 ` Alex Deucher
  2026-02-06 15:32 ` Christian König
  0 siblings, 2 replies; 4+ messages in thread
From: Srinivasan Shanmugam @ 2026-02-06 14:24 UTC (permalink / raw)
  To: Christian König, Alex Deucher
  Cc: amd-gfx, Srinivasan Shanmugam, Dan Carpenter

If amdgpu_vm_flush() fails, amdgpu_ib_schedule() returns early after
calling amdgpu_ring_undo().  This skips the common free_fence cleanup
path.  Other error paths were already changed to use goto free_fence,
but this one was missed.

Change the early return to goto free_fence so all error paths clean up
the same way.

Fixes the below:
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c:232 amdgpu_ib_schedule()
warn: missing unwind goto?

drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
    124 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
    125                        struct amdgpu_ib *ibs, struct amdgpu_job *job,
    126                        struct dma_fence **f)
    127 {

    ...

    224
    225         if (ring->funcs->insert_start)
    226                 ring->funcs->insert_start(ring);
    227
    228         if (job) {
    229                 r = amdgpu_vm_flush(ring, job, need_pipe_sync);
    230                 if (r) {
    231                         amdgpu_ring_undo(ring);
--> 232                         return r;

The patch changed the other error paths to goto free_fence but this one
was accidentally skipped.

    233                 }
    234         }
    235
    236         amdgpu_ring_ib_begin(ring);

    ...

    338
    339 free_fence:
    340         if (!job)
    341                 kfree(af);
    342         return r;
    343 }

Fixes: f903b85ed0f1 ("drm/amdgpu: fix possible fence leaks from job structure")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
index 44f230d67da2..bfa64cd7a62d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
@@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
 		r = amdgpu_vm_flush(ring, job, need_pipe_sync);
 		if (r) {
 			amdgpu_ring_undo(ring);
-			return r;
+			goto free_fence;
 		}
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path
  2026-02-06 14:24 [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path Srinivasan Shanmugam
@ 2026-02-06 15:29 ` Alex Deucher
  2026-02-06 15:32 ` Christian König
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2026-02-06 15:29 UTC (permalink / raw)
  To: Srinivasan Shanmugam
  Cc: Christian König, Alex Deucher, amd-gfx, Dan Carpenter

On Fri, Feb 6, 2026 at 9:32 AM Srinivasan Shanmugam
<srinivasan.shanmugam@amd.com> wrote:
>
> If amdgpu_vm_flush() fails, amdgpu_ib_schedule() returns early after
> calling amdgpu_ring_undo().  This skips the common free_fence cleanup
> path.  Other error paths were already changed to use goto free_fence,
> but this one was missed.
>
> Change the early return to goto free_fence so all error paths clean up
> the same way.
>
> Fixes the below:
> drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c:232 amdgpu_ib_schedule()
> warn: missing unwind goto?
>
> drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
>     124 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
>     125                        struct amdgpu_ib *ibs, struct amdgpu_job *job,
>     126                        struct dma_fence **f)
>     127 {
>
>     ...
>
>     224
>     225         if (ring->funcs->insert_start)
>     226                 ring->funcs->insert_start(ring);
>     227
>     228         if (job) {
>     229                 r = amdgpu_vm_flush(ring, job, need_pipe_sync);
>     230                 if (r) {
>     231                         amdgpu_ring_undo(ring);
> --> 232                         return r;
>
> The patch changed the other error paths to goto free_fence but this one
> was accidentally skipped.
>
>     233                 }
>     234         }
>     235
>     236         amdgpu_ring_ib_begin(ring);
>
>     ...
>
>     338
>     339 free_fence:
>     340         if (!job)
>     341                 kfree(af);
>     342         return r;
>     343 }
>
> Fixes: f903b85ed0f1 ("drm/amdgpu: fix possible fence leaks from job structure")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> index 44f230d67da2..bfa64cd7a62d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> @@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
>                 r = amdgpu_vm_flush(ring, job, need_pipe_sync);
>                 if (r) {
>                         amdgpu_ring_undo(ring);
> -                       return r;
> +                       goto free_fence;
>                 }
>         }
>
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path
  2026-02-06 14:24 [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path Srinivasan Shanmugam
  2026-02-06 15:29 ` Alex Deucher
@ 2026-02-06 15:32 ` Christian König
  2026-02-08  6:31   ` SHANMUGAM, SRINIVASAN
  1 sibling, 1 reply; 4+ messages in thread
From: Christian König @ 2026-02-06 15:32 UTC (permalink / raw)
  To: Srinivasan Shanmugam, Alex Deucher; +Cc: amd-gfx, Dan Carpenter

On 2/6/26 15:24, Srinivasan Shanmugam wrote:
> If amdgpu_vm_flush() fails, amdgpu_ib_schedule() returns early after
> calling amdgpu_ring_undo().  This skips the common free_fence cleanup
> path.  Other error paths were already changed to use goto free_fence,
> but this one was missed.

In general good catch, but amdgpu_vm_flush() never fails :)

I wanted to remove the return code after Alex has cleaned this up but haven't got the time for it yet.

Maybe you can give that a try. It originates in amdgpu_fence_emit().

Thanks,
Christian.

> 
> Change the early return to goto free_fence so all error paths clean up
> the same way.
> 
> Fixes the below:
> drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c:232 amdgpu_ib_schedule()
> warn: missing unwind goto?
> 
> drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
>     124 int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
>     125                        struct amdgpu_ib *ibs, struct amdgpu_job *job,
>     126                        struct dma_fence **f)
>     127 {
> 
>     ...
> 
>     224
>     225         if (ring->funcs->insert_start)
>     226                 ring->funcs->insert_start(ring);
>     227
>     228         if (job) {
>     229                 r = amdgpu_vm_flush(ring, job, need_pipe_sync);
>     230                 if (r) {
>     231                         amdgpu_ring_undo(ring);
> --> 232                         return r;
> 
> The patch changed the other error paths to goto free_fence but this one
> was accidentally skipped.
> 
>     233                 }
>     234         }
>     235
>     236         amdgpu_ring_ib_begin(ring);
> 
>     ...
> 
>     338
>     339 free_fence:
>     340         if (!job)
>     341                 kfree(af);
>     342         return r;
>     343 }
> 
> Fixes: f903b85ed0f1 ("drm/amdgpu: fix possible fence leaks from job structure")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian König <christian.koenig@amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> index 44f230d67da2..bfa64cd7a62d 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c
> @@ -229,7 +229,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,
>  		r = amdgpu_vm_flush(ring, job, need_pipe_sync);
>  		if (r) {
>  			amdgpu_ring_undo(ring);
> -			return r;
> +			goto free_fence;
>  		}
>  	}
>  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path
  2026-02-06 15:32 ` Christian König
@ 2026-02-08  6:31   ` SHANMUGAM, SRINIVASAN
  0 siblings, 0 replies; 4+ messages in thread
From: SHANMUGAM, SRINIVASAN @ 2026-02-08  6:31 UTC (permalink / raw)
  To: Koenig, Christian, Deucher, Alexander
  Cc: amd-gfx@lists.freedesktop.org, Dan Carpenter

[AMD Official Use Only - AMD Internal Distribution Only]

> -----Original Message-----
> From: Koenig, Christian <Christian.Koenig@amd.com>
> Sent: Friday, February 6, 2026 9:03 PM
> To: SHANMUGAM, SRINIVASAN <SRINIVASAN.SHANMUGAM@amd.com>;
> Deucher, Alexander <Alexander.Deucher@amd.com>
> Cc: amd-gfx@lists.freedesktop.org; Dan Carpenter <dan.carpenter@linaro.org>
> Subject: Re: [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule()
> error path
>
> On 2/6/26 15:24, Srinivasan Shanmugam wrote:
> > If amdgpu_vm_flush() fails, amdgpu_ib_schedule() returns early after
> > calling amdgpu_ring_undo().  This skips the common free_fence cleanup
> > path.  Other error paths were already changed to use goto free_fence,
> > but this one was missed.
>
> In general good catch, but amdgpu_vm_flush() never fails :)
>
> I wanted to remove the return code after Alex has cleaned this up but haven't got
> the time for it yet.
>
> Maybe you can give that a try. It originates in amdgpu_fence_emit().

Hi Christian,

Thanks for your feedback, proposed a follow-up for the same https://patchwork.freedesktop.org/patch/703635/

Thanks,
Srini

>
> Thanks,
> Christian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-08  6:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-06 14:24 [PATCH] drm/amdgpu: Fix missing unwind in amdgpu_ib_schedule() error path Srinivasan Shanmugam
2026-02-06 15:29 ` Alex Deucher
2026-02-06 15:32 ` Christian König
2026-02-08  6:31   ` SHANMUGAM, SRINIVASAN

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox