* [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors
@ 2026-11-30 12:10 Arunpravin Paneer Selvam
2026-11-30 12:10 ` [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Arunpravin Paneer Selvam @ 2026-11-30 12:10 UTC (permalink / raw)
To: christian.koenig, amd-gfx
Cc: alexander.deucher, Arunpravin Paneer Selvam, stable
After a GPU reset, a clear job cancelled by the reset leaves its error on
the entity and every following clear job inherits it and is skipped, so
freed VRAM is no longer cleared. Clear jobs don't depend on the previous
job, so let them ignore the entity error.
v2:
- Split into multiple patches (Christian)
Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality")
Cc: stable@vger.kernel.org
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 +++++---
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 1 +
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 8689a3c933b2..b186b5b73de2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -391,9 +391,11 @@ amdgpu_job_prepare_job(struct drm_sched_job *sched_job,
struct dma_fence *fence;
int r;
- r = drm_sched_entity_error(s_entity);
- if (r)
- goto error;
+ if (!job->ignore_entity_error) {
+ r = drm_sched_entity_error(s_entity);
+ if (r)
+ goto error;
+ }
if (job->gang_submit) {
fence = amdgpu_device_switch_gang(ring->adev, job->gang_submit);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
index 18e788f0e790..1947d650cd7f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h
@@ -75,6 +75,7 @@ struct amdgpu_job {
uint32_t preemption_status;
bool vm_needs_flush;
bool gds_switch_needed;
+ bool ignore_entity_error;
uint64_t vm_pd_addr;
unsigned vmid;
unsigned pasid;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d5c1d044403e..346e7be57fd8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2647,6 +2647,8 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev,
if (r)
return r;
+ job->ignore_entity_error = true;
+
for (i = 0; i < num_loops; i++) {
uint32_t cur_size = min(byte_count, max_bytes);
--
2.53.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset 2026-11-30 12:10 [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Arunpravin Paneer Selvam @ 2026-11-30 12:10 ` Arunpravin Paneer Selvam 2026-11-30 12:34 ` sashiko-bot 2026-11-30 12:10 ` [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a " Arunpravin Paneer Selvam 2026-11-30 15:51 ` [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Christian König 2 siblings, 1 reply; 7+ messages in thread From: Arunpravin Paneer Selvam @ 2026-11-30 12:10 UTC (permalink / raw) To: christian.koenig, amd-gfx Cc: alexander.deucher, Arunpravin Paneer Selvam, stable Free blocks marked as cleared can hold old data after a GPU reset, as a pending clear may have been cancelled or VRAM was lost. Reset their cleared state once the GPU reset counter changed. v2: - Split into multiple patches (Christian) - Use gpu_reset_counter, set before job cancel and on any reset (Christian) - Check it in free as well as alloc, so blocks cleared after the reset are not marked dirty again by the next alloc (Sashiko) Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality") Cc: stable@vger.kernel.org Suggested-by: Christian König <christian.koenig@amd.com> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 16 ++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index 249f07f30951..d947e048952d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -431,6 +431,17 @@ int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr, return ret; } +static void amdgpu_vram_mgr_check_reset(struct amdgpu_device *adev, + struct amdgpu_vram_mgr *mgr) +{ + int reset_counter = atomic_read(&adev->gpu_reset_counter); + + if (unlikely(mgr->gpu_reset_counter != reset_counter)) { + gpu_buddy_reset_clear(&mgr->mm, false); + mgr->gpu_reset_counter = reset_counter; + } +} + /** * amdgpu_vram_mgr_new - allocate new ranges * @@ -523,6 +534,8 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, } mutex_lock(&mgr->lock); + amdgpu_vram_mgr_check_reset(adev, mgr); + while (remaining_size) { if (tbo->page_alignment) min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT; @@ -652,6 +665,8 @@ static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, list_for_each_entry(block, &vres->blocks, link) vis_usage += amdgpu_vram_mgr_vis_size(adev, block); + amdgpu_vram_mgr_check_reset(adev, mgr); + gpu_buddy_free_list(mm, &vres->blocks, vres->flags); amdgpu_vram_mgr_do_reserve(man); mutex_unlock(&mgr->lock); @@ -961,6 +976,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev) INIT_LIST_HEAD(&mgr->reserved_pages); INIT_LIST_HEAD(&mgr->allocated_vres_list); mgr->default_page_size = PAGE_SIZE; + mgr->gpu_reset_counter = atomic_read(&adev->gpu_reset_counter); man->func = &amdgpu_vram_mgr_func; err = gpu_buddy_init(&mgr->mm, man->size, PAGE_SIZE); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h index e581cbf52fcb..da1efd0e26a1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h @@ -39,6 +39,7 @@ struct amdgpu_vram_mgr { u64 default_page_size; struct list_head allocated_vres_list; struct dmem_cgroup_region *cg_region; + int gpu_reset_counter; }; struct amdgpu_vres_task { -- 2.53.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset 2026-11-30 12:10 ` [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam @ 2026-11-30 12:34 ` sashiko-bot 0 siblings, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-11-30 12:34 UTC (permalink / raw) To: Arunpravin Paneer Selvam, amd-gfx Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amdgpu: race on gpu_reset_counter in amdgpu_vram_mgr_check_reset() -- commit e2f6a53587f6a83dcd78a77fe71d3295729bf04a Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> drm/amdgpu: Reset cleared state of free VRAM after GPU reset This commit tracks adev->gpu_reset_counter in struct amdgpu_vram_mgr and resets the cleared state of free VRAM buddy blocks during allocation and free when the counter has changed. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > index 249f07f309515..d947e048952d2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > @@ -431,6 +431,17 @@ int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr, > return ret; > } > > +static void amdgpu_vram_mgr_check_reset(struct amdgpu_device *adev, > + struct amdgpu_vram_mgr *mgr) > +{ > + int reset_counter = atomic_read(&adev->gpu_reset_counter); > + > + if (unlikely(mgr->gpu_reset_counter != reset_counter)) { > + gpu_buddy_reset_clear(&mgr->mm, false); > + mgr->gpu_reset_counter = reset_counter; > + } > +} [Severity: Medium] Can amdgpu_vram_mgr_check_reset() update mgr->gpu_reset_counter out of order with an in-progress GPU reset and leave unwiped or lost VRAM blocks marked as GPU_BUDDY_HEADER_CLEAR? Neither amdgpu_vram_mgr_new() nor amdgpu_vram_mgr_del() serializes against adev->reset_domain->sem, and adev->gpu_reset_counter is updated at two points that race with BO release and eviction: 1. During full GPU recovery, amdgpu_device_halt_activities() increments adev->gpu_reset_counter before amdgpu_do_asic_reset() resets the hardware and before amdgpu_device_reinit_after_reset() calls amdgpu_inc_vram_lost(): CPU0 CPU1 amdgpu_device_gpu_recover() amdgpu_device_halt_activities() atomic_inc(&gpu_reset_counter) /* counter is now N + 1 */ amdgpu_bo_release_notify() amdgpu_ttm_clear_buffer() amdgpu_job_alloc() /* captures old vram_lost */ amdgpu_vram_mgr_set_cleared() /* records N + 1 */ amdgpu_do_asic_reset() amdgpu_device_reinit_after_reset() amdgpu_inc_vram_lost() amdgpu_device_sched_resume() amdgpu_job_run() /* skips clear job: generation != vm_generation */ ttm_bo_delayed_delete() amdgpu_vram_mgr_del() amdgpu_vram_mgr_check_reset() mgr->gpu_reset_counter = N + 1 gpu_buddy_free_list(..., CLEARED) <-- unwiped block marked clear For pipelined eviction via amdgpu_move_blit() -> ttm_bo_move_pipeline_evict(), amdgpu_vram_mgr_del() runs immediately in the window between amdgpu_device_halt_activities() and amdgpu_do_asic_reset(), consuming N + 1 and marking the freed blocks cleared before the hardware reset wipes VRAM or cancels the clear job. 2. During per-queue or IP soft reset in amdgpu_job_timedout(), amdgpu_ring_reset() and amdgpu_device_ip_soft_reset() invoke amdgpu_ring_reset_helper_end() -> amdgpu_ring_set_fence_errors_and_reemit() and drm_sched_wqueue_start() before atomic_inc(&ring->adev->gpu_reset_counter): drivers/gpu/drm/amd/amdgpu/amdgpu_job.c:amdgpu_job_timedout() { ... r = amdgpu_ring_reset(ring, job->vmid, job->hw_fence); if (!r) { /* Start the scheduler again */ drm_sched_wqueue_start(&ring->sched); atomic_inc(&ring->adev->gpu_reset_counter); ... } When a clear job's fence is force-completed or re-emitted as NOPs inside amdgpu_ring_set_fence_errors_and_reemit(), ttm_bo_delayed_delete() -> amdgpu_vram_mgr_del() can run on another CPU before gpu_reset_counter is incremented, freeing the unwiped blocks as cleared while adev->gpu_reset_counter still holds the pre-reset value. Subsequent AMDGPU_GEM_CREATE_VRAM_CLEARED allocations will then skip clearing in amdgpu_ttm_clear_buffer() and expose stale VRAM contents. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261130121049.26541-1-Arunpravin.PaneerSelvam@amd.com?part=2 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset 2026-11-30 12:10 [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Arunpravin Paneer Selvam 2026-11-30 12:10 ` [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam @ 2026-11-30 12:10 ` Arunpravin Paneer Selvam 2026-11-30 12:34 ` sashiko-bot 2026-11-30 15:58 ` Christian König 2026-11-30 15:51 ` [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Christian König 2 siblings, 2 replies; 7+ messages in thread From: Arunpravin Paneer Selvam @ 2026-11-30 12:10 UTC (permalink / raw) To: christian.koenig, amd-gfx Cc: alexander.deucher, Arunpravin Paneer Selvam, stable Blocks whose wipe was queued before a GPU reset are freed as cleared, but the wipe may have been cancelled by the reset. Record the GPU reset counter when queueing the wipe and drop the cleared state on free if it changed. v2: - Split into multiple patches (Christian) - Use gpu_reset_counter, set before job cancel and on any reset (Christian) Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality") Cc: stable@vger.kernel.org Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 3 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 5 ++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index d4651f2d437c..01d18e46aa1b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -1366,7 +1366,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); struct dma_fence *fence = NULL; struct amdgpu_bo *abo; - int r; + int reset_counter, r; if (!amdgpu_bo_is_amdgpu_bo(bo)) return; @@ -1398,13 +1398,14 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) if (r) goto out; + reset_counter = atomic_read(&adev->gpu_reset_counter); r = amdgpu_ttm_clear_buffer(amdgpu_ttm_next_clear_entity(adev), abo, &bo->base._resv, &fence, false, AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE); if (WARN_ON(r)) goto out; - amdgpu_vram_mgr_set_cleared(bo->resource); + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); dma_resv_add_fence(&bo->base._resv, fence, DMA_RESV_USAGE_KERNEL); dma_fence_put(fence); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 346e7be57fd8..fa21e2db545a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -435,13 +435,15 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, /* clear the space being freed */ if (old_mem->mem_type == TTM_PL_VRAM && (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) { + int reset_counter = atomic_read(&adev->gpu_reset_counter); struct dma_fence *wipe_fence = NULL; + r = amdgpu_ttm_clear_buffer(entity, abo, NULL, &wipe_fence, false, AMDGPU_KERNEL_JOB_ID_MOVE_BLIT); if (r) { goto error; } else if (wipe_fence) { - amdgpu_vram_mgr_set_cleared(bo->resource); + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); dma_fence_put(fence); fence = wipe_fence; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c index d947e048952d..0706224583ce 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c @@ -666,6 +666,9 @@ static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, vis_usage += amdgpu_vram_mgr_vis_size(adev, block); amdgpu_vram_mgr_check_reset(adev, mgr); + if ((vres->flags & GPU_BUDDY_CLEARED) && + vres->clear_reset_counter != mgr->gpu_reset_counter) + vres->flags &= ~GPU_BUDDY_CLEARED; gpu_buddy_free_list(mm, &vres->blocks, vres->flags); amdgpu_vram_mgr_do_reserve(man); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h index da1efd0e26a1..abd7bc1811fc 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h @@ -59,6 +59,7 @@ struct amdgpu_vram_mgr_resource { unsigned long flags; struct list_head vres_node; struct amdgpu_vres_task task; + int clear_reset_counter; }; static inline u64 amdgpu_vram_mgr_block_start(struct gpu_buddy_block *block) @@ -82,12 +83,14 @@ to_amdgpu_vram_mgr_resource(struct ttm_resource *res) return container_of(res, struct amdgpu_vram_mgr_resource, base); } -static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res) +static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res, + int reset_counter) { struct amdgpu_vram_mgr_resource *ares = to_amdgpu_vram_mgr_resource(res); WARN_ON(ares->flags & GPU_BUDDY_CLEARED); ares->flags |= GPU_BUDDY_CLEARED; + ares->clear_reset_counter = reset_counter; } int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr, -- 2.53.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset 2026-11-30 12:10 ` [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a " Arunpravin Paneer Selvam @ 2026-11-30 12:34 ` sashiko-bot 2026-11-30 15:58 ` Christian König 1 sibling, 0 replies; 7+ messages in thread From: sashiko-bot @ 2026-11-30 12:34 UTC (permalink / raw) To: Arunpravin Paneer Selvam, amd-gfx Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/amdgpu: pipelined eviction in amdgpu_move_blit() frees VRAM before wipe - [Medium] drm/amdgpu: wipes queued during reset cancelled on VRAM loss stay cleared - [Medium] drm/amdgpu: late or missing gpu_reset_counter update on ring and IP resets -- commit 350844d593d950a4b54c4d90ed7eb30ac198678d Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset This commit records adev->gpu_reset_counter when queueing a VRAM wipe on buffer release or move, and drops GPU_BUDDY_CLEARED in amdgpu_vram_mgr_del() if the counter changed before the resource is freed. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > index 6aa895f63aeaf..284f2d47869f9 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > @@ -1344,7 +1344,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) > struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); > struct dma_fence *fence = NULL; > struct amdgpu_bo *abo; > - int r; > + int reset_counter, r; > > if (!amdgpu_bo_is_amdgpu_bo(bo)) > return; > @@ -1376,13 +1376,14 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) > if (r) > goto out; > > + reset_counter = atomic_read(&adev->gpu_reset_counter); > r = amdgpu_ttm_clear_buffer(amdgpu_ttm_next_clear_entity(adev), > abo, &bo->base._resv, &fence, > false, AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE); > if (WARN_ON(r)) > goto out; > > - amdgpu_vram_mgr_set_cleared(bo->resource); > + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); > dma_resv_add_fence(&bo->base._resv, fence, DMA_RESV_USAGE_KERNEL); > dma_fence_put(fence); [Severity: Medium] Can a wipe queued during a GPU reset still be cancelled on VRAM loss while its blocks are freed as GPU_BUDDY_CLEARED? CPU0 CPU1 amdgpu_device_gpu_recover() amdgpu_device_halt_activities() drm_sched_wqueue_stop() atomic_inc(&gpu_reset_counter) amdgpu_bo_release_notify() reset_counter = atomic_read(&gpu_reset_counter) amdgpu_ttm_clear_buffer() ... job->generation = amdgpu_vm_generation() amdgpu_vram_mgr_set_cleared(..., reset_counter) amdgpu_device_asic_reset() ... amdgpu_inc_vram_lost() amdgpu_device_sched_resume() amdgpu_job_run() job->generation != amdgpu_vm_generation() dma_fence_set_error(..., -ECANCELED) ttm_bo_delayed_delete() amdgpu_vram_mgr_del() clear_reset_counter == mgr->gpu_reset_counter <-- keeps GPU_BUDDY_CLEARED Neither amdgpu_bo_release_notify() nor amdgpu_move_blit() serializes against reset_domain->sem. If a BO is released or moved after amdgpu_device_halt_activities() increments gpu_reset_counter, but before amdgpu_device_reinit_after_reset() or amdgpu_device_reset_sriov() calls amdgpu_inc_vram_lost(), the clear job captures the old vram_lost_counter in job->generation while clear_reset_counter records the new gpu_reset_counter. When the scheduler resumes, amdgpu_job_run() skips executing the wipe IB with -ECANCELED, and amdgpu_vram_mgr_del() frees the unwiped blocks as cleared because gpu_reset_counter is not incremented again when vram_lost_counter changes. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > index fd649c5509c97..262172ed9b006 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > @@ -435,13 +435,15 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, > /* clear the space being freed */ > if (old_mem->mem_type == TTM_PL_VRAM && > (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) { > + int reset_counter = atomic_read(&adev->gpu_reset_counter); > struct dma_fence *wipe_fence = NULL; > + > r = amdgpu_ttm_clear_buffer(entity, abo, NULL, &wipe_fence, > false, AMDGPU_KERNEL_JOB_ID_MOVE_BLIT); > if (r) { > goto error; > } else if (wipe_fence) { > - amdgpu_vram_mgr_set_cleared(bo->resource); > + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); > dma_fence_put(fence); > fence = wipe_fence; > } [Severity: High] On pipelined eviction of a non-kernel VRAM BO, does amdgpu_move_blit() free bo->resource before wipe_fence executes on the GPU? Right after setting clear_reset_counter, amdgpu_move_blit() calls ttm_bo_move_accel_cleanup(bo, fence, evict, true, new_mem) for non-kernel BOs. When evict is true, TTM takes the pipelined eviction path: drivers/gpu/drm/ttm/ttm_bo_util.c:ttm_bo_move_pipeline_evict() { ... spin_unlock(&from->eviction_lock); end: ttm_resource_free(bo, &bo->resource); return 0; } ttm_resource_free() -> amdgpu_vram_mgr_del() runs synchronously right after the SDMA wipe job is queued, so clear_reset_counter still matches mgr->gpu_reset_counter and the blocks are returned to gpu_buddy with GPU_BUDDY_CLEARED while the wipe is still pending. ttm_bo_evict_cb() then immediately reallocates those blocks to the evicting BO with GPU_BUDDY_HEADER_CLEAR set, causing amdgpu_bo_create() to skip zeroing them; because the blocks are already allocated (no longer in free_tree), a subsequent GPU reset that cancels the in-flight wipe_fence cannot clear their state via gpu_buddy_reset_clear() either, leaving the new BO with unwiped VRAM. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > index d947e048952d2..0706224583ce5 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > @@ -666,6 +666,9 @@ static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, > vis_usage += amdgpu_vram_mgr_vis_size(adev, block); > > amdgpu_vram_mgr_check_reset(adev, mgr); > + if ((vres->flags & GPU_BUDDY_CLEARED) && > + vres->clear_reset_counter != mgr->gpu_reset_counter) > + vres->flags &= ~GPU_BUDDY_CLEARED; > > gpu_buddy_free_list(mm, &vres->blocks, vres->flags); > amdgpu_vram_mgr_do_reserve(man); [Severity: Medium] Can amdgpu_vram_mgr_del() miss a queue, engine, or IP reset that cancels a wipe job before (or without) incrementing adev->gpu_reset_counter? CPU0 CPU1 amdgpu_job_timedout() amdgpu_ring_reset() ... amdgpu_ring_reset_helper_end() /* signals cancelled fences */ drm_sched_wqueue_start() ttm_bo_delayed_delete() amdgpu_vram_mgr_del() amdgpu_vram_mgr_check_reset() clear_reset_counter == mgr->gpu_reset_counter gpu_buddy_free_list(..., GPU_BUDDY_CLEARED) atomic_inc(&adev->gpu_reset_counter) In amdgpu_job_timedout() (both the amdgpu_ring_reset() and amdgpu_device_ip_soft_reset() paths), amdgpu_ring_soft_recovery(), and the need_emergency_restart path in amdgpu_device_halt_activities(), the cancelled fences are signaled before atomic_inc(&adev->gpu_reset_counter) runs, allowing amdgpu_vram_mgr_del() to race ahead and free the unwiped blocks as GPU_BUDDY_CLEARED. In addition, when KFD resets a hung SDMA engine via reset_hung_queues_sdma() -> amdgpu_sdma_reset_engine(), amdgpu_ring_reset_helper_end() resets the SDMA kernel rings and cancels the first unsignaled fence's context without incrementing adev->gpu_reset_counter at all. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261130121049.26541-1-Arunpravin.PaneerSelvam@amd.com?part=3 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset 2026-11-30 12:10 ` [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a " Arunpravin Paneer Selvam 2026-11-30 12:34 ` sashiko-bot @ 2026-11-30 15:58 ` Christian König 1 sibling, 0 replies; 7+ messages in thread From: Christian König @ 2026-11-30 15:58 UTC (permalink / raw) To: Arunpravin Paneer Selvam, amd-gfx; +Cc: alexander.deucher, stable On 11/30/26 13:10, Arunpravin Paneer Selvam wrote: > Blocks whose wipe was queued before a GPU reset are freed as cleared, but > the wipe may have been cancelled by the reset. Record the GPU reset > counter when queueing the wipe and drop the cleared state on free if it > changed. > > v2: > - Split into multiple patches (Christian) > - Use gpu_reset_counter, set before job cancel and on any reset (Christian) > > Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality") > Cc: stable@vger.kernel.org > Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> Yeah Sashiko also pointed out that this approach has problems. I think we need to approach it the other way around. Instead of adding the reset counter to struct amdgpu_vram_mgr_resource we should add it to struct amdgpu_vram_mgr. And then every time amdgpu_vram_mgr_new() is called and has locked &mgr->lock it checks if mgr->reset_counter still matches adev->gpu_reset_counter. If it doesn't match we save the new value and reset the whole VRAM to uncleared so that all allocations will be cleared again. Regards, Christian. > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 5 +++-- > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 +++- > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 3 +++ > drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h | 5 ++++- > 4 files changed, 13 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > index d4651f2d437c..01d18e46aa1b 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c > @@ -1366,7 +1366,7 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) > struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); > struct dma_fence *fence = NULL; > struct amdgpu_bo *abo; > - int r; > + int reset_counter, r; > > if (!amdgpu_bo_is_amdgpu_bo(bo)) > return; > @@ -1398,13 +1398,14 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo) > if (r) > goto out; > > + reset_counter = atomic_read(&adev->gpu_reset_counter); > r = amdgpu_ttm_clear_buffer(amdgpu_ttm_next_clear_entity(adev), > abo, &bo->base._resv, &fence, > false, AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE); > if (WARN_ON(r)) > goto out; > > - amdgpu_vram_mgr_set_cleared(bo->resource); > + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); > dma_resv_add_fence(&bo->base._resv, fence, DMA_RESV_USAGE_KERNEL); > dma_fence_put(fence); > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > index 346e7be57fd8..fa21e2db545a 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > @@ -435,13 +435,15 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, > /* clear the space being freed */ > if (old_mem->mem_type == TTM_PL_VRAM && > (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) { > + int reset_counter = atomic_read(&adev->gpu_reset_counter); > struct dma_fence *wipe_fence = NULL; > + > r = amdgpu_ttm_clear_buffer(entity, abo, NULL, &wipe_fence, > false, AMDGPU_KERNEL_JOB_ID_MOVE_BLIT); > if (r) { > goto error; > } else if (wipe_fence) { > - amdgpu_vram_mgr_set_cleared(bo->resource); > + amdgpu_vram_mgr_set_cleared(bo->resource, reset_counter); > dma_fence_put(fence); > fence = wipe_fence; > } > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > index d947e048952d..0706224583ce 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c > @@ -666,6 +666,9 @@ static void amdgpu_vram_mgr_del(struct ttm_resource_manager *man, > vis_usage += amdgpu_vram_mgr_vis_size(adev, block); > > amdgpu_vram_mgr_check_reset(adev, mgr); > + if ((vres->flags & GPU_BUDDY_CLEARED) && > + vres->clear_reset_counter != mgr->gpu_reset_counter) > + vres->flags &= ~GPU_BUDDY_CLEARED; > > gpu_buddy_free_list(mm, &vres->blocks, vres->flags); > amdgpu_vram_mgr_do_reserve(man); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h > index da1efd0e26a1..abd7bc1811fc 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h > @@ -59,6 +59,7 @@ struct amdgpu_vram_mgr_resource { > unsigned long flags; > struct list_head vres_node; > struct amdgpu_vres_task task; > + int clear_reset_counter; > }; > > static inline u64 amdgpu_vram_mgr_block_start(struct gpu_buddy_block *block) > @@ -82,12 +83,14 @@ to_amdgpu_vram_mgr_resource(struct ttm_resource *res) > return container_of(res, struct amdgpu_vram_mgr_resource, base); > } > > -static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res) > +static inline void amdgpu_vram_mgr_set_cleared(struct ttm_resource *res, > + int reset_counter) > { > struct amdgpu_vram_mgr_resource *ares = to_amdgpu_vram_mgr_resource(res); > > WARN_ON(ares->flags & GPU_BUDDY_CLEARED); > ares->flags |= GPU_BUDDY_CLEARED; > + ares->clear_reset_counter = reset_counter; > } > > int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr, ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors 2026-11-30 12:10 [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Arunpravin Paneer Selvam 2026-11-30 12:10 ` [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam 2026-11-30 12:10 ` [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a " Arunpravin Paneer Selvam @ 2026-11-30 15:51 ` Christian König 2 siblings, 0 replies; 7+ messages in thread From: Christian König @ 2026-11-30 15:51 UTC (permalink / raw) To: Arunpravin Paneer Selvam, amd-gfx; +Cc: alexander.deucher, stable On 11/30/26 13:10, Arunpravin Paneer Selvam wrote: > After a GPU reset, a clear job cancelled by the reset leaves its error on > the entity and every following clear job inherits it and is skipped, so > freed VRAM is no longer cleared. Clear jobs don't depend on the previous > job, so let them ignore the entity error. > > v2: > - Split into multiple patches (Christian) > > Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality") > Cc: stable@vger.kernel.org > Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141 > Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 8 +++++--- > drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 1 + > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 ++ > 3 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c > index 8689a3c933b2..b186b5b73de2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c > @@ -391,9 +391,11 @@ amdgpu_job_prepare_job(struct drm_sched_job *sched_job, > struct dma_fence *fence; > int r; > > - r = drm_sched_entity_error(s_entity); > - if (r) > - goto error; > + if (!job->ignore_entity_error) { > + r = drm_sched_entity_error(s_entity); > + if (r) > + goto error; > + } > > if (job->gang_submit) { > fence = amdgpu_device_switch_gang(ring->adev, job->gang_submit); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h > index 18e788f0e790..1947d650cd7f 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.h > @@ -75,6 +75,7 @@ struct amdgpu_job { > uint32_t preemption_status; > bool vm_needs_flush; > bool gds_switch_needed; > + bool ignore_entity_error; That needs a better name. Something like kernel_job maybe? > uint64_t vm_pd_addr; > unsigned vmid; > unsigned pasid; > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > index d5c1d044403e..346e7be57fd8 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c > @@ -2647,6 +2647,8 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev, > if (r) > return r; > > + job->ignore_entity_error = true; We should also do this for copies as well. Apart from that looks good to me, Christian. > + > for (i = 0; i < num_loops; i++) { > uint32_t cur_size = min(byte_count, max_bytes); > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-30 15:58 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-30 12:10 [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Arunpravin Paneer Selvam 2026-11-30 12:10 ` [PATCH v2 2/3] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam 2026-11-30 12:34 ` sashiko-bot 2026-11-30 12:10 ` [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a " Arunpravin Paneer Selvam 2026-11-30 12:34 ` sashiko-bot 2026-11-30 15:58 ` Christian König 2026-11-30 15:51 ` [PATCH v2 1/3] drm/amdgpu: Don't let clear jobs inherit entity errors Christian König
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox