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 C0DF5606A31A for ; Wed, 2 Dec 2026 00:15:51 +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=nULwTzk2 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8585210E47E; Wed, 2 Dec 2026 00:15:46 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 00A4F10EA88; Wed, 2 Dec 2026 00:15:39 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id DE4B940F89; Wed, 2 Dec 2026 00:15:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53A2F1F00896; Wed, 2 Dec 2026 00:15:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796170539; bh=bF7/4688E3CI4AfA8xcuhISOPGpkTELraxcQ2z6faJk=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=nULwTzk2zGbnW3fmnnNhTTkbwV4VzTELOcMLQnRI7oV9d7AX0oUd6PkcaFUwNvCrb 3TeCSe+Nw1/CadPZYdUZ+7WzY5qljMTTNZzCl5wP4IHmUFIIzKttDgOMQsXoXGMts3 CGfRF8yC84cTQ/GayWhIa6S2JTg2H2il2ZRGD3NU6owcwl0iyxLXPnZBs5bBufQbZN 13gTuZVF0G46Zo1j8r5XW0gQbq6outRqZ6SeZO0l3srlPA3gAqw7kk2Fp3zpJ9Bb6x 4i8EP1GidPxE3MJ7eIOsgxjKrBdJLcbIZ1r4KHkhsKeHz8ABqF84LBJajAWnFTrQae DOy7E54IpZtRw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 23/33] drm/xe: Preallocate system BO backing outside the dma-resv lock To: "Matthew Brost" , intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261201234915.3305331-24-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-24-matthew.brost@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 00:15:38 +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 2 potential issues to consider: - [Medium] drm/xe: unupdated xe_bo_create_user() callers break DEBUG_PAGE_SIZE build - [Medium] drm/xe: 64-bit shift overflow and truncation in xe_gem_create_prealloc() -- commit f38bc20f3d380a4e01e97e0870f13b9fcff4a845 Author: Matthew Brost drm/xe: Preallocate system BO backing outside the dma-resv lock This commit preallocates backing pages for system-only user buffer objects outside the dma-resv lock in xe_gem_create_ioctl() and threads an optional struct ttm_pool_prealloc through xe_bo_create_user(), __xe_bo_create_locked= (), and xe_bo_init_locked(). > diff --git a/drivers/gpu/drm/xe/tests/xe_bo.c b/drivers/gpu/drm/xe/tests/= xe_bo.c > index 22a2e8f8143ad..2368c803af98f 100644 > --- a/drivers/gpu/drm/xe/tests/xe_bo.c > +++ b/drivers/gpu/drm/xe/tests/xe_bo.c > @@ -366,7 +366,7 @@ static void ccs_test_run_tile(struct xe_device *xe, s= truct xe_tile *tile, > kunit_info(test, "Testing system memory\n"); > =20 > bo =3D xe_bo_create_user(xe, NULL, SZ_1M, DRM_XE_GEM_CPU_CACHING_WC, > - bo_flags, exec); > + bo_flags, NULL, exec); [Severity: Medium] Does this break the build when CONFIG_DRM_XE_KUNIT_TEST and CONFIG_DRM_XE_DEBUG_PAGE_SIZE are both enabled? Two callers inside the #ifdef CONFIG_DRM_XE_DEBUG_PAGE_SIZE block in drivers/gpu/drm/xe/tests/xe_bo.c, run_only_leaf() and xe_bo_page_size_alloc_mixed_bos(), still pass 6 arguments to xe_bo_create_user() instead of 7: drivers/gpu/drm/xe/tests/xe_bo.c:run_only_leaf() { ... bo =3D xe_bo_create_user(xe, NULL, li->alloc_size, DRM_XE_GEM_CPU_CACHING_WC, XE_BO_FLAG_VRAM0, NULL); ... } drivers/gpu/drm/xe/tests/xe_bo.c:xe_bo_page_size_alloc_mixed_bos() { ... bo =3D xe_bo_create_user(xe, NULL, SZ_1G, DRM_XE_GEM_CPU_CACHING_WC, XE_BO_FLAG_VRAM0, NULL); ... } Because drivers/gpu/drm/xe/xe_bo.c includes tests/xe_bo.c directly under CONFIG_DRM_XE_KUNIT_TEST, compiling with CONFIG_DRM_XE_DEBUG_PAGE_SIZE=3Dy fails with a "too few arguments to function 'xe_bo_create_user'" error. [ ... ] > diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c > index 0697d395d2ba3..ed34ab5aeb1e8 100644 > --- a/drivers/gpu/drm/xe/xe_bo.c > +++ b/drivers/gpu/drm/xe/xe_bo.c [ ... ] > @@ -4398,6 +4407,78 @@ static int gem_create_user_extensions(struct xe_de= vice *xe, struct xe_bo *bo, > return 0; > } > =20 > +static bool __xe_bo_needs_ccs_pages(struct xe_device *xe, > + enum ttm_bo_type type, u32 flags, > + u16 cpu_caching); > + > +/* > + * For system-only BOs, preallocate the whole backing outside the dma-re= sv lock > + * so the populate under the validation guard does not stall in > + * reclaim/compaction. The caching mirrors the system-BO path in > + * xe_ttm_tt_create(); the pool falls back to in-line allocation for any > + * shortfall, so a failed fill is harmless. > + * > + * Return: true if @prealloc was filled (possibly partially) and must be > + * released with ttm_pool_prealloc_fini(), false if preallocation was sk= ipped. > + */ > +static bool xe_gem_create_prealloc(struct xe_device *xe, > + const struct drm_xe_gem_create *args, > + u32 bo_flags, > + struct ttm_pool_prealloc *prealloc) > +{ > + struct ttm_resource_manager *tt_man =3D > + ttm_manager_type(&xe->ttm, XE_PL_TT); > + enum ttm_caching caching =3D ttm_cached; > + unsigned long num_pages =3D args->size >> PAGE_SHIFT; > + u64 used, shift_size, avail; > + > + if (!(bo_flags & XE_BO_FLAG_SYSTEM) || > + (bo_flags & (XE_BO_FLAG_DEFER_BACKING | XE_BO_FLAG_VRAM_MASK | > + XE_BO_FLAG_STOLEN))) > + return false; > + > + if (!tt_man) > + return false; > + > + if (!IS_DGFX(xe) && args->cpu_caching =3D=3D DRM_XE_GEM_CPU_CACHING_WC) > + caching =3D ttm_write_combined; > + > + /* > + * Cover the CCS backup pages appended to the tt (see > + * xe_ttm_tt_create()) so the whole tt is preallocated. > + */ > + if (__xe_bo_needs_ccs_pages(xe, ttm_bo_type_device, bo_flags, > + args->cpu_caching)) > + num_pages +=3D DIV_ROUND_UP(xe_device_ccs_bytes(xe, args->size), > + PAGE_SIZE); > + > + /* > + * Only prealloc when the backing fits the currently-available TT space > + * (manager size minus current usage). This skips the up-front > + * reclaim/compaction both for over-large, user-controlled sizes and > + * when TT is already near full; the populate under the validation > + * guard handles those cases. > + */ > + used =3D ttm_resource_manager_usage(tt_man); > + shift_size =3D tt_man->size << PAGE_SHIFT; > + avail =3D shift_size > used ? shift_size - used : 0; > + if ((u64)num_pages << PAGE_SHIFT > avail) > + return false; > + > + /* > + * Back off aggressive reclaim/compaction for higher-order chunks here: > + * Xe runs a background defragmenter that upgrades suboptimal pages to > + * beneficial order in place later, so there is no need to stall this > + * user context reclaiming for contiguity. When defrag is disabled there > + * is no such later upgrade, so do not back off reclaim here: take > + * beneficial-order pages up front. > + */ > + ttm_pool_prealloc_fill_full(&xe->ttm.pool, caching, prealloc, > + num_pages, xe_bo_defrag_supported(xe)); [Severity: Medium] Can ((u64)num_pages << PAGE_SHIFT) overflow 64 bits and bypass the available TT space check when CCS backup pages are added? On 64-bit systems, xe_gem_create_ioctl() allows any page-aligned args->size up to SIZE_MAX (U64_MAX). On an integrated GPU with FlatCCS, adding the CCS backup pages to args->size >> PAGE_SHIFT can push num_pages to or above 1UL << 52 (for example, when args->size >=3D 0xfffffffffff00000ULL). Shift= ing num_pages left by PAGE_SHIFT then wraps around modulo 2^64 to a small byte count, passing the "> avail" check and truncating num_pages to unsigned int in ttm_pool_prealloc_fill_full(), which preallocates up to ~4 GiB of pages for a request that immediately fails in ttm_bo_init_reserved(). Comparing in page units (e.g. num_pages > (avail >> PAGE_SHIFT)) avoids both the 64-bit shift overflow and the 32-bit truncation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201234915.3305= 331-1-matthew.brost@intel.com?part=3D23