Linux Kernel: Is it OK to leave a streaming DMA mapping open indefinitely?

孤人 提交于 2020-01-03 15:16:08

问题


Many guides on device driver programming suggest that streaming DMA mappings (i.e. those created by dma_map_single() and friends), be held open for as short a time as possible, as they consume resources (i.e. IOMMU mapping resources if the platform has one, or a bounce buffer when required).

In my case, I'm working with a PCIe device capable of 64-bit DMA, so a bounce buffer should be unnecessary (and it doesn't seem like special treatment from the IOMMU is required in this case either, correct?). The data is coming from the device (i.e. it's mapped with DMA_TO_CPU), and the device notifies me when new data is available via interrupt, at which point I trigger a dma_sync_for_cpu() before accessing the data that was just DMA-ed to me.

Are there other reasons that I ought not to just leave the mapping open indefinitely (until the data consumer shuts down, of course)?


回答1:


I've found at least one instance in the Linux kernel source where a streaming DMA mapping may be left open for an indeterminate amount of time:

In the firewire driver code for handling isochronous DMA (drivers/firewire/core-iso.c), a DMA mapping is established when userspace invokes mmap(), and it appears that this mapping stays open for as long as userspace keeps the device open.



来源:https://stackoverflow.com/questions/20979107/linux-kernel-is-it-ok-to-leave-a-streaming-dma-mapping-open-indefinitely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!