]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915/selftests: Replace mock_file hackery with drm's true fake
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 7 Nov 2019 18:05:59 +0000 (18:05 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 7 Nov 2019 21:22:16 +0000 (21:22 +0000)
As drm now exports a method to create an anonymous struct file around a
drm_device for internal use, make use of it to avoid our horrible hacks.

Danial suggested that the mock_file_put() wrapper was suitable for
drm-core, along with the mock_drm_getfile() [and that the vestigal
mock_drm_file() in this patch should perhaps be the drm interface
itself]. However, the eventual goal is to remove the mock_drm_file() and
use the struct file and fput() directly, in this patch we take a simple
transition in that direction.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20191107180601.30815-3-chris@chris-wilson.co.uk
14 files changed:
drivers/gpu/drm/i915/Kconfig.debug
drivers/gpu/drm/i915/gem/selftests/huge_pages.c
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c
drivers/gpu/drm/i915/gem/selftests/i915_gem_object_blt.c
drivers/gpu/drm/i915/gt/selftest_context.c
drivers/gpu/drm/i915/gt/selftest_hangcheck.c
drivers/gpu/drm/i915/gt/selftest_workarounds.c
drivers/gpu/drm/i915/selftests/i915_gem.c
drivers/gpu/drm/i915/selftests/i915_gem_evict.c
drivers/gpu/drm/i915/selftests/i915_gem_gtt.c
drivers/gpu/drm/i915/selftests/i915_request.c
drivers/gpu/drm/i915/selftests/intel_memory_region.c
drivers/gpu/drm/i915/selftests/mock_drm.c
drivers/gpu/drm/i915/selftests/mock_drm.h

index 80815a5229a166949f1b54541622607720ae80e7..e28face9fd9f57ada1d94273e43460ddf0952d14 100644 (file)
@@ -29,6 +29,7 @@ config DRM_I915_DEBUG
        select X86_MSR # used by igt/pm_rpm
        select DRM_VGEM # used by igt/prime_vgem (dmabuf interop checks)
        select DRM_DEBUG_MM if DRM=y
+       select DRM_EXPORT_FOR_TESTS if m
        select DRM_DEBUG_SELFTEST
        select DMABUF_SELFTESTS
        select SW_SYNC # signaling validation framework (igt/syncobj*)
@@ -152,6 +153,7 @@ config DRM_I915_SELFTEST
        bool "Enable selftests upon driver load"
        depends on DRM_I915
        default n
+       select DRM_EXPORT_FOR_TESTS if m
        select FAULT_INJECTION
        select PRIME_NUMBERS
        help
index 5c9583349077f5d2fca53aa76f8cb8accaf05f21..2310ed9b8f89597b18198811a97974e6a7908968 100644 (file)
@@ -1944,6 +1944,6 @@ int i915_gem_huge_page_live_selftests(struct drm_i915_private *i915)
        err = i915_subtests(tests, ctx);
 
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
index 62fabc023a83e41720fb8b205ec5d7376fb106d9..47890c92534ca663d220082ff5e4edad8e4fba6c 100644 (file)
@@ -149,7 +149,7 @@ static int live_nop_switch(void *arg)
        }
 
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -377,7 +377,7 @@ out:
        }
        kfree(data);
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -716,7 +716,7 @@ out_file:
                if (igt_live_test_end(&t))
                        err = -EIO;
 
-               mock_file_free(i915, file);
+               mock_file_put(file);
                if (err)
                        return err;
 
@@ -854,7 +854,7 @@ out_test:
        if (igt_live_test_end(&t))
                err = -EIO;
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -1426,7 +1426,7 @@ out_file:
        if (igt_live_test_end(&t))
                err = -EIO;
 
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -1750,7 +1750,7 @@ static int igt_vm_isolation(void *arg)
 out_file:
        if (igt_live_test_end(&t))
                err = -EIO;
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
index e8132aca0bb630a57b2f5d0f365f2175184d4729..d9fdfddb7091678975d1ed22aa3cc3c01cfad288 100644 (file)
@@ -301,7 +301,7 @@ err_flush:
 
        intel_context_put(ce);
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -432,7 +432,7 @@ err_flush:
 
        intel_context_put(ce);
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
index bc720defc6b8bfa0971b53799bc344f366a5bba4..a5688f7d9073b0b7ed80b06da9447f2be5711e29 100644 (file)
@@ -313,7 +313,7 @@ static int live_active_context(void *arg)
        }
 
 out_file:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -423,7 +423,7 @@ static int live_remote_context(void *arg)
        }
 
 out_file:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        return err;
 }
 
index 85e9ccf5c30413c27be043284f10be1ad9363e43..cdaaee4432b2a64bd3dc0928cda058b4109aa2a7 100644 (file)
@@ -439,7 +439,7 @@ static int igt_reset_nop(void *arg)
 
        err = igt_flush_test(gt->i915);
 out:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        if (intel_gt_is_wedged(gt))
                err = -EIO;
        return err;
@@ -535,7 +535,7 @@ static int igt_reset_nop_engine(void *arg)
 
        err = igt_flush_test(gt->i915);
 out:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        if (intel_gt_is_wedged(gt))
                err = -EIO;
        return err;
@@ -752,7 +752,7 @@ static int active_engine(void *data)
        }
 
 err_file:
-       mock_file_free(engine->i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -1325,7 +1325,7 @@ static int igt_reset_evict_ppgtt(void *arg)
        i915_vm_put(vm);
 
 out:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        return err;
 }
 
index abce6e4ec9c06d403415f370db0335ebce454ba8..5c69ec5c5ef940ba25c3727b97e6d6349f3a6720 100644 (file)
@@ -739,7 +739,7 @@ static int live_dirty_whitelist(void *arg)
        }
 
 out_file:
-       mock_file_free(gt->i915, file);
+       mock_file_put(file);
        return err;
 }
 
index d83f6bf6d9d4f561c815cfbf22694cb22f0c1a3b..aa6282adfd0948cb5c7a87e5a7ff263184e502cc 100644 (file)
@@ -163,7 +163,7 @@ static int igt_gem_suspend(void *arg)
 
        err = switch_to_context(ctx);
 out:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -198,7 +198,7 @@ static int igt_gem_hibernate(void *arg)
 
        err = switch_to_context(ctx);
 out:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
index 42e948144f1b428213fb5cff8cec2d37ff1fa1e9..41092dcea5b1c97e742159e9b99c965f4ac2a499 100644 (file)
@@ -515,7 +515,7 @@ static int igt_evict_contexts(void *arg)
                pr_info("Submitted %lu contexts/requests on %s\n",
                        count, engine->name);
 
-               mock_file_free(i915, file);
+               mock_file_put(file);
                if (err)
                        break;
        }
index 3f7e80fb3bbd1d0e49105990b7c0d924f5c22421..c3e0d63c4d0c55cb8f90af99453f69ba42e74c36 100644 (file)
@@ -1026,7 +1026,7 @@ static int exercise_ppgtt(struct drm_i915_private *dev_priv,
        i915_vm_put(&ppgtt->vm);
 
 out_free:
-       mock_file_free(dev_priv, file);
+       mock_file_put(file);
        return err;
 }
 
@@ -2022,7 +2022,7 @@ out_put_bbe:
 out_vm:
        i915_vm_put(vm);
 out_unlock:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
index 9e6d3159cd80a945ca149398b33b9372a7eb9db9..7c56ee38cc5bee76b07337720e546aa00d145b16 100644 (file)
@@ -1430,7 +1430,7 @@ out_threads:
 out_smoke:
        kfree(smoke);
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
 out_rpm:
        intel_runtime_pm_put(&i915->runtime_pm, wakeref);
 
index 95d609abd39b70da1954da1db92e2bad5c72aa4e..f8497ad90f53744c21fd0095b91d6e4aa69f3eef 100644 (file)
@@ -439,7 +439,7 @@ static int igt_lmem_write_gpu(void *arg)
 out_put:
        i915_gem_object_put(obj);
 out_file:
-       mock_file_free(i915, file);
+       mock_file_put(file);
        return err;
 }
 
index 09c7041534568f0193f257a9251c155731c02bcd..c100c3efe2394fddfaa2f4446c73c6e92be2e742 100644 (file)
  *
  */
 
+#include <drm/drm_file.h>
+
 #include "mock_drm.h"
 
 struct drm_file *mock_file(struct drm_i915_private *i915)
 {
-       struct file *filp;
-       struct inode *inode;
-       struct drm_file *file;
-       int err;
-
-       inode = kzalloc(sizeof(*inode), GFP_KERNEL);
-       if (!inode) {
-               err = -ENOMEM;
-               goto err;
-       }
-
-       inode->i_rdev = i915->drm.primary->index;
-
-       filp = kzalloc(sizeof(*filp), GFP_KERNEL);
-       if (!filp) {
-               err = -ENOMEM;
-               goto err_inode;
-       }
-
-       err = drm_open(inode, filp);
-       if (err)
-               goto err_filp;
+       struct file *file;
 
-       file = filp->private_data;
-       memset(&file->filp, POISON_INUSE, sizeof(file->filp));
-       file->authenticated = true;
-
-       kfree(filp);
-       kfree(inode);
-       return file;
-
-err_filp:
-       kfree(filp);
-err_inode:
-       kfree(inode);
-err:
-       return ERR_PTR(err);
-}
-
-void mock_file_free(struct drm_i915_private *i915, struct drm_file *file)
-{
-       struct file filp = { .private_data = file };
+       file = mock_drm_getfile(i915->drm.primary, O_RDWR);
+       if (IS_ERR(file))
+               return ERR_CAST(file);
 
-       drm_release(NULL, &filp);
+       return file->private_data;
 }
index b39beee9f8f6763e9fa64c9ddcd775400a9deb2b..dc4190bd3f5ae42061919b77e22ad174e73829de 100644 (file)
 #ifndef __MOCK_DRM_H
 #define __MOCK_DRM_H
 
+struct drm_file;
+struct drm_i915_private;
+
 struct drm_file *mock_file(struct drm_i915_private *i915);
-void mock_file_free(struct drm_i915_private *i915, struct drm_file *file);
+static inline void mock_file_put(struct drm_file *file)
+{
+       fput(file->filp);
+}
 
 #endif /* !__MOCK_DRM_H */