I've been reading about IOMMU support in Linux and have some questions regarding page tables in IOMMU:
- Does the IOMMU uses the CPU MMU page tables for storing VA->PA mapping?
- If not i.e. the virtual addresses are different then are the mappings created per device or per IOMMU unit?
I haven't looked at any driver code yet so it would be great if anyone can point me to some sample driver code.
Thanks in advance.
No. There are many processes in OS, and every process has its own VA->PA mapping (they all running in separate virtual address spaces).
There is physical memory, controlled by memory controller. And there are devices which want to access physical memory: CPU and external bus controller. CPU has own translation and bus controller has own.
Mappings are created according to capabilities of IOMMU. Some simple IOMMU may have one global mapping for the device bus root controller (PCI-express root comples). Complex IOMMU like Intel's VT-d may have several mappings or nested translations, selected based on some per-port rules. (But two devices behind bridge typically will have same translation.)
https://www.kernel.org/doc/Documentation/Intel-IOMMU.txt
https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt
(check also picture near "Here's a picture and some examples:" in the https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt)
Check also https://events.linuxfoundation.org/sites/events/files/slides/20140429-dma.pdf (2014) and http://www.linuxplumbersconf.org/2014/wp-content/uploads/2014/10/LPC2014_IOMMU.txt
And http://developer.amd.com/wordpress/media/2012/10/IOMMU-ben-yehuda.pdf paper (2012) for history of device memory remapping and IOMMU usage for virtualization.
While osgx's answer is true with historical use of IOMMUs in kernel, shared virtual memory use cases, specially with PCIe PASID will require sharing or shadowing IOMMU and CPU page tables, such that a pointer/VA (say to a pinned buffer) can be passed directly from user space driver to the device without any dma_map related kernel services. Of course this will require new APIs for user space to be able to request SVM/shared page tables.
See https://archive.fosdem.org/2016/schedule/event/intel_svm/attachments/slides/1269/export/events/attachments/intel_svm/slides/1269/FOSDEM_2016___SVM_on_Intel_Graphics.pdf