Skip to content

Commit 17c4a2a

Browse files
thomashvmwsuryasaimadhu
authored andcommitted
dma-mapping: Fix dma_pgprot() for unencrypted coherent pages
When dma_mmap_coherent() sets up a mapping to unencrypted coherent memory under SEV encryption and sometimes under SME encryption, it will actually set up an encrypted mapping rather than an unencrypted, causing devices that DMAs from that memory to read encrypted contents. Fix this. When force_dma_unencrypted() returns true, the linear kernel map of the coherent pages have had the encryption bit explicitly cleared and the page content is unencrypted. Make sure that any additional PTEs we set up to these pages also have the encryption bit cleared by having dma_pgprot() return a protection with the encryption bit cleared in this case. Signed-off-by: Thomas Hellstrom <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Acked-by: Tom Lendacky <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6db73f1 commit 17c4a2a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/dma/mapping.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ EXPORT_SYMBOL(dma_get_sgtable_attrs);
154154
*/
155155
pgprot_t dma_pgprot(struct device *dev, pgprot_t prot, unsigned long attrs)
156156
{
157+
if (force_dma_unencrypted(dev))
158+
prot = pgprot_decrypted(prot);
157159
if (dev_is_dma_coherent(dev) ||
158160
(IS_ENABLED(CONFIG_DMA_NONCOHERENT_CACHE_SYNC) &&
159161
(attrs & DMA_ATTR_NON_CONSISTENT)))

0 commit comments

Comments
 (0)