From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ACFA606A32E for ; Mon, 30 Nov 2026 12:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Aes/3BG3 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB08310EF2F; Mon, 30 Nov 2026 12:34:39 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8164910EF2F for ; Mon, 30 Nov 2026 12:34:33 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 18B1C406A3; Mon, 30 Nov 2026 12:34:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 948AB1F0089A; Mon, 30 Nov 2026 12:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796042072; bh=x6eT41hExBCopZVOgxwegkh6EO3g8B2kV2DGyU9usC0=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=Aes/3BG33llnkmbHB4k8fyxPRQAS5EFJLiLZOWpGuk4/RB8ZsRrSlCY5smWrKj37K FRJg0346AvR/tjx8nxvjX0UV+vJ75FQ8Lbuqpl/ZZOtrmYFSrgzVvCu14UQyiQFD6A g4cJtPXGms+owLDahFq+QrFBqtQP9bCL1qF91gQAFp5+S2vcC9Y2LZvLyduLTjAdbC uw2Mw/NvV4wSsBRjxWcIoozCxaCbzg+xMXHah39gaMl8KqZkbNkeRU9TtRQk+8hBi/ pGXXiXJhUiBcFcr3LDaLnYat1Z9VtiXzuTyxzhI1oaceeu1cp5p/xyBwkkD3JfBErG C4oEB/j/S4Nfw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 3/3] drm/amdgpu: Don't free VRAM as cleared if its wipe predates a GPU reset To: "Arunpravin Paneer Selvam" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261130121049.26541-3-Arunpravin.PaneerSelvam@amd.com> References: <20261130121049.26541-1-Arunpravin.PaneerSelvam@amd.com> <20261130121049.26541-3-Arunpravin.PaneerSelvam@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 12:34:32 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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_obj= ect *bo) > struct amdgpu_device *adev =3D amdgpu_ttm_adev(bo->bdev); > struct dma_fence *fence =3D NULL; > struct amdgpu_bo *abo; > - int r; > + int reset_counter, r; > =20 > if (!amdgpu_bo_is_amdgpu_bo(bo)) > return; > @@ -1376,13 +1376,14 @@ void amdgpu_bo_release_notify(struct ttm_buffer_o= bject *bo) > if (r) > goto out; > =20 > + reset_counter =3D atomic_read(&adev->gpu_reset_counter); > r =3D 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; > =20 > - 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 =3D atomic_read(&gpu_reset_counter) amdgpu_ttm_clear_buffer() ... job->generation =3D 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 !=3D amdgpu_vm_generation() dma_fence_set_error(..., -ECANCELE= D) ttm_bo_delayed_delete() amdgpu_vram_mgr_del() clear_reset_counter =3D=3D 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/am= d/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_objec= t *bo, > /* clear the space being freed */ > if (old_mem->mem_type =3D=3D TTM_PL_VRAM && > (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) { > + int reset_counter =3D atomic_read(&adev->gpu_reset_counter); > struct dma_fence *wipe_fence =3D NULL; > + > r =3D 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 =3D 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/d= rm/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_m= anager *man, > vis_usage +=3D amdgpu_vram_mgr_vis_size(adev, block); > =20 > amdgpu_vram_mgr_check_reset(adev, mgr); > + if ((vres->flags & GPU_BUDDY_CLEARED) && > + vres->clear_reset_counter !=3D mgr->gpu_reset_counter) > + vres->flags &=3D ~GPU_BUDDY_CLEARED; > =20 > 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 =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130121049.2654= 1-1-Arunpravin.PaneerSelvam@amd.com?part=3D3