Skip to content

iommu/apple-dart: report IOMMU_CAP_CACHE_COHERENCY for coherent devices - #3117

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/apple-dart-cache-coherency-cap
Dec 1, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/apple-dart-cache-coherency-cap

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What: Report IOMMU_CAP_CACHE_COHERENCY in apple_dart_capable() for DMA-coherent devices behind ordinary unlocked Apple DARTs, unblocking vfio-pci and iommufd device passthrough.
Tested: Pending 2-generation hardware rows at 07c48e984d47 (arm64 KUnit 37/37 pass including apple_dart_test_cache_coherency, CONFIG_APPLE_DART_J713_DCP=y/n CONFIG_WERROR=y compile pass, targeted apple-dart host tests pass, checkpatch --strict 0/0/0).
Risk: two-way door · all Macs (shared apple-dart IOMMU driver; only affects IOMMU_CAP_CACHE_COHERENCY queries from VFIO/iommufd/vDPA, leaving DMA API paths unchanged).

Not yet

  • Boot a Mac from each of two supported Apple generations and verify the IOMMU groups and a safe vfio-pci bind.

2-generation hardware rows at 07c48e984d47 (boot + regression check on two Apple Silicon generations plus vfio-pci/iommufd bind and passthrough verification).

Details
  • Upstream/Asahi drivers/iommu/apple-dart.c only handled IOMMU_CAP_DEFERRED_FLUSH in apple_dart_capable(). Both vfio_register_group_dev() and iommufd_bind_iommu() require device_iommu_capable(dev, IOMMU_CAP_CACHE_COHERENCY) and otherwise fail with -EINVAL.
  • APPLE_DART (T8020/T8103) operates on a coherent fabric for DMA-coherent masters, and APPLE_DART2 (drivers/iommu/io-pgtable-dart.c) clears APPLE_DART2_PTE_PROT_NO_CACHE whenever IOMMU_CACHE is present in prot.
  • apple_dart_capable() now checks dev_is_dma_coherent(dev) and walks every DART in cfg->stream_maps (for_each_stream_map), rejecting devices with missing/empty configs or any DART that cannot safely support exclusive paging and blocked-domain ownership (pgsize > PAGE_SIZE, locked, managed_sids, retained, retained_mtp, live_mtp, cold_ane, isp_host, preserve_display, v27_provider, or borrowed DCP/display streams).
  • No chip/board/SoC allowlists: eligibility derives strictly from dev_is_dma_coherent(dev) and DART hardware/DT/driver state, covering unlocked PCIe and USB4 PCIe-C DARTs across M1-M5/Neo while excluding non-coherent (dma-noncoherent), managed-SID, retained, borrowed, and locked DARTs.
  • IOMMU_CAP_ENFORCE_CACHE_COHERENCY / .enforce_cache_coherency is intentionally not claimed because Apple DART does not enforce PCIe No-Snoop overrides in hardware, and neither vfio-pci, iommufd, nor arm64 KVM require it.
Evidence
  • Base: origin/main (2943fffab7db7)
  • Head: 07c48e984d47b0a0dffb9b96b217d89ac288b4e1
  • ./scripts/checkpatch.pl --strict --git HEAD: 0 errors, 0 warnings, 0 checks
  • Arm64 KUnit (CONFIG_APPLE_DART=y, CONFIG_APPLE_DART_J713_DCP=y, CONFIG_APPLE_DART_KUNIT_TEST=y, CONFIG_ARM64_16K_PAGES=y, CONFIG_WERROR=y): 37/37 passed (apple-dart 36 subtests including apple_dart_test_cache_coherency, apple-dart-firmware-leaf 1 subtest)
  • Non-DCP build check (CONFIG_APPLE_DART_J713_DCP=n, CONFIG_WERROR=y): drivers/iommu/apple-dart.o compiled cleanly
  • Targeted host tests: apple-dart-dapf-tests.py, apple-dart-fw-tests.py, apple-dart-fw-harness-tests.py, apple-dart-range-tests.py, dart-sleep-snapshot-tests.py, dart-sleep-writer-tests.py all passed

Inherited from upstream/Asahi apple-dart.c, apple_dart_capable() only
handles IOMMU_CAP_DEFERRED_FLUSH and never reports
IOMMU_CAP_CACHE_COHERENCY. Because vfio_register_group_dev() and
iommufd_bind_iommu() require IOMMU_CAP_CACHE_COHERENCY before allowing
userspace to map DMA pages with IOMMU_CACHE, every device behind an
Apple DART is rejected with -EINVAL when binding to vfio-pci or iommufd.

Report IOMMU_CAP_CACHE_COHERENCY when dev_is_dma_coherent(dev) holds
and every DART in the device's stream map can safely support exclusive
paging and blocked-domain ownership:

- APPLE_DART (T8020/T8103) operates on a coherent interconnect for
  DMA-coherent masters, and APPLE_DART2 (T6000/T8110/Gen3) clears
  APPLE_DART2_PTE_PROT_NO_CACHE in io-pgtable-dart.c whenever
  IOMMU_CACHE is set.
- Non-coherent devices (dev_is_dma_coherent(dev) == false, including
  nodes marked dma-noncoherent in DT) and devices with no valid stream
  map continue to return false.
- Every DART in cfg->stream_maps is checked; DARTs that cannot support
  independent paging/blocking (pgsize > PAGE_SIZE, locked, managed_sids,
  retained, retained_mtp, live_mtp, cold_ane, isp_host,
  preserve_display, v27_provider, or borrowed DCP/display streams)
  return false.
- IOMMU_CAP_ENFORCE_CACHE_COHERENCY and .enforce_cache_coherency are
  intentionally not advertised: Apple DART does not enforce PCIe
  No-Snoop overrides in hardware, and neither vfio-pci, iommufd, nor
  arm64 KVM require it.

Add KUnit coverage in apple_dart_test_cache_coherency() exercising
coherent, non-coherent, multi-DART, and ineligible DART configurations.

Signed-off-by: Dj <[email protected]>
@malik-na

Copy link
Copy Markdown
Member

M1 Air row at 07c48e9. Boot and read-only checks only.

Mac Build Result
J313 / T8103 (MacBook Air M1) 07c48e9 (7.3.0-lab07c48e98) boots in 26 s, no warnings or oopses, 0 regressions in omarchy-m-test against 7.3.0-1-1-ARCH

What I checked:

  • IOMMU groups 0 to 16 come up as before. Wi-Fi (01:00.0, brcmfmac) and Bluetooth (01:00.1, hci_bcm4377) share group 16, so a passthrough needs both on vfio-pci.
  • No new apple-dart or iommu lines in dmesg compared with the known-good kernel. Wi-Fi is up on brcmfmac.
  • Config: VFIO=m, VFIO_CONTAINER=y, VFIO_IOMMU_TYPE1=m, VFIO_PCI=m, KVM=y. CONFIG_IOMMUFD is not set in this build, so there's no /dev/iommu and only the legacy VFIO container path can be tried here.

Not done: the vfio-pci bind and the guest passthrough. Wi-Fi is the Air's only network, so I didn't unbind it on an unattended boot. That still needs a run at the Mac. The second-generation row is still open too.

This PR now conflicts with main in drivers/iommu/apple-dart.c (57418f6, 33434da touch it). This row will need a rerun on the rebased head.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 30, 2026 20:45
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 30, 2026 20:45
@github-actions github-actions Bot added area:platform Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at 8d90bf8c: not ready yet

Check Detail
CI at head no failing: apple-build, host-tests, pr-text / pr-text, KUnit ane-boot, KUnit ane-pm, KUnit dcp-fabric
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at 8d90bf8c
Conflicts ok none
PR text ok Risk: two-way · all Macs (shared apple-dart IOMMU driver; only affects IOMMUCAPCACHECOHERENCY queries from VFIO/iommufd/vDPA, leaving DMA API paths unchanged).

Areas: area:platform

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: REQUEST CHANGES at 07c48e98

Blockers:

  1. Branch is CONFLICTING with main. Rebase/merge current main so apple-dart applies cleanly (MERGEABLE) and full CI executes at the rebased head.
  2. Incomplete hardware verification. Only a read-only boot row on M1 Air (J313) has been posted; a second GPU/SoC generation row plus VFIO/iommufd coherency check at the rebased head remains open.

Checked:

  • Metadata and diff summary (+129/-0, 2 files), CONFLICTING against main.
Evidence
  • PR body notes pending 2-generation hardware rows; J313 row (2026-11-30) covered boot/read-only checks only, and the branch now conflicts with main.

Resolve apple-dart-test.c: keep the cache-coherency case from this branch beside the cases main added.

Signed-off-by: DjDeveloperr <[email protected]>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 8d90bf8c0537

Blockers:

  • Hosted CI at 8d90bf8c0537 is still queued (21 jobs queued: apple-build, host-tests, pr-text, readiness, and KUnit suites including apple_dart_test_cache_coherency) — wait for all checks to complete green.
  • Hardware check on the changed IOMMU_CAP_CACHE_COHERENCY path (e.g., VFIO/iommufd coherency probe or a second SoC generation boot alongside the read-only J313 M1 Air boot row at 07c48e98).

Checked:

  • Audited the full 2-file diff (drivers/iommu/apple-dart.c and drivers/iommu/apple-dart-test.c, +129/-0, MERGEABLE against main):
    • apple_dart_supports_cache_coherency() conservatively gates IOMMU_CAP_CACHE_COHERENCY on dev_is_dma_coherent(dev) and verifies every backing DART in cfg->stream_maps has pgsize <= PAGE_SIZE and is unlocked, unmanaged, non-retained, non-MTP, non-cold-ANE, non-ISP-host, non-display, non-v27-provider, and non-borrowed.
    • Merge commit 8d90bf8c0537 cleanly retains apple_dart_test_cache_coherency alongside the KUnit cases added on main.
Evidence
  • Head: 8d90bf8c05372d16e8bfde097abde730a43b024c (base main, MERGEABLE).
  • Status checks at review time: 21 queued, 3 skipped, 0 failed.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the conflict-pass merge commit 8d90bf8 only: single-file union, no hand edits. The resolution keeps what each side had and adds nothing outside the conflict. Approved for the merge-up; merging still waits on CI and the rows at this head.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 8d90bf8c0537

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Audited the full 2-file diff (drivers/iommu/apple-dart.c and drivers/iommu/apple-dart-test.c, +129/-0, MERGEABLE against main):

  • apple_dart_supports_cache_coherency() conservatively gates IOMMU_CAP_CACHE_COHERENCY on dev_is_dma_coherent(dev) and verifies every backing DART in cfg->stream_maps has pgsize <= PAGE_SIZE and is unlocked, unmanaged, non-retained, non-MTP, non-cold-ANE, non-ISP-host, non-display, non-v27-provider, and non-borrowed.
  • Merge commit 8d90bf8c0537 cleanly retains apple_dart_test_cache_coherency alongside the KUnit cases added on main.

Follow-ups (not blocking): queued CI; coherency-path hardware check

@RyanTheTide

Copy link
Copy Markdown
Contributor

J616s (MacBook Pro 14", M4 Pro, T6040) at 8d90bf8c05372d16e8bfde097abde730a43b024c: PASS - vfio-pci bind of the idle GL9755 SD host (0000:02:00.0, alone in IOMMU group 29, DMA-FQ, no card): the probe succeeds, and /dev/vfio/29 and vfio-dev/vfio0 appear. The device then goes back to sdhci-pci and mmc0 returns. On the Mac's default kernel (7.3.0-aurora-edge 933f822), the same bind fails: vfio-pci 0000:02:00.0: probe with driver vfio-pci failed with error -22. On both boots: 0 DART faults, s2idle 3/3, 3 DCPs bound, Wi-Fi up. Only the bind was checked, not passthrough to a guest. J615 (M3 Air, T8122) also booted this kernel twice with 0 DART faults; its only PCIe group is Wi-Fi/BT, which I did not bind. Kernel = main 27d585c8dfb3 + #2161 #3224 #3117 #3217 #3413 (exact heads), one grub2-reboot one-shot boot, default command line and Stage 2.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging at 8d90bf8c0537 (B2 merge train, 12-01 merge bar). Approval at this head: RyanTheTide,aurora-silicon-review[bot]. Row: J616s (M4 Pro) row at this head (B2 rows kernel = main 27d585c + #2161 #3224 #3117 #3217 #3413), posted on this PR. CI: linux train L7 = main 27d585c + #2161 #3224 #3117 #3217: Apple driver compile pass, planned KUnit dcp-topology/jpeg/scaler/asahi/sep/aop pass. Revert: git revert -m 1 <merge commit>.

@RyanTheTide
RyanTheTide merged commit f018df5 into main Dec 1, 2026
6 of 27 checks passed
@RyanTheTide
RyanTheTide deleted the fix/apple-dart-cache-coherency-cap branch December 1, 2026 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants