Skip to content

Fix DMA page lookup for IOMMU allocations - #121

Open
xiaotianxt wants to merge 1 commit into
cisco:masterfrom
xiaotianxt:codex/fix-iommu-dma-page-lookup
Open

Fix DMA page lookup for IOMMU allocations#121
xiaotianxt wants to merge 1 commit into
cisco:masterfrom
xiaotianxt:codex/fix-iommu-dma-page-lookup

Conversation

@xiaotianxt

Copy link
Copy Markdown

Summary

  • add exanic_virt_to_page() to handle both direct-mapped and vmalloc-backed addresses
  • use it at all five page lookups for memory returned by dma_alloc_coherent()

Root cause

With an IOMMU enabled, the DMA API can assemble a coherent allocation from separate pages and expose its CPU mapping through vmap(). Such an address is in vmalloc space. On x86, virt_to_page() is only valid when virt_addr_valid() is true, so applying it to that mapping produces an invalid struct page * and can fault in page_count() or vm_insert_page().

The helper follows the same split used by the Linux IOMMU DMA implementation when releasing coherent allocations: vmalloc_to_page() for vmalloc addresses and virt_to_page() otherwise.

This addresses the IOMMU-dependent kernel faults reported in #94 and #95. A matching vm_insert_page() fault with IOMMU enabled was also reported in #70.

Impact

Avoid kernel page faults while mapping ExaNIC DMA buffers and while checking their mapping reference counts. Non-IOMMU/direct-mapped allocations keep the existing behavior.

Validation

  • built exanic.ko against Debian 12 x86_64 Linux 6.1.180 headers
  • built exanic.ko against Rocky Linux 9 x86_64 Linux 5.14.0-687.36.1 headers
  • verified that all five DMA page lookups route through the helper

Runtime validation still requires an ExaNIC-equipped Linux host with IOMMU enabled.

@xiaotianxt xiaotianxt changed the title [codex] Fix DMA page lookup for IOMMU allocations Fix DMA page lookup for IOMMU allocations Aug 11, 2026
@xiaotianxt
xiaotianxt marked this pull request as ready for review August 11, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant