public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Dave Gordon <david.s.gordon@intel.com>
To: Daniel Vetter <daniel@ffwll.ch>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH v1] drm/i915/guc: Fix a fw content lost issue after it is evicted
Date: Tue, 24 Nov 2015 17:47:08 +0000	[thread overview]
Message-ID: <5654A29C.4050308@intel.com> (raw)
In-Reply-To: <20151124160422.GS17050@phenom.ffwll.local>

On 24/11/15 16:04, Daniel Vetter wrote:
> On Tue, Nov 24, 2015 at 03:47:02PM +0000, Dave Gordon wrote:
>> On 10/11/15 23:27, yu.dai@intel.com wrote:
>>> From: Alex Dai <yu.dai@intel.com>
>>>
>>> We keep a copy of GuC fw in a GEM obj. However its content is lost
>>> if the GEM obj is swapped (igt/gem_evict_*). Therefore, the later
>>> fw loading during GPU reset will fail. Mark the obj dirty after
>>> copying data into the pages. So its content will be kept during
>>> swapped out.
>>>
>>> Signed-off-by: Alex Dai <yu.dai@intel.com>
>>> ---
>>>   drivers/gpu/drm/i915/i915_gem.c | 1 +
>>>   1 file changed, 1 insertion(+)
>>>
>>> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
>>> index f1e3fde..3b15167 100644
>>> --- a/drivers/gpu/drm/i915/i915_gem.c
>>> +++ b/drivers/gpu/drm/i915/i915_gem.c
>>> @@ -5199,6 +5199,7 @@ i915_gem_object_create_from_data(struct drm_device *dev,
>>>   	i915_gem_object_pin_pages(obj);
>>>   	sg = obj->pages;
>>>   	bytes = sg_copy_from_buffer(sg->sgl, sg->nents, (void *)data, size);
>>> +	obj->dirty = 1;
>>>   	i915_gem_object_unpin_pages(obj);
>>>
>>>   	if (WARN_ON(bytes != size)) {
>>
>> Hi,
>>
>> although I liked this at first, on further checking I've found that there
>> are other cases where the CPU writes on a GEM object without marking it
>> dirty, so in theory all of those could also be subject to the same issue.
>>
>> Functions that may suffer from this problem include copy_batch(),
>> relocate_entry_cpu(), and render_state_setup(); hence, the objects that
>> might be affected (CPU updates discarded) would in general be batch buffers.
>>
>> Obviously also i915_gem_object_create_from_data() currently used only for
>> firmware objects; and populate_lr_context() also modifies a GEM object using
>> the CPU, but it already explicitly marks the object dirty and so avoid any
>> problems.
>>
>> At present, setting an object into the GTT domain with intent-to-write
>> causes the object to be marked as dirty, whereas setting it into the CPU
>> domain with intent-to-write doesn't. Since the obj->dirty flag doesn't mean
>> "CPU and GPU views differ" but rather "In-memory version is newer than
>> backing store", setting it should depend only on the intent-to-write flag,
>> not on which domain it's being put into.
>>
>> So my preferred solution would be to set the obj->dirty flag inside
>> i915_gem_object_set_to_cpu_domain(obj, true). Then objects that have been
>> written by the CPU would be swapped out to backing store rather than
>> discarded if the shrinker decides to reclaim the memory.
>>
>> To make this work properly, we also need to audit all the callers of
>> i915_gem_object_set_to_cpu_domain(), because I think in several places the
>> callers pass the second argument as true where it should be false; this
>> would cause objects to unnecessarily be marked dirty, increasing swap
>> requirements and impacting performance.
>>
>> I'll follow up with an actual patch once people have had an opportunity to
>> check that the above analysis is accurate.
>
> set_to_cpu_domain won't cover everyone, since some callers like
> shmem_pwrite/pread do clever tricks with inline flushing.
>
> Also there's a fundamental difference between writing through GTT (where
> we always pin all the pages, even though now we do have partial views),
> and CPU writes, which in most places access the bo page-by-page.
>
> Given that I'm still slightly leaning towards a "cpu writes need to mark
> pages dirty themselves" world-view. At least teaching this to
> set_to_cpu_domain won't be a fully effective magic bullet.
> -Daniel

shmem_pwrite doesn't call set_to_cpu_domain, and it already explicitly 
marks the GEM object as dirty; shmem_pread obviously doesn't need to as 
it's a read operation and doesn't change the object contents.

There's no difference (as far as backing store is concerned) whether the 
object is written via a CPU mapping, a GTT mapping, or by the GPU; the 
end result is that the object in memory is different from the version on 
backing store, and the object should be marked dirty if we want the 
changes to persist across eviction.

There may indeed be additional functions that modify GEM objects in some 
way without first setting them into the CPU domain, in which case they 
will also be responsible for marking the objects dirty. But all the 
(correct) callers of i915_gem_object_set_to_cpu_domain(obj, true) follow 
it by writing on the object, and only one marks the object as dirty, so 
all others are potential victims of having the shrinker discard their 
uncommitted changes.

Fixing it here (i.e when mapping whole objects for CPU write access) 
means that object-level operations then don't have to worry about 
page-level details. Functions that want to be smarter about tracking 
updates at the level of individual pages could still do so, but I don't 
want to impose that requirement on code that just wants to manipulate 
objects.

BTW, I note that the different implementations of put_pages() are not 
consistent about how they treat dirty pages within objects not marked as 
dirty. Does this matter?

.Dave.
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-11-24 17:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-06 21:55 [PATCH] drm/i915/guc: Fix a fw content lost issue after it is evicted yu.dai
2015-11-06 22:07 ` Chris Wilson
2015-11-06 23:18   ` Yu Dai
2015-11-09 10:15     ` Chris Wilson
2015-11-10 23:27       ` [PATCH v1] " yu.dai
2015-11-11  9:07         ` Chris Wilson
2015-11-11 19:01           ` Yu Dai
2015-11-23  9:18           ` akash goel
2015-11-23  9:37             ` Chris Wilson
2015-11-24 15:47         ` Dave Gordon
2015-11-24 16:04           ` Daniel Vetter
2015-11-24 17:47             ` Dave Gordon [this message]
2015-11-24 18:06               ` Daniel Vetter
2015-11-24 23:01                 ` Chris Wilson
2015-11-25  8:40                   ` Daniel Vetter
2015-11-25  9:02                     ` Chris Wilson
2015-11-25  9:59                       ` Daniel Vetter
2015-11-10 23:29       ` [PATCH] " Yu Dai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5654A29C.4050308@intel.com \
    --to=david.s.gordon@intel.com \
    --cc=daniel@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox