[Intel-gfx] [PATCH 32/37] drm/i915: Exercise i915_vma_pin/i915_vma_insert
Chris Wilson
chris at chris-wilson.co.uk
Wed Jan 11 21:09:32 UTC 2017
High-level testing of the struct drm_mm by verifying our handling of
weird requests to i915_vma_pin.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_vma.c | 4 +-
drivers/gpu/drm/i915/i915_vma.h | 4 +-
drivers/gpu/drm/i915/selftests/i915_vma.c | 133 ++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
index af8738a84a85..38c5f1039569 100644
--- a/drivers/gpu/drm/i915/i915_vma.c
+++ b/drivers/gpu/drm/i915/i915_vma.c
@@ -259,8 +259,8 @@ void i915_vma_unpin_and_release(struct i915_vma **p_vma)
__i915_gem_object_release_unless_active(obj);
}
-bool
-i915_vma_misplaced(struct i915_vma *vma, u64 size, u64 alignment, u64 flags)
+bool i915_vma_misplaced(const struct i915_vma *vma,
+ u64 size, u64 alignment, u64 flags)
{
if (!drm_mm_node_allocated(&vma->node))
return false;
diff --git a/drivers/gpu/drm/i915/i915_vma.h b/drivers/gpu/drm/i915/i915_vma.h
index 47b5ceb386c4..7211c9bef637 100644
--- a/drivers/gpu/drm/i915/i915_vma.h
+++ b/drivers/gpu/drm/i915/i915_vma.h
@@ -218,8 +218,8 @@ i915_vma_compare(struct i915_vma *vma,
int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level,
u32 flags);
bool i915_gem_valid_gtt_space(struct i915_vma *vma, unsigned long cache_level);
-bool
-i915_vma_misplaced(struct i915_vma *vma, u64 size, u64 alignment, u64 flags);
+bool i915_vma_misplaced(const struct i915_vma *vma,
+ u64 size, u64 alignment, u64 flags);
void __i915_vma_set_map_and_fenceable(struct i915_vma *vma);
int __must_check i915_vma_unbind(struct i915_vma *vma);
void i915_vma_close(struct i915_vma *vma);
diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c
index ebd200245f88..d229adabc5f8 100644
--- a/drivers/gpu/drm/i915/selftests/i915_vma.c
+++ b/drivers/gpu/drm/i915/selftests/i915_vma.c
@@ -155,10 +155,143 @@ static int igt_vma_create(void *arg)
return err;
}
+struct pin_mode {
+ u64 size;
+ u64 flags;
+ bool (*assert)(const struct i915_vma *,
+ const struct pin_mode *mode,
+ int result);
+};
+
+static bool assert_pin_valid(const struct i915_vma *vma,
+ const struct pin_mode *mode,
+ int result)
+{
+ if (result)
+ return false;
+
+ if (i915_vma_misplaced(vma, mode->size, 0, mode->flags))
+ return false;
+
+ return true;
+}
+
+__maybe_unused
+static bool assert_pin_e2big(const struct i915_vma *vma,
+ const struct pin_mode *mode,
+ int result)
+{
+ return result == -E2BIG;
+}
+
+__maybe_unused
+static bool assert_pin_enospc(const struct i915_vma *vma,
+ const struct pin_mode *mode,
+ int result)
+{
+ return result == -ENOSPC;
+}
+
+__maybe_unused
+static bool assert_pin_einval(const struct i915_vma *vma,
+ const struct pin_mode *mode,
+ int result)
+{
+ return result == -EINVAL;
+}
+
+static int igt_vma_pin1(void *arg)
+{
+ struct drm_i915_private *i915 = arg;
+ const struct pin_mode modes[] = {
+ [0] = { 0, PIN_GLOBAL, assert_pin_valid },
+ [1] = { 0, PIN_GLOBAL | PIN_MAPPABLE, assert_pin_valid },
+
+ [2] = { 0, PIN_GLOBAL | PIN_OFFSET_BIAS | 4096, assert_pin_valid },
+ [3] = { 0, PIN_GLOBAL | PIN_OFFSET_BIAS | 8192, assert_pin_valid },
+ [4] = { 0, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096), assert_pin_valid },
+ [5] = { 0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096), assert_pin_valid },
+ [6] = { 0, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.base.total - 4096), assert_pin_valid },
+
+ [7] = { 0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (i915->ggtt.mappable_end - 4096), assert_pin_valid },
+ [8] = { 0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | i915->ggtt.mappable_end, assert_pin_einval },
+ [9] = { 0, PIN_GLOBAL | PIN_OFFSET_FIXED | (i915->ggtt.base.total - 4096), assert_pin_valid },
+ [10] = { 0, PIN_GLOBAL | PIN_OFFSET_FIXED | i915->ggtt.base.total, assert_pin_einval },
+ [11] = { 0, PIN_GLOBAL | PIN_OFFSET_FIXED | round_down(U64_MAX, PAGE_SIZE), assert_pin_einval },
+
+ [12] = { 4096, PIN_GLOBAL, assert_pin_valid },
+ [13] = { 8192, PIN_GLOBAL, assert_pin_valid },
+ [14] = { i915->ggtt.mappable_end - 4096, PIN_GLOBAL | PIN_MAPPABLE, assert_pin_valid },
+ [15] = { i915->ggtt.mappable_end, PIN_GLOBAL | PIN_MAPPABLE, assert_pin_valid },
+ [16] = { i915->ggtt.mappable_end + 4096, PIN_GLOBAL | PIN_MAPPABLE, assert_pin_e2big },
+ [17] = { i915->ggtt.base.total - 4096, PIN_GLOBAL, assert_pin_valid },
+ [18] = { i915->ggtt.base.total, PIN_GLOBAL, assert_pin_valid },
+ [19] = { i915->ggtt.base.total + 4096, PIN_GLOBAL, assert_pin_e2big },
+ [20] = { round_down(U64_MAX, PAGE_SIZE), PIN_GLOBAL, assert_pin_e2big },
+ [21] = { 8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_FIXED | (i915->ggtt.mappable_end - 4096), assert_pin_einval },
+ [22] = { 8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (i915->ggtt.base.total - 4096), assert_pin_einval },
+ [23] = { 8192, PIN_GLOBAL | PIN_OFFSET_FIXED | (round_down(U64_MAX, PAGE_SIZE) - 4096), assert_pin_einval },
+
+ [24] = { 8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096), assert_pin_valid },
+
+#if !IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
+ /* Misusing BIAS is a programming error (it is not controllable
+ * from userspace) so when debugging is enabled, it explodes.
+ * However, the tests are still quite interesting for checking
+ * variable start, end and size.
+ */
+ [25] = { 0, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | i915->ggtt.mappable_end, assert_pin_enospc },
+ [26] = { 0, PIN_GLOBAL | PIN_OFFSET_BIAS | i915->ggtt.base.total, assert_pin_enospc },
+ [27] = { 8192, PIN_GLOBAL | PIN_MAPPABLE | PIN_OFFSET_BIAS | (i915->ggtt.mappable_end - 4096), assert_pin_enospc },
+ [28] = { 8192, PIN_GLOBAL | PIN_OFFSET_BIAS | (i915->ggtt.base.total - 4096), assert_pin_enospc },
+#endif
+ { },
+ }, *m;
+ struct drm_i915_gem_object *obj;
+ struct i915_vma *vma;
+ int err = -EINVAL;
+
+ GEM_BUG_ON(!drm_mm_clean(&i915->ggtt.base.mm));
+
+ obj = i915_gem_object_create_internal(i915, PAGE_SIZE);
+ if (IS_ERR(obj))
+ return PTR_ERR(obj);
+
+ vma = i915_gem_obj_lookup_or_create_vma(obj, &i915->ggtt.base, NULL);
+ if (IS_ERR(vma))
+ goto err;
+
+ for (m = modes; m->assert; m++) {
+ err = i915_vma_pin(vma, m->size, 0, m->flags);
+ if (!m->assert(vma, m, err)) {
+ pr_err("%s to pin single page into GGTT with mode[%ld]: size=%llx flags=%llx, err=%d\n",
+ m->assert == assert_pin_valid ? "Failed" : "Unexpectedly succeeded",
+ m - modes, m->size, m->flags, err);
+ err = -EINVAL;
+ goto err;
+ }
+
+ if (!err) {
+ i915_vma_unpin(vma);
+ err = i915_vma_unbind(vma);
+ if (err) {
+ pr_err("Failed to unbind single page from GGTT, err=%d\n", err);
+ goto err;
+ }
+ }
+ }
+
+ err = 0;
+err:
+ i915_gem_object_put(obj);
+ return err;
+}
+
int i915_vma_mock_selftests(void)
{
static const struct i915_subtest tests[] = {
SUBTEST(igt_vma_create),
+ SUBTEST(igt_vma_pin1),
};
struct drm_i915_private *i915;
int err;
--
2.11.0
More information about the Intel-gfx
mailing list