Skip to content

Commit

Permalink
dma-direct: don't call dma_set_decrypted for remapped allocations
Browse files Browse the repository at this point in the history
[ Upstream commit 5570449 ]

Remapped allocations handle the encrypted bit through the pgprot passed
to vmap, so there is no call dma_set_decrypted.  Note that this case is
currently entirely theoretical as no valid kernel configuration supports
remapped allocations and memory encryption currently.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Christoph Hellwig authored and gregkh committed Jun 9, 2022
1 parent 82b3f04 commit 9ba801c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions kernel/dma/direct.c
Expand Up @@ -241,8 +241,6 @@ void *dma_direct_alloc(struct device *dev, size_t size,
__builtin_return_address(0));
if (!ret)
goto out_free_pages;
if (dma_set_decrypted(dev, ret, size))
goto out_free_pages;
memset(ret, 0, size);
goto done;
}
Expand Down Expand Up @@ -316,12 +314,13 @@ void dma_direct_free(struct device *dev, size_t size,
dma_free_from_pool(dev, cpu_addr, PAGE_ALIGN(size)))
return;

dma_set_encrypted(dev, cpu_addr, 1 << page_order);

if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr))
if (IS_ENABLED(CONFIG_DMA_REMAP) && is_vmalloc_addr(cpu_addr)) {
vunmap(cpu_addr);
else if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))
arch_dma_clear_uncached(cpu_addr, size);
} else {
if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_CLEAR_UNCACHED))
arch_dma_clear_uncached(cpu_addr, size);
dma_set_encrypted(dev, cpu_addr, 1 << page_order);
}

__dma_direct_free_pages(dev, dma_direct_to_page(dev, dma_addr), size);
}
Expand Down

0 comments on commit 9ba801c

Please sign in to comment.