rockchip64: fix RK3568 IOMMU v2 page table allocation for NPU workloads - #10366
rockchip64: fix RK3568 IOMMU v2 page table allocation for NPU workloads#10366frepkovsky wants to merge 1 commit into
Conversation
This patch originates from here: https://lore.kernel.org/all/20260331075010.1463-1-midgy971@gmail.com/#t On boards with more than 4 GB of RAM (e.g. 8 GB LPDDR4X), removing GFP_DMA32 causes two distinct failure modes: 1. Direct allocation above 4 GB: iommu_alloc_pages_sz() may return memory above 0x100000000. The hardware page-table walker issues a bus error trying to dereference those addresses, causing an IOMMU fault on the first DMA transaction. 2. SWIOTLB bounce-buffer poisoning: without GFP_DMA32, page tables land above the SWIOTLB window. dma_map_single() with DMA_BIT_MASK(32) then bounces them into a buffer below 4 GB. rk_dte_get_page_table() returns phys_to_virt() of the bounce buffer address; PTEs are written there; the next dma_sync_single_for_device(DMA_TO_DEVICE) copies the original (zero) data back over the bounce buffer, silently erasing the freshly written PTEs. The IOMMU faults because every PTE reads as zero. Restore GFP_DMA32 (and DMA_BIT_MASK(32)) for iommu_data_ops_v2, which currently only serves "rockchip,rk3568-iommu" in mainline.
Hey @frepkovsky! 👋Thanks for submitting your first pull request to the Armbian project — we're excited to have you contributing! 🧡 If you'd like to stay informed about project updates or collaborate more closely with the team, Also, don’t forget to ⭐ star the repo if you haven’t already — and welcome aboard! 🚀 |
📝 WalkthroughWalkthroughThe Rockchip IOMMU v2 patch now uses a 32-bit DMA mask and ChangesRockchip IOMMU DMA32 configuration
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
This PR updates the RK3568 IOMMU v2 patch originally introduced in PR #9403.
While testing NPU enablement on an ODROID-M1 (RK3568, 8 GB RAM), I found that the existing patch was not sufficient to reliably support RKNN inference workloads. The NPU driver and runtime initialized correctly, but inference failed when the first NPU job was submitted.
Problem
With the NPU IOMMU enabled, RKNN model execution failed with errors similar to:
As a temporary workaround, disabling the NPU IOMMU in the DTS allowed inference to complete successfully, indicating that the issue was related to the IOMMU path rather than the NPU driver, runtime, clocks, power domain, or devfreq configuration.
Root Cause
The RK3568 NPU appears to be unable to reliably operate when IOMMU v2 page tables are allocated above the 4 GB physical address boundary.
The existing patch addressed part of the issue, but iommu_data_ops_v2 was still configured in a way that allowed allocations outside the range that the NPU can handle.
Fix
Update iommu_data_ops_v2 to use:
Discussion and Background
Updated IOMMU patch is based on the original upstream discussion
The issue and investigation details have been discussed on the Armbian forum:
ODROID-M1 NPU fully working on Armbian 6.18.x
The forum thread contains the testing history, DTS changes, NPU bring-up work, troubleshooting steps, and validation results that led to identifying the incomplete IOMMU v2 configuration.
Documentation summary for feature / change
How Has This Been Tested?
Results:
Checklist:
Please delete options that are not relevant.
Summary by CodeRabbit