Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.12 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796168963; b=kpBTYQW7Vh828L2DXps2uG8aabj1xTAYiakanJxxlEi1U867XI5YnHxqaxcCIGHrKaBW UxhR/NBw2LjUBLYbXesLSGjh5lpklDlBeIpYVXMDATckW84O9He53DVubZUud/6xY7rov DN/H0+qI9hMUmcO1CCudtEObOEzJrgbSVMJN6h4gafZ+6fVgdAvU7fOiGVuLxyda/bPPe fCkKJ6Iy6cSNhXs9o300Ubo8NdDTltsORnxp6NUgI1/cpZiMM0RlV1eTaRmjxWI6p4yVL eVj9etnTAzzL+EYol8O8PSNC2moktEpO39VAa2YkRdIeYNGjDwI5VB+WFzO/IDjAmRw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796168963; 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=XZ+SUlREtGgwdIcvchOaUHmjNF9JefDwcSkFbaFod2s=; b=TnrWuuGJKtGatoEjLMv6LduQIYn/98261RUYAiG29zdkfktGIuCZbiV3GOGBdOa+H9sD P1zS/uAE6B5XdCTJq+R0iKm5uHsFQCSpJebx3n8EpMzZWm9n3kAL+dIWqtRuMWpbwefEK RL8zaFepeGra1CFsBM/S0XggqGhueCLwi9yHhEVyZioUOpqtCWbpxUBce5ZhWhJIlLqwM aUw9qchYt8F0tWy18j9XvTQu8K9K0I1mtCjfINEEmJHwAEPKHWA1A9P+sfEJsi8u+VIW4 75afp6gfeXknTdMUYbNZpyITQh3VzTiJPPiFp2kCRGWD1+bKc/rjecAJtkkwilFAdTA== 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=MNflCSXO; arc=none smtp.remote-ip=192.198.163.12 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (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 B4058606A323 for ; Tue, 1 Dec 2026 23:49:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B4058606A323 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=MNflCSXO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796168963; x=1827704963; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XZ+SUlREtGgwdIcvchOaUHmjNF9JefDwcSkFbaFod2s=; b=MNflCSXOFsWotKHcnPek8g6IZonYbrA5r/DGpno2tczPnsGgVVFG86Fz 3RAGYgWfakBhyiCBowE5pKFjKA1ufp+jEVZWXSfS/jLhHlLObbOku+QaO IsCsbY0IQDBnFgayLZBiJNY9wKpud6KDw4erhbynuFBMaUnVG5zf+JzdB rF+1/3ikJXWMxasjFrqB9AvqkfPkCFrytC6Ya6crfbdRMuBbujii1e6K5 UfWWNHYnIlyh/PA6pZTqJG3OYPJeywSGpXUzoKRF0da+r2/bvxxi0uzA+ 8z9OKEfgbvdaEanllSOFhB993lWdiB/uRQjUKIaF+FUB+ZlZwjNAtHSGi Q==; X-CSE-ConnectionGUID: sCW4/BJCR565e68Of1dDjw== X-CSE-MsgGUID: 7L9X4vy7RgKsb06Ak8niCQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4977343" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4977343" 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-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 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