Re: [RFC PATCH 1/3] dma-mapping: introduce a new dma api dma_addr_to_phys_addr()
From: Laurentiu Tudor
Date: Wed Oct 23 2019 - 07:54:26 EST
Hi Robin,
On 22.10.2019 16:25, Robin Murphy wrote:
> On 22/10/2019 13:55, Laurentiu Tudor wrote:
>> From: Laurentiu Tudor <laurentiu.tudor@xxxxxxx>
>>
>> Introduce a new dma map op called dma_addr_to_phys_addr() that converts
>> a dma address to the physical address backing it up and add wrapper for
>> it.
>
> I'd really love it if there was a name which could encapsulate that this
> is *only* for extreme special cases of constrained descriptors/pagetable
> entries/etc. where there's simply no practical way to keep track of a
> CPU address alongside the DMA address, and the only option is this
> potentially-arbitrarily-complex operation (I mean, on some systems it
> may end up taking locks and poking hardware).
>
> Either way it's tricky - much as I don't like adding an interface which
> is ripe for drivers to misuse, I also really don't want hacks like
> bdf95923086f shoved into other APIs to compensate, so on balance I'd
> probably consider this proposal ever so slightly the lesser evil.
We had an internal discussion over these points you are raising and
Madalin (cc-ed) came up with another idea: instead of adding this prone
to misuse api how about experimenting with a new dma unmap and dma sync
variants that would return the physical address by calling the newly
introduced dma map op. Something along these lines:
* phys_addr_t dma_unmap_page_ret_phys(...)
* phys_addr_t dma_unmap_single_ret_phys(...)
* phys_addr_t dma_sync_single_for_cpu_ret_phys(...)
I'm thinking that this proposal should reduce the risks opened by the
initial variant.
Please let me know what you think.
---
Thanks & Best Regards, Laurentiu