From 4ad71b88134de20ae0aefa1fe9f6ce3bfd209b06 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 25 Nov 2026 04:16:06 +0300 Subject: [PATCH] iommu/apple-dart: wait out stalled display invalidates on locked DARTs On the MacBook Air 15" M5 (J815) the internal display's DART logs apple-dart 286300000.iommu: TLB command 0x1 for stream 0 timed out (0x8700e100) when the compositor starts and when the display powers back on, 0 to 32 lines per boot, and kwin's framebuffer import fails at the same instant: kwin_wayland: drmPrimeFDToHandle failed: Invalid argument kwin_wayland: Failed to create framebuffer: Invalid argument That is the J700 stall that 911de8e40402 ("iommu/apple-dart: wait out stalled J700 display invalidates") waits out: a FLUSH_SID by range (V2, RANGE, STT) of the display subsystem's stream 0, still busy after 2 ms. The wait was gated on the reserved firmware table handoff, which J700's loader sets up. J815's loader leaves disp0 locked without the handoff, so the same stall still fails there after 2 ms. What the wait relies on is the DART being one the display subsystem scans out through, and taking range invalidates, which only locked DARTs get. Decide display_scanout from the lock instead of the handoff; every handed-off DART is locked, so J700 keeps the wait. The DCP firmware DARTs, other devices' DARTs and DARTs with sleep lists or a CTC flush still fail after the short wait. The host test's no-handoff case now expects the wait, and the mutation that drops the scan-out check is renamed every-dart. Signed-off-by: Nick --- drivers/iommu/apple-dart.c | 35 ++++++++++++----------- tools/asahi/apple-dart-tlb-stall-tests.py | 28 ++++++++++-------- tools/asahi/run-host-tests.py | 4 +-- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 2834878283a52..a6b635e30f34c 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -462,7 +462,7 @@ struct apple_dart { bool commands_gated; /* TLB commands written, counted under the lock: see apple_dart_t8110_tlb_wait(). */ unsigned long tlb_commands; - /* A handed-off DART a display subsystem scans out through: apple_dart_display_scanout(). */ + /* A locked DART a display subsystem scans out through: apple_dart_display_scanout(). */ bool display_scanout; /* * A real sleep took the ISP host streams' registers: the next runtime resume, its @@ -1081,9 +1081,10 @@ static bool apple_dart_fw_handoff_enabled(const struct apple_dart *dart) * Whether an available display subsystem, the component master the DRM driver * binds and the loader walks for the scan-out DARTs it hands off, lists a * stream of @np in its iommus: the display pipe scans out through this DART. - * On J700 that is disp0 and dispext0. The DCP and DCPEXT firmware DARTs are - * named only by their coprocessors, and a PCIe device such as the Wi-Fi - * reaches its DART through its host bridge's iommu-map. + * On J700 that is disp0 and dispext0, on J815 disp0, dispext0 and dispext1. + * The DCP and DCPEXT firmware DARTs are named only by their coprocessors, and + * a PCIe device such as the Wi-Fi reaches its DART through its host bridge's + * iommu-map. */ static bool apple_dart_display_scanout(struct device_node *np) { @@ -1782,16 +1783,17 @@ static bool apple_dart_t8110_tlb_settled(struct apple_dart *dart, * held: before a command (@issued 0) until it is idle, after one until * command @issued finished. * - * On J700 the boot loader hands the display DARTs' roots off (fw_handoff). - * There a range invalidate of the internal display's stream 0 can stay busy - * well past DART_T8110_FLUSH_BUSY_TIMEOUT while the display pipe changes - * what it scans out (screen locker, panel power-off, after a resume), - * reading 0x8700e100, and it finishes on its own: the next commands work. - * Giving up fails the mapping of a framebuffer the compositor imports, and - * returns from an unmap while the TLB can still translate to the pages its - * caller frees next. So keep waiting on the DARTs the display subsystem - * scans out through (display_scanout: disp0 and dispext0), not on the - * handed-off DCP firmware DARTs or any other device's DART, for up to + * On J700 (whose boot loader hands the display DARTs' roots off) and on + * J815 (locked, no handoff) a range invalidate of the internal display's + * stream 0 can stay busy well past DART_T8110_FLUSH_BUSY_TIMEOUT while the + * display pipe changes what it scans out (compositor start, screen locker, + * panel power-off, after a resume), reading 0x8700e100, and it finishes on + * its own: the next commands work. Giving up fails the mapping of a + * framebuffer the compositor imports, and returns from an unmap while the + * TLB can still translate to the pages its caller frees next. So keep + * waiting on the locked DARTs the display subsystem scans out through + * (display_scanout: disp0, and dispext0 when the loader locked it), not on + * the DCP firmware DARTs or any other device's DART, for up to * DART_T8110_FLUSH_STALL_TIMEOUT more, without the lock and with interrupts * as the caller had them. Every command here waits for an idle engine * before it is written, so the engine needs no lock meanwhile (the @@ -1814,7 +1816,7 @@ static int apple_dart_t8110_tlb_wait(struct apple_dart *dart, unsigned long *fla !(*status & DART_T8110_TLB_CMD_BUSY), 1, DART_T8110_FLUSH_BUSY_TIMEOUT, false, dart, DART_T8110_TLB_CMD); - if (!ret || !range || !dart->fw_handoff || !dart->display_scanout || + if (!ret || !range || !dart->display_scanout || dart->ctc_flush || dart->sleep_restore.count) return ret; @@ -6261,7 +6263,8 @@ static int apple_dart_probe(struct platform_device *pdev) &dart->sleep_restore_late); /* Reserved table-page lifetime requires the matched three-level loader. */ dart->fw_handoff = apple_dart_fw_handoff_enabled(dart); - dart->display_scanout = dart->fw_handoff && apple_dart_display_scanout(dev->of_node); + /* Only a locked DART takes the range invalidates apple_dart_t8110_tlb_wait() waits out. */ + dart->display_scanout = dart->locked && apple_dart_display_scanout(dev->of_node); /* * Preserve our retained-root path when no reserved-table handoff exists. * T6050's boot loader leaves every display DART locked on four-level diff --git a/tools/asahi/apple-dart-tlb-stall-tests.py b/tools/asahi/apple-dart-tlb-stall-tests.py index cc6e3582c07d5..706ad2ab7e83d 100644 --- a/tools/asahi/apple-dart-tlb-stall-tests.py +++ b/tools/asahi/apple-dart-tlb-stall-tests.py @@ -34,7 +34,7 @@ 'DART_T8110_FLUSH_STALL_TIMEOUT', 'DART_T8110_FLUSH_STALL_POLL', 'DART_T8110_TLB_CMD_STREAM', 'DART_T8110_CTC_FLUSH') OPTIONAL_DEFINES = {'DART_T8110_FLUSH_STALL_TIMEOUT', 'DART_T8110_FLUSH_STALL_POLL'} -CASES = ('fast', 'stall-after', 'stall-before', 'stuck', 'not-handoff', 'not-scanout', +CASES = ('fast', 'stall-after', 'stall-before', 'stuck', 'no-handoff', 'not-scanout', 'not-range', 'ctc-flush', 'sleep-listed', 'superseded', 'gated', 'two-streams') J700 = 'arch/arm64/boot/dts/apple/t8140-j700.dts' # What the J700 display subsystem scans out through: disp0 and dispext0. @@ -342,18 +342,22 @@ assert(now >= DART_T8110_FLUSH_STALL_TIMEOUT); assert(now <= DART_T8110_FLUSH_STALL_TIMEOUT + 2 * DART_T8110_FLUSH_BUSY_TIMEOUT + 100); assert(!dart.lock); - } else if (!strcmp(c, "not-handoff")) { - /* Other DARTs keep failing after the short wait, lock held throughout. */ + } else if (!strcmp(c, "no-handoff")) { + /* + * The J815 display: locked by the loader without the root handoff, + * the same 40 ms stall is waited out too. + */ reset(false); durations[0] = 40000; ndurations = 1; - assert(range() == -ETIMEDOUT); - assert(commands == 1 && errors_logged == 1 && lock_drops == 1); - assert(now <= DART_T8110_FLUSH_BUSY_TIMEOUT + 10); + assert(!range()); + assert(commands == 1 && !errors_logged && infos_logged == 1); + assert(info_us >= 38000 && info_us <= 41000); + check_range_command(0, 0); } else if (!strcmp(c, "not-scanout")) { /* - * A handed-off DART no display subsystem scans out through, such as - * the DCP's own: the same stall fails after the short wait, lock held. + * A DART no display subsystem scans out through, such as the DCP's + * own: the same stall fails after the short wait, lock held. */ dart.display_scanout = false; durations[0] = 40000; @@ -583,8 +587,8 @@ def main(): parser.add_argument('--source', type=Path, help='an apple-dart.c to test (default: this tree)') parser.add_argument('--ref', help='test drivers/iommu/apple-dart.c of this revision instead') parser.add_argument('--case', action='append') - parser.add_argument('--mutation', choices=('every-handoff',), - help='every-handoff: wait on every handed-off DART, not just the scan-out ones') + parser.add_argument('--mutation', choices=('every-dart',), + help='every-dart: wait on every locked DART, not just the scan-out ones') parser.add_argument('--dtc', help="this kernel's built scripts/dtc/dtc: also check the J700 tree") args = parser.parse_args() if args.ref: @@ -592,11 +596,11 @@ def main(): args.ref + ':drivers/iommu/apple-dart.c'], text=True) else: text = (args.source or ROOT / 'drivers/iommu/apple-dart.c').read_text() - if args.mutation == 'every-handoff': + if args.mutation == 'every-dart': cut = ' !dart->display_scanout ||' if text.count(cut) != 1: # Not a kill: the harness counts a traceback as a broken run. - raise RuntimeError('every-handoff: no display_scanout check to remove') + raise RuntimeError('every-dart: no display_scanout check to remove') text = text.replace(cut, '') defines = [] diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 7cb81bda543cf..18ada0aa24266 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -142,11 +142,11 @@ def mutations(flag, names, base, expect=KILL): 'apple-dart-fw-harness-tests.py': [([], PASS)], 'apple-dart-range-tests.py': [([], PASS)], # 551b937502b5 gives up on a stalled J700 display invalidate after 2 ms; the - # every-handoff mutation waits it out on every handed-off DART, not just the display's. + # every-dart mutation waits it out on every locked DART, not just the display's. 'apple-dart-tlb-stall-tests.py': [(['--dtc', '{dtc}'], PASS), (['--ref', '551b937502b54b0d1eb250bba6d9442b3672a0fb'], KILL), - (['--dtc', '{dtc}', '--mutation', 'every-handoff'], + (['--dtc', '{dtc}', '--mutation', 'every-dart'], KILL)], 'apple-router-sleep-tests.py': [(out('--output'), PASS)], 'asahi-stats-raw-tests.py': [([], PASS)],