Skip to content

soc: apple: mailbox: Do not sleep past free FIFO space - #596

Closed
RyanTheTide wants to merge 1 commit into
aurora-wipfrom
fix/mbox-tx-wake-every-sender
Closed

RyanTheTide wants to merge 1 commit into
aurora-wipfrom
fix/mbox-tx-wake-every-sender

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

A sleeping sender in apple_mbox_send() can time out after 500 ms with room in the send FIFO. This is the root cause behind the J616s AOP start stall that #547 bounded.

Two ways it misses free space:

  • The send-empty interrupt reports an empty FIFO. A firmware that takes some queued messages but not all frees space without raising it.
  • Two senders can wait at once (a driver starting endpoints while the RTKit work item acknowledges syslog messages). The handler masks the interrupt and calls complete(), which wakes one waiter. The other sleeps on with the interrupt masked until its timeout. A sender that timed out also masked the interrupt and stranded the rest.

Evidence, J616s warm boot (aoploop2 boot 5, 7.3.0-aurora-j616s-aopfix1):

2.891389 ep 0x28 init sent
3.395337 RTKit: Failed to send management message type 0x05: -110
3.395341 RTKit: Retrying unsent endpoint start 0x29
3.395344..3.395354 ep 0x29, 0x2a, 0x2b init sent
3.402107 syslog: ===( AOP IS READY )===

The failed send gave up exactly 500 ms after it was issued. The retry and three more requests then went out within 20 us, so the FIFO had room, and the firmware reported ready 7 ms later. The "slow firmware" in the #547 boot (ready at 370 ms, then an AFK init timing out on a full mailbox) has the same shape. The AOP firmware was emitting syslog messages at that moment, so the RTKit work item was sending acks on the same mailbox.

The change:

  • complete_all() in the send-empty handler, so every waiter rechecks the FIFO. A waiter that still finds it full rearms the interrupt before waiting, as before.
  • Waiters also recheck the FIFO every 2 ms, up to the same 500 ms deadline.
  • A sender that times out leaves the interrupt unmasked for the others. tx_irq_unmasked still tracks the state, so enable/disable stays balanced (the handler or provider removal masks it). This keeps the fix for the earlier unbalanced-enable bug intact.
  • Atomic senders (polling) and the G17 no-IRQ path are unchanged. struct apple_mbox layout is unchanged (comment only in the header).

Testing:

  • Universal config (defconfig + asahi.config) on aurora-wip: drivers/soc/apple/mailbox.o and rtkit.o build with W=1 and no warnings. A full Image+modules build (7.3.0-aurora-mboxwake1) is queued on the buildbox.
  • checkpatch --strict: 0 errors. The only warnings are about the required Co-Authored-By trailer.
  • Not yet run on hardware. The J616s test is a warm-reboot loop counting Failed to send management message, AFK init not sent and the AOP ready time.

🤖 Generated with Claude Code

A sleeping sender that finds the send FIFO full waits on tx_empty for
the send-empty interrupt, and gives up after 500 ms. Two things make it
miss free space and time out with room in the FIFO:

- The interrupt reports an empty FIFO. A firmware that takes some of
  the queued messages but not all of them frees space without raising
  it.
- Two senders can wait at once, for example a driver starting its
  endpoints while the RTKit work item acknowledges a syslog message.
  The handler masks the interrupt and calls complete(), which wakes
  only one of them. The other sleeps on with the interrupt masked. A
  sender that timed out also masked it, stranding any sender still
  waiting.

On the J616s (M4 Pro) this delayed the AOP start on some warm boots.
One endpoint start failed 504 ms after it was issued, while the AOP
firmware was logging over syslog:

  2.891389 aop: ep 0x28 init sent
  3.395337 aop: Failed to send management message type 0x05: -110
  3.395341 aop: Retrying unsent endpoint start 0x29
  3.395354 aop: ep 0x2b init sent
  3.402107 aop: syslog message: ... AOP IS READY

The retry and the next three requests went out within 20 us, so the
FIFO had room when the first send gave up, and the firmware reported
ready 7 ms later. In an earlier boot the same stall made an AFK init
time out after the firmware had reported ready, and the probe failed.

Wake every waiter with complete_all(), and check the FIFO again every
2 ms while waiting, until the same 500 ms deadline. A woken sender that
still finds the FIFO full rearms the interrupt before it waits, as
before. A sender that times out now leaves the interrupt unmasked for
the others. tx_irq_unmasked still records the state, so the enable
stays balanced: the handler masks it when it fires, and provider
removal masks it otherwise. Atomic senders, which poll, are unchanged.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Boot-tested in fleet10 (7.3.0-aurora-fleet10): integration/aurora 1173b79 plus 587, 588, 589, 590, 596, 599, 600, 601, 603, 604, 605, 607 and 608, built with the shipping recipe (Fedora Asahi base + asahi.config, 0 mismatches, all distro gates). apple-dcp host selftests 80/80, and the other host tests match integration/aurora exactly (62 pass, the same 26 pre-existing failures). One-shot boots on the Neo (J700), the M2 and the M1 Pro, compared with each machine's fleet9 boot; fleet10 is now the default on all three. Full dmesg and journals are in aurora-ctl reports/fleet10-20261030.

This commit conflicts with integration/aurora, which has the TX wait failed report from d9d9ee6. For fleet10 I kept this PR's behaviour (complete_all, a recheck every 2 ms, the interrupt left unmasked on a timeout) and moved that report to the 500 ms deadline, printed only for interrupt-driven waits, so the G17 no-IRQ path stays quiet. The resolved commit is 46b7a93f on buildbox fleet/u10. The aurora-wip branch also reports a conflict, so this needs a rebase before it can merge anywhere.

Result on the machines tested: no regression.

  • Neo, 3 fleet10 boots: 0 Failed to send management message, 0 TX wait failed, 0 AFK init not sent, 0 RTKit timeouts.
  • M2: AOP ready at 0.759 s (fleet9 0.751 s), no mailbox errors.
  • M1 Pro, 2 boots: AOP ready at 0.805 and 0.803 s (fleet9 0.809 s), no mailbox errors.
  • The bug it fixes was seen on the J616s, so the real test (warm-reboot loop there) is still open. Not merging before that.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

J616s warm-reboot loop on fleet10 (7.3.0-aurora-fleet10, src 46b7a93f, carries this PR). Wi-Fi ssh, no tether, same pattern as the fleet9 baseline (fast, fast, normal reboots). Each boot was a one-shot GRUB entry with fleet9 kept as the saved default.

fleet9 baseline fleet10
boots 14 clean (boot 15 hung) 20 of 20 clean, plus the one-shot boot before it
AOP RTKit init to AOP IS READY, min / median / max 64.7 / 65.0 / 67.2 ms 64.6 / 65.5 / 73.0 ms
mean 65.3 ms 65.8 ms
Failed to send management message 0 0
AFK init not sent / Retrying unsent / did not start / TX wait failed 0 0
WARNING / Oops / BUG 0 0
ssh up after reboot 30 to 33 s 29 to 30 s

All 20 boots came up with gdm active, /dev/sep-bio present, PMP ready, 3 DCPs started and systemctl is-system-running = running. The single 73.0 ms boot (boot 2) has no mailbox message of any kind, the other 19 sit between 64.6 and 67.7 ms. So no regression in AOP start time, and no failed send in 20 boots. The stall this PR fixes was intermittent on fleet9 too (0 in 14 there), so this shows the change is safe, not that the stall can no longer happen.

The fleet9 hang at boot 15 is not an AOP or mailbox problem: its journal stops at plymouth-read-write.service (plymouthd never answers while the external DCP comes up), and the 12:30 hang has the same signature. Details are in the night report.

Per-boot dmesg and journals: reports/j616s-aop-mbox-20261030/fleet10/.

🤖 Generated with Claude Code

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged into aurora-wip as #630, the same change rebased over the TX wait failed report (mailbox.c and mailbox.h identical to the fleet10 commit 46b7a93f14c0 that passed the Neo, M2, M1 Pro boots and the J616s 20-boot loop). integration/aurora still needs it; the fleet10 resolution applies there as is.

🤖 Generated with Claude Code

@RyanTheTide
RyanTheTide deleted the fix/mbox-tx-wake-every-sender branch October 30, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant