summaryrefslogtreecommitdiff
path: root/kernel/dma
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2020-06-11 22:20:29 +0300
committerChristoph Hellwig <hch@lst.de>2020-06-17 10:29:38 +0300
commit96a539fa3bb71f443ae08e57b9f63d6e5bb2207c (patch)
tree629b9409853529afaf4e47afc668c5de2db56d7e /kernel/dma
parent633d5fce78a61e8727674467944939f55b0bcfab (diff)
downloadlinux-96a539fa3bb71f443ae08e57b9f63d6e5bb2207c.tar.xz
dma-direct: re-encrypt memory if dma_direct_alloc_pages() fails
If arch_dma_set_uncached() fails after memory has been decrypted, it needs to be re-encrypted before freeing. Fixes: fa7e2247c572 ("dma-direct: make uncached_kernel_address more general") Signed-off-by: David Rientjes <rientjes@google.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'kernel/dma')
-rw-r--r--kernel/dma/direct.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index c93e3c8e3d01..80d33f215a2e 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -220,7 +220,7 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
arch_dma_prep_coherent(page, size);
ret = arch_dma_set_uncached(ret, size);
if (IS_ERR(ret))
- goto out_free_pages;
+ goto out_encrypt_pages;
}
done:
if (force_dma_unencrypted(dev))
@@ -228,6 +228,11 @@ done:
else
*dma_handle = phys_to_dma(dev, page_to_phys(page));
return ret;
+
+out_encrypt_pages:
+ if (force_dma_unencrypted(dev))
+ set_memory_encrypted((unsigned long)page_address(page),
+ 1 << get_order(size));
out_free_pages:
dma_free_contiguous(dev, page, size);
return NULL;