Skip to content

Commit 4fe87e8

Browse files
author
Christoph Hellwig
committed
dma-mapping: move pgprot_decrypted out of dma_pgprot
pgprot_decrypted is used by AMD SME systems to allow access to memory that was set to not encrypted using set_memory_decrypted. That only happens for dma-direct memory as the IOMMU solves the addressing challenges for the encryption bit using its own remapping. Move the pgprot_decrypted call out of dma_pgprot which is also used by the IOMMU mappings and into dma-direct so that it is only used with memory that was set decrypted. Fixes: f5ff79f ("dma-mapping: remove CONFIG_DMA_REMAP") Reported-by: Alex Xu (Hello71) <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Tested-by: Alex Xu (Hello71) <[email protected]>
1 parent 05b0ebd commit 4fe87e8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

kernel/dma/direct.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,16 @@ void *dma_direct_alloc(struct device *dev, size_t size,
277277
}
278278

279279
if (remap) {
280+
pgprot_t prot = dma_pgprot(dev, PAGE_KERNEL, attrs);
281+
282+
if (force_dma_unencrypted(dev))
283+
prot = pgprot_decrypted(prot);
284+
280285
/* remove any dirty cache lines on the kernel alias */
281286
arch_dma_prep_coherent(page, size);
282287

283288
/* create a coherent mapping */
284-
ret = dma_common_contiguous_remap(page, size,
285-
dma_pgprot(dev, PAGE_KERNEL, attrs),
289+
ret = dma_common_contiguous_remap(page, size, prot,
286290
__builtin_return_address(0));
287291
if (!ret)
288292
goto out_free_pages;
@@ -535,6 +539,8 @@ int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma,
535539
int ret = -ENXIO;
536540

537541
vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs);
542+
if (force_dma_unencrypted(dev))
543+
vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
538544

539545
if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret))
540546
return ret;

kernel/dma/mapping.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,6 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs);
407407
*/
408408
pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
409409
{
410-
if (force_dma_unencrypted(dev))
411-
prot = pgprot_decrypted(prot);
412410
if (dev_is_dma_coherent(dev))
413411
return prot;
414412
#ifdef CONFIG_ARCH_HAS_DMA_WRITE_COMBINE

0 commit comments

Comments
 (0)