@@ -6,6 +6,7 @@
#include "i915_drv.h"
#include "i915_selftest.h"
+#include "gt/intel_migrate.h"
#include "mock_dmabuf.h"
#include "selftests/mock_gem_device.h"
@@ -148,13 +149,15 @@ static int igt_dmabuf_import_same_driver(struct drm_i915_private *i915,
struct drm_gem_object *import;
struct dma_buf *dmabuf;
struct dma_buf_attachment *import_attach;
+ struct i915_request *rq;
struct sg_table *st;
+ u32 *vaddr;
long timeout;
- int err;
+ int err, i;
force_different_devices = true;
- obj = __i915_gem_object_create_user(i915, PAGE_SIZE,
+ obj = __i915_gem_object_create_user(i915, SZ_8M,
regions, num_regions);
if (IS_ERR(obj)) {
pr_err("__i915_gem_object_create_user failed with err=%ld\n",
@@ -194,6 +197,19 @@ static int igt_dmabuf_import_same_driver(struct drm_i915_private *i915,
goto out_import;
}
+ err = intel_context_migrate_clear(to_gt(i915)->migrate.context, NULL,
+ import_obj->mm.pages->sgl,
+ import_obj->cache_level,
+ false,
+ 0xdeadbeaf, &rq);
+ if (rq) {
+ err = dma_resv_reserve_fences(obj->base.resv, 1);
+ if (!err)
+ dma_resv_add_fence(obj->base.resv, &rq->fence,
+ DMA_RESV_USAGE_KERNEL);
+ i915_request_put(rq);
+ }
+
/*
* If the exported object is not in system memory, something
* weird is going on. TODO: When p2p is supported, this is no
@@ -206,6 +222,23 @@ static int igt_dmabuf_import_same_driver(struct drm_i915_private *i915,
i915_gem_object_unlock(import_obj);
+ if (err)
+ goto out_import;
+
+ vaddr = i915_gem_object_pin_map_unlocked(obj, I915_MAP_WB);
+ if (IS_ERR(vaddr)) {
+ err = PTR_ERR(vaddr);
+ goto out_import;
+ }
+
+ for (i = 0; i < obj->base.size / sizeof(u32); i++) {
+ if (vaddr[i] != 0xdeadbeaf) {
+ pr_err("Data mismatch [%d]=%u\n", i, vaddr[i]);
+ err = -EINVAL;
+ goto out_import;
+ }
+ }
+
/* Now try a fake an importer */
import_attach = dma_buf_attach(dmabuf, obj->base.dev->dev);
if (IS_ERR(import_attach)) {
Using PAGE_SIZE here potentially hides issues so bump that to something larger. This should also make it possible for iommu to coalesce entries for us. With that in place verify we can write from the GPU using the importers sg_table, followed by checking that our writes match when read from the CPU side. References: https://gitlab.freedesktop.org/drm/intel/-/issues/7306 Signed-off-by: Matthew Auld <matthew.auld@intel.com> Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> --- .../drm/i915/gem/selftests/i915_gem_dmabuf.c | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-)