Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.20 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796329439; b=K+5x40hQmBFBhfw2eKpUiw/6pKbzbe3CZvNF4Ypbf8M8uMlq8cS0nBXycFHX0qaw8d5q xLEi7mwnadoV5f5mLqEaic9cmBHkuAHJrWvKSIIT8VYdr0mJZdUeInR/rmxGDunVMjQzA O7QI0GUTp2dlAXbM34kkm9PCcgSlx5G4ZiRCPcj7PH4VcIFWJfi+EQFUFJsIOJJ6pMwq0 FAZ/n1X5YjRWKAh5qIPupgUUZfK1xF8mEoP5wB7gfasxtCRrjUbwNem0FTJbLw1KJpTXw pIMFp3BcXjFJzjK7C/+2Je5TAUjfIQYkvhsNdc+ykcSZPuw+B6KrG77/FKG37K8z8Uw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329439; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=xGD6bZzX0eG33Pela8tfJ0Izgr1CCRCO7VQqbG55cQ4=; b=JYyAeeJ2Kl87N3x20LyfRIj1LrsZ67GZ9I6YGTqRvZGwEk3YSv0V9tPFwOdwesirRbpm X/+emF/Ox/0juZoA4doxdOF8vQMCu/RwIkDXGzWC4URXbunXjEXfwtOpyr9/wRYGVYyhY aN2d/yC0RWngGf8BcQVqgH6kuab6t0Tf+KavZImc7MCQb3RW628Dw8Y/4/XGmCjkzr36a OqKqjeADLKXVF2f7PWhzXYfl0fWXplEfD+V0kMyiI/ZTYCBtJDF9A3XzuFKR4h0+KBLWM a4y1GGN3CjCWaxC3n+1vwOixHr9xcxGMD8pgP1l73MB0WsslDulni0nCAkH6aWrALZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=LS7cTlOB; arc=none smtp.remote-ip=198.175.65.20 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC7AC606A330 for ; Thu, 3 Dec 2026 20:23:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AC7AC606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com 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=LS7cTlOB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329439; x=1827865439; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xGD6bZzX0eG33Pela8tfJ0Izgr1CCRCO7VQqbG55cQ4=; b=LS7cTlOBlCsW66lflFWDSyOIRf+LON5PmsLOXa/eN+wOCoXL7hMBiHRj 5x+F8j0E3FSSb2HouzbPGo7GOgatpVUYD/yRYSQxsTsEEuEil/I5pV7G4 NJvOSlcaz5VQpw3IyruiRl7nU3TSPVIk7bPkQeh8/Wgn1/Szgvq5HheYb l9bC2te6z9/thdsY22XX7Jf7OA4DxICVZifjAxpLWDs0IJm5hyTz4f8aC YPAJz22KJL7Nfz+7al/quPXInfrrnDoKpI6KBKgCoZLTgCqV56tQ69ob1 hid9ItzHsFvorUXqS7ywRpGcKCCLYSg4qeC6HKgaasxF2vSzuQKPPv1h/ g==; X-CSE-ConnectionGUID: OwgLOhzXT+i7QFvjkh/Ubw== X-CSE-MsgGUID: chPuQ1JRTyujPONsP4ikLg== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5350995" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5350995" 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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