Re: Regression due to d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)

From: Lucas Stach
Date: Wed Aug 07 2019 - 11:24:24 EST


Am Dienstag, den 06.08.2019, 17:44 +0200 schrieb Christoph Hellwig:
> On Tue, Aug 06, 2019 at 04:06:58PM +0200, Lucas Stach wrote:
> >
> > dma_direct_free_pages() then needs the same check, as otherwise the cpu
> > address is treated as a cookie instead of a real address and the
> > encryption needs to be re-enabled.
>
> Ok, lets try this one instead:
>
> --
> From 3a7aa9fe38a5eae5d879831b4f8c1032e735a0b6 Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@xxxxxx>
> Date: Tue, 6 Aug 2019 14:33:23 +0300
> Subject: dma-direct: fix DMA_ATTR_NO_KERNEL_MAPPING
>
> The new DMA_ATTR_NO_KERNEL_MAPPING needs to actually assign
> a dma_addr to work.ÂÂAlso skip it if the architecture needs
> forced decryption handling, as that needs a kernel virtual
> address.
>
> Fixes: d98849aff879 (dma-direct: handle DMA_ATTR_NO_KERNEL_MAPPING in common code)
> Signed-off-by: Christoph Hellwig <hch@xxxxxx>
> ---
> Âkernel/dma/direct.c | 7 +++++--
> Â1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
> index 59bdceea3737..4c211c87a719 100644
> --- a/kernel/dma/direct.c
> +++ b/kernel/dma/direct.c
> @@ -130,11 +130,13 @@ void *dma_direct_alloc_pages(struct device *dev, size_t size,
> Â if (!page)
> Â return NULL;
> Â
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + ÂÂÂÂ!force_dma_unencrypted(dev)) {
> Â /* remove any dirty cache lines on the kernel alias */
> Â if (!PageHighMem(page))
> Â arch_dma_prep_coherent(page, size);
> Â /* return the page pointer as the opaque cookie */
> + *dma_handle = phys_to_dma(dev, page_to_phys(page));

I would suggest to place this line above the comment, as the comment
only really applies to the return value. Other than this nitpick, this
matches my understanding of the required changes, so:

Reviewed-by: Lucas Stach <l.stach@xxxxxxxxxxxxxx>


> Â return page;
> Â }
> Â
> @@ -178,7 +180,8 @@ void dma_direct_free_pages(struct device *dev, size_t size, void *cpu_addr,
> Â{
> Â unsigned int page_order = get_order(size);
> Â
> - if (attrs & DMA_ATTR_NO_KERNEL_MAPPING) {
> + if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) &&
> + ÂÂÂÂ!force_dma_unencrypted(dev)) {
> Â /* cpu_addr is a struct page cookie, not a kernel address */
> Â __dma_direct_free_pages(dev, size, cpu_addr);
> Â return;