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 63C3E606A320 for ; Wed, 2 Dec 2026 00:17:21 +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=LE+tSRMw Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C6CB310E795; Wed, 2 Dec 2026 00:17:15 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id EF54310E795; Wed, 2 Dec 2026 00:17:08 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id EF4D362107; Wed, 2 Dec 2026 00:17:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 716171F0089F; Wed, 2 Dec 2026 00:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170627; bh=LMkTv/c89tItrcm/PdoulcHcnNaJRmgD3h8p4TMI0hk=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=LE+tSRMwQnxmNipWvU4DHftvVCYqu5HYx05HX5vEO+3Qe6fhgE0qnsjxRrnI7dDek tKYHt+5M0fRWPKcVH9hkKPp6ljV47u+Cyw+ior6X3Kjp0CDkWtFnLk2ag6WR12GqZ2 FFyvVUBRBcSksnSH+yali9ZrvMpDFKAPbytGQkIH6BKmtWMrJvGnC+PS39XgtvbqJT VoIso6pMmeo0WeIwESI5CphRy58malrvHNv+Yluv2xQSXBqaKwhV37y1W8Fd4/hL1E p/YzvojfIvWAxUuh+J1BH3DZKqoWllVXSBLXmEGXWhmC1yYVvvjiRqqlj50MxXeHRj cJJaWQJjf9mpg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 14/33] drm/xe: Track BOs backed at a sub-optimal page order To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-15-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-15-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 00:17:07 +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 4 potential issues to consider: - [Medium] drm/xe: display fb pin/unpin in xe_bo_pin_account() bypasses defrag tracking - [Medium] drm/xe: unconditional xe_bo_defrag_update() in xe_bo_move() drops failed BO - [Medium] drm/xe: xe_bo_fault_migrate() contends on defrag lock and misses SYSTEM BOs - [Low] drm/xe: redundant xe_bo_defrag_remove() in xe_ttm_bo_purge() and stale docs -- commit cb4a8fed0f656c3f34b03b2d3b239e7886b9b49f Author: Matthew Brost drm/xe: Track BOs backed at a sub-optimal page order This commit adds per-device tracking for buffer objects whose backing TT pages were allocated below the pool's beneficial order, maintaining them on a device defrag list across moves, faults, pin/unpin, and purge transitions. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 920b7b6094582..0351079eae64e 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -1171,9 +1175,116 @@ int xe_ttm_bo_purge(struct ttm_buffer_object *ttm= _bo, struct ttm_operation_ctx * > /* Commit the state transition only once invalidation was queued */ > xe_bo_set_purgeable_state(bo, XE_MADV_PURGEABLE_PURGED); > =20 > + /* > + * The backing store is gone, so the BO no longer needs defrag. Drop it > + * from the defrag list here so the count stays accurate even for purge > + * paths that don't pass through xe_bo_move() (e.g. swap_notify). > + */ > + xe_bo_defrag_remove(bo); > + > return 0; > } > =20 > +/** > + * xe_bo_defrag_init_early() - Initialize the device defrag BO tracking > + * @xe: The xe device > + * > + * Initialize the list, lock and count used to track BOs whose backing TT > + * pages were allocated at a sub-optimal order. > + */ > +void xe_bo_defrag_init_early(struct xe_device *xe) > +{ > + spin_lock_init(&xe->mem.defrag.lock); > + INIT_LIST_HEAD(&xe->mem.defrag.list); > +} [Severity: Low] This isn't a bug, but xe_bo_set_purgeable_state() right above already calls xe_bo_defrag_update(bo), which removes the purged BO from the defrag list, making the explicit xe_bo_defrag_remove(bo) here redundant. Also, the comment here, the kernel-doc on xe_bo_defrag_init_early(), and the commit message still mention a defrag count that was dropped in v4. [ ... ] > @@ -1426,6 +1537,8 @@ static int xe_bo_move(struct ttm_buffer_object *ttm= _bo, bool evict, > if (!ret && ttm_bo->resource && ttm_bo->resource->mem_type =3D=3D XE_PL= _TT) > bo->lru_stamp =3D jiffies; > =20 > + xe_bo_defrag_update(bo); > + > return ret; > } [Severity: Medium] Can an error in xe_bo_move() during a defrag move drop a still-fragmented BO from xe->mem.defrag.list? During a defrag move, ttm_bo_handle_move_mem() stashes the sub-optimal TT in bo->defrag_old_tt and sets bo->ttm to the newly allocated TT before calling xe_bo_move(), only rolling bo->ttm back to bo->defrag_old_tt after xe_bo_move() returns an error: 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 xe_bo_defrag_update(bo) runs even when ret !=3D 0, it inspects the new bo->ttm (which lacks TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) and removes the BO from xe->mem.defrag.list before TTM restores the sub-optimal defrag_old_tt. [ ... ] > @@ -2259,8 +2383,11 @@ static int xe_bo_fault_migrate(struct xe_bo *bo, s= truct ttm_operation_ctx *ctx, > =20 > if (ttm_manager_type(tbo->bdev, tbo->resource->mem_type)->use_tt) { > err =3D xe_bo_wait_usage_kernel(bo, ctx); > - if (!err) > + if (!err) { > err =3D ttm_bo_populate(&bo->ttm, ctx); > + if (!err) > + xe_bo_defrag_update(bo); > + } > } else if (should_migrate_to_smem(bo)) { [Severity: Medium] Does calling xe_bo_defrag_update(bo) here contend on xe->mem.defrag.lock on every CPU fault for XE_PL_TT BOs while still missing BOs populated in XE_PL_SYSTEM? For a sub-optimal BO already in XE_PL_TT, ttm_bo_populate() is a no-op and the BO is already on xe->mem.defrag.list, yet every CPU page fault calls xe_bo_defrag_add(bo), which unconditionally takes the device-wide xe->mem.defrag.lock spinlock before checking list_empty(&bo->defrag_link). Conversely, when ttm_bo_populate() actually populates an unpopulated BO on a CPU fault (such as a XE_BO_FLAG_DEFER_BACKING or swapped-out BO), tbo->resource->mem_type is XE_PL_SYSTEM, so xe_bo_needs_defrag(bo) returns false and does not track it. [ ... ] > @@ -3464,6 +3592,8 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_pl= ace, struct drm_exec *exec) > =20 > xe_bo_pin_account(bo); > =20 > + xe_bo_defrag_remove(bo); > + > /* > * FIXME: If we always use the reserve / unreserve functions for locking > * we do not need this. > @@ -3520,6 +3650,8 @@ int xe_bo_pin(struct xe_bo *bo, struct drm_exec *ex= ec) > =20 > xe_bo_pin_account(bo); > =20 > + xe_bo_defrag_remove(bo); > + > /* > * FIXME: If we always use the reserve / unreserve functions for locking > * we do not need this. > @@ -3548,6 +3680,7 @@ void xe_bo_unpin_external(struct xe_bo *bo) > xe_assert(xe, xe_bo_is_user(bo)); > =20 > xe_bo_unpin_account(bo); > + xe_bo_defrag_update(bo); > =20 > /* > * FIXME: If we always use the reserve / unreserve functions for locking > @@ -3578,6 +3711,7 @@ void xe_bo_unpin(struct xe_bo *bo) > } > } > xe_bo_unpin_account(bo); > + xe_bo_defrag_update(bo); > } [Severity: Medium] Should xe_bo_defrag_remove() and xe_bo_defrag_update() live inside xe_bo_pin_account() and xe_bo_unpin_account() rather than their callers? Display framebuffer pinning in __xe_pin_fb_vma() and __xe_unpin_fb_vma() pins and unpins user ttm_bo_type_device scanout BOs by calling xe_bo_pin_account() and xe_bo_unpin_account() directly: drivers/gpu/drm/xe/display/xe_fb_pin.c:__xe_pin_fb_vma() { ... ret =3D xe_bo_validate(bo, NULL, true, &exec); drm_exec_retry_on_contention(&exec); xe_validation_retry_on_oom(&ctx, &ret); if (!ret) xe_bo_pin_account(bo); ... } On integrated GPUs where scanout BOs reside in XE_PL_TT, validating and pinning a sub-optimal framebuffer BO leaves it on xe->mem.defrag.list while pinned, and unpinning it via __xe_unpin_fb_vma() never calls xe_bo_defrag_update() to re-add it once the last pin is dropped. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D14