Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6.18.y] drm/xe/dma-buf: Validate BOs on export to charge the exporter
       [not found] <2026120256-untainted-bankable-4a8f@gregkh>
@ 2026-12-04  0:42 ` Sasha Levin
  0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2026-12-04  0:42 UTC (permalink / raw)
  To: stable
  Cc: Thomas Hellström, Matthew Brost, Matthew Auld, Dave Airlie,
	Rodrigo Vivi, intel-xe, Sasha Levin

From: Thomas Hellström <thomas.hellstrom@linux.intel.com>

[ Upstream commit 22e05ee854e1bdacebcfa36ecd3f33ec80cf897a ]

xe_gem_prime_export() calls ttm_bo_setup_export() to make sure the
exporter is charged for the memory backing an exported BO. However,
that only populates a TTM_PL_SYSTEM tt. A BO that has been evicted, or
that has deferred backing, will instead get its memory allocated when
the importer maps it. For p2p imports this happens through
xe_bo_validate() in xe_dma_buf_map(), so the importer, not the
exporter, is charged for the allocation.

Call xe_bo_validate() at export time instead, so that the BO is moved
into its preferred placement and the exporter is charged.

Do the purgeable checks and the validation in the same
xe_validation_guard() transaction, to avoid locking the BO twice.

The commit message and code was drafted using LLM.

Link: https://patchwork.freedesktop.org/patch/747480/?series=172524&rev=1
Fixes: 91494dee1091 ("xe: populate buffers before exporting them.")
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: intel-xe@lists.freedesktop.org
Cc: stable@vger.kernel.org # v6.18+
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patch.msgid.link/20261111100929.2228-1-thomas.hellstrom@linux.intel.com
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
(cherry picked from commit 451162b9f6570d19da1c5944aa0a0e3e8f17773d)
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
[ sashal: Replaced ttm_bo_setup_export() with an xe_bo_validate() call under xe_validation_guard, omitting the purgeable-BO checks and willneed get/put that this tree lacks. ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/xe/xe_dma_buf.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
index 07010f097e584..dcaf3d0cce6b7 100644
--- a/drivers/gpu/drm/xe/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/xe_dma_buf.c
@@ -203,20 +203,32 @@ static const struct dma_buf_ops xe_dmabuf_ops = {
 struct dma_buf *xe_gem_prime_export(struct drm_gem_object *obj, int flags)
 {
 	struct xe_bo *bo = gem_to_xe_bo(obj);
+	struct xe_validation_ctx ctx;
+	struct drm_exec exec;
 	struct dma_buf *buf;
-	struct ttm_operation_ctx ctx = {
-		.interruptible = true,
-		.no_wait_gpu = true,
-		/* We opt to avoid OOM on system pages allocations */
-		.gfp_retry_mayfail = true,
-		.allow_res_evict = false,
-	};
-	int ret;
+	int ret = 0;
 
 	if (bo->vm)
 		return ERR_PTR(-EPERM);
 
-	ret = ttm_bo_setup_export(&bo->ttm, &ctx);
+	xe_validation_guard(&ctx, &xe_bo_device(bo)->val, &exec,
+			    (struct xe_val_flags) {.interruptible = true}, ret) {
+		ret = drm_exec_lock_obj(&exec, &bo->ttm.base);
+		drm_exec_retry_on_contention(&exec);
+		if (ret)
+			break;
+
+		/*
+		 * Make sure the BO is backed in its preferred placement so that
+		 * the exporter, rather than the importer, is charged for the
+		 * memory allocation.
+		 */
+		ret = xe_bo_validate(bo, NULL, false, &exec);
+		drm_exec_retry_on_contention(&exec);
+		xe_validation_retry_on_oom(&ctx, &ret);
+		if (ret)
+			break;
+	}
 	if (ret)
 		return ERR_PTR(ret);
 
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04  0:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <2026120256-untainted-bankable-4a8f@gregkh>
2026-12-04  0:42 ` [PATCH 6.18.y] drm/xe/dma-buf: Validate BOs on export to charge the exporter Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox