From: Christoph Hellwig Subject: Re: [PATCH v2 3/4] drm/ttm, drm/vmwgfx: Correctly support support AMD memory encryption Date: Wed, 4 Sep 2019 11:16:37 -0700 Message-ID: <20190904181637.GA26475@infradead.org> References: <6d0fafcc-b596-481b-7b22-1f26f0c02c5c@intel.com> <7fa3b178-b9b4-2df9-1eee-54e24d48342e@intel.com> <44b094c8-63fe-d9e5-1bf4-7da0788caccf@shipmail.org> <6d122d62-9c96-4c29-8d06-02f7134e5e2a@shipmail.org> <3393108b-c7e3-c9be-b65b-5860c15ca228@shipmail.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Content-Disposition: inline In-Reply-To: <3393108b-c7e3-c9be-b65b-5860c15ca228@shipmail.org> Sender: linux-kernel-owner@vger.kernel.org To: Thomas =?iso-8859-1?Q?Hellstr=F6m_=28VMware=29?= Cc: Andy Lutomirski , Andy Lutomirski , Dave Hansen , Daniel Vetter , dri-devel , pv-drivers@vmware.com, VMware Graphics , Linux Kernel Mailing List , Tom Lendacky , Thomas Hellstrom , Peter Zijlstra , Dave Hansen , Heiko Carstens , Christian Borntraeger , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Thomas Gleixner , Christian =?iso-8859-1?Q?K=F6nig?= List-Id: dri-devel@lists.freedesktop.org On Wed, Sep 04, 2019 at 08:49:03AM +0200, Thomas Hellström (VMware) wrote: > For device DMA address purposes, the encryption status is encoded in the dma > address by the dma layer in phys_to_dma(). > > > > There doesn’t seem to be any real funny business in dma_mmap_attrs() or dma_common_mmap(). > > No, from what I can tell the call in these functions to dma_pgprot() > generates an incorrect page protection since it doesn't take unencrypted > coherent memory into account. I don't think anybody has used these functions > yet with SEV. Yes, I think dma_pgprot is not correct for SEV. Right now that function isn't used much on x86, it had more grave bugs up to a few -rcs ago.. > > Would it make sense to add a vmf_insert_dma_page() to directly do exactly what you’re trying to do? > > Yes, but as a longer term solution I would prefer a general dma_pgprot() > exported, so that we could, in a dma-compliant way, use coherent pages with > other apis, like kmap_atomic_prot() and vmap(). That is, basically split > coherent page allocation in two steps: Allocation and mapping. The thing is that dma_pgprot is of no help for you at all, as the DMA API hides the page from you entirely. In fact we do have backends that do not even have a page backing. But I think we can have a vmf_insert_page equivalent that does the right thing behind your back for the varius different implementation (contiguous page(s) in the kernel lineary, contiguous page(s) with a vmap/ioremap remapping in various flavours, non-contigous pages(s) with a vmap remapping, and deeply magic firmware populated pools (well, except maybe for the last, but at least we can fail gracefully there)).