All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Le Ma <le.ma@amd.com>, amd-gfx@lists.freedesktop.org
Cc: hawking.zhang@amd.com, lijo.lazar@amd.com
Subject: Re: [PATCH 1/1] drm/amdgpu: fix the memleak caused by fence not released
Date: Wed, 12 Feb 2025 14:08:17 +0100	[thread overview]
Message-ID: <9c02ec5d-4dd1-4eac-a69c-19c623ef5c6d@amd.com> (raw)
In-Reply-To: <20250212113001.2286084-1-le.ma@amd.com>

Am 12.02.25 um 12:30 schrieb Le Ma:
> On systems with CONFIG_SLUB_DEBUG enabled, the memleak like below
> will show up explicitly during driver unloading if created bo without
> drm_timeline object before.
>
>      BUG drm_sched_fence (Tainted: G           OE     ): Objects remaining in drm_sched_fence on __kmem_cache_shutdown()
>      -----------------------------------------------------------------------------
>      Call Trace:
>      <TASK>
>      dump_stack_lvl+0x4c/0x70
>      dump_stack+0x14/0x20
>      slab_err+0xb0/0xf0
>      ? srso_alias_return_thunk+0x5/0xfbef5
>      ? flush_work+0x12/0x20
>      ? srso_alias_return_thunk+0x5/0xfbef5
>      __kmem_cache_shutdown+0x163/0x2e0
>      kmem_cache_destroy+0x61/0x170
>      drm_sched_fence_slab_fini+0x19/0x900
>
> Thus call dma_fence_put properly to avoid the memleak.

Good catch, but there is even more broken here.

The call to amdgpu_gem_update_timeline_node() comes way to late, we need 
to make sure that this is called *before* doing the update. Probably 
best to just inline the functionality.

Then AMDGPU_VM_DELAY_UPDATE and is mutual exclusive to specifying the 
syncobj when the update is completed.

>
> Signed-off-by: Le Ma <le.ma@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> index 8b67aae6c2fe..ad3c5fdf6970 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -125,8 +125,11 @@ amdgpu_gem_update_bo_mapping(struct drm_file *filp,
>   	struct amdgpu_vm *vm = &fpriv->vm;
>   	struct dma_fence *last_update;
>   
> -	if (!syncobj)
> +	if (!syncobj) {
> +		dma_fence_wait(fence, false);

Please drop that wait, this is just nonsense.

> +		dma_fence_put(fence);
>   		return;
> +	}

We might want to move all this into amdgpu_gem_va_update_vm().

Regards,
Christian.

>   
>   	/* Find the last update fence */
>   	switch (operation) {


      reply	other threads:[~2025-02-12 13:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 11:30 [PATCH 1/1] drm/amdgpu: fix the memleak caused by fence not released Le Ma
2025-02-12 13:08 ` Christian König [this message]

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=9c02ec5d-4dd1-4eac-a69c-19c623ef5c6d@amd.com \
    --to=christian.koenig@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=hawking.zhang@amd.com \
    --cc=le.ma@amd.com \
    --cc=lijo.lazar@amd.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.