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 45E41606A330 for ; Wed, 2 Dec 2026 23:56:22 +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=EkX4qTQ/ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A66F3112698; Wed, 2 Dec 2026 23:56:16 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id CCA8A112698; Wed, 2 Dec 2026 23:56:10 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B5FED41135; Wed, 2 Dec 2026 23:56:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654501F0089C; Wed, 2 Dec 2026 23:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796255770; bh=riAgDb/WoveBdycthWtiaqMp7D5Fh3RxXbJcZEht84w=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=EkX4qTQ//yvoXUxt35HIxewpyU9+E+0AtqFhlp2dXfINX1Bf/P0Fsee/wScskY7Pd ssVtdOLw4OhL0F6CFRxoMj/BjJcT6SeghVx4Cgo1ItkUyuYI3B+8I2W0mtaIXky6jh 9qQ3mePEVDhECbmqi9e95+auODNDnM4hppihLJeqCItnftwq9+N8Y56OHPElTpazSv ellgscyYbE0NNzKDj2o5d71E1jy5wwmZ55nUxoW6x/CMGZhLro+4QG6uAPgaxcEiXW z4IZClyLssom7GydjysTkMOqv9Bz82ip0gUznSV9lupZwf9jgPfDuO/7IRBz4jYB+Q BlQEdaCQxoV/w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261202233323.3743190-22-matthew.brost@intel.com> References: <20261202233323.3743190-1-matthew.brost@intel.com> <20261202233323.3743190-22-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 23:56:10 +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 2 potential issues to consider: - [Medium] drm/xe: FlatCCS extra_pages size mismatch in xe_bo_defrag_one() - [Medium] drm/xe: TTM WC/UC page pool bypass in xe_bo_defrag_one() preallocation -- commit 27539e0916948f7e33871d52a57501de9005f821 Author: Matthew Brost drm/xe: Defrag using out-of-lock page preallocation This commit converts xe_bo_defrag_one() to preallocate beneficial-order pages via ttm_pool_prealloc_fill() outside the BO dma-resv lock before validating the BO with the preallocated page bag. > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index af9bdb7f05ef4..f3ce4e7ed98d1 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c > @@ -1510,16 +1510,65 @@ static int xe_bo_defrag_one(struct xe_device *xe,= struct xe_bo *bo, > .defrag_bytes_remaining =3D budget, > }; > struct ttm_buffer_object *ttm_bo =3D &bo->ttm; > + struct ttm_pool *pool =3D &ttm_bo->bdev->pool; > + struct ttm_pool_prealloc pp =3D {}; > struct ttm_placement placement; > struct ttm_place place; > + enum ttm_caching tt_caching; > + unsigned int order, want =3D 0; > int ret =3D 0; > =20 > *consumed =3D 0; > *needs_more =3D false; > =20 > + /* > + * Phase 1: under the BO lock, re-check eligibility and estimate how > + * many beneficial-order chunks the move will (re)allocate, bounded by > + * the run's byte budget. Then drop the lock so the high-order, possibly > + * reclaim/compaction stalling allocations happen unlocked. > + */ > + xe_bo_lock(bo, false); > + if (!xe_bo_needs_defrag(bo)) { > + xe_bo_defrag_remove(bo); > + xe_bo_unlock(bo); > + goto out; > + } > + tt_caching =3D bo->ttm.ttm->caching; > + order =3D ttm_pool_prealloc_order(pool); > + if (order && ttm_bo->ttm) { > + u32 suboptimal =3D ttm_tt_suboptimal_pages(ttm_bo->ttm); > + u64 cap =3D min_t(u64, budget, xe_bo_size(bo)) >> PAGE_SHIFT; > + > + /* Prealloc only the beneficial-order chunks the move replaces. */ > + want =3D DIV_ROUND_UP_ULL(min_t(u64, suboptimal, cap), 1UL << order); > + } [Severity: Medium] Can capping want by xe_bo_size(bo) while reading suboptimal from ttm_tt_suboptimal_pages() trigger XE_WARN_ON(!fence) in __xe_migrate_copy() on integrated GPUs with FlatCCS? For compressible system-memory BOs, xe_ttm_tt_create() appends FlatCCS extra_pages beyond xe_bo_size(bo), and ttm_pool accounts sub-optimal chunks across the full tt->num_pages range. On a 1 GiB compressible BO (512 order-9 data chunks plus one order-9 extra_pages chunk), cap limits want to 512 even with a 1 GiB budget, so the first pass upgrades the 512 data chunks and harvests the extra_pages chunk as sub-optimal. On the next pass (or whenever all data chunks are already at order 9 and only the trailing extra_pages chunk is sub-optimal), want is 1. ttm_bo_validate() borrows all data pages and reallocates only the extra_pages chunk, but __xe_migrate_copy() only iterates over xe_bo_size(src_bo), finds no non-borrowed pages to copy, hits XE_WARN_ON(!fence), and fails with -EINVAL while leaving the BO on the defrag list to repeat on later runs. > + > + /* > + * Nothing the move could upgrade: TTM would fail a defrag move that > + * allocates no chunk, so drop the BO rather than retry it forever. It > + * is re-added if a later populate backs it sub-optimally again. > + */ > + if (!want) { > + xe_bo_defrag_remove(bo); > + xe_bo_unlock(bo); > + goto out; > + } > + xe_bo_unlock(bo); > + > + /* Phase 2: preallocate outside the lock; */ > + ret =3D ttm_pool_prealloc_fill(pool, tt_caching, &pp, want); > + if (ret || !pp.count) { > + ret =3D ret ?: -ENOMEM; > + xe_gt_stats_incr(xe_root_mmio_gt(xe), > + XE_GT_STATS_ID_DEFRAG_FAILED_COUNT, 1); > + goto out_err; > + } [Severity: Medium] Does switching to ttm_pool_prealloc_fill() and ttm_pool_prealloc_fini() bypass the TTM WC/UC page pools during defragmentation? Before this change, in-line allocation via ttm_pool_iter_acquire_page() checked ttm_pool_select_type() and ttm_pool_type_take() first to reuse already cache-converted order-9 pages from the TTM pool. Unlike ttm_pool_prealloc_fill_full(), ttm_pool_prealloc_fill() never consults the TTM pool: it unconditionally calls ttm_pool_alloc_page() for fresh write-back pages from the buddy allocator and converts their PAT caching via ttm_pool_prealloc_apply_caching(). Similarly, ttm_pool_prealloc_fini() frees unconsumed chunks via ttm_pool_free_page() (converting each chunk back to write-back) instead of returning WC/UC chunks to the TTM pool. For WC and UC system-memory BOs on x86, this forces order-9 buddy allocations, direct reclaim/compaction, and cross-CPU PAT/TLB shootdown IPIs (or -ENOMEM defrag failures) even when pre-converted order-9 pages are sitting idle in the TTM pool. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202233323.3743= 190-1-matthew.brost@intel.com?part=3D21