All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "Felix Kuehling" <felix.kuehling@amd.com>,
	"Christian König" <ckoenig.leichtzumerken@gmail.com>,
	"Chen, Xiaogang" <xiaogang.chen@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/6] drm/amdgpu: Generalize KFD dmabuf import
Date: Mon, 16 Jan 2023 12:42:19 +0100	[thread overview]
Message-ID: <bac027e4-0e91-8341-3baa-74520c60c808@amd.com> (raw)
In-Reply-To: <e55cc02a-3180-20b9-8255-f95f5910e7fe@amd.com>

[SNIP]
>>> When the BO is imported into the same GPU, you get a reference to 
>>> the same BO, so the imported BO has the same mmap_offset as the 
>>> original BO.
>>>
>>> When the BO is imported into a different GPU, it is a new BO with a 
>>> new mmap_offset.
>>
>> That won't work.
>>
>>> I don't think this is incorrect.
>>
>> No, this is completely incorrect. It mixes up the reverse tracking of 
>> mappings and might crash the system.
>
> I don't understand that. The imported BO is a different BO with a 
> different mmap offset in a different device file. I don't see how that 
> messes with the tracking of mappings.

The tracking keeps note which piece of information is accessible through 
which address space object and offset. I you suddenly have two address 
spaces and offsets pointing to the same piece of information that won't 
work any more.

>
>> This is the reason why we can't mmap() imported BOs.
>
> I don't see anything preventing that. For userptr BOs, there is this 
> code in amdgpu_gem_object_mmap:
>
>         if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm))
>                 return -EPERM;
>
> I don't see anything like this preventing mmapping of imported dmabuf 
> BOs. What am I missing?
>

At some point I really need to make a big presentation about all this 
stuff, we had the same discussion multiple times now :)

It's the same reason why you can't mmap() VRAM through the kfd node: 
Each file can have only one address space object associated with it.

See dma_buf_mmap() and vma_set_file() how this is worked around in DMA-buf.

>>
>>> mmapping the memory with that new offset should still work. The 
>>> imported BO is created with ttm_bo_type_sg, and AFAICT ttm_bo_vm.c 
>>> supports mapping of SG BOs.
>>
>> Actually it shouldn't. This can go boom really easily.
>
> OK. I don't think we're doing this, but after Xiaogang raised the 
> question I went looking through the code whether it's theoretically 
> possible. I didn't find anything in the code that says that mmapping 
> imported dmabufs would be prohibited or even dangerous. On the 
> contrary, I found that ttm_bo_vm explicitly supports mmapping SG BOs.
>
>
>>
>> When you have imported a BO the only correct way of to mmap() it is 
>> to do so on the original exporter.
>
> That seems sensible, and this is what we do today. That said, if 
> mmapping an imported BO is dangerous, I'm missing a mechanism to 
> protect against this. It could be as simple as setting 
> AMDGPU_GEM_CREATE_NO_CPU_ACCESS in amdgpu_dma_buf_create_obj.

At least for the GEM mmap() handler this is double checked very early by 
looking at obj->import_attach and then either rejecting it or 
redirecting the request to the DMA-buf file instead.

We probably need something similar when stuff is mapped through the KFD 
node. But I think we don't do that any more for "normal" BOs anyway, 
don't we?

Regards,
Christian.

>
> Regards,
>   Felix


  reply	other threads:[~2023-01-16 11:42 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12  1:31 [PATCH 0/6] Enable KFD to use render node BO mappings Felix Kuehling
2023-01-12  1:31 ` [PATCH 1/6] drm/amdgpu: Generalize KFD dmabuf import Felix Kuehling
2023-01-12 22:41   ` Chen, Xiaogang
2023-01-13 22:26     ` Felix Kuehling
2023-01-13 23:00       ` Chen, Xiaogang
2023-01-13 23:15         ` Felix Kuehling
2023-01-15 16:43           ` Christian König
2023-01-15 18:32             ` Felix Kuehling
2023-01-16 11:42               ` Christian König [this message]
2023-01-16 14:52                 ` Felix Kuehling
2023-01-16 15:11                   ` Christian König
2023-01-17  1:06                     ` Dmitry Osipenko
2023-02-16 12:22                       ` Daniel Vetter
2023-02-16 12:22                         ` Daniel Vetter
2023-01-16 22:04   ` Errabolu, Ramesh
2023-01-16 22:25     ` Felix Kuehling
2023-01-12  1:31 ` [PATCH 2/6] drm/amdkfd: Implement DMA buf fd export from KFD Felix Kuehling
2023-01-13  8:03   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 3/6] drm/amdkfd: Improve amdgpu_vm_handle_moved Felix Kuehling
2023-01-13  8:05   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 4/6] drm/amdgpu: Attach eviction fence on alloc Felix Kuehling
2023-01-13  8:12   ` Chen, Xiaogang
2023-01-16 22:11   ` Errabolu, Ramesh
2023-01-16 22:51     ` Felix Kuehling
2023-01-12  1:31 ` [PATCH 5/6] drm/amdgpu: update mappings not managed by KFD Felix Kuehling
2023-01-13 20:02   ` Chen, Xiaogang
2023-01-12  1:31 ` [PATCH 6/6] drm/amdgpu: Do bo_va ref counting for KFD BOs Felix Kuehling
2023-01-13 22:58   ` Chen, Xiaogang
2023-01-16 22:12     ` Errabolu, Ramesh
2023-01-16 22:58       ` Felix Kuehling
2023-01-12  7:18 ` [PATCH 0/6] Enable KFD to use render node BO mappings Christian König
  -- strict thread matches above, loose matches on Subject: below --
2022-11-18 23:44 Felix Kuehling
2022-11-18 23:44 ` [PATCH 1/6] drm/amdgpu: Generalize KFD dmabuf import Felix Kuehling

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=bac027e4-0e91-8341-3baa-74520c60c808@amd.com \
    --to=christian.koenig@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=felix.kuehling@amd.com \
    --cc=xiaogang.chen@amd.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.