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 D371F606A339 for ; Tue, 1 Dec 2026 09:08:00 +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=oBNn5+94 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BC5510F68A; Tue, 1 Dec 2026 09:07:55 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D0E710E90E for ; Tue, 1 Dec 2026 09:07:49 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 118584146B; Tue, 1 Dec 2026 09:07:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69D471F00893; Tue, 1 Dec 2026 09:07:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796116068; bh=SI9Jb6QsJJUIj+//Pu68b7HY/3ZG0AEfvuxMm9aCMV4=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=oBNn5+948S5nLek1eczJ/+hKjXSBwM7XnqIv0DCHEkPIYwch3NcorB93pEmLSr2wg kuHUG5akxYFbZgBLMo5fWwaXZmebfPGBzBE5gKwcVVayqm/bHFljIi5ZXM+4HChmgD Wj+QUPcb6vpsnGsVKDAl3l/N/oB4LLcneFeQUqOM7sTHgwKIFbM73BG5xUs56bc9wD 4mApiqGWtT+UfCCWgXhyRbrPeCx+wG7aIL4xc0T6KvskB3uQx91TZfMhUReke2V/9V Ej0qLUFN63PaGH2KI4IkPbS6v2cVBXVCycc8+wGhNa13ieE4OXZ4o5lOIz50vQneKN 8RiDO3V6Gim7w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/3] drm/ttm: Narrow the eviction lock scope when adding move fences To: "Perry Yuan" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261201090028.86494-3-perry.yuan@amd.com> References: <20261201090028.86494-1-perry.yuan@amd.com> <20261201090028.86494-3-perry.yuan@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 09:07:48 +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 no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] drm/amdgpu: insufficient fence slot reservation in amdgpu_dma_buf_move_notify() [1] -- commit d22882cc6158883831770886db4d0852012b8d1a Author: Perry Yuan drm/ttm: Narrow the eviction lock scope when adding move fences This commit snapshots pending eviction fences under man->eviction_lock and adds them to the BO's reservation object after releasing the lock. > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c > index 53c68e29ebc21..f833982073c6a 100644 > --- a/drivers/gpu/drm/ttm/ttm_bo.c > +++ b/drivers/gpu/drm/ttm/ttm_bo.c > @@ -908,33 +908,38 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo) > EXPORT_SYMBOL(ttm_bo_unpin); > =20 > /* > - * Add the pipelined eviction fencesto the BO as kernel dependency and r= eserve new > - * fence slots. > + * Add pending eviction fences to the BO as kernel dependencies and rese= rve > + * new fence slots. > */ > static int ttm_bo_add_pipelined_eviction_fences(struct ttm_buffer_object= *bo, > struct ttm_resource_manager *man, > bool no_wait_gpu) > { > + struct dma_fence *fences[TTM_NUM_MOVE_FENCES]; > struct dma_fence *fence; > - int i; > + int i, count =3D 0; > =20 > spin_lock(&man->eviction_lock); > for (i =3D 0; i < TTM_NUM_MOVE_FENCES; i++) { > fence =3D man->eviction_fences[i]; > - if (!fence) > + if (!fence || dma_fence_is_signaled(fence)) > continue; > =20 > if (no_wait_gpu) { > - if (!dma_fence_is_signaled(fence)) { > - spin_unlock(&man->eviction_lock); > - return -EBUSY; > - } > - } else { > - dma_resv_add_fence(bo->base.resv, fence, DMA_RESV_USAGE_KERNEL); > + spin_unlock(&man->eviction_lock); > + return -EBUSY; > } > + > + /* The manager may replace this fence once we drop the lock. */ > + fences[count++] =3D dma_fence_get(fence); > } > spin_unlock(&man->eviction_lock); > =20 > + for (i =3D 0; i < count; i++) { > + dma_resv_add_fence(bo->base.resv, fences[i], DMA_RESV_USAGE_KERNEL); > + dma_fence_put(fences[i]); > + } > + > /* TODO: this call should be removed. */ > return dma_resv_reserve_fences(bo->base.resv, 1); > } [Severity: High] This problem wasn't introduced by this patch, but can reserving only 1 fence slot here after consuming up to TTM_NUM_MOVE_FENCES slots hit the BUG_ON() in dma_resv_add_fence() during amdgpu_dma_buf_move_notify() [1]? amdgpu_dma_buf_move_notify() reserves 2 fence slots on the VM root BO reservation object for the page table update fence and the TLB flush fence (when vm->need_tlb_fence is enabled). If amdgpu_vm_update_range() allocates a new page table BO sharing that reservation object, ttm_bo_alloc_resource() reserves TTM_NUM_MOVE_FENCES slots and ttm_bo_add_pipelined_eviction_fences() can consume all TTM_NUM_MOVE_FENCES of them before calling dma_resv_reserve_fences(bo->base.resv, 1). Because dma_resv_reserve_fences() is not additive, if the reservation object started with TTM_NUM_MOVE_FENCES + 1 free slots, neither reservation call reallocates the list and only 1 free slot remains after BO creation. amdgpu_vm_sdma_commit() takes that slot for vm->delayed, and amdgpu_vm_tlb_flush() then overflows fobj->max_fences when adding vm->last_tlb_inv. [1] https://sashiko.dev/#/bug/linux-8e6fd858-557e-4ca0-9558-be9bf089c7d4 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201090028.8649= 4-1-perry.yuan@amd.com?part=3D3