0

In Linux kernel driver, can I initiate DMA with continuous physical memory region when IOMMU is in the middle?

Here's my understanding of IOMMU features:

  • Memory protection for security reasons
  • Provides IOVA for peripherals for DMA to relax 'continuous physical address` restriction. However, if virtual memory is involved, kernel (or something else) should maintain page table and it would be an overhead.

Given above, I wonder if there's an IOMMU hardware that does not support IOVA for the performance reasons.

Also, is there an IOMMU hardware that can be programmed to turn on/off IOVA supports? If it is, does linux kernel provide portable library for it (or vendor specific)?

I'm interested more on the ARM environment, but I'd appreciate any answer about any architecture(s).

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
lymose
  • 71
  • 4
  • You seem confused, and need to study HW datasheets. The typical cost-constrained (Linux) system only has an MMU for the CPU. That means only the CPU uses virtual addressing, and devices (including the DMA Controller) have to access the RAM using physical memory addresses and those pages have to be locked down. But if the system does have an IOMMU, then the kernel can also program devices (e.g. the DMAC) with virtual addresses (assuming the mappings can be shared). The MMU and IOMMU are configurable, and are effectively disabled on powerup. – sawdust May 15 '23 at 04:10
  • 1
    The "*memory protection for security reasons*" comes from using virtual addressing. So if you insist on not using "*IOVA for the performance reasons*", then you also lose the "*memory protection for security reasons*". IOW "*turning off IOVA*" effectively means disabling the IOMMU. – sawdust May 15 '23 at 04:15
  • 1
    BTW contiguous physical memory pages are not a requirement when the DMAC supports DMA chaining operations, and the driver constructs a scatter/gather list (of physical addresses & lengths) for the DMA buffer in virtual memory. – sawdust May 15 '23 at 04:26
  • I thought that I/O virtual memory is how peripheral sees the main memory, so it's separate address space from both { virtual | physical } memory address space which CPU sees the main memory. Am I misunderstanding? – lymose May 15 '23 at 07:10
  • BTW, thank you for the answer and the keyword 'scatter/gather list'. I could find `DMA_ATTR_FORCE_CONTIGUOUS` with the keyword :) – lymose May 15 '23 at 07:24
  • 1
    “The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.” Knuth – stark May 15 '23 at 12:21

0 Answers0