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 CCD61606A32C for ; Thu, 3 Dec 2026 00:12:55 +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=fcyGCVsr Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 452D0112642; Thu, 3 Dec 2026 00:12:50 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8469B112642; Thu, 3 Dec 2026 00:12:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 3899E4054A; Thu, 3 Dec 2026 00:12:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F19E21F000C1; Thu, 3 Dec 2026 00:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796256764; bh=Iwjc0g3bzmSCD7rEF9HaoaaNs3itceJHi7Bk89CE8jA=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=fcyGCVsrYGfigvbLNCgLoKtkrobesoEBtKI1Z08mEu+HbSQyOTIYraIBh/YveATp8 WnNHUGTke0YUWeUuNi9HjZwISGznTYUUrtOhUGEhGUngxbjr/YYoL7QMCLrSgY1YIV ZvahYRNhFZh8uwo5DrTeikrw68fjO3JB2d/e7uxHEMlK5+G9fV/k4nGoL1QSRnuVz5 NBhXZ7TndpaAZUqLpaBfIyZ0xGm45ErtUZMfszHVZO0gK0+Ap8sVEVMDNM/D+2Pzr9 buKE9ol133sVS8H6q2pETkVA00fOycAiifDnTQvLezoRismvWKa5mUTdzyEfCsd/kE ckz2IloaFV/dg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 18/36] drm/xe: Add a page defragmentation worker To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261202233323.3743190-19-matthew.brost@intel.com> References: <20261202233323.3743190-1-matthew.brost@intel.com> <20261202233323.3743190-19-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 00:12:43 +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=unavailable 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 wedge and shutdown checks for xe_bo_defrag_worker() - [High] drm/xe: sliced defrag of FlatCCS BOs hits WARN_ON in __xe_migrate_copy() - [Medium] drm/xe: stop defrag worker in xe_device_shutdown() before GT reset and FLR -- commit 2827cf9a3258f09b55ed0523757aafd710c5214d Author: Matthew Brost drm/xe: Add a page defragmentation worker This commit adds a delayed worker that walks the per-device defrag list and attempts to reallocate and GPU-copy BO backing pages at the device's beneficial order in budget-limited slices. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 85fb888d5db4e..5944077ba997d 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -1292,6 +1457,216 @@ static void xe_bo_defrag_update(struct xe_bo *bo) [ ... ] > +static void xe_bo_defrag_worker(struct work_struct *w) > +{ > + struct delayed_work *dwork =3D to_delayed_work(w); > + struct xe_device *xe =3D > + container_of(dwork, struct xe_device, mem.defrag.worker); > + u64 defrag_bytes =3D 0; > + bool requeue =3D false; > + int idx; > + > + if (!drm_dev_enter(&xe->drm, &idx)) > + return; > + > + if (!xe_pm_runtime_get_if_active(xe)) { [Severity: High] Can xe_bo_defrag_worker() replace live BO contents with uninitialized pages when the device is wedged? When xe_wedge_declare() or prepare_device_for_reset() runs, xe_wedge_get() holds a runtime PM reference, so xe_pm_runtime_get_if_active() still succee= ds while tile->migrate->q is marked wedged or killed. ttm_bo_validate() then allocates uninitialized beneficial-order pages for the new bo->ttm and calls xe_bo_move() -> xe_migrate_copy_defrag(). In guc_exec_queue_run_job(), hardware submission is skipped for wedged/killed queues while job->fence is still returned, so ttm_bo_move_accel_cleanup() commits the uncopied new bo->ttm and frees defrag_old_tt once TDR signals job->fence with -ETIME. Should xe_bo_defrag_worker() check xe_wedged(xe) (or should xe_wedge_declare() and prepare_device_for_reset() stop the defrag worker)? [ ... ] > + /* > + * Bound the per-BO move to the run's remaining byte budget. A > + * large object is upgraded in budget-sized slices across runs; > + * the slices already upgraded come back as free already- > + * beneficial harvests, so each run only spends budget on new > + * forward progress. > + */ > + ret =3D xe_bo_defrag_one(xe, bo, XE_BO_DEFRAG_SIZE_LIMIT - defrag_byte= s, > + &consumed, &needs_more); > + defrag_bytes +=3D consumed; > + > + if (ret || needs_more) { [Severity: High] Can sliced defragmentation of a large FlatCCS BO hit XE_WARN_ON(!fence) in __xe_migrate_copy() and get stuck at the head of xe->mem.defrag.list? For compressible BOs on integrated FlatCCS platforms, xe_ttm_tt_create() appends extra_pages beyond xe_bo_size(bo) to tt->num_pages (reaching 2MB or more once xe_bo_size(bo) is at least 1GB on Xe2 iGPU). Slicing such a BO in XE_BO_DEFRAG_SIZE_LIMIT passes upgrades the data pages in [0, xe_bo_size(bo)) first, leaving only the trailing extra_pages sub-optimal with TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED still set. On the next pass, ttm_pool_alloc() borrows all data pages from defrag_old_tt and reallocates only the trailing extra_pages. Because __xe_migrate_copy() iterates over xe_bo_size(src_bo) during the XE_MIGRATE_COPY_DEFRAG_DATA pas= s, emit_copy_chunks() finds no unborrowed data pages, leaving fence NULL: drivers/gpu/drm/xe/xe_migrate.c:__xe_migrate_copy() { ... if (XE_WARN_ON(!fence)) return ERR_PTR(-EINVAL); } The move fails with -EINVAL and restores defrag_old_tt with the failed-order flag still set, so the BO remains at the head of xe->mem.defrag.list, triggering the warning on every retry and starving any BOs queued behind it. [ ... ] > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_devic= e.c > index 67d648833030c..637f9e71e78b0 100644 > --- a/drivers/gpu/drm/xe/xe_device.c > +++ b/drivers/gpu/drm/xe/xe_device.c [ ... ] > @@ -1445,9 +1456,12 @@ int xe_device_suspend(struct xe_device *xe, bool h= ibernate, bool flr) > u8 id; > int err; > =20 > + /* No defrag moves (GPU copies) while suspending or across FLR. */ > + xe_bo_defrag_suspend(xe); > + > err =3D xe_pxp_pm_suspend(xe->pxp); [Severity: Medium] Should xe_device_shutdown() also call xe_bo_defrag_suspend(xe)? During system shutdown, pci_device_shutdown() calls pm_runtime_resume() rig= ht before xe_pci_shutdown() -> xe_device_shutdown(). If the device was runtime suspended with a non-empty defrag list, xe_pm_runtime_resume() calls xe_bo_defrag_kick(xe), arming xe_bo_defrag_worker() to run and issue GPU migration copies while xe_device_shutdown() suspends IRQs, resets GTs and runs __xe_driver_flr(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202233323.3743= 190-1-matthew.brost@intel.com?part=3D18