All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors
@ 2026-12-02 13:22 Arunpravin Paneer Selvam
  2026-12-02 13:22 ` [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam
  2026-12-02 13:36 ` [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors sashiko-bot
  0 siblings, 2 replies; 4+ messages in thread
From: Arunpravin Paneer Selvam @ 2026-12-02 13:22 UTC (permalink / raw)
  To: christian.koenig, amd-gfx
  Cc: alexander.deucher, Ke.Chen, Arunpravin Paneer Selvam, stable

After a GPU reset, a job cancelled by the reset leaves its error on the
TTM entity and every following copy and clear job inherits it and is
skipped, so freed VRAM is no longer cleared. These kernel jobs don't
depend on the result of the previous job, so let them ignore the entity
error.

v2:
- Split into multiple patches (Christian)

v3:
- Rename the flag to kernel_job and also set it for copy jobs (Christian)

Fixes: a68c7eaa7a8f ("drm/amdgpu: Enable clear page functionality")
Cc: stable@vger.kernel.org
Reported-by: Ke Chen <Ke.Chen@amd.com>
Closes: https://gitlab.freedesktop.org/drm/amd/-/issues/6141
Tested-by: Ke Chen <Ke.Chen@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_ttm.c | 4 ++++
 3 files changed, 10 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..0185f7c76755 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->kernel_job) {
+		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..0d75bd7f54e5 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			kernel_job;
 	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..b7ed98321b4c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2603,6 +2603,8 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev,
 	if (r)
 		goto error_free;
 
+	job->kernel_job = true;
+
 	for (i = 0; i < num_loops; i++) {
 		uint32_t cur_size_in_bytes = min(byte_count, max_bytes);
 
@@ -2647,6 +2649,8 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev,
 	if (r)
 		return r;
 
+	job->kernel_job = 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] 4+ messages in thread

* [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset
  2026-12-02 13:22 [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors Arunpravin Paneer Selvam
@ 2026-12-02 13:22 ` Arunpravin Paneer Selvam
  2026-12-02 13:39   ` sashiko-bot
  2026-12-02 13:36 ` [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors sashiko-bot
  1 sibling, 1 reply; 4+ messages in thread
From: Arunpravin Paneer Selvam @ 2026-12-02 13:22 UTC (permalink / raw)
  To: christian.koenig, amd-gfx
  Cc: alexander.deucher, Ke.Chen, Arunpravin Paneer Selvam, stable

Free blocks marked as cleared can hold old data after a GPU reset, as
VRAM may have been lost or a pending clear cancelled. Track the GPU reset
counter in the VRAM manager and reset the cleared state of all free
blocks on the first allocation after it 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)

v3:
- Drop the per resource reset counter patch and the check in free, only
  check the counter in alloc (Christian)

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 | 10 +++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.h |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 249f07f30951..6aa6d49b8e80 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 reset_counter, 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);
+
+	reset_counter = atomic_read(&adev->gpu_reset_counter);
+	if (unlikely(mgr->reset_counter != reset_counter)) {
+		gpu_buddy_reset_clear(mm, false);
+		mgr->reset_counter = reset_counter;
+	}
+
 	while (remaining_size) {
 		if (tbo->page_alignment)
 			min_block_size = (u64)tbo->page_alignment << PAGE_SHIFT;
@@ -961,6 +968,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->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..65d9bff9e57f 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 reset_counter;
 };
 
 struct amdgpu_vres_task {
-- 
2.53.0


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

* Re: [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors
  2026-12-02 13:22 [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors Arunpravin Paneer Selvam
  2026-12-02 13:22 ` [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam
@ 2026-12-02 13:36 ` sashiko-bot
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 13:36 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, amd-gfx

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: GART mapping jobs skipped on reset entity before
  copy or fill
--

commit 8e8b892180ec2dcc253bf2cd1dc6c2ab470bab03
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>

drm/amdgpu: Don't let kernel jobs inherit entity errors

This commit adds a kernel_job flag to struct amdgpu_job and sets it in
amdgpu_copy_buffer() and amdgpu_ttm_fill_mem() so that TTM copy and fill
jobs ignore prior errors on their scheduler entity in
amdgpu_job_prepare_job().

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 4d0b9897a5233..9d8f7008c6f64 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -2595,6 +2595,8 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev,
>  	if (r)
>  		goto error_free;
>  
> +	job->kernel_job = true;
> +
>  	for (i = 0; i < num_loops; i++) {
>  		uint32_t cur_size_in_bytes = min(byte_count, max_bytes);
>  
> @@ -2639,6 +2641,8 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev,
>  	if (r)
>  		return r;
>  
> +	job->kernel_job = true;
> +
>  	for (i = 0; i < num_loops; i++) {
>  		uint32_t cur_size = min(byte_count, max_bytes);

[Severity: High]
Can this cause amdgpu_copy_buffer() and amdgpu_ttm_fill_mem() to DMA
through stale GART window PTEs after a GPU reset?

When a move, clear, or KFD SVM migration needs a GART window (for example
in amdgpu_ttm_copy_mem_to_mem(), amdgpu_ttm_clear_buffer(), or
svm_migrate_copy_memory_gart()), it first queues a GART PTE update job on
the same entity via amdgpu_ttm_map_buffer() or svm_migrate_gart_map().
Those functions do not set job->kernel_job = true.

If a prior GPU reset left an error on that entity, amdgpu_job_prepare_job()
fails the GART mapping job and skips the PTE update, but the paired
amdgpu_copy_buffer() or amdgpu_ttm_fill_mem() job now ignores the entity
error and runs SDMA against the unupdated GART window address, reading or
writing physical memory mapped by a previous transfer.

Kernel jobs submitted on adev->mman.default_entity by
amdgpu_ttm_access_memory_sdma() and amdgpu_gmc_flush_gpu_tlb() also leave
job->kernel_job unset and will still be skipped after an error on that
entity.

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

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

* Re: [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset
  2026-12-02 13:22 ` [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam
@ 2026-12-02 13:39   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 13:39 UTC (permalink / raw)
  To: Arunpravin Paneer Selvam, amd-gfx

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdgpu: stale clear flag on in-flight BOs in
  amdgpu_vram_mgr_del()
- [Medium] drm/amdgpu: post-reset cleared VRAM marked dirty in
  amdgpu_vram_mgr_new()
--

commit 2577c3d1b0a535240f16afc3751845e6b2fd1bb7
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 the VRAM manager and resets
the cleared state of free buddy blocks on the first VRAM allocation after
a GPU reset.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 249f07f309515..6aa6d49b8e80b 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 reset_counter, 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);
> +
> +	reset_counter = atomic_read(&adev->gpu_reset_counter);
> +	if (unlikely(mgr->reset_counter != reset_counter)) {
> +		gpu_buddy_reset_clear(mm, false);
> +		mgr->reset_counter = reset_counter;
> +	}
> +

[Severity: High]
Can a BO whose wipe-on-release clear job was in flight across a GPU reset
still return its uncleared blocks to the buddy allocator with
GPU_BUDDY_CLEARED after gpu_buddy_reset_clear() has already run?

amdgpu_bo_release_notify() sets GPU_BUDDY_CLEARED on bo->resource as soon
as amdgpu_ttm_clear_buffer() submits the asynchronous SDMA clear job,
while the blocks remain allocated until the fence signals and
ttm_bo_delayed_delete() calls amdgpu_vram_mgr_del():

CPU0                                    CPU1 / bdev->wq
amdgpu_bo_release_notify()
  amdgpu_ttm_clear_buffer()
  amdgpu_vram_mgr_set_cleared()
                                        amdgpu_device_halt_activities()
                                          atomic_inc(&gpu_reset_counter)
amdgpu_vram_mgr_new()
  gpu_buddy_reset_clear(mm, false)
  mgr->reset_counter = reset_counter
                                        ... (reset cancels clear fence
                                             or loses VRAM)
                                        ttm_bo_delayed_delete()
                                          amdgpu_vram_mgr_del()
                                            gpu_buddy_free_list(...,
                                              vres->flags)  <-- marks dirty
                                                                blocks clear

Because vres->blocks were not in mm->free_tree when amdgpu_vram_mgr_new()
ran, gpu_buddy_reset_clear() did not touch them, and
amdgpu_vram_mgr_del() later frees them with GPU_BUDDY_CLEARED while
mgr->reset_counter is already up to date.  Subsequent
AMDGPU_GEM_CREATE_VRAM_CLEARED allocations can then skip zeroing those
blocks and expose stale pre-reset VRAM contents across userspace
processes.

[Severity: Medium]
What happens if one or more BOs are released and cleared by SDMA after a
GPU reset finishes, before the first post-reset call to
amdgpu_vram_mgr_new()?

Because amdgpu_vram_mgr_del() does not check or update
mgr->reset_counter, any blocks that were genuinely cleared and freed
during post-reset teardown are placed into mm->free_tree while
mgr->reset_counter still holds its pre-reset value.  The first subsequent
amdgpu_vram_mgr_new() then sees mgr->reset_counter != reset_counter and
calls gpu_buddy_reset_clear(mm, false), wiping the cleared state of those
post-reset blocks and forcing redundant SDMA clear passes on reallocation.

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

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

end of thread, other threads:[~2026-12-02 13:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:22 [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors Arunpravin Paneer Selvam
2026-12-02 13:22 ` [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset Arunpravin Paneer Selvam
2026-12-02 13:39   ` sashiko-bot
2026-12-02 13:36 ` [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors sashiko-bot

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.