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 6E03E606A320 for ; Wed, 2 Dec 2026 00:19:18 +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=WvoPERvC Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C99DB10EAF7; Wed, 2 Dec 2026 00:19:12 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0048110FE1A; Wed, 2 Dec 2026 00:19:06 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 1670A60E3F; Wed, 2 Dec 2026 00:19:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACD031F00896; Wed, 2 Dec 2026 00:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170745; bh=Mdg8ectfEzDUoeEv0lX1g5NdoS56DnGllCGn0LVGrsE=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=WvoPERvCqXENVyTO/bqBW+mzQlo+BFyjzIPN/YWTXohBBB2tjr3P1azAO49vHhN5Q 8llIm6qRTa1dogcMT058Pyy/Xqz82fXjK1Jr8ptDAklEcqJqOWNoUqLSN8UulL8tn1 UOR1/kZZj3lNd8uXi/pXB2Pw8eXDLLWARZHHy7FxPG+3DXDymWC9lpurcdz/cI+ayv JesEjLFxaM2x7q50C9gBSfvesaKCpOYZXzYexIWxDcItnGaAuuM8M1hxVjVzhPRqO0 tZ0cqf4/V0q13IHQoQc59iCSqTW2OUP+XI/qmtNLFlIX16daTAQEzzVzAYp9JQbdWA SETxh0hQPJYRQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 16/33] drm/xe: Handle defrag moves in xe_bo_move() To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-17-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-17-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 00:19:05 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "dri-devel" 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 2 potential issues to consider: - [High] drm/xe: unreserved dma_resv fence slot in xe_bo_move() after move_notify - [Medium] drm/xe: premature defrag list removal in xe_bo_move() on defrag failure -- commit cbbba44cdb964f67db155806c03129d18d8b4375 Author: Matthew Brost drm/xe: Handle defrag moves in xe_bo_move() This commit teaches xe_bo_move() to handle defragmentation moves by copying the old ttm_tt contents stored in defrag_old_tt to the newly allocated backing via xe_migrate_copy_defrag(). > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 0351079eae64e..7448e43eedf58 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c > @@ -1300,6 +1300,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm= _bo, bool evict, > bool move_lacks_source; > bool tt_has_data; > bool needs_clear; > + bool has_defrag_old_tt =3D !!ttm_bo->defrag_old_tt; > bool handle_system_ccs =3D (!IS_DGFX(xe) && xe_bo_needs_ccs_pages(bo) && > ttm && ttm_tt_is_populated(ttm)) ? true : false; > int ret =3D 0; > @@ -1340,6 +1341,13 @@ static int xe_bo_move(struct ttm_buffer_object *tt= m_bo, bool evict, > move_lacks_source =3D !old_mem || (handle_system_ccs ? (!bo->ccs_cleare= d) : > (!mem_type_is_vram(old_mem_type) && !tt_has_data)); > =20 > + /* > + * A defrag move always copies the existing contents from the stashed > + * old tt into the freshly (re)allocated backing. > + */ > + if (has_defrag_old_tt) > + move_lacks_source =3D false; > + > needs_clear =3D (ttm && ttm->page_flags & TTM_TT_FLAG_ZERO_ALLOC) || > (!ttm && ttm_bo->type =3D=3D ttm_bo_type_device); > =20 > @@ -1383,9 +1391,12 @@ static int xe_bo_move(struct ttm_buffer_object *tt= m_bo, bool evict, > /* > * Failed multi-hop where the old_mem is still marked as > * TTM_PL_FLAG_TEMPORARY, should just be a dummy move. > + * > + * For a defrag move the old and new tt differ, so fallthrough to the > + * copy path instead of treating it as a no-op. > */ > if (old_mem_type =3D=3D XE_PL_TT && > - new_mem->mem_type =3D=3D XE_PL_TT) { > + new_mem->mem_type =3D=3D XE_PL_TT && !has_defrag_old_tt) { > ttm_bo_move_null(ttm_bo, new_mem); > goto out; > } [Severity: Medium] Can a failed defrag move drop bo from xe->mem.defrag.list while leaving it on its fragmented backing? If xe_tt_map_sg(), xe_bo_move_notify(), or xe_migrate_copy_defrag() fails, control jumps to the out label where xe_bo_defrag_update(bo) runs unconditionally before ttm_bo_handle_move_mem() rolls ttm_bo->ttm back to ttm_bo->defrag_old_tt: drivers/gpu/drm/xe/xe_bo.c:xe_bo_move() { ... out: ... if (!ret && ttm_bo->resource && ttm_bo->resource->mem_type =3D=3D XE_PL_TT) bo->lru_stamp =3D jiffies; xe_bo_defrag_update(bo); return ret; } At that point ttm_bo->ttm still points to the newly allocated beneficial- order ttm_tt, so xe_bo_needs_defrag() sees !ttm_tt_is_beneficial_order_failed(tt) and calls xe_bo_defrag_remove(bo). ttm_bo_handle_move_mem() then destroys the new ttm_tt and restores bo->ttm =3D bo->defrag_old_tt, leaving the fragmented BO resident in XE_PL_TT but untracked for future defragmentation. > @@ -1472,6 +1483,12 @@ static int xe_bo_move(struct ttm_buffer_object *tt= m_bo, bool evict, > =20 > fence =3D xe_migrate_clear(migrate, bo, new_mem, flags, > ctx->interruptible); > + } else if (has_defrag_old_tt) { > + struct xe_ttm_tt *old_xe_tt =3D > + container_of(ttm_bo->defrag_old_tt, struct xe_ttm_tt, ttm); > + > + fence =3D xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem, > + old_xe_tt->sg, handle_system_ccs); > } else { > fence =3D xe_migrate_copy(migrate, bo, bo, old_mem, new_mem, > handle_system_ccs, ctx->interruptible); [Severity: High] Can ttm_bo_move_accel_cleanup() hit BUG_ON(fobj->num_fences >=3D fobj->max_fences) in dma_resv_add_fence() after a defrag move's xe_bo_move_notify()? ttm_bo_handle_move_mem() reserves one fence slot in bo->base.resv before calling xe_bo_move(). For a defrag move, xe_bo_move() runs xe_bo_move_notify() -> xe_bo_trigger_rebind() -> xe_vm_flush_vm_bo_tlb_async() -> xe_vma_tlb_flush_client(): drivers/gpu/drm/xe/xe_vm.c:xe_vma_tlb_flush_client() { ... err =3D dma_resv_reserve_fences(resv, 1); if (err) goto out_put; /* Cannot fail; takes its own ref on @dep and returns a referenced fence. = */ fence =3D xe_tlb_inval_job_push(job, dep); dma_resv_add_fence(resv, fence, DMA_RESV_USAGE_KERNEL); ... } Because dma_resv_reserve_fences(resv, 1) does not reallocate when at least one free slot already exists, adding the TLB invalidation fence can consume the final slot that ttm_bo_handle_move_mem() reserved, leaving fobj->num_fences =3D=3D fobj->max_fences. With no fence wait or dma_resv_reserve_fences() between xe_bo_move_notify() and ttm_bo_move_accel_cleanup(), adding the migration fence from a different fence context then triggers BUG_ON(fobj->num_fences >=3D fobj->max_fences). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D16