History

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.

Christoph Hellwig committed 4 years ago

Commit 4fe87e81 parent 05b0ebd2 files · +8 −4Browse files

Showing the changes to kernel (2 of 2 files). Show all

Unified · Split

2 files
  1. kernel/dma/direct.c +8 −2
  2. kernel/dma/mapping.c +0 −2
kernel/dma/direct.c+8−2
@@ -277,12 +277,16 @@ void *dma_direct_alloc(struct device *dev, size_t size, · 276 unmodified lines
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, · 246 unmodified lines
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+0−2
@@ -407,8 +407,6 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs); · 406 unmodified lines
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