UAPI Changes: - GuC hwconfig support and query (John Harrison, Rodrigo Vivi, Tvrtko Ursulin) - Sysfs support for multi-tile devices (Andi Shyti, Sujaritha Sundaresan) - Per client GPU utilisation via fdinfo (Tvrtko Ursulin, Ashutosh Dixit) - Add DRM_I915_QUERY_GEOMETRY_SUBSLICES (Matt Atwood) Cross-subsystem Changes: - Add GSC as a MEI auxiliary device (Tomas Winkler, Alexander Usyskin) Core Changes: - Document fdinfo format specification (Tvrtko Ursulin) Driver Changes: - Fix prime_mmap to work when using LMEM (Gwan-gyeong Mun) - Fix vm open count and remove vma refcount (Thomas Hellström) - Fixup setting screen_size (Matthew Auld) - Opportunistically apply ALLOC_CONTIGIOUS (Matthew Auld) - Limit where we apply TTM_PL_FLAG_CONTIGUOUS (Matthew Auld) - Drop aux table invalidation on FlatCCS platforms (Matt Roper) - Add missing boundary check in vm_access (Mastan Katragadda) - Update topology dumps for Xe_HP (Matt Roper) - Add support for steered register writes (Matt Roper) - Add steering info to GuC register save/restore list (Daniele Ceraolo Spurio) - Small PCI BAR enabling (Matthew Auld, Akeem G Abodunrin, CQ Tang) - Add preemption changes for Wa_14015141709 (Akeem G Abodunrin) - Add logical mapping for video decode engines (Matthew Brost) - Don't evict unmappable VMAs when pinning with PIN_MAPPABLE (v2) (Vivek Kasireddy) - GuC error capture support (Alan Previn, Daniele Ceraolo Spurio) - avoid concurrent writes to aux_inv (Fei Yang) - Add Wa_22014226127 (José Roberto de Souza) - Sunset igpu legacy mmap support based on GRAPHICS_VER_FULL (Matt Roper) - Evict and restore of compressed objects (Ramalingam C) - Update to GuC version 70.1.1 (John Harrison) - Add Wa_22011802037 force cs halt (Tilak Tangudu) - Enable Wa_22011802037 for gen12 GuC based platforms (Umesh Nerlige Ramappa) - GuC based workarounds for DG2 (Vinay Belgaumkar, John Harrison, Matthew Brost, José Roberto de Souza) - consider min_page_size when migrating (Matthew Auld) - Prep work for next GuC firmware release (John Harrison) - Support platforms with CCS engines but no RCS (Matt Roper, Stuart Summers) - Don't overallocate subslice storage (Matt Roper) - Reduce stack usage in debugfs due to SSEU (John Harrison) - Report steering details in debugfs (Matt Roper) - Refactor some x86-ism out to prepare for non-x86 builds (Michael Cheng) - add lmem_size modparam (CQ Tang) - Refactor for non-x86 driver builds (Casey Bowman) - Centralize computation of freq caps (Ashutosh Dixit) - Update dma_buf_ops.unmap_dma_buf callback to use drm_gem_unmap_dma_buf() (Gwan-gyeong Mun) - Limit the async bind to bind_async_flags (Matthew Auld) - Stop checking for NULL vma->obj (Matthew Auld) - Reduce overzealous alignment constraints for GGTT (Matthew Auld) - Remove GEN12_SFC_DONE_MAX from register defs header (Matt Roper) - Fix renamed struct field (Lucas De Marchi) - Do not return '0' if there is nothing to return (Andi Shyti) - fix i915_reg_t initialization (Jani Nikula) - move the migration sanity check (Matthew Auld) - handle more rounding in selftests (Matthew Auld) - Perf and i915 query kerneldoc updates (Matt Roper) - Use i915_probe_error instead of drm_err (Vinay Belgaumkar) - sanity check object size in the buddy allocator (Matthew Auld) - fixup selftests min_alignment usage (Matthew Auld) - tweak selftests misaligned_case (Matthew Auld) Signed-off-by: Dave Airlie <airlied@redhat.com> # Conflicts: # drivers/gpu/drm/i915/i915_vma.c From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/Ymkfy8FjsG2JrodK@tursulin-mobl2
432 lines
9.8 KiB
C
432 lines
9.8 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2020-2021 Intel Corporation
|
|
*/
|
|
|
|
#include "gt/intel_migrate.h"
|
|
#include "gt/intel_gpu_commands.h"
|
|
#include "gem/i915_gem_ttm_move.h"
|
|
|
|
#include "i915_deps.h"
|
|
|
|
#include "selftests/igt_spinner.h"
|
|
|
|
static int igt_fill_check_buffer(struct drm_i915_gem_object *obj,
|
|
bool fill)
|
|
{
|
|
struct drm_i915_private *i915 = to_i915(obj->base.dev);
|
|
unsigned int i, count = obj->base.size / sizeof(u32);
|
|
enum i915_map_type map_type =
|
|
i915_coherent_map_type(i915, obj, false);
|
|
u32 *cur;
|
|
int err = 0;
|
|
|
|
assert_object_held(obj);
|
|
cur = i915_gem_object_pin_map(obj, map_type);
|
|
if (IS_ERR(cur))
|
|
return PTR_ERR(cur);
|
|
|
|
if (fill)
|
|
for (i = 0; i < count; ++i)
|
|
*cur++ = i;
|
|
else
|
|
for (i = 0; i < count; ++i)
|
|
if (*cur++ != i) {
|
|
pr_err("Object content mismatch at location %d of %d\n", i, count);
|
|
err = -EINVAL;
|
|
break;
|
|
}
|
|
|
|
i915_gem_object_unpin_map(obj);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int igt_create_migrate(struct intel_gt *gt, enum intel_region_id src,
|
|
enum intel_region_id dst)
|
|
{
|
|
struct drm_i915_private *i915 = gt->i915;
|
|
struct intel_memory_region *src_mr = i915->mm.regions[src];
|
|
struct intel_memory_region *dst_mr = i915->mm.regions[dst];
|
|
struct drm_i915_gem_object *obj;
|
|
struct i915_gem_ww_ctx ww;
|
|
int err = 0;
|
|
|
|
GEM_BUG_ON(!src_mr);
|
|
GEM_BUG_ON(!dst_mr);
|
|
|
|
/* Switch object backing-store on create */
|
|
obj = i915_gem_object_create_region(src_mr, dst_mr->min_page_size, 0, 0);
|
|
if (IS_ERR(obj))
|
|
return PTR_ERR(obj);
|
|
|
|
for_i915_gem_ww(&ww, err, true) {
|
|
err = i915_gem_object_lock(obj, &ww);
|
|
if (err)
|
|
continue;
|
|
|
|
err = igt_fill_check_buffer(obj, true);
|
|
if (err)
|
|
continue;
|
|
|
|
err = i915_gem_object_migrate(obj, &ww, dst);
|
|
if (err)
|
|
continue;
|
|
|
|
err = i915_gem_object_pin_pages(obj);
|
|
if (err)
|
|
continue;
|
|
|
|
if (i915_gem_object_can_migrate(obj, src))
|
|
err = -EINVAL;
|
|
|
|
i915_gem_object_unpin_pages(obj);
|
|
err = i915_gem_object_wait_migration(obj, true);
|
|
if (err)
|
|
continue;
|
|
|
|
err = igt_fill_check_buffer(obj, false);
|
|
}
|
|
i915_gem_object_put(obj);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int igt_smem_create_migrate(void *arg)
|
|
{
|
|
return igt_create_migrate(arg, INTEL_REGION_LMEM_0, INTEL_REGION_SMEM);
|
|
}
|
|
|
|
static int igt_lmem_create_migrate(void *arg)
|
|
{
|
|
return igt_create_migrate(arg, INTEL_REGION_SMEM, INTEL_REGION_LMEM_0);
|
|
}
|
|
|
|
static int igt_same_create_migrate(void *arg)
|
|
{
|
|
return igt_create_migrate(arg, INTEL_REGION_LMEM_0, INTEL_REGION_LMEM_0);
|
|
}
|
|
|
|
static int lmem_pages_migrate_one(struct i915_gem_ww_ctx *ww,
|
|
struct drm_i915_gem_object *obj,
|
|
struct i915_vma *vma)
|
|
{
|
|
int err;
|
|
|
|
err = i915_gem_object_lock(obj, ww);
|
|
if (err)
|
|
return err;
|
|
|
|
if (vma) {
|
|
err = i915_vma_pin_ww(vma, ww, obj->base.size, 0,
|
|
0UL | PIN_OFFSET_FIXED |
|
|
PIN_USER);
|
|
if (err) {
|
|
if (err != -EINTR && err != ERESTARTSYS &&
|
|
err != -EDEADLK)
|
|
pr_err("Failed to pin vma.\n");
|
|
return err;
|
|
}
|
|
|
|
i915_vma_unpin(vma);
|
|
}
|
|
|
|
/*
|
|
* Migration will implicitly unbind (asynchronously) any bound
|
|
* vmas.
|
|
*/
|
|
if (i915_gem_object_is_lmem(obj)) {
|
|
err = i915_gem_object_migrate(obj, ww, INTEL_REGION_SMEM);
|
|
if (err) {
|
|
pr_err("Object failed migration to smem\n");
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (i915_gem_object_is_lmem(obj)) {
|
|
pr_err("object still backed by lmem\n");
|
|
err = -EINVAL;
|
|
}
|
|
|
|
if (!i915_gem_object_has_struct_page(obj)) {
|
|
pr_err("object not backed by struct page\n");
|
|
err = -EINVAL;
|
|
}
|
|
|
|
} else {
|
|
err = i915_gem_object_migrate(obj, ww, INTEL_REGION_LMEM_0);
|
|
if (err) {
|
|
pr_err("Object failed migration to lmem\n");
|
|
if (err)
|
|
return err;
|
|
}
|
|
|
|
if (i915_gem_object_has_struct_page(obj)) {
|
|
pr_err("object still backed by struct page\n");
|
|
err = -EINVAL;
|
|
}
|
|
|
|
if (!i915_gem_object_is_lmem(obj)) {
|
|
pr_err("object not backed by lmem\n");
|
|
err = -EINVAL;
|
|
}
|
|
}
|
|
|
|
return err;
|
|
}
|
|
|
|
static int __igt_lmem_pages_migrate(struct intel_gt *gt,
|
|
struct i915_address_space *vm,
|
|
struct i915_deps *deps,
|
|
struct igt_spinner *spin,
|
|
struct dma_fence *spin_fence)
|
|
{
|
|
struct drm_i915_private *i915 = gt->i915;
|
|
struct drm_i915_gem_object *obj;
|
|
struct i915_vma *vma = NULL;
|
|
struct i915_gem_ww_ctx ww;
|
|
struct i915_request *rq;
|
|
int err;
|
|
int i;
|
|
|
|
/* From LMEM to shmem and back again */
|
|
|
|
obj = i915_gem_object_create_lmem(i915, SZ_2M, 0);
|
|
if (IS_ERR(obj))
|
|
return PTR_ERR(obj);
|
|
|
|
if (vm) {
|
|
vma = i915_vma_instance(obj, vm, NULL);
|
|
if (IS_ERR(vma)) {
|
|
err = PTR_ERR(vma);
|
|
goto out_put;
|
|
}
|
|
}
|
|
|
|
/* Initial GPU fill, sync, CPU initialization. */
|
|
for_i915_gem_ww(&ww, err, true) {
|
|
err = i915_gem_object_lock(obj, &ww);
|
|
if (err)
|
|
continue;
|
|
|
|
err = ____i915_gem_object_get_pages(obj);
|
|
if (err)
|
|
continue;
|
|
|
|
err = intel_migrate_clear(>->migrate, &ww, deps,
|
|
obj->mm.pages->sgl, obj->cache_level,
|
|
i915_gem_object_is_lmem(obj),
|
|
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 (err)
|
|
continue;
|
|
|
|
if (!vma) {
|
|
err = igt_fill_check_buffer(obj, true);
|
|
if (err)
|
|
continue;
|
|
}
|
|
}
|
|
if (err)
|
|
goto out_put;
|
|
|
|
/*
|
|
* Migrate to and from smem without explicitly syncing.
|
|
* Finalize with data in smem for fast readout.
|
|
*/
|
|
for (i = 1; i <= 5; ++i) {
|
|
for_i915_gem_ww(&ww, err, true)
|
|
err = lmem_pages_migrate_one(&ww, obj, vma);
|
|
if (err)
|
|
goto out_put;
|
|
}
|
|
|
|
err = i915_gem_object_lock_interruptible(obj, NULL);
|
|
if (err)
|
|
goto out_put;
|
|
|
|
if (spin) {
|
|
if (dma_fence_is_signaled(spin_fence)) {
|
|
pr_err("Spinner was terminated by hangcheck.\n");
|
|
err = -EBUSY;
|
|
goto out_unlock;
|
|
}
|
|
igt_spinner_end(spin);
|
|
}
|
|
|
|
/* Finally sync migration and check content. */
|
|
err = i915_gem_object_wait_migration(obj, true);
|
|
if (err)
|
|
goto out_unlock;
|
|
|
|
if (vma) {
|
|
err = i915_vma_wait_for_bind(vma);
|
|
if (err)
|
|
goto out_unlock;
|
|
} else {
|
|
err = igt_fill_check_buffer(obj, false);
|
|
}
|
|
|
|
out_unlock:
|
|
i915_gem_object_unlock(obj);
|
|
out_put:
|
|
i915_gem_object_put(obj);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int igt_lmem_pages_failsafe_migrate(void *arg)
|
|
{
|
|
int fail_gpu, fail_alloc, ret;
|
|
struct intel_gt *gt = arg;
|
|
|
|
for (fail_gpu = 0; fail_gpu < 2; ++fail_gpu) {
|
|
for (fail_alloc = 0; fail_alloc < 2; ++fail_alloc) {
|
|
pr_info("Simulated failure modes: gpu: %d, alloc: %d\n",
|
|
fail_gpu, fail_alloc);
|
|
i915_ttm_migrate_set_failure_modes(fail_gpu,
|
|
fail_alloc);
|
|
ret = __igt_lmem_pages_migrate(gt, NULL, NULL, NULL, NULL);
|
|
if (ret)
|
|
goto out_err;
|
|
}
|
|
}
|
|
|
|
out_err:
|
|
i915_ttm_migrate_set_failure_modes(false, false);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* This subtest tests that unbinding at migration is indeed performed
|
|
* async. We launch a spinner and a number of migrations depending on
|
|
* that spinner to have terminated. Before each migration we bind a
|
|
* vma, which should then be async unbound by the migration operation.
|
|
* If we are able to schedule migrations without blocking while the
|
|
* spinner is still running, those unbinds are indeed async and non-
|
|
* blocking.
|
|
*
|
|
* Note that each async bind operation is awaiting the previous migration
|
|
* due to the moving fence resulting from the migration.
|
|
*/
|
|
static int igt_async_migrate(struct intel_gt *gt)
|
|
{
|
|
struct intel_engine_cs *engine;
|
|
enum intel_engine_id id;
|
|
struct i915_ppgtt *ppgtt;
|
|
struct igt_spinner spin;
|
|
int err;
|
|
|
|
ppgtt = i915_ppgtt_create(gt, 0);
|
|
if (IS_ERR(ppgtt))
|
|
return PTR_ERR(ppgtt);
|
|
|
|
if (igt_spinner_init(&spin, gt)) {
|
|
err = -ENOMEM;
|
|
goto out_spin;
|
|
}
|
|
|
|
for_each_engine(engine, gt, id) {
|
|
struct ttm_operation_ctx ctx = {
|
|
.interruptible = true
|
|
};
|
|
struct dma_fence *spin_fence;
|
|
struct intel_context *ce;
|
|
struct i915_request *rq;
|
|
struct i915_deps deps;
|
|
|
|
ce = intel_context_create(engine);
|
|
if (IS_ERR(ce)) {
|
|
err = PTR_ERR(ce);
|
|
goto out_ce;
|
|
}
|
|
|
|
/*
|
|
* Use MI_NOOP, making the spinner non-preemptible. If there
|
|
* is a code path where we fail async operation due to the
|
|
* running spinner, we will block and fail to end the
|
|
* spinner resulting in a deadlock. But with a non-
|
|
* preemptible spinner, hangcheck will terminate the spinner
|
|
* for us, and we will later detect that and fail the test.
|
|
*/
|
|
rq = igt_spinner_create_request(&spin, ce, MI_NOOP);
|
|
intel_context_put(ce);
|
|
if (IS_ERR(rq)) {
|
|
err = PTR_ERR(rq);
|
|
goto out_ce;
|
|
}
|
|
|
|
i915_deps_init(&deps, GFP_KERNEL);
|
|
err = i915_deps_add_dependency(&deps, &rq->fence, &ctx);
|
|
spin_fence = dma_fence_get(&rq->fence);
|
|
i915_request_add(rq);
|
|
if (err)
|
|
goto out_ce;
|
|
|
|
err = __igt_lmem_pages_migrate(gt, &ppgtt->vm, &deps, &spin,
|
|
spin_fence);
|
|
i915_deps_fini(&deps);
|
|
dma_fence_put(spin_fence);
|
|
if (err)
|
|
goto out_ce;
|
|
}
|
|
|
|
out_ce:
|
|
igt_spinner_fini(&spin);
|
|
out_spin:
|
|
i915_vm_put(&ppgtt->vm);
|
|
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Setting ASYNC_FAIL_ALLOC to 2 will simulate memory allocation failure while
|
|
* arming the migration error check and block async migration. This
|
|
* will cause us to deadlock and hangcheck will terminate the spinner
|
|
* causing the test to fail.
|
|
*/
|
|
#define ASYNC_FAIL_ALLOC 1
|
|
static int igt_lmem_async_migrate(void *arg)
|
|
{
|
|
int fail_gpu, fail_alloc, ret;
|
|
struct intel_gt *gt = arg;
|
|
|
|
for (fail_gpu = 0; fail_gpu < 2; ++fail_gpu) {
|
|
for (fail_alloc = 0; fail_alloc < ASYNC_FAIL_ALLOC; ++fail_alloc) {
|
|
pr_info("Simulated failure modes: gpu: %d, alloc: %d\n",
|
|
fail_gpu, fail_alloc);
|
|
i915_ttm_migrate_set_failure_modes(fail_gpu,
|
|
fail_alloc);
|
|
ret = igt_async_migrate(gt);
|
|
if (ret)
|
|
goto out_err;
|
|
}
|
|
}
|
|
|
|
out_err:
|
|
i915_ttm_migrate_set_failure_modes(false, false);
|
|
return ret;
|
|
}
|
|
|
|
int i915_gem_migrate_live_selftests(struct drm_i915_private *i915)
|
|
{
|
|
static const struct i915_subtest tests[] = {
|
|
SUBTEST(igt_smem_create_migrate),
|
|
SUBTEST(igt_lmem_create_migrate),
|
|
SUBTEST(igt_same_create_migrate),
|
|
SUBTEST(igt_lmem_pages_failsafe_migrate),
|
|
SUBTEST(igt_lmem_async_migrate),
|
|
};
|
|
|
|
if (!HAS_LMEM(i915))
|
|
return 0;
|
|
|
|
return intel_gt_live_subtests(tests, to_gt(i915));
|
|
}
|