dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Zack Rusin" <zackr@vmware.com>,
	"alexdeucher@gmail.com" <alexdeucher@gmail.com>
Cc: "dri-devel@lists.freedesktop.org" <dri-devel@lists.freedesktop.org>
Subject: Re: Decrypting tt maps in ttm
Date: Tue, 19 Sep 2023 09:47:25 +0200	[thread overview]
Message-ID: <beb209b5-fb67-5b53-62b8-bc1c78b41cc5@amd.com> (raw)
In-Reply-To: <53e09f13-eb54-9662-a511-77c012df9646@linux.intel.com>

Am 19.09.23 um 08:56 schrieb Thomas Hellström:
>
> On 9/19/23 07:39, Christian König wrote:
>> Am 19.09.23 um 03:26 schrieb Zack Rusin:
>>> On Mon, 2023-09-18 at 16:21 -0400, Alex Deucher wrote:
>>>> !! External Email
>>>>
>>>> On Mon, Sep 18, 2023 at 3:06 PM Thomas Hellström
>>>> <thomas.hellstrom@linux.intel.com> wrote:
>>>>>
>>>>> On 9/18/23 17:52, Zack Rusin wrote:
>>>>>> On Mon, 2023-09-18 at 17:13 +0200, Thomas Hellström wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> On 9/18/23 16:56, Thomas Hellström wrote:
>>>>>>>> Hi Zack, Christian
>>>>>>>>
>>>>>>>> On 9/18/23 13:36, Christian König wrote:
>>>>>>>>> Hi Zack,
>>>>>>>>>
>>>>>>>>> adding Thomas and Daniel.
>>>>>>>>>
>>>>>>>>> I briefly remember that I talked with Thomas and some other 
>>>>>>>>> people
>>>>>>>>> about that quite a while ago as well, but I don't fully 
>>>>>>>>> remember the
>>>>>>>>> outcome.
>>>>>>>> Found one old thread, but didn't read it:
>>>>>>>>
>>>>>>>> https://lists.freedesktop.org/archives/dri-devel/2019-September/234100.html 
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> /Thomas
>>>>>>>>
>>>>>>>>
>>>>>>> Ugh. Now starting to read that thread I have a vague 
>>>>>>> recollection it all
>>>>>>> ended with not supporting mapping any device pages whatsoever 
>>>>>>> when SEV
>>>>>>> was enabled, but rather resorting to llvmpipe and VM-local bos.
>>>>>> Hi, Thomas.
>>>>>>
>>>>>> Thanks for finding this! I'd (of course) like to solve it 
>>>>>> properly and get
>>>>>> vmwgfx
>>>>>> running with 3d support with SEV-ES active instead of essentially 
>>>>>> disabling
>>>>>> the
>>>>>> driver when SEV-ES is active.
>>>>>>
>>>>>> I think there are two separate discussions there, the 
>>>>>> non-controversial one
>>>>>> and the
>>>>>> controversial one:
>>>>>> 1) The non-controversial: is there a case where drivers would 
>>>>>> want encrypted
>>>>>> memory
>>>>>> for TT pages but not for io mem mappings? Because if not then as 
>>>>>> Christian
>>>>>> pointed
>>>>>> out we could just add pgprot_decrypted to ttm_io_prot and be 
>>>>>> essentially done.
>>>>>> The
>>>>>> current method of decrypting io mem but leaving sys mem mappings 
>>>>>> encrypted is
>>>>>> a bit
>>>>>> weird anyway.
>>>>>>
>>>>>> If the answer to that question is "yes, some driver does want the 
>>>>>> TT mappings
>>>>>> to be
>>>>>> encrypted" then your "[PATCH v2 3/4] drm/ttm, drm/vmwgfx: 
>>>>>> Correctly support
>>>>>> support
>>>>>> AMD memory encryption" solves that. I think getting one of those 
>>>>>> two in makes
>>>>>> sense
>>>>>> regardless of everything else, agreed?
>>>>> Well, there is more to it I think.
>>>>>
>>>>> IIRC, the AMD SME encryption mode has a way for a device to have the
>>>>> memory controller (?) encrypt / decrypt device traffic by using an
>>>>> address range alias, so in theory it supports encrypted TT pages, and
>>>>> the dma-layer may indeed hand encrypted DMA pages to TTM on such 
>>>>> systems
>>>>> depending on the device's DMA mask. That's why I think that
>>>>> force_dma_unencrypted() export was needed, and If the amdgpu driver
>>>>> accesses TT memory in SME mode *without* pgprot_decrypted() and it 
>>>>> still
>>>>> works, then I think that mode is actually used. How could it 
>>>>> otherwise work?
>>>> For SME, as long as the encrypted bit is set in the physical address
>>>> used for DMA, the memory controller will handle the encrypt/decrypt
>>>> for the device.  For devices with a limited dma mask, you need to use
>>>> the IOMMU so that the encrypted bit is retained when the address hits
>>>> the memory controller.
>>> How does that work on systems with swiotlb, e.g. swiotlb=force, or 
>>> i.e. what would
>>> decrypt the ttm tt mappings when copying between system and vram 
>>> when iommu is
>>> disabled/absent?
>>
>> SME makes it mandatory that all devices can handle the physical 
>> address used for DMA, either native or with the help of IOMMU.
>>
>> Hacks like SWIOTLB are not directly supported as far as I know. Maybe 
>> somehow SWIOTLB manually decrypts the data while copying it or 
>> something like this, but I'm not 100% sure if that is actually 
>> implemented.
>>
>> Regards,
>> Christian.
>
> A bold guess after looking at various code and patches:
>
> 1) Devices under SME that don't support the encryption bit and SEV:
> a) Coherent memory is unencrypted.
> b) Streaming DMA under IOMMU: The IOMMU sets the encrypted bit.
> c) Streaming DMA with SWIOTLB: The bounce buffer is unencrypted. 
> Copying to/from bounce-buffer decrypts/encrypts.
>
> 2) Devices under SME that do support the encryption bit (which I 
> believe is most graphics devices in general on SME systems, not just 
> amdgpu; it "just works")
> *) Coherent memory is encrypted. The DMA layer sets dma addresses and 
> pgprot accordingly.
> *) Streaming DMA is encrypted.
>
> So the bug in TTM would then be it's not handling 1a) and 1b) correctly.
>
> Remedy:
> 1b) Shouldn't be used with encryption.
> 1a) This is what we should try to fix. Exporting 
> dma_force_unencrypted() didn't seem to be a way forward. Properly 
> fixing this would, I guess, mean implement the missing functionality 
> in the dma layer: For vmap / kmap we could simply reuse the virtual 
> addresses we get back from dma_alloc_coherent(), but for faulting one 
> would want something like dma_coherent_insert_pfn() (if it doesn't 
> exist already) after a proper disussion with Christoph Hellwig.

Christoph once pointed me to dma_mmap_attrs() for this, but I never 
found the time to fully look into it.

Christian.

>
> /Thomas
>
>
>>
>>>
>>> z
>>>
>>


  reply	other threads:[~2023-09-19  7:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <15c9beb5f8dcb091b00c35d6206b84aa100d729e.camel@vmware.com>
     [not found] ` <60f15275-ebfd-2fd6-64c4-c8907520e5dd@amd.com>
     [not found]   ` <3fa9b4d0-e12a-59b6-14c5-68f7406df129@linux.intel.com>
     [not found]     ` <fc935b9f-9b25-bcab-717c-0c31373fcfee@linux.intel.com>
     [not found]       ` <e9ba0f7a0620cd252adfc1df43cd15d16dcea74d.camel@vmware.com>
2023-09-18 17:11         ` Decrypting tt maps in ttm Thomas Hellström
2023-09-18 20:21           ` Alex Deucher
2023-09-19  1:26             ` Zack Rusin
2023-09-19  5:39               ` Christian König
2023-09-19  6:56                 ` Thomas Hellström
2023-09-19  7:47                   ` Christian König [this message]
2023-09-20  3:43                     ` Zack Rusin
2023-09-20  7:36                       ` Thomas Hellström
2023-09-20 10:48                         ` Christian König
2023-09-20 16:39                           ` Zack Rusin
2023-09-20 17:17                             ` Thomas Hellström
2023-09-20 18:24                               ` Zack Rusin
2023-09-20 19:22                                 ` Thomas Hellström
2023-09-21  3:51                                   ` Zack Rusin
2023-09-21  7:12                                     ` Thomas Hellström
2023-09-22 10:46                                       ` Christian König

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=beb209b5-fb67-5b53-62b8-bc1c78b41cc5@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexdeucher@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=zackr@vmware.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