Skip to content

rockchip64: fix RK3568 IOMMU v2 page table allocation for NPU workloads - #10366

Open
frepkovsky wants to merge 1 commit into
armbian:mainfrom
frepkovsky:iommu-rk3568-gfp-dma32
Open

rockchip64: fix RK3568 IOMMU v2 page table allocation for NPU workloads#10366
frepkovsky wants to merge 1 commit into
armbian:mainfrom
frepkovsky:iommu-rk3568-gfp-dma32

Conversation

@frepkovsky

@frepkovsky frepkovsky commented Aug 8, 2026

Copy link
Copy Markdown

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:

E RKNN: failed to submit, op id: 1
E RKNN: op name: Conv:/model.0/convsp/Conv
rknn_run fail! ret=-1

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:

.dma_bit_mask = DMA_BIT_MASK(32)
.gfp_flags = GFP_DMA32

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

  • short description: [iommu/rockchip: force 32-bit DMA for RK3568 IOMMU v2](rockchip64: fix RK3568 IOMMU v2 page table allocation for NPU workloads)
  • summary: This patch fixes IOMMU page table allocation on RK3568 boards with more than 4GB of RAM, enabling proper operation of the NPU and other 32-bit DMA devices. The patch forces IOMMU page tables to be allocated below 4GB, which is required for devices that cannot access high memory addresses.
  • example of usage: After applying this patch and installing RKNPU DKMS drivers, users can verify NPU operation with:
# dmesg | grep -i rkn
[drm] Initialized rknpu 0.9.8 for fde40000.npu on minor 1
RKNPU fde40000.npu: RKNPU: DKMS: /dev/rknpu registered (DMA-BUF import only)
RKNPU fde40000.npu: RKNPU: SCMI clock 198 MHz
RKNPU fde40000.npu: RKNPU: devfreq active (SCMI-only, OPP 200-1000 MHz)
RKNPU fde40000.npu: RKNPU: thermal throttling enabled
RKNPU fde40000.npu: RKNPU: sram region: [0x00000000fdcc0000, 0x00000000fdccb000), sram size: 0xb000

# dmesg | grep -i iommu
iommu: Default domain type: Translated
iommu: DMA domain TLB invalidation policy: strict mode
platform fde40000.npu: Adding to iommu group 0
platform fdea0000.video-codec: Adding to iommu group 1
platform fdee0000.video-codec: Adding to iommu group 2
platform fe040000.vop: Adding to iommu group 3 

How Has This Been Tested?

  • Board: ODROID-M1 (RK3568)
  • RAM: 8 GB
  • Kernel: 6.18.42-current-rockchip64
  • Driver: community DKMS RKNPU driver
  • Runtime: RKNN runtime 2.3.2

Results:

  • NPU driver loads successfully
  • /dev/rknpu is created
  • NPU devfreq operates correctly
  • IOMMU remains enabled
  • RKNN YOLOv5 inference completes successfully
  • Object detection results are produced correctly

Checklist:

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

Summary by CodeRabbit

  • Bug Fixes
    • Improved DMA memory handling for Rockchip RK3568 systems.
    • Enhanced compatibility and stability for devices using the Rockchip IOMMU v2 hardware.
    • Resolved issues that could affect memory allocation and device operation when addressing DMA buffers.

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.
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Hey @frepkovsky! 👋

Thanks for submitting your first pull request to the Armbian project — we're excited to have you contributing! 🧡
Your effort doesn’t just improve Armbian — it benefits the entire community of users and developers.

If you'd like to stay informed about project updates or collaborate more closely with the team,
you can optionally share some personal contact preferences at armbian.com/update-data.
This helps us keep in touch without relying solely on GitHub notifications.

Also, don’t forget to ⭐ star the repo if you haven’t already — and welcome aboard! 🚀

@github-actions github-actions Bot added 08 Milestone: Third quarter release size/medium PR with more then 50 and less then 250 lines labels Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Rockchip IOMMU v2 patch now uses a 32-bit DMA mask and GFP_DMA32 for page-table allocations. The patch metadata and rationale were also updated.

Changes

Rockchip IOMMU DMA32 configuration

Layer / File(s) Summary
Force DMA32 for IOMMU v2
patch/kernel/rockchip64-current/0001-iommu-rockchip-force-DMA32-for-rk3568-iommu-v2.patch
iommu_data_ops_v2 now uses DMA_BIT_MASK(32) and GFP_DMA32 instead of a 40-bit mask and zero GFP flags. Patch metadata was updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • armbian/build#9403: Modifies the same Rockchip IOMMU v2 patch to use GFP_DMA32 page-table allocations.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the RK3568 IOMMU v2 page-table allocation fix for NPU workloads, which matches the main change.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added Needs review Seeking for review Hardware Hardware related like kernel, U-Boot, ... Patches Patches related to kernel, U-Boot, ... labels Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

08 Milestone: Third quarter release Hardware Hardware related like kernel, U-Boot, ... Needs review Seeking for review Patches Patches related to kernel, U-Boot, ... size/medium PR with more then 50 and less then 250 lines

Development

Successfully merging this pull request may close these issues.

1 participant