From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796254410; b=EPAWpphw0cz9MJ+UfCmk70hPTfn+RpeV6UGtQkqkIbp11hLPsfMOWjHFUvvetUWiAqsq 8nQ+5cL+8bxhWAd5InX0UtyJTa/f6JK9b/gwiB24HCGDIDlkscjWELFq9lNw4tC0IQ+6l R2G3fJlY65Shw+uia4/Lp/5rtCxEvAep1cG0uJ+ZYySRMaWPtnJf/looWj/+Q3vBcvAeI YWO8oQxNRU7KcaCJP8+9WJx2hA6wqcBhTvtF+VMAnxETpxz/cRd6zHOg72nr5FXFqqmUF xdxC2qthot68DXWIwu8Eu6tpFPaCfMWt1aRnWphV4UaI2QSpzjLnJ/HumTObvoTYN5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796254410; 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=Pfn+2cpOK/BBhAKfHvr53wwQTGG1fnIGCQmBaptJCW7qu3vFg/rq0l07290YoecgL59M DyZjeeqiIB5g/fHzqVAXfJdbNEUp7o6fVBz4P5123bcncT6Xg4J1Y88rjaXXcR2xYz0GW g5jo7Dy61XDd3cxDmUAVY7VODEM0l3G1wIH4OCEidCbxTlaNiLcg81uuAecxDWAPajxSp WJZyjUEV7LqPWT2Wk9+3gPgW9pKMUwcSgnGQIVGqQ79bVJSNlD+5uCBxq7qskxEqqnIzk MMsXTgIKOxG5gNnqMpAAxze5m4N+Wy94AiqXsGJrvvotttZRqkFewkpD8h4+IAdLIiA== 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=Ntx5L288; arc=none smtp.remote-ip=192.198.163.17 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 500BE606A322 for ; Wed, 2 Dec 2026 23:33:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 500BE606A322 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=Ntx5L288 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796254411; x=1827790411; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xGD6bZzX0eG33Pela8tfJ0Izgr1CCRCO7VQqbG55cQ4=; b=Ntx5L2887l2L7x1rlo+PJUsVqWlfEosiizW6j+GSwiAWxA7w9Zrmw5AF 9G/szqc5rqomySpQSyBcEQMkNOHk1+bKazjtwyRA/xmBLh5QBFXBgMbPj DBJUSqj641NoEpBLVxtUNIgb/AlU7/L2UjsULQrMgCA3ZsNGgUlMD2Z/s wT/RpPqzRJelJZuFwJZ4iHMDfy92Gug3PJvkSWfsgTXjPe8tAyxFrNB84 nNxRYGNuyvtX4o3wlh2wgkJy4N0/o1QHLygt6Txpt1RvrkVVnaw/OitBE D7XyCofTcEHRPmS+XgxS6cUaCscFpMxRtk74An+MnlxJF8DTjmL+OTKBU A==; X-CSE-ConnectionGUID: ruZyJxIiReyTR5trgM3Iog== X-CSE-MsgGUID: JKiRMs/SS2KfsEZLvFiTng== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5203073" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5203073" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:28 -0800 X-CSE-ConnectionGUID: quaL5gkBT/iJiKefaXDsDQ== X-CSE-MsgGUID: Lx/gz84XQ0uigtEN+2Bd4A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13484027" Received: from gsse-cloud1.jf.intel.com ([10.54.39.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 15:33:28 -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 v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Date: Wed, 2 Dec 2026 15:32:49 -0800 Message-Id: <20261202233323.3743190-3-matthew.brost@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202233323.3743190-1-matthew.brost@intel.com> References: <20261202233323.3743190-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