All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Benjamin Cheng <benjamin.cheng@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org
Cc: Sunil Khatri <sunil.khatri@amd.com>
Subject: Re: [PATCH v2] drm/amdgpu: wait for tlb flush before freeing BO
Date: Fri, 6 Nov 2026 17:04:11 +0100	[thread overview]
Message-ID: <26bbdd2a-b26a-4e76-9eba-092a7e61660c@amd.com> (raw)
In-Reply-To: <20261106152031.4040973-2-benjamin.cheng@amd.com>



On 11/6/26 16:20, Benjamin Cheng wrote:
> On gem object close, we previously only attached the fence of its own
> clear_freed() call to the BO's resv. If an unmap of this BO happened
> prior to the close call, clear_freed() would be invoked, leaving
> vm->freed empty, and no meaningful fence to be attached to the resv.
> Because of that the memory may be freed before the TLB flush is
> complete, and give a running userq potential access to a stale
> address translation.
> 
> Fix this by attaching the last_tlb_inv fence to the BO's resv.
> 
> Fixes: a1d201e16940 ("drm/amdgpu: enable GFX-V11 userqueue support")
> Signed-off-by: Benjamin Cheng <benjamin.cheng@amd.com>
> ---
> v2:
> - Rebase on "drm/amdgpu: fix TLB invalidation fence handling v4" to get
>   last_tlb_inv
> - Move the fence after the clear_freed call to make sure we wait for the
>   right invalidation.
> ---
>  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 6137ab4211be..36b0bd85616f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
> @@ -371,11 +371,14 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
>  		dev_err(adev->dev, "failed to clear page "
>  			"tables on GEM object close (%ld)\n", r);
>  	if (r || !fence)
> -		goto out_unlock;
> +		goto out_tlb;
>  
>  	amdgpu_bo_fence(bo, fence, true);
>  	dma_fence_put(fence);
>  
> +out_tlb:
> +	amdgpu_bo_fence(bo, vm->last_tlb_inv, true);

You need to change the drm_exec_prepare_obj() call above from 1 to 2 since we are now attaching 2 fences.

Apart from that looks good to me.

Regards,
Christian.

> +
>  out_unlock:
>  	if (r && !drm_dev_is_unplugged(adev_to_drm(adev)))
>  		dev_err(adev->dev, "leaking bo va (%ld)\n", r);


  reply	other threads:[~2026-11-06 16:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  2:21 [PATCH] drm/amdgpu: wait for tlb flush before freeing BO Benjamin Cheng
2026-10-14  7:17 ` Christian König
2026-10-14 12:46   ` Benjamin Cheng
2026-10-14 13:09     ` Christian König
2026-11-06 15:20 ` [PATCH v2] " Benjamin Cheng
2026-11-06 16:04   ` Christian König [this message]
2026-11-06 16:07     ` Benjamin Cheng
2026-11-09  9:58       ` Christian König
2026-11-09 14:57 ` [PATCH v3 1/2] " Benjamin Cheng
2026-11-09 14:57   ` [PATCH v3 2/2] drm/amdgpu/gem: use dma_resv_add_fence directly Benjamin Cheng
2026-11-09 15:00     ` Christian König
2026-11-09 15:02       ` Benjamin Cheng
2026-11-12 16:44 ` [PATCH 1/3] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
2026-11-12 16:44   ` [PATCH 2/3] drm/amdgpu/uvd: " Benjamin Cheng
2026-11-12 16:44   ` [PATCH 3/3] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
2026-11-12 16:52     ` sashiko-bot
2026-11-12 17:22   ` [PATCH 1/3] drm/amdgpu/vm: stop using amdgpu_bo_fence sashiko-bot

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=26bbdd2a-b26a-4e76-9eba-092a7e61660c@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=benjamin.cheng@amd.com \
    --cc=sunil.khatri@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.