Re: [RFC PATCH V2 0/7] Do not read from descripto ring
From: Christoph Hellwig
Date: Thu May 06 2021 - 08:40:35 EST
On Thu, May 06, 2021 at 04:12:17AM -0400, Michael S. Tsirkin wrote:
> Let's try for just a bit, won't make this window anyway:
>
> I have an old idea. Add a way to find out that unmap is a nop
> (or more exactly does not use the address/length).
> Then in that case even with DMA API we do not need
> the extra data. Hmm?
So we actually do have a check for that from the early days of the DMA
API, but it only works at compile time: CONFIG_NEED_DMA_MAP_STATE.
But given how rare configs without an iommu or swiotlb are these days
it has stopped to be very useful. Unfortunately a runtime-version is
not entirely trivial, but maybe if we allow for false positives we
could do something like this
bool dma_direct_need_state(struct device *dev)
{
/* some areas could not be covered by any map at all */
if (dev->dma_range_map)
return false;
if (force_dma_unencrypted(dev))
return false;
if (dma_direct_need_sync(dev))
return false;
return *dev->dma_mask == DMA_BIT_MASK(64);
}
bool dma_need_state(struct device *dev)
{
const struct dma_map_ops *ops = get_dma_ops(dev);
if (dma_map_direct(dev, ops))
return dma_direct_need_state(dev);
return ops->unmap_page ||
ops->sync_single_for_cpu || ops->sync_single_for_device;
}