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.
Unified · Split
| @@ -277,12 +277,16 @@ void *dma_direct_alloc(struct device *dev, size_t size, · 276 unmodified lines | ||
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | 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 | + | |
| 280 | 285 | /* remove any dirty cache lines on the kernel alias */ |
| 281 | 286 | arch_dma_prep_coherent(page, size); |
| 282 | 287 | |
| 283 | 288 | /* 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, | |
| 286 | 290 | __builtin_return_address(0)); |
| 287 | 291 | if (!ret) |
| 288 | 292 | goto out_free_pages; |
| @@ -535,6 +539,8 @@ int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma, · 246 unmodified lines | ||
| 535 | 539 | int ret = -ENXIO; |
| 536 | 540 | |
| 537 | 541 | 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); | |
| 538 | 544 | |
| 539 | 545 | if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) |
| 540 | 546 | return ret; |
| @@ -407,8 +407,6 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs); · 406 unmodified lines | ||
| 407 | 407 | */ |
| 408 | 408 | pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs) |
| 409 | 409 | { |
| 410 | − if (force_dma_unencrypted(dev)) | |
| 411 | − prot = pgprot_decrypted(prot); | |
| 412 | 410 | if (dev_is_dma_coherent(dev)) |
| 413 | 411 | return prot; |
| 414 | 412 | #ifdef CONFIG_ARCH_HAS_DMA_WRITE_COMBINE |