AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Benjamin Cheng" <benjamin.cheng@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 5/7] drm/amdgpu/vm: stop using amdgpu_bo_fence
Date: Thu, 19 Nov 2026 15:04:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-223337@kernel.org> (raw)
In-Reply-To: <20261119144049.2057674-5-benjamin.cheng@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu/vm: unreserved fence slot usage in
  amdgpu_vm_update_range()
--

commit 62a2ba953c5e8b9b18301c84fc57052868fd3e60
Author: Benjamin Cheng <benjamin.cheng@amd.com>

drm/amdgpu/vm: stop using amdgpu_bo_fence

This commit replaces the amdgpu_bo_fence() call in amdgpu_vm_update_range()
with a direct dma_resv_add_fence() call using DMA_RESV_USAGE_BOOKKEEP.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index a0e6bb34ae0be..d4d8cb15ffd38 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -1215,7 +1215,8 @@ int amdgpu_vm_update_range(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>  	if (!unlocked && !dma_fence_is_signaled(vm->last_unlocked)) {
>  		struct dma_fence *tmp = dma_fence_get_stub();
>  
> -		amdgpu_bo_fence(vm->root.bo, vm->last_unlocked, true);
> +		dma_resv_add_fence(vm->root.bo->tbo.base.resv, vm->last_unlocked,
> +				   DMA_RESV_USAGE_BOOKKEEP);
>  		swap(vm->last_unlocked, tmp);
>  		dma_fence_put(tmp);
>  	}

[Severity: High]
Can this dma_resv_add_fence() call consume an unreserved fence slot and
hit BUG_ON(fobj->num_fences >= fobj->max_fences) when vm->root.bo already
holds a newer fence from vm->delayed?

Callers such as amdgpu_vm_lock_pd() and amdgpu_dma_buf_move_notify()
reserve only two fence slots for VM updates (one for vm->delayed and one
for the TLB flush fence), relying on vm->last_unlocked and locked SDMA
commits sharing the vm->delayed slot.  However, dma_resv_add_fence() only
replaces an unsignaled same-context slot when
dma_fence_is_later_or_same(fence, old) is true.

An unlocked update on vm->delayed can leave vm->last_unlocked with a
seqno older than the fence already in vm->root.bo->tbo.base.resv:

CPU0 (locked update)              CPU1 (SVM MMU notifier)
amdgpu_vm_update_range()
  /* checks vm->last_unlocked */
  amdgpu_vm_ptes_update()
    amdgpu_vm_pt_alloc()
      amdgpu_vm_end_critical()
                                  svm_range_unmap_from_gpu()
                                    amdgpu_vm_update_range(unlocked=true)
                                      /* submits seqno N on vm->delayed */
                                      /* vm->last_unlocked = seqno N */
      amdgpu_vm_begin_critical()
  /* submits seqno N+1 on vm->delayed */
  /* adds seqno N+1 to vm->root.bo */

amdgpu_vm_update_range()
  dma_resv_add_fence(..., vm->last_unlocked, ...)
    /* seqno N < seqno N+1: allocates a new slot */
    BUG_ON(fobj->num_fences >= fobj->max_fences)

The same ordering can occur when an unlocked update sets
vm->last_unlocked before amdgpu_vm_update_pdes(), which submits on
vm->delayed and adds its fence to vm->root.bo without flushing
vm->last_unlocked.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119144049.2057674-1-benjamin.cheng@amd.com?part=5

  reply	other threads:[~2026-11-19 15:04 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 19:07 [PATCH v2 00/10] Consolidate and fix root PD fence resverations Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 01/10] drm/amdkfd: reserve TTM move fences Benjamin Cheng
2026-11-19 13:53   ` Christian König
2026-11-18 19:07 ` [PATCH v2 02/10] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
2026-11-19 13:58   ` Christian König
2026-11-18 19:07 ` [PATCH v2 03/10] drm/amdgpu/vm: reserve more fences in amdgpu_vm_lock_pd Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 04/10] drm/amdgpu/dma_buf: reserve AMDGPU_VM_UPDATE_FENCES for move_notify Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 05/10] drm/amdgpu/vm: reserve AMDGPU_VM_UPDATE_FENCES for handle_fault Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 06/10] drm/amdgpu: reserve only what the caller asks for in lock_pd Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 07/10] drm/amdgpu/userq: remove extra fence request when locking PD Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 08/10] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 09/10] drm/amdgpu/uvd: " Benjamin Cheng
2026-11-18 19:07 ` [PATCH v2 10/10] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
2026-11-18 19:29   ` sashiko-bot
2026-11-19 14:40 ` [PATCH v3 1/7] drm/amdkfd: reserve TTM move fences Benjamin Cheng
2026-11-19 14:40   ` [PATCH v3 2/7] drm/amdgpu/gem: reserve fences on the VM root PD Benjamin Cheng
2026-11-19 14:40   ` [PATCH v3 3/7] drm/amdgpu/vm: reserve TTM_NUM_MOVE_FENCES in amdgpu_vm_lock_pd Benjamin Cheng
2026-11-19 14:40   ` [PATCH v3 4/7] drm/amdgpu/vm: reserve space for last_unlocked in handle_fault Benjamin Cheng
2026-11-19 14:40   ` [PATCH v3 5/7] drm/amdgpu/vm: stop using amdgpu_bo_fence Benjamin Cheng
2026-11-19 15:04     ` sashiko-bot [this message]
2026-11-19 14:40   ` [PATCH v3 6/7] drm/amdgpu/uvd: " Benjamin Cheng
2026-11-19 14:40   ` [PATCH v3 7/7] drm/amdgpu/object: get rid of amdgpu_bo_fence Benjamin Cheng
2026-11-19 14:46     ` 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=sashiko-outbox-223337@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=benjamin.cheng@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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