From: sashiko-bot@kernel.org
To: "Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>,
amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset
Date: Mon, 30 Nov 2026 12:34:32 +0000 [thread overview]
Message-ID: <sashiko-outbox-241063@kernel.org> (raw)
In-Reply-To: <20261130121049.26541-3-Arunpravin.PaneerSelvam@amd.com>
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
next prev parent reply other threads:[~2026-11-30 12:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-241063@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Arunpravin.PaneerSelvam@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox