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 57D3D60A5BCB for ; Tue, 1 Dec 2026 23:49:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CyLatcKD Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4BA1D10FDF2; Tue, 1 Dec 2026 23:49:32 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7941210EAA4; Tue, 1 Dec 2026 23:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796168964; x=1827704964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XZ+SUlREtGgwdIcvchOaUHmjNF9JefDwcSkFbaFod2s=; b=CyLatcKDqAR+QXYpoMpdYDkJvQcKTYk5RHoJMzFpoTQsJ/CGmZelxFbI N1piDsAtaPX/IE4OoWKBEXRGyfbIZxiKTCuQkg0ZLdViKwGYCswRazOgq YDnPk5cW+0JYVE2CGdItsqjmSWHTs9fTLr//vMbdyTQGXRaTGVErii1Td KhnyldbnazQ1/QHTVIXLEE+p/n1el5I730SCACw6YpOGySaxhu9aP+K13 a0CXIklcRP4MW50OsyYInVjehz7gZM1sSugWpfft244jGm/KPCfqZZjM+ Q84ifaLHwqSEsUJimnCHL1rFdZJ4nYBppDTMve46HJIseMb8wQxuCKeVy w==; X-CSE-ConnectionGUID: xRg5oBTKTQGjr84zwjl+YQ== X-CSE-MsgGUID: cm5YAojISNOgYUYNDRmIrA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4977347" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4977347" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 15:49:21 -0800 X-CSE-ConnectionGUID: y98Gf7JQTd+VrbQTMnsTzw== X-CSE-MsgGUID: HB2BS7gdRDuC/CrB7OQtLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13919907" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 15:49:21 -0800 From: Matthew Brost To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org, =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Niranjana Vishwanathapura Subject: [PATCH v4 02/33] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Date: Tue, 1 Dec 2026 15:48:44 -0800 Message-Id: <20261201234915.3305331-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201234915.3305331-1-matthew.brost@intel.com> References: <20261201234915.3305331-1-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Sender: "Intel-xe" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 TTM records the allocation order of a multi-order page in page->private at allocation time. For pools that do not use dma_alloc the order is stored directly, while dma_alloc pools store a struct ttm_pool_dma pointer there instead. Drivers that do their own DMA mapping (e.g. Xe) need the per-page order to walk a populated ttm_tt one chunk at a time, but cannot rely on folio_order(): TTM allocates high-order pages with alloc_pages_node() without __GFP_COMP, so they are not compound and folio_order() always returns 0. Expose ttm_pool_page_order_nodma(), a thin wrapper that returns the order recorded in page->private. It is only valid for pages from a pool that does not use dma_alloc; whether a TTM device uses dma_alloc is fixed at ttm device init time, so callers know from their device configuration that this helper applies. Use it from the existing internal ttm_pool_page_order() to keep a single source of truth. v4: - const struct page (Niranjana) Cc: Carlos Santa Cc: Ryan Neph Cc: Natalie Vock Cc: Arun Pravin Cc: Matthew Auld Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Simona Vetter Cc: dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org Cc: Thomas Hellström Assisted-by: LLM Signed-off-by: Matthew Brost Reviewed-by: Matthew Auld Reviewed-by: Niranjana Vishwanathapura --- drivers/gpu/drm/ttm/ttm_pool.c | 25 ++++++++++++++++++++++++- include/drm/ttm/ttm_pool.h | 2 ++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c index 16fd125d7375..c6fbcdba9bdb 100644 --- a/drivers/gpu/drm/ttm/ttm_pool.c +++ b/drivers/gpu/drm/ttm/ttm_pool.c @@ -477,6 +477,29 @@ static unsigned int ttm_pool_shrink(int nid, unsigned long num_to_free) return num_pages; } +/** + * ttm_pool_page_order_nodma() - Allocation order of a non-dma_alloc TTM page + * @p: The page to query. + * + * Return the allocation order that the TTM pool allocator recorded in + * @p->private at allocation time. This only works for pages that were + * allocated from a pool which does *not* use dma_alloc (i.e. pages backed by + * alloc_pages_node()), where TTM stores the order directly in page->private. + * + * For dma_alloc pools, page->private instead holds a struct ttm_pool_dma + * pointer and this helper must not be used. Whether a TTM device uses + * dma_alloc is fixed at ttm device init time, so callers are expected to know + * from their TTM device configuration that their pages are not dma_alloc + * backed before using this helper. + * + * Return: The allocation order of the page. + */ +unsigned int ttm_pool_page_order_nodma(const struct page *p) +{ + return p->private; +} +EXPORT_SYMBOL(ttm_pool_page_order_nodma); + /* Return the allocation order based for a page */ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p) { @@ -486,7 +509,7 @@ static unsigned int ttm_pool_page_order(struct ttm_pool *pool, struct page *p) return dma->vaddr & ~PAGE_MASK; } - return p->private; + return ttm_pool_page_order_nodma(p); } /* diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h index bb6347e5b297..429f4f987a19 100644 --- a/include/drm/ttm/ttm_pool.h +++ b/include/drm/ttm/ttm_pool.h @@ -94,6 +94,8 @@ long ttm_pool_backup(struct ttm_pool *pool, struct ttm_tt *ttm, int ttm_pool_restore_and_alloc(struct ttm_pool *pool, struct ttm_tt *tt, const struct ttm_operation_ctx *ctx); +unsigned int ttm_pool_page_order_nodma(const struct page *p); + int ttm_pool_mgr_init(void); void ttm_pool_mgr_fini(void); -- 2.34.1