drm/i915/gem: Always call obj->ops->migrate unless can_migrate fails
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 23 Jul 2021 17:21:40 +0000 (12:21 -0500)
committerMatthew Auld <matthew.auld@intel.com>
Mon, 26 Jul 2021 15:37:35 +0000 (16:37 +0100)
commit76b62448dc8ffc3cfcfc40603d965b710a1840e3
treea2247e100139d5233f35d97a912c7dd48543662d
parent75e382850b7ea516cbeaecf2dd22dd040e144ad9
drm/i915/gem: Always call obj->ops->migrate unless can_migrate fails

Without TTM, we have no such hook so we exit early but this is fine
because we use TTM on all LMEM platforms and, on integrated platforms,
there is no real migration.  If we do have the hook, it's better to just
let TTM handle the migration because it knows where things are actually
placed.

This fixes a bug where i915_gem_object_migrate fails to migrate newly
created LMEM objects.  In that scenario, the object has obj->mm.region
set to LMEM but TTM has it in SMEM because that's where all new objects
are placed there prior to getting actual pages.  When we invoke
i915_gem_object_migrate, it exits early because, from the point of view
of the GEM object, it's already in LMEM and no migration is needed.
Then, when we try to pin the pages, __i915_ttm_get_pages is called
which, unaware of our failed attempt at a migration, places the object
in SMEM.  This only happens on newly created objects because they have
this weird state where TTM thinks they're in SMEM, GEM thinks they're in
LMEM, and the reality is that they don't exist at all.

It's better if GEM just always calls into TTM and let's TTM handle
things.  That way the lies stay better contained.  Once the migration is
complete, the object will have pages, obj->mm.region will be correct,
and we're done lying.

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210723172142.3273510-7-jason@jlekstrand.net
drivers/gpu/drm/i915/gem/i915_gem_object.c