Re: [PATCH] kernel: dma: let dma use vmalloc area

From: Christoph Hellwig
Date: Mon Nov 27 2023 - 04:32:18 EST


On Mon, Nov 27, 2023 at 04:56:45PM +0800, Zhaoyang Huang wrote:
> Sorry for the confusion, please find below codes for more information.
> dma_init_coherent_memory
> memremap
> addr = ioremap_wt(offset, size);
> What I mean is addr is a vmalloc address, which is implicitly mapped
> by dma's framework and not be aware of to the driver.

Yes. And it is only returned from dma_alloc_coherent, which should
never be passed to dma_map_<anything>.

> Please correct me if I am wrong. According to my understanding, cache
> consistency could be solved inside dma_map_page via either
> dma_direct_map_page(swio/arch_sync_dma_for_device) or ops->map_page.
> The original thought of rejecting vmalloc is that this pa is not safe
> as this mapping could go in any time. What I am suggesting is to let
> this kind of va be enrolled.

But that only works for the direct mapping. It does not work for the
additional aliases created by vmap/ioremap/memremap. Now that only
matters if the cache is virtually indexed, which is rather unusual
these days.