* [PATCH 1/3] drm/amdgpu: keep PTL disable requests across GPU reset and resume
@ 2026-12-01 9:00 Perry Yuan
2026-12-01 9:00 ` [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit Perry Yuan
2026-12-01 9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan
0 siblings, 2 replies; 5+ messages in thread
From: Perry Yuan @ 2026-12-01 9:00 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan
gfx_v9_4_3_perf_monitor_ptl_init() sets ptl->disable_ref to 0 every
time it runs. Besides the first init, that is late_init after a GPU
reset and on resume, and hw_fini on suspend. The KFD processes holding
a PTL disable request survive all of these, and so do their
pdd->ptl_disable_req and the AMDGPU_PTL_DISABLE_PROFILER bit.
If a process holds the profiler lock across a GPU reset, its release
afterwards, by unlock, exit or kill, takes disable_ref from 0 to -1.
The 1 -> 0 transition that clears the PROFILER bit and enables PTL
never happens, neither for this process nor for later profilers, which
move the counter between -1 and 0. A write to ptl_enable is blocked by
the PROFILER bit. PTL stays disabled until amdgpu is reloaded.
disable_ref starts at 0 in the zeroed amdgpu_device and is balanced by
the request/release pairs, so there is nothing to reset. Drop the reset
so that the counter keeps matching the requests that are held.
Fixes: dd61e27535a6 ("drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
---
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
index e140430ce059..78ce980ac319 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c
@@ -2463,7 +2463,11 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool ena
ptl->hw_supported_state = AMDGPU_PTL_HW_SUPPORTED;
- atomic_set(&ptl->disable_ref, 0);
+ /*
+ * disable_ref counts the KFD processes holding a PTL disable request.
+ * They survive GPU reset and suspend/resume, so it must not be reset
+ * here.
+ */
if (!enable && !amdgpu_in_reset(adev) && !adev->in_suspend) {
dev_dbg(adev->dev,
"PTL disabled (amdgpu.ptl=%d)\
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit 2026-12-01 9:00 [PATCH 1/3] drm/amdgpu: keep PTL disable requests across GPU reset and resume Perry Yuan @ 2026-12-01 9:00 ` Perry Yuan 2026-12-01 9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan 1 sibling, 0 replies; 5+ messages in thread From: Perry Yuan @ 2026-12-01 9:00 UTC (permalink / raw) To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan When the last profiler releases its PTL disable request, KFD tries to enable PTL. If that fails, KFD restores the request so the owner can retry. At process teardown, however, kfd_process_destroy_pdds() frees the owner immediately after the release. The restored request then has no owner. Subsequent profiler sessions never drop the reference count to zero, and the profiler bit blocks attempts to enable PTL via sysfs. On the final release, report the enable error but do not restore the request. The next profiler release or sysfs enable can then retry the hardware operation. Keep the existing rollback for explicit releases. Fixes: dd61e27535a6 ("drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic") Signed-off-by: Perry Yuan <perry.yuan@amd.com> --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 16 +++++++++------- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index ae5b430a0031..43cb0af5e527 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -1882,8 +1882,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, return ret; } -int kfd_ptl_disable_release(struct kfd_process_device *pdd, - struct kfd_process *p) +int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final) { struct amdgpu_device *adev = pdd->dev->adev; struct amdgpu_ptl *ptl = &adev->psp.ptl; @@ -1901,10 +1900,13 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, clear_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); ret = kfd_ptl_control(pdd, true); if (ret) { - atomic_inc(&ptl->disable_ref); - set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); dev_warn(adev->dev, "Failed to enable PTL on release: %d\n", ret); - goto out; + /* Only a live pdd can retry the release. */ + if (!final) { + atomic_inc(&ptl->disable_ref); + set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); + goto out; + } } } pdd->ptl_disable_req = false; @@ -1930,7 +1932,7 @@ static int kfd_profiler_ptl_control(struct kfd_process *p, if (args->enable == 0) ret = kfd_ptl_disable_request(pdd, p); else - ret = kfd_ptl_disable_release(pdd, p); + ret = kfd_ptl_disable_release(pdd, false); return ret; } @@ -3444,7 +3446,7 @@ static inline int profile_lock_device(struct kfd_process *p, up_read(&kfd->adev->reset_domain->sem); if (ptl->hw_supported_state == AMDGPU_PTL_HW_SUPPORTED) { - status = kfd_ptl_disable_release(pdd, p); + status = kfd_ptl_disable_release(pdd, false); if (status) dev_err(kfd_device, "Failed to unlock device %d for profiling, error %d\n", diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 8eac086aa108..4950a8b9d162 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1661,8 +1661,7 @@ static inline bool kfd_is_first_node(struct kfd_node *node) /* PTL support */ int kfd_ptl_disable_request(struct kfd_process_device *pdd, struct kfd_process *p); -int kfd_ptl_disable_release(struct kfd_process_device *pdd, - struct kfd_process *p); +int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final); /* Debugfs */ #if defined(CONFIG_DEBUG_FS) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 5dc657f32d38..a5ec822077b6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -1258,7 +1258,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_process_profiler_release(p, pdd); if (pdd->ptl_disable_req) - kfd_ptl_disable_release(pdd, p); + kfd_ptl_disable_release(pdd, true); kfd_process_device_destroy_cwsr_dgpu(pdd); kfd_process_device_destroy_ib_mem(pdd); -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences 2026-12-01 9:00 [PATCH 1/3] drm/amdgpu: keep PTL disable requests across GPU reset and resume Perry Yuan 2026-12-01 9:00 ` [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit Perry Yuan @ 2026-12-01 9:00 ` Perry Yuan 2026-12-01 9:07 ` sashiko-bot 2026-12-01 13:40 ` Christian König 1 sibling, 2 replies; 5+ messages in thread From: Perry Yuan @ 2026-12-01 9:00 UTC (permalink / raw) To: amd-gfx; +Cc: Alexander.Deucher, Christian.Koenig, Yifan1.Zhang, perry.yuan The resource manager's eviction_lock protects its eviction_fences array. When attaching those fences to a BO, TTM also holds eviction_lock while dma_resv_add_fence() scans the BO's reservation list for an entry to replace. That list is protected by the reservation lock, not by the manager lock. Take references to pending fences under eviction_lock and add them to the reservation object after dropping it. This keeps the list scan out of the critical section shared with other allocators using the same manager. Skip completed fences, which are no longer dependencies, and keep returning -EBUSY for a pending fence in the no-wait path. Signed-off-by: Perry Yuan <perry.yuan@amd.com> --- drivers/gpu/drm/ttm/ttm_bo.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index ef56c18ded1b..45adcd2678a3 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -909,33 +909,38 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo) EXPORT_SYMBOL(ttm_bo_unpin); /* - * Add the pipelined eviction fencesto the BO as kernel dependency and reserve new - * fence slots. + * Add pending eviction fences to the BO as kernel dependencies and reserve + * new fence slots. */ static int ttm_bo_add_pipelined_eviction_fences(struct ttm_buffer_object *bo, struct ttm_resource_manager *man, bool no_wait_gpu) { + struct dma_fence *fences[TTM_NUM_MOVE_FENCES]; struct dma_fence *fence; - int i; + int i, count = 0; spin_lock(&man->eviction_lock); for (i = 0; i < TTM_NUM_MOVE_FENCES; i++) { fence = man->eviction_fences[i]; - if (!fence) + if (!fence || dma_fence_is_signaled(fence)) continue; if (no_wait_gpu) { - if (!dma_fence_is_signaled(fence)) { - spin_unlock(&man->eviction_lock); - return -EBUSY; - } - } else { - dma_resv_add_fence(bo->base.resv, fence, DMA_RESV_USAGE_KERNEL); + spin_unlock(&man->eviction_lock); + return -EBUSY; } + + /* The manager may replace this fence once we drop the lock. */ + fences[count++] = dma_fence_get(fence); } spin_unlock(&man->eviction_lock); + for (i = 0; i < count; i++) { + dma_resv_add_fence(bo->base.resv, fences[i], DMA_RESV_USAGE_KERNEL); + dma_fence_put(fences[i]); + } + /* TODO: this call should be removed. */ return dma_resv_reserve_fences(bo->base.resv, 1); } -- 2.34.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences 2026-12-01 9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan @ 2026-12-01 9:07 ` sashiko-bot 2026-12-01 13:40 ` Christian König 1 sibling, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-01 9:07 UTC (permalink / raw) To: Perry Yuan, amd-gfx Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] drm/amdgpu: insufficient fence slot reservation in amdgpu_dma_buf_move_notify() [1] -- commit d22882cc6158883831770886db4d0852012b8d1a Author: Perry Yuan <perry.yuan@amd.com> drm/ttm: Narrow the eviction lock scope when adding move fences This commit snapshots pending eviction fences under man->eviction_lock and adds them to the BO's reservation object after releasing the lock. > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c > index 53c68e29ebc21..f833982073c6a 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -908,33 +908,38 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo) > EXPORT_SYMBOL(ttm_bo_unpin); > > /* > - * Add the pipelined eviction fencesto the BO as kernel dependency and reserve new > - * fence slots. > + * Add pending eviction fences to the BO as kernel dependencies and reserve > + * new fence slots. > */ > static int ttm_bo_add_pipelined_eviction_fences(struct ttm_buffer_object *bo, > struct ttm_resource_manager *man, > bool no_wait_gpu) > { > + struct dma_fence *fences[TTM_NUM_MOVE_FENCES]; > struct dma_fence *fence; > - int i; > + int i, count = 0; > > spin_lock(&man->eviction_lock); > for (i = 0; i < TTM_NUM_MOVE_FENCES; i++) { > fence = man->eviction_fences[i]; > - if (!fence) > + if (!fence || dma_fence_is_signaled(fence)) > continue; > > if (no_wait_gpu) { > - if (!dma_fence_is_signaled(fence)) { > - spin_unlock(&man->eviction_lock); > - return -EBUSY; > - } > - } else { > - dma_resv_add_fence(bo->base.resv, fence, DMA_RESV_USAGE_KERNEL); > + spin_unlock(&man->eviction_lock); > + return -EBUSY; > } > + > + /* The manager may replace this fence once we drop the lock. */ > + fences[count++] = dma_fence_get(fence); > } > spin_unlock(&man->eviction_lock); > > + for (i = 0; i < count; i++) { > + dma_resv_add_fence(bo->base.resv, fences[i], DMA_RESV_USAGE_KERNEL); > + dma_fence_put(fences[i]); > + } > + > /* TODO: this call should be removed. */ > return dma_resv_reserve_fences(bo->base.resv, 1); > } [Severity: High] This problem wasn't introduced by this patch, but can reserving only 1 fence slot here after consuming up to TTM_NUM_MOVE_FENCES slots hit the BUG_ON() in dma_resv_add_fence() during amdgpu_dma_buf_move_notify() [1]? amdgpu_dma_buf_move_notify() reserves 2 fence slots on the VM root BO reservation object for the page table update fence and the TLB flush fence (when vm->need_tlb_fence is enabled). If amdgpu_vm_update_range() allocates a new page table BO sharing that reservation object, ttm_bo_alloc_resource() reserves TTM_NUM_MOVE_FENCES slots and ttm_bo_add_pipelined_eviction_fences() can consume all TTM_NUM_MOVE_FENCES of them before calling dma_resv_reserve_fences(bo->base.resv, 1). Because dma_resv_reserve_fences() is not additive, if the reservation object started with TTM_NUM_MOVE_FENCES + 1 free slots, neither reservation call reallocates the list and only 1 free slot remains after BO creation. amdgpu_vm_sdma_commit() takes that slot for vm->delayed, and amdgpu_vm_tlb_flush() then overflows fobj->max_fences when adding vm->last_tlb_inv. [1] https://sashiko.dev/#/bug/linux-8e6fd858-557e-4ca0-9558-be9bf089c7d4 -- Sashiko AI review · https://sashiko.dev/#/patchset/20261201090028.86494-1-perry.yuan@amd.com?part=3 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences 2026-12-01 9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan 2026-12-01 9:07 ` sashiko-bot @ 2026-12-01 13:40 ` Christian König 1 sibling, 0 replies; 5+ messages in thread From: Christian König @ 2026-12-01 13:40 UTC (permalink / raw) To: Perry Yuan, Natalie Vock, Paneer Selvam, Arunpravin, Pelloux-Prayer, Pierre-Eric Cc: Alexander.Deucher, Yifan1.Zhang, amd-gfx, dri-devel@lists.freedesktop.org Hi Perry, first of all TTM patches needs to be send to Natalie, Arun and the dri-devel mailing list. I'm also adding Pierre-Eric since we came up with the TTM_NUM_MOVE_FENCES together. On 12/1/26 10:00, Perry Yuan wrote: > The resource manager's eviction_lock protects its eviction_fences array. > When attaching those fences to a BO, TTM also holds eviction_lock while > dma_resv_add_fence() scans the BO's reservation list for an entry to > replace. That list is protected by the reservation lock, not by the > manager lock. > > Take references to pending fences under eviction_lock and add them to > the reservation object after dropping it. This keeps the list scan out > of the critical section shared with other allocators using the same > manager. Skip completed fences, which are no longer dependencies, and > keep returning -EBUSY for a pending fence in the no-wait path. > > Signed-off-by: Perry Yuan <perry.yuan@amd.com> > --- > drivers/gpu/drm/ttm/ttm_bo.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c > index ef56c18ded1b..45adcd2678a3 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -909,33 +909,38 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo) > EXPORT_SYMBOL(ttm_bo_unpin); > > /* > - * Add the pipelined eviction fencesto the BO as kernel dependency and reserve new > - * fence slots. > + * Add pending eviction fences to the BO as kernel dependencies and reserve > + * new fence slots. > */ > static int ttm_bo_add_pipelined_eviction_fences(struct ttm_buffer_object *bo, > struct ttm_resource_manager *man, > bool no_wait_gpu) > { > + struct dma_fence *fences[TTM_NUM_MOVE_FENCES]; > struct dma_fence *fence; > - int i; > + int i, count = 0; > > spin_lock(&man->eviction_lock); > for (i = 0; i < TTM_NUM_MOVE_FENCES; i++) { > fence = man->eviction_fences[i]; > - if (!fence) > + if (!fence || dma_fence_is_signaled(fence)) I think that should be dropped, skipping adding signaled fences doesn't make things much faster but can hide bugs. Apart from that looks like a valid improvement to me, but did that really show up in some benchmark? That sounds quite unlikely for real world use cases. Regards, Christian. > continue; > > if (no_wait_gpu) { > - if (!dma_fence_is_signaled(fence)) { > - spin_unlock(&man->eviction_lock); > - return -EBUSY; > - } > - } else { > - dma_resv_add_fence(bo->base.resv, fence, DMA_RESV_USAGE_KERNEL); > + spin_unlock(&man->eviction_lock); > + return -EBUSY; > } > + > + /* The manager may replace this fence once we drop the lock. */ > + fences[count++] = dma_fence_get(fence); > } > spin_unlock(&man->eviction_lock); > > + for (i = 0; i < count; i++) { > + dma_resv_add_fence(bo->base.resv, fences[i], DMA_RESV_USAGE_KERNEL); > + dma_fence_put(fences[i]); > + } > + > /* TODO: this call should be removed. */ > return dma_resv_reserve_fences(bo->base.resv, 1); > } ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 13:40 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-01 9:00 [PATCH 1/3] drm/amdgpu: keep PTL disable requests across GPU reset and resume Perry Yuan 2026-12-01 9:00 ` [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit Perry Yuan 2026-12-01 9:00 ` [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences Perry Yuan 2026-12-01 9:07 ` sashiko-bot 2026-12-01 13:40 ` Christian König
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.