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 7AF03606C52B for ; Thu, 3 Dec 2026 20:24:11 +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=Y+BbGspH Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3C1DB112B8B; Thu, 3 Dec 2026 20:24:06 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id B0480112B64; Thu, 3 Dec 2026 20:23:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329440; x=1827865440; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xGD6bZzX0eG33Pela8tfJ0Izgr1CCRCO7VQqbG55cQ4=; b=Y+BbGspHpKXCqsh5K1Yh0iWO1E5dcQN/G94Q2jCNuDosbHjp+VOCgeRe KQsjgCo/gBWfRoWhn7XmANRlF04Z/oy70OIQl/ao3V+03/y1V8c0ufIrl 2fEGoNpr1A5QeEJEwoq11VXIq3FPd+HfAmtlKdFRJpJzC4sxmRsWFJl3l xEtpYKmKFz4E+RjTGdoYLiZedrNf8lMWfuYIDqxj0At140Fi6+ZlDYEJi vr22v6/LnMMreqb90aY7+XaurMZr103csGudtYyv5PcbgODnOqQxZb84D 8GCzPUSnJ8RctRGhCJ+Q4h1HsYzSHPaa5A5GmgXgx4AhK47Ve95IxEX5g Q==; X-CSE-ConnectionGUID: QWTxLxLNRzeMnQhG3OxJRA== X-CSE-MsgGUID: fRrsk5YNTH2HoyPoLFvxrQ== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5350992" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5350992" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:23:58 -0800 X-CSE-ConnectionGUID: VqlivmyCQ6C6ZgR3JaW+XQ== X-CSE-MsgGUID: zTFR55EbTBWvDDqtB48haw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862410" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 12:23:58 -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 v6 02/35] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Date: Thu, 3 Dec 2026 12:23:19 -0800 Message-Id: <20261203202352.4153159-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203202352.4153159-1-matthew.brost@intel.com> References: <20261203202352.4153159-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 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