From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796168971; b=TimeWLoW6ztGuuO/nvwupru6/9J6F5NDTnbEZ/rapsEnuY6mz6ZLBnP8MLfTnxVQH/ee 84X7SAonzLcxsgAXD0m8WpOmSIEY9T7ah1lPHE2/9vv5kP3gH1cEFtFnbwVXFPljxsXOr cCUWpNUSQdmQADiPcQH+8d/e/6XLHxzw1zEAQULKwXFiNHFPlE1IwlmYJOGNEnJHWSAet aJS5qD0amaEgZh9cuZ+8Kc4xsXuJh1RSPoAJcEPug03icQl0P1UBF5p9FiripXeCVwxcm DuIaDcMeWyL+0aYEE09GCNCZJap04L9ViuIfxHhTT7bCVYvTHn5se7UJj/CnK6+wJCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796168971; 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=tHGUjwVj+t4YgqS4H2/R1fBVeyBR1Rp8VHPlDPd7tzA=; b=lAqOueHqIUxqKfu7+7LzQhNZYf+/8hJBiKg06xBDmMeguWe4hKUPlL9Pb5sqII0e+FN8 ifwMFdxTJdE/FKftOwvKf/TkEh7HmmRx3Vt1YylUw97Ko0wOz4wV7gslCYlWGcJuzU90m Gzzxl/DBama18yFy2CLxKAoZQdZ6GAeauBxYy7AvCWmzlqJUPc3DxG+aEUEnkGY1+YaDL A+XlEWYaKovvjXrfG8XM4G387164Vk5fO4n2x0YWUQNQ7qA+R8Bz/5tapnqGaN/FacaYY MApWWVjK2zw+Ra7uxEz4mTyvcZZjaWAXxzEF4cQkH8PuwPyraR6F8t07uk0+0eg2BWA== 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=IqCH8R7U; 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 5140360A5BC1 for ; Tue, 1 Dec 2026 23:49:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5140360A5BC1 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=IqCH8R7U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796168971; x=1827704971; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tHGUjwVj+t4YgqS4H2/R1fBVeyBR1Rp8VHPlDPd7tzA=; b=IqCH8R7UmaZdy3+Tsvw4pMnaFqMYZpeZwtj7l7dIzr9ZPkqkQ4pd4rjS n0gvYc1QFnIxWfEheX5kfoEvw9+tngMFfR/DPvMlyzQPqnSesYP9pQRok 7q+lPB6kZGcuKxq9fEjASSwQ8gCHKJu096QWfeYluaHwl7UKcahGnyJIU b4TV01L8WvN2ysKn2I473Ryxsbp9R58RGP6itlQgUVNUd+ewEZCx+G+eV 1mqqaIHktnwwq7Qx7Xyjpe5qP0xppH9GZTn0R3KATK5EEdft1/U45zER6 N9V4BxcAfCTZZeOCtwFyFZbg4wzyiQi62Kk6b60h3SzNzVgYaIA7ulcaz A==; X-CSE-ConnectionGUID: /Hr/Y3zSRoSVsadm5Zs51w== X-CSE-MsgGUID: sLE433CwSaiO1yIdfGYM7A== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="4977536" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="4977536" 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:31 -0800 X-CSE-ConnectionGUID: UnZEGjKGTs64oH20mWZzNA== X-CSE-MsgGUID: 7UnCd1YUR1edCq0lnsKqew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13919987" 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:30 -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?= Subject: [PATCH v4 25/33] drm/xe: Add IOVA-based xe_res_cursor variant Date: Tue, 1 Dec 2026 15:49:07 -0800 Message-Id: <20261201234915.3305331-26-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 Introduce xe_res_first_iova() to walk a buffer that was DMA mapped using the IOVA-based DMA API (dma_iova_try_alloc() and friends). Such a mapping is described by a struct dma_iova_state and is a single contiguous IOVA range, so the cursor walks it as one segment. Add an is_iova flag to struct xe_res_cursor to distinguish this case. When set, xe_res_dma() returns the IOVA backing the current position (state->addr + cursor offset), xe_res_next() advances within the single contiguous segment, and xe_res_is_vram() returns false since IOVA mappings never point to same-device VRAM. The flag is explicitly cleared in the existing xe_res_first(), xe_res_first_sg() and xe_res_first_dma() initializers so stale stack values cannot leak into the new path. 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 --- drivers/gpu/drm/xe/xe_res_cursor.h | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/xe_res_cursor.h b/drivers/gpu/drm/xe/xe_res_cursor.h index c3a037e5f34e..b3ff92b4d837 100644 --- a/drivers/gpu/drm/xe/xe_res_cursor.h +++ b/drivers/gpu/drm/xe/xe_res_cursor.h @@ -24,6 +24,7 @@ #ifndef _XE_RES_CURSOR_H_ #define _XE_RES_CURSOR_H_ +#include #include #include @@ -67,6 +68,12 @@ struct xe_res_cursor { u64 dma_start; /** @dma_seg_size: Size of the current DMA segment. */ u64 dma_seg_size; + /** + * @is_iova: Whether the cursor walks a single contiguous IOVA + * mapping described by a struct dma_iova_state. When true, the + * DMA address is @dma_start + @start and never points to VRAM. + */ + bool is_iova; }; static struct gpu_buddy *xe_res_get_buddy(struct ttm_resource *res) @@ -93,6 +100,7 @@ static inline void xe_res_first(struct ttm_resource *res, { cur->sgl = NULL; cur->dma_addr = NULL; + cur->is_iova = false; if (!res) goto fallback; @@ -224,6 +232,7 @@ static inline void xe_res_first_sg(const struct sg_table *sg, cur->dma_addr = NULL; cur->sgl = sg->sgl; cur->mem_type = XE_PL_TT; + cur->is_iova = false; __xe_res_sg_next(cur); } @@ -256,6 +265,40 @@ static inline void xe_res_first_dma(const struct drm_pagemap_addr *dma_addr, __xe_res_dma_next(cur); cur->sgl = NULL; cur->mem_type = XE_PL_TT; + cur->is_iova = false; +} + +/** + * xe_res_first_iova() - initialize a xe_res_cursor with a dma_iova_state + * + * @state: struct dma_iova_state describing a single contiguous IOVA mapping + * @start: Start of the range + * @size: Size of the range + * @cur: cursor object to initialize + * + * Start walking over the range of an allocation that was DMA mapped using the + * IOVA-based DMA API (see dma_iova_try_alloc()). Such a mapping is a single + * contiguous IOVA range, so the cursor walks it as one segment. Subsequent + * calls to xe_res_next() advance within that range and xe_res_dma() returns + * the IOVA backing the current position. xe_res_is_vram() always returns false + * for such a cursor. + */ +static inline void xe_res_first_iova(struct dma_iova_state *state, + u64 start, u64 size, + struct xe_res_cursor *cur) +{ + XE_WARN_ON(!state); + XE_WARN_ON(start + size > dma_iova_size(state)); + + cur->node = NULL; + cur->start = start; + cur->remaining = size; + cur->size = size; + cur->dma_addr = NULL; + cur->sgl = NULL; + cur->dma_start = state->addr; + cur->mem_type = XE_PL_TT; + cur->is_iova = true; } /** @@ -284,6 +327,10 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size) return; } + /* IOVA cursors are a single segment, fully consumed by the above. */ + if (XE_WARN_ON(cur->is_iova)) + return; + if (cur->dma_addr) { cur->start += size; __xe_res_dma_next(cur); @@ -335,7 +382,7 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size) */ static inline u64 xe_res_dma(const struct xe_res_cursor *cur) { - if (cur->dma_addr) + if (cur->is_iova || cur->dma_addr) return cur->dma_start + cur->start; else if (cur->sgl) return sg_dma_address(cur->sgl) + cur->start; @@ -352,6 +399,9 @@ static inline u64 xe_res_dma(const struct xe_res_cursor *cur) */ static inline bool xe_res_is_vram(const struct xe_res_cursor *cur) { + if (cur->is_iova) + return false; + if (cur->dma_addr) return cur->dma_addr->proto == XE_INTERCONNECT_VRAM; -- 2.34.1