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.
Showing the changes to kernel (2 of 2 files). Show all
Unified · Split
| @@ -277,12 +277,16 @@ void *dma_direct_alloc(struct device *dev, size_t size, · 276 unmodified lines | |||
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | if (remap) { | 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 | /* remove any dirty cache lines on the kernel alias */ | 285 | /* remove any dirty cache lines on the kernel alias */ |
| 281 | arch_dma_prep_coherent(page, size); | 286 | arch_dma_prep_coherent(page, size); |
| 282 | 287 | ||
| 283 | /* create a coherent mapping */ | 288 | /* create a coherent mapping */ |
| 284 | ret = dma_common_contiguous_remap(page, size, | 289 | ret = dma_common_contiguous_remap(page, size, prot, |
| 285 | dma_pgprot(dev, PAGE_KERNEL, attrs), | ||
| 286 | __builtin_return_address(0)); | 290 | __builtin_return_address(0)); |
| 287 | if (!ret) | 291 | if (!ret) |
| 288 | goto out_free_pages; | 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 | int ret = -ENXIO; | 539 | int ret = -ENXIO; |
| 536 | 540 | ||
| 537 | vma->vm_page_prot = dma_pgprot(dev, vma->vm_page_prot, attrs); | 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 | if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) | 545 | if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) |
| 540 | return ret; | 546 | return ret; |
| @@ -407,8 +407,6 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs); · 406 unmodified lines | |||
| 407 | */ | 407 | */ |
| 408 | pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs) | 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 | if (dev_is_dma_coherent(dev)) | 410 | if (dev_is_dma_coherent(dev)) |
| 413 | return prot; | 411 | return prot; |
| 414 | #ifdef CONFIG_ARCH_HAS_DMA_WRITE_COMBINE | 412 | #ifdef CONFIG_ARCH_HAS_DMA_WRITE_COMBINE |