All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset
@ 2026-11-26 14:42 Arunpravin Paneer Selvam
  2026-11-26 15:14 ` sashiko-bot
  2026-11-27  8:58 ` Christian König
  0 siblings, 2 replies; 3+ messages in thread
From: Arunpravin Paneer Selvam @ 2026-11-26 14:42 UTC (permalink / raw)
  To: christian.koenig, amd-gfx; +Cc: alexander.deucher, Arunpravin Paneer Selvam

After a VRAM lost reset, freed VRAM can be handed out with old data:

1. Clear jobs inherit the error of a job cancelled by the reset and are
   skipped. Let clear jobs ignore the entity error.
2. Free blocks marked as cleared before the reset are not clear anymore.
   Reset their cleared state when the VRAM lost counter changes.
3. Blocks whose wipe was queued before the reset are freed as cleared,
   but the wipe may have been dropped. Don't mark them as cleared then.

Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141
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_job.c      |  8 +++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   |  5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      |  6 +++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 15 ++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h |  6 +++++-
 6 files changed, 33 insertions(+), 8 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_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index d4651f2d437c..9512c778c4f1 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 vram_lost, 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;
 
+	vram_lost = atomic_read(&adev->vram_lost_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, vram_lost);
 	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 d5c1d044403e..5c683df901ca 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 vram_lost = atomic_read(&adev->vram_lost_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, vram_lost);
 			dma_fence_put(fence);
 			fence = wipe_fence;
 		}
@@ -2647,6 +2649,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);
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 249f07f30951..ef4c7b438406 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -456,7 +456,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 	struct gpu_buddy *mm = &mgr->mm;
 	struct gpu_buddy_block *block;
 	unsigned long pages_per_block;
-	int r;
+	int vram_lost, r;
 
 	lpfn = (u64)place->lpfn << PAGE_SHIFT;
 	if (!lpfn || lpfn > man->size)
@@ -523,6 +523,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 	}
 
 	mutex_lock(&mgr->lock);
+
+	vram_lost = atomic_read(&adev->vram_lost_counter);
+	if (unlikely(mgr->vram_lost_counter != vram_lost)) {
+		gpu_buddy_reset_clear(mm, false);
+		mgr->vram_lost_counter = vram_lost;
+	}
+
 	while (remaining_size) {
 		if (tbo->page_alignment)
 			min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT;
@@ -652,6 +659,11 @@ 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);
 
+	if ((vres->flags & GPU_BUDDY_CLEARED) &&
+	    vres->clear_vram_lost_counter != atomic_read(&adev->vram_lost_counter)) {
+		vres->flags &= ~GPU_BUDDY_CLEARED;
+	}
+
 	gpu_buddy_free_list(mm, &vres->blocks, vres->flags);
 	amdgpu_vram_mgr_do_reserve(man);
 	mutex_unlock(&mgr->lock);
@@ -961,6 +973,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->vram_lost_counter = atomic_read(&adev->vram_lost_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..378e9c89be7d 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 vram_lost_counter;
 };
 
 struct amdgpu_vres_task {
@@ -58,6 +59,7 @@ struct amdgpu_vram_mgr_resource {
 	unsigned long flags;
 	struct list_head vres_node;
 	struct amdgpu_vres_task task;
+	int clear_vram_lost_counter;
 };
 
 static inline u64 amdgpu_vram_mgr_block_start(struct gpu_buddy_block *block)
@@ -81,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 vram_lost_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_vram_lost_counter = vram_lost_counter;
 }
 
 int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr,
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset
  2026-11-26 14:42 [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset Arunpravin Paneer Selvam
@ 2026-11-26 15:14 ` sashiko-bot
  2026-11-27  8:58 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-26 15:14 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, amd-gfx

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/amdgpu: map and copy jobs on TTM entities skipped after
  reset
- [High] drm/amdgpu: unwiped VRAM blocks freed as cleared in
  amdgpu_vram_mgr_del()
- [Low] drm/amdgpu: missing mgr->vram_lost_counter sync in
  amdgpu_vram_mgr_del()
- [Low] drm/amdgpu: missing Fixes trailer for commit a68c7eaa7a8f
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] drm/amdgpu: NULL pointer dereference and job leak in
  amdgpu_ttm_prepare_job() [1]
--

commit 644d53e55a5fbf61b0bce43757d1045f37e6f6c6
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

> drm/amdgpu: Fix VRAM clearing after GPU reset
>
> After a VRAM lost reset, freed VRAM can be handed out with old data:
>
> 1. Clear jobs inherit the error of a job cancelled by the reset and are
>    skipped. Let clear jobs ignore the entity error.
> 2. Free blocks marked as cleared before the reset are not clear anymore.
>    Reset their cleared state when the VRAM lost counter changes.
> 3. Blocks whose wipe was queued before the reset are freed as cleared,
>    but the wipe may have been dropped. Don't mark them as cleared then.
>
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141
> Suggested-by: Christian König <christian.koenig@amd.com>
> Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

[Severity: Low]
This fixes a bug in the VRAM clear-on-release tracking.  Should it include:

  Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality")

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index d3a875a32af1e..703c0952776e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

[ ... ]

> @@ -2639,6 +2641,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);

[Severity: High]
This problem wasn't introduced by this patch, but amdgpu_ttm_prepare_job()
leaves its output job pointer in an inconsistent state on failure [1],
which can cause a NULL pointer dereference in amdgpu_copy_buffer() or leak
job in amdgpu_ttm_fill_mem():

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:amdgpu_ttm_prepare_job() {
	...
	r = amdgpu_job_alloc_with_ib(adev, &entity->base,
				     AMDGPU_FENCE_OWNER_UNDEFINED,
				     num_dw * 4, pool, k_job_id, job);
	if (r)
		return r;
	...
	return drm_sched_job_add_resv_dependencies(&(*job)->base, resv,
						   DMA_RESV_USAGE_BOOKKEEP);
}

When amdgpu_job_alloc_with_ib() fails, *job is NULL, and amdgpu_copy_buffer()
jumps to error_free and passes NULL to amdgpu_job_free(), dereferencing
job->base.entity.  When drm_sched_job_add_resv_dependencies() fails after
amdgpu_job_alloc_with_ib() succeeds, amdgpu_ttm_fill_mem() returns r without
calling amdgpu_job_free(job), leaking the allocated job and its IB.

[Severity: High]
Should GART mapping jobs in amdgpu_ttm_map_buffer() and buffer copy jobs in
amdgpu_copy_buffer() also set job->ignore_entity_error = true?

The TTM scheduler entities (move_entities and clear_entities) persist across
GPU resets because amdgpu_ttm_disable_buffer_funcs() and
amdgpu_ttm_enable_buffer_funcs() return early when amdgpu_in_reset(adev) is
true.  If a reset cancels any job on move_entities[e], that entity's
last_scheduled fence remains at -ECANCELED.

In a later amdgpu_move_blit() on that entity for a BO with
AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE, the map and copy jobs submitted by
amdgpu_ttm_copy_mem_to_mem() have ignore_entity_error == false and are
aborted by amdgpu_job_prepare_job(), whereas the trailing wipe job from
amdgpu_ttm_fill_mem() ignores the entity error and zeroes old_mem in VRAM
before its contents were copied to new_mem.  Similarly, in
amdgpu_ttm_clear_buffer(), any GART window mapping job submitted by
amdgpu_ttm_map_buffer() is skipped while amdgpu_ttm_fill_mem() runs against
a stale GART window.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 249f07f309515..ef4c7b4384061 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -456,7 +456,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
>  	struct gpu_buddy *mm = &mgr->mm;
>  	struct gpu_buddy_block *block;
>  	unsigned long pages_per_block;
> -	int r;
> +	int vram_lost, r;
>  
>  	lpfn = (u64)place->lpfn << PAGE_SHIFT;
>  	if (!lpfn || lpfn > man->size)
> @@ -523,6 +523,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
>  	}
>  
>  	mutex_lock(&mgr->lock);
> +
> +	vram_lost = atomic_read(&adev->vram_lost_counter);
> +	if (unlikely(mgr->vram_lost_counter != vram_lost)) {
> +		gpu_buddy_reset_clear(mm, false);
> +		mgr->vram_lost_counter = vram_lost;
> +	}
> +
>  	while (remaining_size) {
>  		if (tbo->page_alignment)
>  			min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT;
> @@ -652,6 +659,11 @@ 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);
>  
> +	if ((vres->flags & GPU_BUDDY_CLEARED) &&
> +	    vres->clear_vram_lost_counter != atomic_read(&adev->vram_lost_counter)) {
> +		vres->flags &= ~GPU_BUDDY_CLEARED;
> +	}
> +
>  	gpu_buddy_free_list(mm, &vres->blocks, vres->flags);
>  	amdgpu_vram_mgr_do_reserve(man);
>  	mutex_unlock(&mgr->lock);

[Severity: High]
Can amdgpu_vram_mgr_del() still free unwiped blocks as GPU_BUDDY_CLEARED
when a GPU reset aborts an in-flight wipe job?

Comparing vres->clear_vram_lost_counter against adev->vram_lost_counter in
amdgpu_vram_mgr_del() misses three cases where the counters still match even
though the wipe job never ran:

1. In amdgpu_move_blit(), when evict is true on a non-kernel BO,
   ttm_bo_move_accel_cleanup() calls ttm_bo_move_pipeline_evict(), which
   frees old_mem via amdgpu_vram_mgr_del() synchronously right after queuing
   wipe_fence.  At that point adev->vram_lost_counter has not changed yet,
   so the blocks are returned to gpu_buddy with GPU_BUDDY_CLEARED before the
   wipe job runs on the hardware.
2. During a VRAM-lost reset, amdgpu_device_pre_asic_reset() calls
   amdgpu_fence_driver_force_completion() to signal in-flight SDMA fences
   with -ECANCELED before the ASIC reset runs, whereas amdgpu_inc_vram_lost()
   is only called later in amdgpu_device_reinit_after_reset().  Force-
   completing the wipe fence immediately schedules ttm_bo_delayed_delete()
   to run amdgpu_vram_mgr_del() while adev->vram_lost_counter still matches
   vres->clear_vram_lost_counter:

CPU0 (reset)                      CPU1 (bdev->wq)
amdgpu_device_pre_asic_reset()
  amdgpu_fence_driver_force_completion()
    /* signals wipe fence (-ECANCELED) */
                                  ttm_bo_delayed_delete()
                                    ...
                                    amdgpu_vram_mgr_del()
                                      /* vram_lost_counter unchanged */
                                      gpu_buddy_free_list(...,
                                        GPU_BUDDY_CLEARED)
amdgpu_do_asic_reset()
  amdgpu_device_reinit_after_reset()
    amdgpu_inc_vram_lost()

3. On a GPU reset where VRAM is not lost (such as Mode 2 reset on APUs),
   amdgpu_device_pre_asic_reset() still force-completes in-flight wipe fences
   with -ECANCELED, but amdgpu_inc_vram_lost() is never called.

In each case, the unwiped blocks are marked clear in gpu_buddy and can be
handed out to later AMDGPU_GEM_CREATE_VRAM_CLEARED allocations with stale
data.

[Severity: Low]
Should amdgpu_vram_mgr_del() also synchronize mgr->vram_lost_counter and run
gpu_buddy_reset_clear(mm, false) before calling gpu_buddy_free_list()?

If a BO is released and wiped after a VRAM-lost reset completes, but before
the next amdgpu_vram_mgr_new() call, amdgpu_vram_mgr_del() frees those
Freshly wiped blocks into mm as cleared while mgr->vram_lost_counter still
holds the pre-reset value.  The first subsequent amdgpu_vram_mgr_new() then
sees mgr->vram_lost_counter != vram_lost and calls
gpu_buddy_reset_clear(mm, false), marking those post-reset cleared blocks
dirty again.

[1] https://sashiko.dev/#/bug/linux-1b68b982-50e9-427b-a5c7-1a7c0cf5aa51

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126144240.598627-1-Arunpravin.PaneerSelvam@amd.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset
  2026-11-26 14:42 [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset Arunpravin Paneer Selvam
  2026-11-26 15:14 ` sashiko-bot
@ 2026-11-27  8:58 ` Christian König
  1 sibling, 0 replies; 3+ messages in thread
From: Christian König @ 2026-11-27  8:58 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, amd-gfx; +Cc: alexander.deucher

On 11/26/26 15:42, Arunpravin Paneer Selvam wrote:
> After a VRAM lost reset, freed VRAM can be handed out with old data:
> 
> 1. Clear jobs inherit the error of a job cancelled by the reset and are
>    skipped. Let clear jobs ignore the entity error.
> 2. Free blocks marked as cleared before the reset are not clear anymore.
>    Reset their cleared state when the VRAM lost counter changes.
> 3. Blocks whose wipe was queued before the reset are freed as cleared,
>    but the wipe may have been dropped. Don't mark them as cleared then.

Please split that up into multiple patches, especially the error handling for kernel entities.

Regards,
Christian.

> 
> Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141
> 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_job.c      |  8 +++++---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h      |  1 +
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   |  5 +++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      |  6 +++++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 15 ++++++++++++++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h |  6 +++++-
>  6 files changed, 33 insertions(+), 8 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_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index d4651f2d437c..9512c778c4f1 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 vram_lost, 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;
>  
> +	vram_lost = atomic_read(&adev->vram_lost_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, vram_lost);
>  	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 d5c1d044403e..5c683df901ca 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 vram_lost = atomic_read(&adev->vram_lost_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, vram_lost);
>  			dma_fence_put(fence);
>  			fence = wipe_fence;
>  		}
> @@ -2647,6 +2649,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);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 249f07f30951..ef4c7b438406 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -456,7 +456,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
>  	struct gpu_buddy *mm = &mgr->mm;
>  	struct gpu_buddy_block *block;
>  	unsigned long pages_per_block;
> -	int r;
> +	int vram_lost, r;
>  
>  	lpfn = (u64)place->lpfn << PAGE_SHIFT;
>  	if (!lpfn || lpfn > man->size)
> @@ -523,6 +523,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
>  	}
>  
>  	mutex_lock(&mgr->lock);
> +
> +	vram_lost = atomic_read(&adev->vram_lost_counter);
> +	if (unlikely(mgr->vram_lost_counter != vram_lost)) {
> +		gpu_buddy_reset_clear(mm, false);
> +		mgr->vram_lost_counter = vram_lost;
> +	}
> +
>  	while (remaining_size) {
>  		if (tbo->page_alignment)
>  			min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT;
> @@ -652,6 +659,11 @@ 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);
>  
> +	if ((vres->flags & GPU_BUDDY_CLEARED) &&
> +	    vres->clear_vram_lost_counter != atomic_read(&adev->vram_lost_counter)) {
> +		vres->flags &= ~GPU_BUDDY_CLEARED;
> +	}
> +
>  	gpu_buddy_free_list(mm, &vres->blocks, vres->flags);
>  	amdgpu_vram_mgr_do_reserve(man);
>  	mutex_unlock(&mgr->lock);
> @@ -961,6 +973,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->vram_lost_counter = atomic_read(&adev->vram_lost_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..378e9c89be7d 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 vram_lost_counter;
>  };
>  
>  struct amdgpu_vres_task {
> @@ -58,6 +59,7 @@ struct amdgpu_vram_mgr_resource {
>  	unsigned long flags;
>  	struct list_head vres_node;
>  	struct amdgpu_vres_task task;
> +	int clear_vram_lost_counter;
>  };
>  
>  static inline u64 amdgpu_vram_mgr_block_start(struct gpu_buddy_block *block)
> @@ -81,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 vram_lost_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_vram_lost_counter = vram_lost_counter;
>  }
>  
>  int amdgpu_vram_mgr_query_address_block_info(struct amdgpu_vram_mgr *mgr,


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27  8:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 14:42 [PATCH] drm/amdgpu: Fix VRAM clearing after GPU reset Arunpravin Paneer Selvam
2026-11-26 15:14 ` sashiko-bot
2026-11-27  8:58 ` 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.