drm/i915/ttm: add unmap_virtual callback
authorMatthew Auld <matthew.auld@intel.com>
Thu, 6 Jan 2022 17:49:09 +0000 (17:49 +0000)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Mon, 10 Jan 2022 13:55:07 +0000 (13:55 +0000)
Ensure we call ttm_bo_unmap_virtual when releasing the pages.
Importantly this should now handle the ttm swapping case, and all other
places that already call into i915_ttm_move_notify().

v2: fix up the selftest

Fixes: cf3e3e86d779 ("drm/i915: Use ttm mmap handling for ttm bo's.")
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220106174910.280616-3-matthew.auld@intel.com
(cherry picked from commit 903e0387270eef14a711c0feb23b7bf62d2480df)
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
drivers/gpu/drm/i915/gem/i915_gem_mman.c
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
drivers/gpu/drm/i915/gem/i915_gem_ttm.c
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c

index aaf970c37aa2b240d2510490e9ad09b10e74aa12..1478c02a82cbef49bbbe02163f3193b04c8920dc 100644 (file)
@@ -538,6 +538,9 @@ void i915_gem_object_release_mmap_offset(struct drm_i915_gem_object *obj)
 {
        struct i915_mmap_offset *mmo, *mn;
 
+       if (obj->ops->unmap_virtual)
+               obj->ops->unmap_virtual(obj);
+
        spin_lock(&obj->mmo.lock);
        rbtree_postorder_for_each_entry_safe(mmo, mn,
                                             &obj->mmo.offsets, offset) {
index f9f7e44099fe3c622a7948d9f99dc8309ff54442..4b4829eb16c2d3642a536e90c88961e1a1d04361 100644 (file)
@@ -67,6 +67,7 @@ struct drm_i915_gem_object_ops {
        int (*pwrite)(struct drm_i915_gem_object *obj,
                      const struct drm_i915_gem_pwrite *arg);
        u64 (*mmap_offset)(struct drm_i915_gem_object *obj);
+       void (*unmap_virtual)(struct drm_i915_gem_object *obj);
 
        int (*dmabuf_export)(struct drm_i915_gem_object *obj);
 
index 8d61d4538a6439acaf6aa90f64928757160ebc0c..1530d9f0bc8177ebc0610828d38a6b725a66a6b5 100644 (file)
@@ -950,6 +950,11 @@ static u64 i915_ttm_mmap_offset(struct drm_i915_gem_object *obj)
        return drm_vma_node_offset_addr(&obj->base.vma_node);
 }
 
+static void i915_ttm_unmap_virtual(struct drm_i915_gem_object *obj)
+{
+       ttm_bo_unmap_virtual(i915_gem_to_ttm(obj));
+}
+
 static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = {
        .name = "i915_gem_object_ttm",
        .flags = I915_GEM_OBJECT_IS_SHRINKABLE |
@@ -965,6 +970,7 @@ static const struct drm_i915_gem_object_ops i915_gem_ttm_obj_ops = {
        .migrate = i915_ttm_migrate,
 
        .mmap_offset = i915_ttm_mmap_offset,
+       .unmap_virtual = i915_ttm_unmap_virtual,
        .mmap_ops = &vm_ops_ttm,
 };
 
index 743e6ab2c40ba4baf103b4883edcbbf5c33135b4..c6291429b00cf1157b259ce0587149549283c017 100644 (file)
@@ -1368,20 +1368,10 @@ static int __igt_mmap_revoke(struct drm_i915_private *i915,
                }
        }
 
-       if (!obj->ops->mmap_ops) {
-               err = check_absent(addr, obj->base.size);
-               if (err) {
-                       pr_err("%s: was not absent\n", obj->mm.region->name);
-                       goto out_unmap;
-               }
-       } else {
-               /* ttm allows access to evicted regions by design */
-
-               err = check_present(addr, obj->base.size);
-               if (err) {
-                       pr_err("%s: was not present\n", obj->mm.region->name);
-                       goto out_unmap;
-               }
+       err = check_absent(addr, obj->base.size);
+       if (err) {
+               pr_err("%s: was not absent\n", obj->mm.region->name);
+               goto out_unmap;
        }
 
 out_unmap: