Repository navigation
iommu/apple-dart: fix the J700 internal display and SLC with handed-off display DARTs - #235
Conversation
Since the boot loader marks the T8140 display DARTs with apple,firmware-root-handoff, the J700 internal display stays on simpledrm. disp0_dart fails to probe: iommu apple-dart.412300000.iommu: IOMMU driver was not able to establish FW requested direct mapping. apple-dart 412300000.iommu: probe with driver apple-dart failed with error -16 and the internal DCP waits for it forever. The display subsystem is one domain over two DARTs, disp0 and dispext0. Its framebuffer and region94 reservations come from disp0's firmware tables, which scan out the boot framebuffer. dispext0 does not hold the same translation, so apple_dart_inherited_phys() cannot report the region as mapped for the whole domain, and the core maps it. In handoff mode apple_dart_check_fw_map() refuses any page in a firmware-held slot, including one that repeats the firmware translation exactly, so the direct mapping fails with -EBUSY both before and after attach and the DART probe is rolled back. Without the handoff property the same DARTs take the retained-root mirror path, which accepts such a page when the firmware leaf maps it to the same physical address with the same protection. With that path the same 7.2.10 package bound the internal DCP on this machine before the boot loader started setting the property. Apply the same per-page rule to handed-off slots. Every other page in a firmware slot is still refused, four-level streams still refuse everything, and apple_dart_publish_root() already requires the whole Linux leaf to mirror the firmware leaf before it accepts the slot, so the firmware slot is never written. dispext0 receives the copy in a vacant root slot. In the host fixture, core-second-dart reproduces the two-DART -EBUSY on the old code. The map cases now cover a hole, a wrong physical address, a wrong protection, a changed root and a four-level stream, all still refused. The T8112 SEP DMA host test, which compiles apple_dart_check_fw_map(), stubs the new helper like the other firmware-slot helpers it does not reach. (cherry picked from commit e772e7f) Signed-off-by: DjDeveloperr <[email protected]>
A whole-stream invalidate on a T8140 DART can break DMA that still runs through firmware-held root slots, such as the boot framebuffer scanout of the internal display, as apple_dart_fw_invalidate() describes. Range flushes already route both the retained-root mirror and the reserved-table handoff through apple_dart_fw_invalidate(), but the stream invalidate used at attach, at release and on resume did so only for the mirror path. A handed-off DART, which the boot loader now selects for the J700 display DARTs, got a whole-stream flush there. Treat handed-off DARTs like mirrored ones: invalidate only the slots Linux published, by DVA range, and do it while retiring a root, before the root is unmapped. This is what these DARTs did before the boot loader started handing their roots off. (cherry picked from commit ff5c39a) Signed-off-by: DjDeveloperr <[email protected]>
2a98a50 to
e2fecd9
Compare
|
Hardware result on a fresh omarchy-pkgs install (J700, 10-28) The released display-subsystem never binds, apple-drm never loads, the panel stays on simpledrm, and apple-mcc never binds either. The same tree plus this PR's two commits (95e86af, e2fecd9), packaged as
Host reproduction, using the production function bodies compiled by
|
maralcbr
left a comment
There was a problem hiding this comment.
Thanks @DjDeveloperr, good find, and your J700 result on a fresh install (internal display lost on 6/6 boots with aurora8, back with this PR) makes this urgent. The admission rule is right. A firmware-held slot only accepts a page its firmware leaf already maps to the same physical address with the same protection (apple-dart.c:675-687, :1629-1634). Four-level streams still refuse, and apple_dart_publish_root() never writes the firmware slot. Routing the handoff stream invalidate through apple_dart_fw_invalidate() (:1262-1265) is right too.
I checked the blast radius. Handoff only turns on for a locked apple,t8140-dart (:609-612), the mirror path only for T8140/T8142 (:3135-3137), and apple_dart_check_fw_map() skips every other DART up front (:1582). So M1, M2 and M3 DARTs see no change. The mirror refactor's leaf index is the same as before.
Locally at e2fecd94, tools/asahi/apple-dart-fw-tests.py passes 68/68. Against the base apple-dart.c, core-second-dart, map-firmware and map-attached fail, so the reproduction holds. CI is green.
One thing before merge:
- A failed invalidate no longer stops
domain_free()from freeing the page tables on handed-off DARTs.apple_dart_hw_unmap_locked_ttbr()now runs the range invalidate while retiring the root, but drops its result (:953), always returns 0, and clearslocked_ttbr(:958). Theinvalidate_tlb()thatdomain_free()checks (:2184-2191) then reachesapple_dart_fw_invalidate()with no root, issues no command and returns 0 (:1229-1230), so the tables are freed (:2193) even after a TLB timeout. On the base, handed-off DARTs got a realFLUSH_SIDthere, and its error kept the tables. The mirror path already has this gap; this PR extends it to every handed-off DART. Please return the retire-time error and remember it per stream, sodomain_free()still keeps the tables whenapple_dart_release_device()(:2116) or the attach rollback (:1803) did the unmap first. A fixture case that forces the TLB command to time out would cover direct free, release-before-free and rollback-before-free. Today the fixture doesn't includeapple_dart_hw_unmap_locked_ttbr()orapple_dart_domain_free().
Smaller things:
- If firmware ever changes a page Linux now mirrors on disp0,
apple_dart_publish_root()refuses the whole root (:738-750), and every later map on that stream fails and rolls back. Failing closed is right, but please confirm it doesn't happen in practice: a Neo session with DP-1 hotplug and an s2idle cycle, and no "failed to publish" lines. - nit: the comment at
:1625says "its snapshotted leaf", but only the root entry is snapshotted.fw->leafmaps the live firmware table (:850-853). - nit: commit 2's message says the stream invalidate is used "at attach, at release and on resume".
apple_dart_resume()returns early for locked DARTs (:3516), and handoff requireslocked, so resume never reaches it. - nit: the PR body says the fixture covers "another SoC with handoff".
handoff-other-soconly shows handoff stays off outside T8140 (fixture.c:134-135). The fixture'siommu_map()also only callsapple_dart_check_fw_map()(fixture.c:106), socore-second-dartdoesn't exercise publication.
For release: a cold boot on your Neo at the final head, plus the hotplug and s2idle check above.
| continue; | ||
| apple_dart_retire_root(live, owned, dart->pgsize / sizeof(*live)); | ||
| if (dart->fw_mirror && dart->version >= 0x0202 && !idx) { | ||
| if ((dart->fw_mirror || dart->fw_handoff) && |
There was a problem hiding this comment.
With fw_handoff here, the result of the apple_dart_fw_invalidate() below is dropped and locked_ttbr is cleared, so the later invalidate_tlb() in domain_free() returns 0 without issuing a command and the page tables are freed even after a TLB timeout. Please return the error and remember it per stream (see the main comment).
| apple_dart_t8110_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) | ||
| { | ||
| if (stream_map->dart->fw_mirror && stream_map->dart->version >= 0x0202) | ||
| /* Keep out of firmware-held slots; see apple_dart_fw_invalidate(). */ |
There was a problem hiding this comment.
Right for the attach and release flushes. Note that after apple_dart_hw_unmap_locked_ttbr() this returns 0 without a command, which is what the :948 issue relies on.
| continue; | ||
| /* | ||
| * All pages of an inherited slot remain firmware's; | ||
| * only a page its snapshotted leaf already maps the |
There was a problem hiding this comment.
nit: only the root entry is snapshotted; fw->leaf maps the live firmware table (:850-853). Suggest "only a page its firmware leaf already maps the same way may be repeated".
…retire On DARTs with a firmware root mirror or handoff, retiring a locked root runs a range invalidate of the slots Linux published. apple_dart_hw_unmap_locked_ttbr() dropped its result, returned 0 and cleared the root. The invalidate that apple_dart_domain_free() checks afterwards then found no root, issued no command and returned 0, so the domain's page tables were freed even after a TLB timeout, while the hardware could still cache translations through them. Before the handoff DARTs took that path, a whole-stream flush there returned the error and the page tables were kept. Return the first retire-time invalidate error, and remember it per stream on the DART. apple_dart_domain_free() keeps the page tables when its own retire or invalidate fails, and also when a consumer release or an attach rollback retired the root first and its invalidate failed. The remembered error is never cleared, because only the hardware could show that the TLB no longer holds those entries; later domains on that stream keep their page tables too. The host fixture now builds apple_dart_hw_unmap_locked_ttbr(), apple_dart_release_device() and apple_dart_domain_free(), and forces the TLB command to time out for a direct free, a release before the free and a rollback before the free. Each keeps the page tables, and the timeout cases fail on the old code. A comment in apple_dart_check_fw_map() now says the firmware leaf is checked, because only the root entry is snapshotted. The previous commit's message also lists resume as a user of the stream invalidate, but apple_dart_resume() returns early for locked DARTs, and handoff requires a locked DART, so resume never reaches it. Signed-off-by: DjDeveloperr <[email protected]>
|
Thanks for the careful review. Fixed in 07d64c6:
Testing at 07d64c6:
The same change is aurora-silicon/linux#546. I'll post the Neo cold boot at this head, plus the DP-1 hotplug and s2idle check, when I have them. |
maralcbr
left a comment
There was a problem hiding this comment.
@DjDeveloperr thanks, this is the fix I was after.
apple_dart_hw_unmap_locked_ttbr()now returns the first error from the firmware-root invalidate and records it per stream inlocked_retire_errunderdart->lock(apple-dart.c:968-973).apple_dart_domain_free()keeps the page tables if any retire, its owninvalidate_tlb(), or an earlier retire from release or attach rollback failed (:2217-2234, usingapple_dart_retire_error()). That covers the case I flagged:locked_ttbris cleared, so the laterinvalidate_tlb()returns 0 without issuing a command.- The new fixture cases cover a clean free and release, plus the three timeout regressions (free, release, rollback). The timeout cases fail on e2fecd9's
apple-dart.c. The rollback case calls the helper directly rather than going through a real attach rollback, which is fine for what it checks.
Not blocking: locked_retire_err is never cleared, so one TLB timeout means every later domain on that stream keeps its page tables until reboot. If domains keep being recreated, the retained page tables and domain objects add up with no cap. Keeping them is still the safe trade over freeing tables the TLB may hold. A one-time dev_warn when a stream first gets marked would make it obvious in a bug report. Separately, and not new here: the ordinary unmap path still drops invalidate errors (:1550-1565). That's outside this PR.
Approving. Your Neo results show this is what brings the internal display back when m1n1 marks the T8140 display DARTs apple,firmware-root-handoff (aurora21 and later), so I'd like it in the next kernel pin.
chriskearney
left a comment
There was a problem hiding this comment.
Reviewed 07d64c6b829a: firmware-leaf matching and retire-time invalidation-error retention preserve firmware-owned mappings and retain backing on uncertainty. The firmware-DART and SEP DMA host checks passed. The combined M3/G15 regression run passed boot, native GL/Vulkan readbacks (zero wrong pixels), unchanged OMT status maps and the bounded A/B/A workload suite, followed by exact restoration. Full source pins, timings and limits.
Approval is for the reviewed source and this regression coverage; the Neo-specific inherited display-DART path was not exercised by our J516S run.
|
Thanks for merging. The one-time warning you suggested is in #272: the first time a stream records a retire-time invalidate error, it logs that the stream's page tables are kept until reboot. The ordinary unmap path's dropped invalidate errors are left as they are, as you said. |
Summary
On Neo (J700, T8140), 7.2.11 never enables the system level cache, and the internal display stays on simpledrm. Both come from the display DARTs:
apple,firmware-root-handoff. In handoff mode,apple_dart_check_fw_map()refuses every page in a firmware-held slot, even one that repeats the firmware translation exactly. The display subsystem's direct mapping covers two DARTs, and only disp0 holds the translation, so the core maps the region and gets -EBUSY. disp0's DART probe is rolled back:apple,boot-dma-devices, so it stays deferred ("waiting for /display-subsystem to bind").These are the two commits from aurora-silicon/linux#404:
apple_dart_publish_root()still requires the whole Linux leaf to mirror the firmware leaf, so the firmware slot is never written.apple_dart_fw_invalidate()for handed-off DARTs too, as it already did for mirrored ones. A whole-stream flush could otherwise break the boot framebuffer scanout through firmware-held slots. The pick needed a one-line resolution, because integration/aurora has noapple_dart_has_borrowed(). (Its commit message also lists resume, butapple_dart_resume()returns early for locked DARTs, so resume never reaches it.)apple_dart_domain_free()keeps the page tables after a TLB timeout, also when a consumer release or an attach rollback retired the root first.Only DARTs the boot loader hands off take the new paths.
handoff-other-socchecks that handoff stays off outside T8140.Testing
Host fixture
tools/asahi/apple-dart-fw-tests.py: 73/73 pass on this branch.core-second-dartreproduces the two-DART -EBUSY on the old code; the fixture'siommu_map()only callsapple_dart_check_fw_map(), so it covers admission, not publication. The map cases cover a hole, a wrong physical address, a wrong protection, a changed root and a four-level stream, and all of them are still refused. Theretire-*cases force the TLB command to time out for a direct free, a release before the free and a rollback before the free; each keeps the page tables, and the timeout cases fail on the old code.Neo, 7.2.11 with this branch: disp0's DART binds and appledrm binds both DCPs (eDP-1 and DP-1), so the internal display leaves simpledrm. apple-mcc logs "system level cache allocation enabled on 4 planes", and the "irq 55: nobody cared" path no longer occurs.
GPU rows, µs per submit, with the same G17 driver (drm/asahi: G17 (Neo, T8140) driver update for 7.2.11 #229) and Mesa on both kernels. "7.3" is aurora-silicon with the SLC enabled.
A diagnostic module that does only the MCC probe's SLC write, on an unfixed 7.2.11 boot, gave the same improvement, so the GPU change comes from the SLC.