[PATCH 2/2] drm/xe: Copy cpu_caching when importing DMA-BUF.

Maarten Lankhorst dev at lankhorst.se
Thu Mar 20 21:15:19 UTC 2025


When testing xe with P2PDMA DMA-BUF import,
VM_BIND was failing because cpu_caching was not set.

Set cpu_caching if available from another xe driver,
to allow uncached VM_BIND on imported DMA-BUF.

Signed-off-by: Maarten Lankhorst <dev at lankhorst.se>
---
 drivers/gpu/drm/xe/xe_dma_buf.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_dma_buf.c b/drivers/gpu/drm/xe/xe_dma_buf.c
index c5b95470fa324..9b1813e65e0a4 100644
--- a/drivers/gpu/drm/xe/xe_dma_buf.c
+++ b/drivers/gpu/drm/xe/xe_dma_buf.c
@@ -266,12 +266,12 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 	const struct dma_buf_attach_ops *attach_ops;
 	struct dma_buf_attachment *attach;
 	struct drm_gem_object *obj;
-	struct xe_bo *bo;
+	struct xe_bo *bo, *foreign_bo = NULL;
 
-	if (dma_buf->ops == &xe_dmabuf_ops) {
+	if (dma_buf->ops == &xe_dmabuf_ops &&
+	    !XE_TEST_ONLY(test && test->force_different_devices)) {
 		obj = dma_buf->priv;
-		if (obj->dev == dev &&
-		    !XE_TEST_ONLY(test && test->force_different_devices)) {
+		if (obj->dev == dev) {
 			/*
 			 * Importing dmabuf exported from out own gem increases
 			 * refcount on gem itself instead of f_count of dmabuf.
@@ -279,6 +279,8 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 			drm_gem_object_get(obj);
 			return obj;
 		}
+
+		foreign_bo = gem_to_xe_bo(obj);
 	}
 
 	/*
@@ -310,6 +312,9 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
 
 	get_dma_buf(dma_buf);
 	obj->import_attach = attach;
+	if (foreign_bo)
+		bo->cpu_caching = foreign_bo->cpu_caching;
+
 	return obj;
 
 out_err:
-- 
2.45.2



More information about the Intel-xe mailing list