Re: [PATCH 1/4] dma-mapping: add a new dma_need_sync API
From: Jonathan Lemon <hidden>
Date: 2020-07-07 15:11:22
Also in:
bpf, linux-iommu, lkml
On Tue, Jul 07, 2020 at 08:47:30AM +0200, Christoph Hellwig wrote:
On Mon, Jul 06, 2020 at 12:42:27PM -0700, Jonathan Lemon wrote:quoted
On Mon, Jun 29, 2020 at 03:03:56PM +0200, Christoph Hellwig wrote:quoted
Add a new API to check if calls to dma_sync_single_for_{device,cpu} are required for a given DMA streaming mapping. +:: + + bool + dma_need_sync(struct device *dev, dma_addr_t dma_addr); + +Returns %true if dma_sync_single_for_{device,cpu} calls are required to +transfer memory ownership. Returns %false if those calls can be skipped.Hi Christoph - Thie call above is for a specific dma_addr. For correctness, would I need to check every addr, or can I assume that for a specific memory type (pages returned from malloc), that the answer would be identical?You need to check every mapping. E.g. this API pairs with a dma_map_single/page call. For S/G mappings you'd need to call it for each entry, although if you have a use case for that we really should add a dma_sg_need_sync helper instea of open coding the scatterlist walk.
My use case is setting up a pinned memory area, and caching the dma
mappings. I'd like to bypass storing the DMA addresses if they aren't
needed. For example:
setup()
{
if (dma_need_sync(dev, addr, len)) {
kvmalloc_array(...)
cache_dma_mappings(...)
}
dev_get_dma(page)
{
if (!cache)
return page_to_phys(page)
return dma_cache_lookup(...)
The reason for doing it this way is that the page in question may be
backed by either system memory, or device memory such as a GPU. For the
latter, the GPU provides a table of DMA addresses where data may be
accessed, so I'm unable to use the dma_map_page() API.
--
Jonathan