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 51A2B606A31A for ; Wed, 2 Dec 2026 01:03:43 +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=HMll4OsF Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 177CF10E416; Wed, 2 Dec 2026 01:03:38 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3514110E416; Wed, 2 Dec 2026 01:03:32 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E5FC3441A4; Wed, 2 Dec 2026 01:03:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0D3B1F00897; Wed, 2 Dec 2026 01:03:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796173411; bh=jklcOFd7SqdKJrPvdFgcNr7gWav7rOwSf5vKsftEYi8=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=HMll4OsF/HrblZWq5NpIWFG4B0/RmTY7oCopbRasg4KRiLK2JhIcAMs74Enln63ds 7hxMhObtXBmWGD4U3ZaFS9NcWD3BFBreOWjT8m3YHmykRhm9YtMQ9DoS4yvoS95UDD E4ZxEvbpdZCr5iSh5n/4+0fuNqJj16bT6eWNB4VholIkUN9Yg5ueAE9Fn7DUI8NyFB eu8kdu+ZhzkPgXP/u57U/mnGUdbQDj4rmpolVGwUVtwn5iQGU64zJVIZV7sShMZN+D 57g0IdPUDpbCYyBTsUpcuUmebUPjld/qK/0Dw0jZSW8mfgZiOvAm8cN1+Tcd4Mz5BO AVbtiSlXKCoQw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 30/33] drm/xe: Finalize defrag-IOVA moves with post-copy job To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-31-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-31-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 01:03:31 +0000 X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Intel-xe" 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/xe: missing kernel fence wait for preempt VMs in xe_bo_trigger_rebind() - [High] drm/xe: missing dma-resv fence dependencies in xe_bo_defrag_iova_copy() - [Medium] drm/xe: premature defrag list removal in xe_bo_move() on defrag move error -- commit a09033f4b293c49cfeeb973f5688f58056145822 Author: Matthew Brost drm/xe: Finalize defrag-IOVA moves with post-copy job This commit wires up end-to-end defragmentation for IOVA-mapped BOs by copying only changed pages into a packed temporary mapping, transferring the IOVA reservation to the new TT, and running a post-copy job to relink changed pages at their natural offsets without marking the BO evicted. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 1a02fe407d78a..db9a0c7bd44e0 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -1181,6 +1302,159 @@ static void xe_tt_iova_transfer(struct xe_device = *xe, > old_tt->use_iova =3D false; > } > =20 > +/* > + * xe_bo_defrag_iova_copy - Run an IOVA defrag move with a packed copy m= apping. > + * > + * Only the changed (non-borrowed) pages of @new_tt are DMA mapped, pack= ed > + * contiguously into the front of its reservation, the GPU copy blits th= em from > + * the old tt at natural offsets, and a post-copy finalize job adopts th= e old > + * tt's full reservation and relinks the changed runs. Returns the final= ize > + * job's finished fence (the fence the move waits on), or an ERR_PTR on = failure > + * with all partial state unwound. > + */ > +static struct dma_fence * > +xe_bo_defrag_iova_copy(struct xe_device *xe, struct xe_migrate *migrate, > + struct xe_bo *bo, struct ttm_resource *old_mem, > + struct ttm_resource *new_mem, struct ttm_tt *old_tt, > + bool handle_system_ccs) > +{ > + struct ttm_tt *new_tt =3D bo->ttm.ttm; > + struct xe_ttm_tt *new_xe_tt =3D container_of(new_tt, struct xe_ttm_tt, = ttm); > + struct xe_ttm_tt *old_xe_tt =3D container_of(old_tt, struct xe_ttm_tt, = ttm); > + struct drm_sched_entity *entity =3D > + xe_dep_scheduler_entity(xe->mem.defrag.iova_sched); > + struct xe_iova_defrag_job *job; > + struct dma_fence *copy_fence; > + struct dma_fence *fence; > + struct xe_tt_iova_copy copy; > + bool packed =3D false; > + int err; > + > + xe_assert(xe, new_xe_tt->iova_eligible && !new_xe_tt->use_iova); > + xe_assert(xe, old_xe_tt->use_iova && old_xe_tt->iova_linked); > + > + err =3D xe_tt_iova_copy_init(new_tt, old_tt, ©); > + if (err) > + return ERR_PTR(err); > + > + if (copy.nr_changed) { > + err =3D xe_tt_map_iova_copy(xe, new_tt, ©); > + if (err) > + goto err_copy; > + packed =3D true; > + > + copy_fence =3D xe_migrate_copy_defrag_iova(migrate, bo, old_mem, > + new_mem, old_tt, > + copy.nr_changed, > + handle_system_ccs); > + } else { > + copy_fence =3D dma_fence_get_stub(); > + } > + if (IS_ERR(copy_fence)) { > + err =3D PTR_ERR(copy_fence); > + goto err_unmap; > + } > + > + job =3D kzalloc(sizeof(*job), GFP_KERNEL); > + if (!job) { > + err =3D -ENOMEM; > + goto err_fence; > + } > + > + job->dep.ops =3D &xe_iova_defrag_job_ops; > + job->xe =3D xe; > + job->new_tt =3D new_tt; > + if (packed) > + job->copy_iova =3D new_xe_tt->iova; > + job->copy_bytes =3D (size_t)copy.nr_changed << PAGE_SHIFT; > + job->copy =3D copy; > + > + err =3D drm_sched_job_init(&job->dep.drm, entity, 1, NULL, 0); > + if (err) > + goto err_job; > + > + err =3D drm_sched_job_add_dependency(&job->dep.drm, > + dma_fence_get(copy_fence)); > + if (err) > + goto err_job_init; [Severity: High] Does job->dep.drm also need dependencies on bo->ttm.base.resv (DMA_RESV_USAGE_BOOKKEEP) when copy_fence is dma_fence_get_stub()? For non-fault-mode VMs, xe_bo_trigger_rebind() does not synchronously wait on DMA_RESV_USAGE_BOOKKEEP fences. When copy.nr_changed is 0 (or on integrated platforms with Flat-CCS when all data pages are borrowed and only the trailing CCS backup extra_pages changed, so __xe_migrate_copy() creates no migration job and returns dma_fence_get_stub()), copy_fence is already signaled and carries no bo->ttm.base.resv dependencies. With no unsignaled dependency on job->dep.drm, xe_iova_defrag_job_run() unlinks and relinks xe_tt->iova immediately, and the ghost object created by ttm_bo_move_accel_cleanup() tears down old_tt and frees its non-borrowed pages while prior GPU work in bo->ttm.base.resv is still in flight. [ ... ] > @@ -1574,12 +1849,25 @@ static int xe_bo_trigger_rebind(struct xe_device = *xe, struct xe_bo *bo, > dma_resv_iter_end(&cursor); > } > =20 > + /* > + * A defrag move that reallocates IOVA-mapped backing preserves the > + * device-visible addresses: the IOVA reservation is transferred from > + * the old to the new tt, so the existing GPU PTEs stay valid and the > + * BO must not be marked evicted (the rebind paths in xe_exec_ioctl() > + * and preempt_rebind_work_func() would otherwise needlessly rebind). > + * Preempt fences still need to be triggered, and fault-mode / L2 > + * flush-optimized configs still need a TLB invalidation below, so only > + * the eviction marking is skipped. > + */ > + defrag_iova =3D xe_bo_defrag_use_iova(&bo->ttm); > + > drm_gem_for_each_gpuvm_bo(vm_bo, obj) { > struct xe_vm *vm =3D gpuvm_to_vm(vm_bo->vm); > struct drm_gpuva *gpuva; > =20 > if (!xe_vm_in_fault_mode(vm)) { > - drm_gpuvm_bo_evict(vm_bo, true); > + if (!defrag_iova) > + drm_gpuvm_bo_evict(vm_bo, true); [Severity: High] Can skipping drm_gpuvm_bo_evict() here allow a preempt-fence-mode VM to resume or start GPU execution while the IOVA defrag copy and xe_iova_defrag_job_run() are still unlinking and relinking IOMMU mappings? For an external BO (bo->vm =3D=3D NULL), ttm_bo_move_accel_cleanup() instal= ls the finalize job's fence into bo->ttm.base.resv (DMA_RESV_USAGE_KERNEL), not xe_vm_resv(vm). Previously, marking vm_bo evicted caused preempt_rebind_work_func() to rebind the VMA, which chained bo->ttm.base.resv's kernel fence into xe_vm_resv(vm). When drm_gpuvm_bo_evict() is skipped, no rebind runs, and preempt_rebind_work_func() only waits on xe_vm_resv(vm) before resuming execution: drivers/gpu/drm/xe/xe_vm.c:preempt_rebind_work_func() { ... /* Wait on rebinds and munmap style VM unbinds */ wait =3D dma_resv_wait_timeout(xe_vm_resv(vm), DMA_RESV_USAGE_KERNEL, false, MAX_SCHEDULE_TIMEOUT); ... err =3D resume_and_reinstall_preempt_fences(vm, &exec); } Similarly, if the IOVA defrag move starts before the first compute queue is attached to the VM, leaving vm->gpuvm.evict.list empty means a concurrent xe_vm_add_compute_exec_queue() sees no pending eviction or rebind and does not signal the new queue's preempt fence to wait for the in-flight move. [ ... ] > @@ -2602,9 +2898,16 @@ static int xe_bo_move(struct ttm_buffer_object *tt= m_bo, bool evict, > fence =3D xe_migrate_clear(migrate, bo, new_mem, flags, > ctx->interruptible); > } else if (has_defrag_old_tt) { > - fence =3D xe_migrate_copy_defrag(migrate, bo, old_mem, new_mem, > - ttm_bo->defrag_old_tt, > - handle_system_ccs); > + if (defrag_iova) > + fence =3D xe_bo_defrag_iova_copy(xe, migrate, bo, old_mem, > + new_mem, > + ttm_bo->defrag_old_tt, > + handle_system_ccs); > + else > + fence =3D xe_migrate_copy_defrag(migrate, bo, old_mem, > + new_mem, > + ttm_bo->defrag_old_tt, > + handle_system_ccs); > } else { > fence =3D xe_migrate_copy(migrate, bo, bo, old_mem, new_mem, > handle_system_ccs, ctx->interruptible); [Severity: Medium] If xe_bo_defrag_iova_copy() fails and jumps to out, does the unconditional xe_bo_defrag_update(bo) at the end of xe_bo_move() drop the still-fragmented BO from xe->mem.defrag.list? At the out label of xe_bo_move(), bo->ttm.ttm still points to the newly populated beneficial-order TT, while ttm_bo_handle_move_mem() only destroys that TT and restores bo->ttm =3D bo->defrag_old_tt after xe_bo_move() returns: drivers/gpu/drm/ttm/ttm_bo.c:ttm_bo_handle_move_mem() { ... out_err: if (bo->defrag_old_tt) { ttm_tt_defrag_disown_borrowed(bo->ttm, bo->defrag_old_tt); ttm_bo_tt_destroy(bo); bo->ttm =3D bo->defrag_old_tt; bo->defrag_old_tt =3D NULL; } } Because ttm_tt_is_beneficial_order_failed(bo->ttm.ttm) is false on the new TT, xe_bo_defrag_update(bo) sees xe_bo_needs_defrag(bo) =3D=3D false and removes the BO from xe->mem.defrag.list before defrag_old_tt is restored. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D30