Commit 9771d5f7 authored by Abdiel Janulgue's avatar Abdiel Janulgue Committed by Chris Wilson

drm/i915/selftests: Extend fault handler selftests to all memory regions

Instead of testing individually our new fault handlers, iterate over all
memory regions and test all from one interface.
Signed-off-by: default avatarAbdiel Janulgue <abdiel.janulgue@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20200103204137.2131004-2-chris@chris-wilson.co.uk
parent 4e598fad
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "gt/intel_engine_pm.h" #include "gt/intel_engine_pm.h"
#include "gt/intel_gt.h" #include "gt/intel_gt.h"
#include "gt/intel_gt_pm.h" #include "gt/intel_gt_pm.h"
#include "gem/i915_gem_region.h"
#include "huge_gem_object.h" #include "huge_gem_object.h"
#include "i915_selftest.h" #include "i915_selftest.h"
#include "selftests/i915_random.h" #include "selftests/i915_random.h"
...@@ -725,114 +726,230 @@ static int igt_mmap_offset_exhaustion(void *arg) ...@@ -725,114 +726,230 @@ static int igt_mmap_offset_exhaustion(void *arg)
goto out; goto out;
} }
#define expand32(x) (((x) << 0) | ((x) << 8) | ((x) << 16) | ((x) << 24)) static int gtt_set(struct drm_i915_gem_object *obj)
static int igt_mmap(void *arg, enum i915_mmap_type type)
{ {
struct drm_i915_private *i915 = arg; struct i915_vma *vma;
struct drm_i915_gem_object *obj; void __iomem *map;
struct i915_mmap_offset *mmo; int err = 0;
struct vm_area_struct *area;
unsigned long addr;
void *vaddr;
int err = 0, i;
if (!i915_ggtt_has_aperture(&i915->ggtt)) vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
return 0; if (IS_ERR(vma))
return PTR_ERR(vma);
obj = i915_gem_object_create_internal(i915, PAGE_SIZE); intel_gt_pm_get(vma->vm->gt);
if (IS_ERR(obj)) map = i915_vma_pin_iomap(vma);
return PTR_ERR(obj); i915_vma_unpin(vma);
if (IS_ERR(map)) {
err = PTR_ERR(map);
goto out;
}
memset_io(map, POISON_INUSE, obj->base.size);
i915_vma_unpin_iomap(vma);
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); out:
if (IS_ERR(vaddr)) { intel_gt_pm_put(vma->vm->gt);
err = PTR_ERR(vaddr); return err;
}
static int gtt_check(struct drm_i915_gem_object *obj)
{
struct i915_vma *vma;
void __iomem *map;
int err = 0;
vma = i915_gem_object_ggtt_pin(obj, NULL, 0, 0, PIN_MAPPABLE);
if (IS_ERR(vma))
return PTR_ERR(vma);
intel_gt_pm_get(vma->vm->gt);
map = i915_vma_pin_iomap(vma);
i915_vma_unpin(vma);
if (IS_ERR(map)) {
err = PTR_ERR(map);
goto out; goto out;
} }
memset(vaddr, POISON_INUSE, PAGE_SIZE);
if (memchr_inv((void __force *)map, POISON_FREE, obj->base.size)) {
pr_err("%s: Write via mmap did not land in backing store (GTT)\n",
obj->mm.region->name);
err = -EINVAL;
}
i915_vma_unpin_iomap(vma);
out:
intel_gt_pm_put(vma->vm->gt);
return err;
}
static int wc_set(struct drm_i915_gem_object *obj)
{
void *vaddr;
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WC);
if (IS_ERR(vaddr))
return PTR_ERR(vaddr);
memset(vaddr, POISON_INUSE, obj->base.size);
i915_gem_object_flush_map(obj); i915_gem_object_flush_map(obj);
i915_gem_object_unpin_map(obj); i915_gem_object_unpin_map(obj);
mmo = mmap_offset_attach(obj, type, NULL); return 0;
if (IS_ERR(mmo)) { }
err = PTR_ERR(mmo);
goto out; static int wc_check(struct drm_i915_gem_object *obj)
{
void *vaddr;
int err = 0;
vaddr = i915_gem_object_pin_map(obj, I915_MAP_WC);
if (IS_ERR(vaddr))
return PTR_ERR(vaddr);
if (memchr_inv(vaddr, POISON_FREE, obj->base.size)) {
pr_err("%s: Write via mmap did not land in backing store (WC)\n",
obj->mm.region->name);
err = -EINVAL;
} }
i915_gem_object_unpin_map(obj);
return err;
}
static bool can_mmap(struct drm_i915_gem_object *obj, enum i915_mmap_type type)
{
if (type == I915_MMAP_TYPE_GTT &&
!i915_ggtt_has_aperture(&to_i915(obj->base.dev)->ggtt))
return false;
if (type != I915_MMAP_TYPE_GTT &&
!i915_gem_object_type_has(obj,
I915_GEM_OBJECT_HAS_STRUCT_PAGE |
I915_GEM_OBJECT_HAS_IOMEM))
return false;
return true;
}
#define expand32(x) (((x) << 0) | ((x) << 8) | ((x) << 16) | ((x) << 24))
static int __igt_mmap(struct drm_i915_private *i915,
struct drm_i915_gem_object *obj,
enum i915_mmap_type type)
{
struct i915_mmap_offset *mmo;
struct vm_area_struct *area;
unsigned long addr;
int err, i;
if (!can_mmap(obj, type))
return 0;
err = wc_set(obj);
if (err == -ENXIO)
err = gtt_set(obj);
if (err)
return err;
mmo = mmap_offset_attach(obj, type, NULL);
if (IS_ERR(mmo))
return PTR_ERR(mmo);
addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED); addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED);
if (IS_ERR_VALUE(addr)) { if (IS_ERR_VALUE(addr))
err = addr; return addr;
goto out;
}
pr_debug("igt_mmap() @ %lx\n", addr); pr_debug("igt_mmap(%s, %d) @ %lx\n", obj->mm.region->name, type, addr);
area = find_vma(current->mm, addr); area = find_vma(current->mm, addr);
if (!area) { if (!area) {
pr_err("Did not create a vm_area_struct for the mmap\n"); pr_err("%s: Did not create a vm_area_struct for the mmap\n",
obj->mm.region->name);
err = -EINVAL; err = -EINVAL;
goto out_unmap; goto out_unmap;
} }
if (area->vm_private_data != mmo) { if (area->vm_private_data != mmo) {
pr_err("vm_area_struct did not point back to our mmap_offset object!\n"); pr_err("%s: vm_area_struct did not point back to our mmap_offset object!\n",
obj->mm.region->name);
err = -EINVAL; err = -EINVAL;
goto out_unmap; goto out_unmap;
} }
for (i = 0; i < PAGE_SIZE / sizeof(u32); i++) { for (i = 0; i < obj->base.size / sizeof(u32); i++) {
u32 __user *ux = u64_to_user_ptr((u64)(addr + i * sizeof(*ux))); u32 __user *ux = u64_to_user_ptr((u64)(addr + i * sizeof(*ux)));
u32 x; u32 x;
if (get_user(x, ux)) { if (get_user(x, ux)) {
pr_err("Unable to read from mmap, offset:%zd\n", pr_err("%s: Unable to read from mmap, offset:%zd\n",
i * sizeof(x)); obj->mm.region->name, i * sizeof(x));
err = -EFAULT; err = -EFAULT;
break; goto out_unmap;
} }
if (x != expand32(POISON_INUSE)) { if (x != expand32(POISON_INUSE)) {
pr_err("Read incorrect value from mmap, offset:%zd, found:%x, expected:%x\n", pr_err("%s: Read incorrect value from mmap, offset:%zd, found:%x, expected:%x\n",
obj->mm.region->name,
i * sizeof(x), x, expand32(POISON_INUSE)); i * sizeof(x), x, expand32(POISON_INUSE));
err = -EINVAL; err = -EINVAL;
break; goto out_unmap;
} }
x = expand32(POISON_FREE); x = expand32(POISON_FREE);
if (put_user(x, ux)) { if (put_user(x, ux)) {
pr_err("Unable to write to mmap, offset:%zd\n", pr_err("%s: Unable to write to mmap, offset:%zd\n",
i * sizeof(x)); obj->mm.region->name, i * sizeof(x));
err = -EFAULT; err = -EFAULT;
break; goto out_unmap;
} }
} }
out_unmap: if (type == I915_MMAP_TYPE_GTT)
vm_munmap(addr, PAGE_SIZE); intel_gt_flush_ggtt_writes(&i915->gt);
vaddr = i915_gem_object_pin_map(obj, I915_MAP_FORCE_WC);
if (IS_ERR(vaddr)) {
err = PTR_ERR(vaddr);
goto out;
}
if (err == 0 && memchr_inv(vaddr, POISON_FREE, PAGE_SIZE)) {
pr_err("Write via mmap did not land in backing store\n");
err = -EINVAL;
}
i915_gem_object_unpin_map(obj);
out: err = wc_check(obj);
i915_gem_object_put(obj); if (err == -ENXIO)
err = gtt_check(obj);
out_unmap:
vm_munmap(addr, obj->base.size);
return err; return err;
} }
static int igt_mmap_gtt(void *arg) static int igt_mmap(void *arg)
{ {
return igt_mmap(arg, I915_MMAP_TYPE_GTT); struct drm_i915_private *i915 = arg;
} struct intel_memory_region *mr;
enum intel_region_id id;
for_each_memory_region(mr, i915, id) {
unsigned long sizes[] = {
PAGE_SIZE,
mr->min_page_size,
SZ_4M,
};
int i;
static int igt_mmap_cpu(void *arg) for (i = 0; i < ARRAY_SIZE(sizes); i++) {
{ struct drm_i915_gem_object *obj;
return igt_mmap(arg, I915_MMAP_TYPE_WC); int err;
obj = i915_gem_object_create_region(mr, sizes[i], 0);
if (obj == ERR_PTR(-ENODEV))
continue;
if (IS_ERR(obj))
return PTR_ERR(obj);
err = __igt_mmap(i915, obj, I915_MMAP_TYPE_GTT);
if (err == 0)
err = __igt_mmap(i915, obj, I915_MMAP_TYPE_WC);
i915_gem_object_put(obj);
if (err)
return err;
}
}
return 0;
} }
static int check_present_pte(pte_t *pte, unsigned long addr, void *data) static int check_present_pte(pte_t *pte, unsigned long addr, void *data)
...@@ -887,32 +1004,24 @@ static int prefault_range(u64 start, u64 len) ...@@ -887,32 +1004,24 @@ static int prefault_range(u64 start, u64 len)
return __get_user(c, end - 1); return __get_user(c, end - 1);
} }
static int igt_mmap_revoke(void *arg, enum i915_mmap_type type) static int __igt_mmap_revoke(struct drm_i915_private *i915,
struct drm_i915_gem_object *obj,
enum i915_mmap_type type)
{ {
struct drm_i915_private *i915 = arg;
struct drm_i915_gem_object *obj;
struct i915_mmap_offset *mmo; struct i915_mmap_offset *mmo;
unsigned long addr; unsigned long addr;
int err; int err;
if (!i915_ggtt_has_aperture(&i915->ggtt)) if (!can_mmap(obj, type))
return 0; return 0;
obj = i915_gem_object_create_internal(i915, SZ_4M);
if (IS_ERR(obj))
return PTR_ERR(obj);
mmo = mmap_offset_attach(obj, type, NULL); mmo = mmap_offset_attach(obj, type, NULL);
if (IS_ERR(mmo)) { if (IS_ERR(mmo))
err = PTR_ERR(mmo); return PTR_ERR(mmo);
goto out;
}
addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED); addr = igt_mmap_node(i915, &mmo->vma_node, 0, PROT_WRITE, MAP_SHARED);
if (IS_ERR_VALUE(addr)) { if (IS_ERR_VALUE(addr))
err = addr; return addr;
goto out;
}
err = prefault_range(addr, obj->base.size); err = prefault_range(addr, obj->base.size);
if (err) if (err)
...@@ -922,8 +1031,10 @@ static int igt_mmap_revoke(void *arg, enum i915_mmap_type type) ...@@ -922,8 +1031,10 @@ static int igt_mmap_revoke(void *arg, enum i915_mmap_type type)
!atomic_read(&obj->bind_count)); !atomic_read(&obj->bind_count));
err = check_present(addr, obj->base.size); err = check_present(addr, obj->base.size);
if (err) if (err) {
pr_err("%s: was not present\n", obj->mm.region->name);
goto out_unmap; goto out_unmap;
}
/* /*
* After unbinding the object from the GGTT, its address may be reused * After unbinding the object from the GGTT, its address may be reused
...@@ -947,24 +1058,43 @@ static int igt_mmap_revoke(void *arg, enum i915_mmap_type type) ...@@ -947,24 +1058,43 @@ static int igt_mmap_revoke(void *arg, enum i915_mmap_type type)
} }
err = check_absent(addr, obj->base.size); err = check_absent(addr, obj->base.size);
if (err) if (err) {
pr_err("%s: was not absent\n", obj->mm.region->name);
goto out_unmap; goto out_unmap;
}
out_unmap: out_unmap:
vm_munmap(addr, obj->base.size); vm_munmap(addr, obj->base.size);
out:
i915_gem_object_put(obj);
return err; return err;
} }
static int igt_mmap_gtt_revoke(void *arg) static int igt_mmap_revoke(void *arg)
{ {
return igt_mmap_revoke(arg, I915_MMAP_TYPE_GTT); struct drm_i915_private *i915 = arg;
} struct intel_memory_region *mr;
enum intel_region_id id;
static int igt_mmap_cpu_revoke(void *arg) for_each_memory_region(mr, i915, id) {
{ struct drm_i915_gem_object *obj;
return igt_mmap_revoke(arg, I915_MMAP_TYPE_WC); int err;
obj = i915_gem_object_create_region(mr, PAGE_SIZE, 0);
if (obj == ERR_PTR(-ENODEV))
continue;
if (IS_ERR(obj))
return PTR_ERR(obj);
err = __igt_mmap_revoke(i915, obj, I915_MMAP_TYPE_GTT);
if (err == 0)
err = __igt_mmap_revoke(i915, obj, I915_MMAP_TYPE_WC);
i915_gem_object_put(obj);
if (err)
return err;
}
return 0;
} }
int i915_gem_mman_live_selftests(struct drm_i915_private *i915) int i915_gem_mman_live_selftests(struct drm_i915_private *i915)
...@@ -973,10 +1103,8 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915) ...@@ -973,10 +1103,8 @@ int i915_gem_mman_live_selftests(struct drm_i915_private *i915)
SUBTEST(igt_partial_tiling), SUBTEST(igt_partial_tiling),
SUBTEST(igt_smoke_tiling), SUBTEST(igt_smoke_tiling),
SUBTEST(igt_mmap_offset_exhaustion), SUBTEST(igt_mmap_offset_exhaustion),
SUBTEST(igt_mmap_gtt), SUBTEST(igt_mmap),
SUBTEST(igt_mmap_cpu), SUBTEST(igt_mmap_revoke),
SUBTEST(igt_mmap_gtt_revoke),
SUBTEST(igt_mmap_cpu_revoke),
}; };
return i915_subtests(tests, i915); return i915_subtests(tests, i915);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment