Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: "Zeng, Oak" <oak.zeng@intel.com>,
	"Landwerlin, Lionel G" <lionel.g.landwerlin@intel.com>,
	"Vishwanathapura,
	Niranjana" <niranjana.vishwanathapura@intel.com>
Cc: "Zanoni, Paulo R" <paulo.r.zanoni@intel.com>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"Hellstrom, Thomas" <thomas.hellstrom@intel.com>,
	"Wilson, Chris P" <chris.p.wilson@intel.com>,
	"Vetter, Daniel" <daniel.vetter@intel.com>,
	"christian.koenig@amd.com" <christian.koenig@amd.com>,
	"Auld, Matthew" <matthew.auld@intel.com>
Subject: Re: [Intel-gfx] [PATCH v3 3/3] drm/doc/rfc: VM_BIND uapi definition
Date: Fri, 24 Jun 2022 09:32:06 +0100	[thread overview]
Message-ID: <1d36da1a-9224-5750-d103-60e7cdfdf8df@linux.intel.com> (raw)
In-Reply-To: <BN6PR11MB1633C90D1B2E40359F1F168F92B59@BN6PR11MB1633.namprd11.prod.outlook.com>


On 23/06/2022 22:05, Zeng, Oak wrote:
>> -----Original Message-----
>> From: Intel-gfx <intel-gfx-bounces@lists.freedesktop.org> On Behalf Of Tvrtko
>> Ursulin
>> Sent: June 23, 2022 7:06 AM
>> To: Landwerlin, Lionel G <lionel.g.landwerlin@intel.com>; Vishwanathapura,
>> Niranjana <niranjana.vishwanathapura@intel.com>
>> Cc: Zanoni, Paulo R <paulo.r.zanoni@intel.com>; intel-gfx@lists.freedesktop.org;
>> dri-devel@lists.freedesktop.org; Hellstrom, Thomas <thomas.hellstrom@intel.com>;
>> Wilson, Chris P <chris.p.wilson@intel.com>; Vetter, Daniel
>> <daniel.vetter@intel.com>; christian.koenig@amd.com; Auld, Matthew
>> <matthew.auld@intel.com>
>> Subject: Re: [Intel-gfx] [PATCH v3 3/3] drm/doc/rfc: VM_BIND uapi definition
>>
>>
>> On 23/06/2022 09:57, Lionel Landwerlin wrote:
>>> On 23/06/2022 11:27, Tvrtko Ursulin wrote:
>>>>>
>>>>> After a vm_unbind, UMD can re-bind to same VA range against an active
>>>>> VM.
>>>>> Though I am not sue with Mesa usecase if that new mapping is required
>>>>> for
>>>>> running GPU job or it will be for the next submission. But ensuring the
>>>>> tlb flush upon unbind, KMD can ensure correctness.
>>>>
>>>> Isn't that their problem? If they re-bind for submitting _new_ work
>>>> then they get the flush as part of batch buffer pre-amble.
>>>
>>> In the non sparse case, if a VA range is unbound, it is invalid to use
>>> that range for anything until it has been rebound by something else.
>>>
>>> We'll take the fence provided by vm_bind and put it as a wait fence on
>>> the next execbuffer.
>>>
>>> It might be safer in case of memory over fetching?
>>>
>>>
>>> TLB flush will have to happen at some point right?
>>>
>>> What's the alternative to do it in unbind?
>>
>> Currently TLB flush happens from the ring before every BB_START and also
>> when i915 returns the backing store pages to the system.
> 
> 
> Can you explain more why tlb flush when i915 retire the backing storage? I never figured that out when I looked at the codes. As I understand it, tlb caches the gpu page tables which map a va to a pa. So it is straight forward to me that we perform a tlb flush when we change the page table (either at vm bind time or unbind time. Better at unbind time for performance reason).

I don't know what performs better - someone can measure the two 
approaches? Certainly on platforms where we only have global TLB 
flushing the cost is quite high so my thinking was to allow i915 to 
control when it will be done and not guarantee it in the uapi if it 
isn't needed for security reasons.

> But it is rather tricky to me to flush tlb when we retire a backing storage. I don't see how backing storage can be connected to page table. Let's say user unbind va1 from pa1, then bind va1 to pa2. Then retire pa1. Submit shader code using va1. If we don't tlb flush after unbind va1, the new shader code which is supposed to use pa2 will still use pa1 due to the stale entries in tlb, right? The point is, tlb cached is tagged with virtual address, not physical address. so after we unbind va1 from pa1, regardless we retire pa1 or not, va1 can be bound to another pa2.

When you say "retire pa1" I will assume you meant release backing 
storage for pa1. At this point i915 currently does do the TLB flush and 
that ensures no PTE can point to pa1.

This approach deals with security of the system as a whole. Client may 
still cause rendering corruption or a GPU hang for itself but that 
should be completely isolated. (This is the part where you say 
"regardless if we retire pa1 or not" I think.)

But I think those are advanced use cases where userspace wants to 
manipulate PTEs while something is running on the GPU in parallel. AFAIK 
limited to compute "infinite batch" so my thinking is to avoid adding a 
performance penalty to the common case. Especially on platforms which 
only have global flush.

But.. to circle back on the measuring angle. Until someone invests time 
and effort to benchmark the two approaches (flush on unbind vs flush on 
backing store release) we don't really know. All I know is the perf hit 
with the current solution was significant, AFAIR up to teen digits on 
some games. And considering the flushes were driven only by the shrinker 
activity, my thinking was they would be less frequent than the unbinds, 
therefore have the potential for a smaller perf hit.

Regards,

Tvrtko

  reply	other threads:[~2022-06-24  8:32 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  3:56 [Intel-gfx] [PATCH v3 0/3] drm/doc/rfc: i915 VM_BIND feature design + uapi Niranjana Vishwanathapura
2022-06-22  3:56 ` [Intel-gfx] [PATCH v3 1/3] drm/doc/rfc: VM_BIND feature design document Niranjana Vishwanathapura
2022-06-22  3:56 ` [Intel-gfx] [PATCH v3 2/3] drm/i915: Update i915 uapi documentation Niranjana Vishwanathapura
2022-06-22  3:56 ` [Intel-gfx] [PATCH v3 3/3] drm/doc/rfc: VM_BIND uapi definition Niranjana Vishwanathapura
2022-06-22  8:10   ` Tvrtko Ursulin
2022-06-22 15:12     ` Niranjana Vishwanathapura
2022-06-22 15:57       ` Tvrtko Ursulin
2022-06-22 16:44         ` Niranjana Vishwanathapura
2022-06-22 18:53           ` Niranjana Vishwanathapura
2022-06-23  8:27           ` Tvrtko Ursulin
2022-06-23  8:57             ` Lionel Landwerlin
2022-06-23 11:05               ` Tvrtko Ursulin
2022-06-23 12:41                 ` Lionel Landwerlin
2022-06-23 21:05                 ` Zeng, Oak
2022-06-24  8:32                   ` Tvrtko Ursulin [this message]
2022-06-24 20:23                     ` Zeng, Oak
2022-06-27  8:30                       ` Tvrtko Ursulin
2022-06-27 18:58                         ` Zeng, Oak
2022-06-28  8:58                           ` Tvrtko Ursulin
2022-06-28 13:53                             ` Zeng, Oak
2022-06-23 14:47             ` Niranjana Vishwanathapura
2022-06-23  9:28       ` Lionel Landwerlin
2022-06-23 14:43         ` Niranjana Vishwanathapura
2022-06-22 19:49 ` [Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/doc/rfc: i915 VM_BIND feature design + uapi Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2022-06-22 18:50 [Intel-gfx] [PATCH v4 0/3] " Niranjana Vishwanathapura
2022-06-22 18:50 ` [Intel-gfx] [PATCH v3 3/3] drm/doc/rfc: VM_BIND uapi definition Niranjana Vishwanathapura

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=1d36da1a-9224-5750-d103-60e7cdfdf8df@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris.p.wilson@intel.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=lionel.g.landwerlin@intel.com \
    --cc=matthew.auld@intel.com \
    --cc=niranjana.vishwanathapura@intel.com \
    --cc=oak.zeng@intel.com \
    --cc=paulo.r.zanoni@intel.com \
    --cc=thomas.hellstrom@intel.com \
    /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