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=1796329446; b=P7LVGYbS4GR5LvrrU2HhsdhmEdbVfcLntfUa2hywlmsQHNGIlFkVsfOlHLNR5KNBgKyS MZRBs1WVRLIedvYDAhSOgdzghCsCsrsZMGsBR5Jm6Q9DIPvnO76JgoDAoZtcxqkWtvGdD MfcnvDOkxt3ZOKmX1eEB9xZHvxEqI6I8oHK/21TNKDrDfVrhpsWPNHZ15G5CgfvemYF+I wwxXaBJQt/9LIlL6Wtv93Np9Tv40gIuFi9ZPo38m6Ax4vGROTtTC7rpkuOhr6iroVisn1 2ruB619NqwjDgqizfLtuEBOomoo7eg00JRMQzbnpPKe1hpVhaNDi6uU9oIdIeIzEaeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329446; 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=3xY1Q7Cs24dgW0B+//wsmC3VF1FcdScx9TueLo2oDaE=; b=KU4zGt0pCdutgyL0hq92GA4irZHZQcAkMlIfaMy5wRDC/OLoEvlqVJHKgTODwu35Iw8f bO9Z1p5PI/shacscMf5xZQa1A4SjdCEAGKQ1gw5T9VtDCoqQfOi5diiF3+lH9AH9B0Ozy Wm7cVpnyfi7wODgGAlEw82+KluWBu0zlATzGi4oqFUCHJpY9m9pSLRL4GZuskZHRhF9q5 aADs3ySAib8QmDOW1xNgb1D/yKxs/svFEMF53xMAzGz6kw7t/zhnUDPKEwon0J4WQ8wyr /9jAI/gaWndoN1x6IjAh0xS+xXGh19YgdhWiqsMqOMCNHg2ezC7OT0y2qkCrGgyI3Ug== 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=n9b5Xqpg; 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 2586960A6F52 for ; Thu, 3 Dec 2026 20:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2586960A6F52 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=n9b5Xqpg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796329447; x=1827865447; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3xY1Q7Cs24dgW0B+//wsmC3VF1FcdScx9TueLo2oDaE=; b=n9b5XqpgMZFwxyMq0aqrrAvlx1TGzGOwGd4SPkAVTX5NgETaHkFi8wus jj9UDwfpxmCbqxF4vNM8nrH3SBTmkvMidUMyr/xmGULmmN/llteoTLk84 +VvjJmEYLWe4JiBphMSVvt1xNae9Q1Vxl2JnT90/zsN2Qum+gbZ2SoEVS KZA83N+SW0tmJoV0t8PjB/1bWbm81kZ2hB57iJ2iZLBgnV2E980bBpC1x 8YzjNGQtqPZrciyZx0Y6mUaeQWAeJm4XQ7Qx+1Tbyd8QLUwD4ffVGJR/m +LNtYGm/pQ6MBgOMPRRbAqiUJeZJxVEQaaU4Bz8C3bY7MzNS+e5ibZY4T Q==; X-CSE-ConnectionGUID: r9WPqDNHTD+URwjvXmTaNQ== X-CSE-MsgGUID: t9hYaJO5QP+8mZo2JTH5uQ== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5351199" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5351199" 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:24:06 -0800 X-CSE-ConnectionGUID: 1c5PvQBRSkmG0dGagUoMtA== X-CSE-MsgGUID: nj4JIfW0QwWtvQyouDK6lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="15862507" 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:24:06 -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 25/35] drm/xe: Add IOVA-based xe_res_cursor variant Date: Thu, 3 Dec 2026 12:23:42 -0800 Message-Id: <20261203202352.4153159-26-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 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 Signed-off-by: Matthew Brost Reviewed-by: Matthew Auld Reviewed-by: Niranjana Vishwanathapura --- 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