All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arunpravin Paneer Selvam" <Arunpravin.PaneerSelvam@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH v3 2/2] drm/amdgpu: Reset cleared state of free VRAM after GPU reset
Date: Wed, 02 Dec 2026 13:39:00 +0000	[thread overview]
Message-ID: <sashiko-outbox-245890@kernel.org> (raw)
In-Reply-To: <20261202132224.217180-2-Arunpravin.PaneerSelvam@amd.com>

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

  reply	other threads:[~2026-12-02 13:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-02 13:36 ` [PATCH v3 1/2] drm/amdgpu: Don't let kernel jobs inherit entity errors sashiko-bot

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-245890@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 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.