Do we always need to reserve an iova before iommu_map?
Hi all,
According to the routine of iommu_dma_alloc(), it allocates an iova then does iommu_map() to map the iova to a physical address of new allocated pages. However, in remoteproc_core.c, I see its code try to iommu_map() without having an alloc_iova() or alloc_iova_fast().
Is it safe to do so? If an iova range is not allocated but mapped, would a later iommu_dma_alloc() happen to hit this iova range when doing its alloc_iova() and then fail to map?
And I am not very familiar with remoteproc code, so if I am missing something, please kindly educate me.
Thanks
Nicolin
Quoted 7 lines · Nicolin Chen
Hi all,
According to the routine of
iommu_dma_alloc(), it allocates an iova then doesiommu_map()to map the iova to a physical address of new allocated pages. However, inremoteproc_core.c, I see its code try toiommu_map()without having analloc_iova()oralloc_iova_fast().
Quoted 6 lines
Is it safe to do so? If an iova range is not allocated but mapped, would a later
iommu_dma_alloc()happen to hit this iova range when doing itsalloc_iova()and then fail to map?And I am not very familiar with remoteproc code, so if I am missing something, please kindly educate me.
AFAICS that area of the remoteproc code is using its own IOMMU domain, so it's free to manage that domain's address space however it wants - the generic IOVA allocator is a good option for the DMA API where the only constraint is that the address we get fits within a mask, but drivers with more specific requirements may well be better off using other allocation methods. See also various DRM drivers (Tegra/Rockchip/etc.) that do similar, using a drm_mm to manage the address space.
Robin.
Thanks for the reply Robin.
Quoted 10 lines · Robin Murphy
Quoted 9 lines · Nicolin Chen
According to the routine of
iommu_dma_alloc(), it allocates an iova then doesiommu_map()to map the iova to a physical address of new allocated pages. However, inremoteproc_core.c, I see its code try toiommu_map()without having analloc_iova()oralloc_iova_fast().Is it safe to do so? If an iova range is not allocated but mapped, would a later
iommu_dma_alloc()happen to hit this iova range when doing itsalloc_iova()and then fail to map?
Quoted 5 lines
Quoted 2 lines
And I am not very familiar with remoteproc code, so if I am missing something, please kindly educate me.
AFAICS that area of the remoteproc code is using its own IOMMU domain, so it's free to manage that domain's address space however it wants - the
I see. So it seems that it would be safe to map to an iova without dealing with iova_domain, as long as the device is attached to a separately allocated iommu_domain; for those who use DMA API would need to go through iova management.
Quoted 5 lines
generic IOVA allocator is a good option for the DMA API where the only constraint is that the address we get fits within a mask, but drivers with more specific requirements may well be better off using other allocation methods. See also various DRM drivers (Tegra/Rockchip/etc.) that do similar, using a
drm_mmto manage the address space.
Yea, I am aware of DRM drivers that manage both iommu_domain and iova_domain manually. But it feels a bit heavy for our use case:
We have a downstream driver using DMA API for iommu_dma_alloc(). And it is happy with the API because the same API works for both IOMMU and non-IOMMU configurations. But it also has one single allocation that requires (same as remoteproc) to iommu_map to a hard coded iova. Although it's so far a downstream use case, we want to seek for a solution that could be closer to the mainline.
The current solution seems to give up the API and add own IOMMU domain and iova management like DRM drivers. Could there be any way of reserving an IOVA without giving up the API?
Thank you
Nicolin