Repository navigation
iommu/apple-dart: fail closed when an unmap's TLB retirement fails - #3310
DjDeveloperr wants to merge 6 commits into
Conversation
apple_dart_domain_flush_tlb_range() returns the first error of a DART that could not be powered, could not publish a locked root, or whose TLB invalidate failed or timed out. apple_dart_iotlb_sync() discarded it, and dma-iommu then freed the IOVA, and its caller the pages, while that DART could still translate them. Only managed streams were quarantined on an invalidate failure. Fail closed instead, in iotlb_sync and, for a flush-queue domain, in flush_iotlb_all, which retires its queued unmaps: - A DART that failed while it could be reached (powered by the flush, its commands not gated) has the domain's streams disabled, and each TCR must read back disabled: a disabled stream reaches no memory, whatever its TLB or tables still hold. - A DART that could not be reached (runtime PM did not resume it, or it is dark or closed for its owner's power cycle with a locked root left unpublished), or whose streams did not take the disable, cannot be shown to have stopped: panic, as the T6050 display sleep's live unmap already does, rather than let the pages be handed out again. - The domain then refuses mappings with -EIO until it is freed. Gated commands are not a failure: the DART's sleep list stopped every stream and flushed the TLB before gating them, and nothing translates until a restore. Borrowed DCP domains keep their own failure handling. A flush that succeeds changes nothing. Add KUnit cases that inject each failure: a hardware TLB invalidate timeout, a failed firmware invalidate, an unpublishable locked root (live, then with the display dark), a runtime-PM resume failure, and streams that do not take the disable; that gated commands and a clean flush leave the domain alone; and that a full flush fails closed only for a flush-queue domain. With the failure discarded as before, all the failure cases fail. Signed-off-by: DjDeveloperr <[email protected]>
No check ran the apple-dart KUnit suite. Add drivers/iommu/apple-dart.kunitconfig, list it in MAINTAINERS, and run it in the KUnit matrix; the workflow already starts on drivers/iommu changes. Signed-off-by: DjDeveloperr <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
J700 (MacBook Neo, G17P) at
|
apple_dart_domain_flush_tlb_range() took a fifth argument in the last change, but the two flushes of the DCP shared-buffer publication in apple-dart-dcp-shared.h, built with APPLE_DART_J713_DCP, still passed four. Both publish a new mapping on a DCP domain, which never reaches the retirement record: pass NULL. Update the host harnesses that compile the production functions: - apple-dart-range-tests and bcm4377-radio-sids pass NULL and stub apple_dart_retire_fail(), asserting that their map and attach flushes carry no record; their stand-in DART gains commands_gated. - dart-s2idle-retention's stand-in domain gains retire_failed, which apple_dart_map_pages_unguarded() reads. - The apple-dart-fw fixture defines IS_ENABLED() as off, so the KUnit-only hook in apple_dart_fw_invalidate() drops out. In the CLOSED-gate branch, record the failure before putting the writer's reference, which leaves the put, error and continue lines together as dart-sleep-writer-tests' negative control expects. Signed-off-by: DjDeveloperr <[email protected]>
…sync-fail-closed # Conflicts: # drivers/iommu/apple-dart-test.c
|
Verdict at Blockers: none. At Hardware rows and CI at this head are still owed; see the notes. Checked
Notes, not blocking
EvidenceLocal runs, arm64 QEMU, clang. Rig logs (dmesg and journal captures): |
|
J773g (M4 Mac mini) row at The kernel was built natively on this Mac and booted once as Display and compositor:
DMA and media, before and after one RTC s2idle: the sleep counted as a success (+1, fail +0), the boot was the same, and Wi-Fi reconnected.
Kernel log, whole boot:
No timeout showed up, so the comparison run on main ( |
|
J714s (MacBook Pro 14" M5 Pro, T6050) row at
1. Boot: 0 kernel lines matching 2. Media and DMA smoke, run before the sleep and again after it with the same results:
3. Display:
4. One deep 5. Kernel log and units over the test boot:
A full power-off wasn't run: this unattended lab Mac has no remote way to power back on. The clean reboot path was exercised. |
There was a problem hiding this comment.
Verdict: FINISH, then merge at ef9eb651
Blockers:
- Merge conflict (
CONFLICTING) againstmain; rebase onto currentmainand re-run CI (3 checks were cancelled atef9eb651).
Checked:
- Verified mergeability (
CONFLICTING) and existingJ714sM5 Pro PASS row atef9eb651. - Deferred final diff approval until the conflict against
mainis resolved and CI finishes green.
Evidence
- Head
ef9eb651vsmain:CONFLICTING; CI 25 passed, 3 cancelled.
Resolve apple-dart.c: main now counts dark-display writers under managed_lock and sets display_tlb_stale there; keep that and still record the dark DART's publish result in the retirement record before the writer count drops. Every apple_dart_domain_flush_tlb_range() caller already passes a record (or NULL where nothing is freed). Keep both sides' KUnit cases in apple-dart-test.c and both sides' struct apple_dart fields (commands_gated, display_writers) in the host-test harnesses. Signed-off-by: Ryan Murray <[email protected]>
|
Pushed 9539200, a forward merge of main (1957bb7) into this branch. No force push. |
There was a problem hiding this comment.
Verdict: MERGE at 9539200 after exact-head CI.
Checked: The forward merge records failed dark-DART publication before dropping main’s writer count. Retiring paths pass the retirement record and check it after the flush, while map-only and panic-on-failure paths retain their separate behavior. The updated host fixtures and reported arm64 KUnit exercise the merged implementation. If #3227 lands first, preserve both host fixture changes and recheck the landing tree.
|
code-owner ping @DjDeveloperr: closeout merge at |
|
J716c (16-inch M5 Max, T6050) at EvidenceBatched kernel Vulkan CTS with Borealis Exercised DARTs: GPU (CTS), the DCPs driving |
|
J700 (MacBook Neo, T8140) at
|
|
Merge-train review (non-author, per the agents-desk ask) at |
What: A strict DART unmap (
iotlb_sync), or a flush-queue domain's full flush, whose TLB retirement fails no longer returns as if it worked. Before, the IOVA and pages could be reused while a DART still translated them. Now the domain's streams on the failing DART are stopped (TCR disabled and read back), or, when that can't be shown, the kernel panics as the T6050 live-unmap path already does. The domain then refuses new mappings. The Apple DART KUnit suite also runs in CI now.Tested: no hardware row yet at ef9eb65 (merged with main 2094ccb). On arm64 QEMU with 16 KiB pages and APPLE_DART_J713_DCP=y the apple-dart KUnit suite runs 48/48. With the 4 KiB kunitconfig it runs 39: 37 pass and 2 are skipped because they need 16 KiB pages. The 7 new fault-injection cases pass, and 6 of them fail with the old discard behaviour. apple-dart.o builds W=1-clean with defconfig + asahi.config (J713_DCP=y). The DART host tests (16/16) and bcm4377-radio-sids pass.
Risk: two-way door · all Macs (shared apple-dart code). A flush failure that used to be logged and ignored now stops that device's DMA, or panics if the DART can't be reached or doesn't take the stop. Normal unmaps, gated commands during sleep and DCP-borrowed domains are unchanged.
Not yet: hardware rows on at least two generations; the checklist is under Testing.
Details
Problem.
apple_dart_domain_flush_tlb_range()collects errors from four places:apple_dart_hw_sync_locked());It returns the first one, but
apple_dart_iotlb_sync()andapple_dart_flush_iotlb_all()discarded it. dma-iommu frees the IOVA right afteriommu_iotlb_sync(), and the caller then frees or reuses the pages. A DART that failed to retire the mapping could still translate to them. Only managed streams were quarantined, and only on an invalidate failure. The driver's own comment onapple_dart_t8110_tlb_wait()already names this hazard, and the T6050 display-sleep unmap already panics on it.Change (
struct apple_dart_retire, filled in by the flush when its caller frees what was unmapped):apple_dart_retire_fence()). Each TCR must then read backtcr_disabled. A disabled stream reaches no memory, whatever its TLB or tables hold.apple_dart_retire_stuck()then panics, rather than letting the pages be handed out again.apple_dart_retire_check()setsdomain->retire_failed, andapple_dart_map_pages_unguarded()then returns-EIOuntil the domain is freed.iotlb_sync(strict unmaps), andflush_iotlb_allonly forIOMMU_DOMAIN_DMA_FQdomains, where it retires the queued unmaps. In strict domains a full flush retires nothing, so a failure there is logged as before.-EHOSTDOWN(gated commands): the DART's sleep list stopped every stream and flushed its TLB before gating, and nothing translates until a restore.iotlb_sync_mapand the T6050 live unmap are unchanged.CI. No check ran the apple-dart KUnit suite before. This adds
drivers/iommu/apple-dart.kunitconfigto the KUnit matrix.Evidence
kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/iommu/apple-dart.kunitconfigat ef9eb65: 37 run, 36 passed, 1 skipped (apple_dart_test_independent_remap_rootsneeds 16 KiB kernel pages). No lockdep, BUG or WARNING lines.apple_dart_test_retire_tlb_timeout)-EIO_fw_invalidate)-EIO_publish)_pm)-EIO_unfenced)_flush_queue)_gated_and_clean)The fix commit 4e39888 passes
NULLat the two DCP shared-buffer publication flushes inapple-dart-dcp-shared.h, which are built withAPPLE_DART_J713_DCP. Both are map flushes on a DCP domain, which never reaches the retirement record. The same commit updates the host harnesses that compile the production functions:apple_dart_retire_fail()that asserts no record is passed;retire_failed;IS_ENABLED()as off.kunit.pywith--kconfig_add CONFIG_ARM64_16K_PAGES=y --kconfig_add CONFIG_APPLE_DART_J713_DCP=y: 48 run, 48 passed.make W=1 drivers/iommu/apple-dart.owith defconfig + asahi.config: no warnings.run-host-tests.py --only dart: 16/16, and--only bcm4377-radio: 1/1.The panic is a static-stub hook in the tests. The existing
apple_dart_test_unmap_flush_after_publish_failurestill passes: both DARTs are invalidated and PM references stay balanced.make W=1 drivers/iommu/apple-dart.o: no warnings. checkpatch --strict: both commits clean.Testing still owed (hardware)
Shared apple-dart code needs rows on at least two generations, for example J714s (M5 Pro) plus J700 (Neo) or J516s (M3 Pro). On each Mac at ef9eb65:
unmapped pages not retired|streams .* stopped|failed to power DART for TLB|failed to publish host page-table|Kernel panic.dd), a USB storage copy, and Wi-Fi traffic.memon J714s, a test sleep on J700), then repeat 2.Risk
Two-way: a revert restores the old behaviour. The new behaviour only applies when a flush fails, which the old code logged and ignored. A DART that hits one (for example a display DART whose invalidate stays busy past its extended timeout) now has its streams stopped, or the kernel panics if they can't be stopped, where before it carried on with pages possibly still mapped.