Skip to content

Commit

Permalink
dma-direct: re-encrypt memory if dma_direct_alloc_pages() fails
Browse files Browse the repository at this point in the history
If arch_dma_set_uncached() fails after memory has been decrypted, it needs
to be re-encrypted before freeing.

Fixes: fa7e224 ("dma-direct: make uncached_kernel_address more general")
Signed-off-by: David Rientjes <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
rientjes authored and Christoph Hellwig committed Jun 17, 2020
1 parent 633d5fc commit 96a539f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernel/dma/direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,19 @@ 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))
*dma_handle = __phys_to_dma(dev, page_to_phys(page));
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;
Expand Down

0 comments on commit 96a539f

Please sign in to comment.