Skip to content

dmaengine: apple-sio: hold tags and ended transfers until the firmware is done with them - #3195

Merged
RyanTheTide merged 10 commits into
mainfrom
fix/apple-sio-tag-binding
Nov 30, 2026
Merged

RyanTheTide merged 10 commits into
mainfrom
fix/apple-sio-tag-binding

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: Three fixes to how apple-sio holds its own state until the firmware has answered for it:

  • An SIO tag now records the endpoint and reply type of the request it went out with. A reply that doesn't match is dropped, and the tag stays with its request.
  • A call that times out keeps its tag until its late reply comes (or the firmware is reset), instead of handing it to the next request.
  • A transfer whose channel didn't confirm TERMINATE is no longer freed, and its descriptors are no longer handed to another transfer, until the channel is stopped. sio_synchronize() returns only once the firmware no longer reads the client's buffer. Callers that keep the buffer (a system sleep's prepare, a display unplug under the DCP audio link lock) get a bounded wait instead, and the sleep is refused as before.

The SIO KUnit suites also run in CI now.
Tested:

  • J714s (M5 Pro) at 8e07966, in a combined candidate with the same files: PASS, no regression. SIO protocol v10 probe and 128 channels with 0 setup errors. One deep sleep ended with the SIO restarted. 0 SIO warnings, 0 sleep refusals, 0 WARN. Its DP audio doesn't use SIO DMA.
  • J473 (M2 mini, HDMI audio through SIO DMA) at 3525449, before the bounded paths: no stall, 0 TERMINATE retries (row by Ryan).
  • J714s at fb1af1e: no regression.

KUnit on arm64 QEMU with lockdep, at 8e07966:

  • SIO suites: 44 run, 43 passed, 1 skipped (it was skipped before too).
  • DCP display and audio suites, with SIO and native audio on, at 3c3a4bd (the DCP side is unchanged since): 234 run, 233 passed, the same 1 skipped.

W=1 and checkpatch --strict are clean.

  • SIO suites: 44 run, 43 passed, 1 skipped (it was skipped before too).
  • DCP display and audio suites, with SIO and native audio on: 234 run, 233 passed, the same 1 skipped.

W=1 and checkpatch --strict are clean.
Risk: two-way door · every Mac with an SIO (DisplayPort/HDMI audio DMA): M1, M2, M3 Pro, M4, M4 Pro/Max, M5, Neo. The DCP audio change affects native audio links (M3 Pro, M4 Pro/Max, Neo).
Not yet: rows at 8e07966:

  • J473 PEER-ROW: silent HDMI loop, the SIO DMA path.
  • J700 (Neo, no external display) and J516s (M3 Pro, no HDMI display): the boot handshake (START, SETUP, CONFIGURE) and a sleep/wake.
  • T8132 (M4): a J713/J715, where the SIO is enabled. The J773g's SIO is left disabled on main, so it can't cover this.

Open by design (see Details): a firmware that never stops the channel blocks the stream's close, and a crashed firmware is taken as stopped once its descriptors had 500 ms to drain.

Details

Tags: the problem. A firmware reply names a tag, an endpoint byte and a type. sio_recv_msg() checked only that the tag was outstanding:

  • An ACK or NACK naming another channel than the one its tag's ISSUE went to ran the ISSUE callback on that other channel.
    • In the old accounting this took one of that channel's pending ISSUEs. It could also advance the channel's current transfer when the DMA cookies matched, which is common because each channel numbers its own.
    • In the ring accounting it cleared the other channel's issuing state and advanced its last issued descriptor.
    • The tag was then freed, so the first channel's real ACK was dropped.
  • A STARTED naming any outstanding tag was taken as that tag's ACK, and set the protocol number.
  • sio_call() freed a call's tag as soon as its 100 ms wait timed out. Tags on the wire are 1 to 15, handed out in turn, with no generation. So the 15th request after a timeout got that tag again, and a late reply to the timed-out call was taken as the new request's reply.

Tags: the change.

  • sio_alloc_tag() binds the tag to the request's endpoint byte, and to whether it's a START. For an ISSUE it also stores the callback and cookie. This happens under a new tags.lock, before the message is sent.
  • sio_recv_reply() matches each reply under that lock. A reply answers its tag only if:
    • it names the request's endpoint, and
    • it's a STARTED for a START, an ACK for any other request, or a NACK for any request.
      Anything else is dropped with a rate-limited warning, and the tag stays outstanding.
  • A call whose wait times out marks its tag stale instead of freeing it.
    • A matching late reply frees the tag and answers nothing else.
    • A firmware reset (the refused-sleep restart path) frees all stale tags.
    • A reply that lands between the timeout and the give-up still answers the call (try_wait_for_completion() under the lock).
  • The quarantine is bounded: while 7 of the 15 tags are stale, new calls fail with -EBUSY. ISSUEs from running channels still get the other 8.
  • The ISSUE callback runs after its tag is released, with the tag lock dropped, because it may issue again.
    • Lock order is vc.lock → tags.lock, and tags.lock is never held while taking a channel lock.
    • Replies come in order from the RTKit ordered workqueue.
  • A failed send gives its tag back only if the tag is still held by the same allocation. A host-only generation number guards this.

Ended transfers: the problem. sio_terminate_work() sent TERMINATE, took a NACK as success and only logged a timeout. It waited 500 ms for the descriptors and then freed the transfer whatever came of it. sio_synchronize() returned after that, so the client could free its buffer while the firmware still held descriptors pointing at it, and another transfer could take those descriptor slots.

Ended transfers: the change.

  • A transfer is freed only once the firmware no longer reads its descriptors, which means one of:

    • it ACKed a TERMINATE (the same fence sio_stop_quiet() already uses);
    • it reported every descriptor;
    • it crashed (apple_rtkit_is_crashed()), so it issues nothing more, and the descriptors had 500 ms to drain.
  • sio_terminate_work(), which runs on the system workqueue, tries TERMINATE twice, each followed by a 500 ms drain wait. If the channel still isn't stopped, the transfer stays as the channel's current one, keeps its descriptor slots, and nothing else is issued on that channel.

  • sio_synchronize() doesn't return while a transfer is held. It sends TERMINATE again every round until one of the stops above happens, and logs a still-stopped channel on the first round and then every 30 rounds. So the client can't free a buffer the firmware may still read, and a held channel no longer outlives synchronize. That means it refuses a system sleep only while its client is waiting for it.

  • The ring accounting gets the same treatment. Transfers retired by the handover to the idle transfer are kept until their descriptors complete or the channel stops: sio_synchronize() repeats sio_stop_quiet() instead of returning after a dev_WARN_ONCE.

  • A transfer with nothing in flight is freed whatever TERMINATE answers.

  • In the old accounting, an ISSUE ACKed after the transfer ended is now counted (nlate) until its report.

  • A report no longer calls the client back for a transfer it ended, as in the ring accounting.

  • Bounded where nothing is freed. Synchronizing also runs where the buffer stays allocated:

    • in a system sleep's prepare, where the stream is only suspended;
    • when a display is unplugged or its processor recovers, where the DCP audio driver holds its link lock.

    There it's bounded, as it was before this PR:

    • From the SIO's own .prepare to its .complete, sio_synchronize() stops the channel once more at most. A transfer still not stopped stays held, so sio_suspend_late() refuses the sleep. Both callbacks run with tasks frozen, and the SIO's prepare runs before its DMA clients', which its device links order after it. So a stream closed at any other time always gets the unbounded wait.
    • apple_sio_synchronize_bounded() (new, in include/linux/dma/apple-sio.h) does the same for a caller that keeps the buffers, and returns -EBUSY while transfers are still held. The DCP audio driver uses it under the link lock in dcpaud_release_link() and in sync_stop's handover to the held link's silence. That sync_stop then waits for a DMA that didn't stop with dmaengine_synchronize(), after dropping the link lock and before the buffer can be freed.
  • Concurrency. A synchronize that waits until the channel stops can now run while its client's bounded calls run. Synchronizing and setting or removing the idle transfer take a per-channel sync_lock. A bounded caller waits for it as long as synchronizing a channel that stops takes, then fails with -EBUSY and touches nothing.

  • Kconfig. DRM_APPLE depends on APPLE_SIO || !APPLE_SIO, as it already does for the DART.

  • What stays open:

    • A firmware that refuses TERMINATE forever and never reports makes the stream's close (hw_free) wait until it stops. That's the safe side: the buffer stays allocated, and sleep and unplug aren't held up. Resetting the SIO at runtime would also stop every other SIO channel and needs the service set up again, so it isn't done here.
    • The crash case relies on a crashed SIO issuing nothing more once its last descriptor drains.

Firmware that answers each request on its own endpoint, in time, and ACKs TERMINATE sees no change. The one exception is that the client isn't called back for a transfer it has already ended.

CI. No check ran the SIO KUnit suites before. This adds drivers/dma/apple-sio.kunitconfig (with spinlock debugging and lockdep) to the Apple build and KUnit workflow, builds drivers/dma/apple-sio.o in the Apple build job, and starts the workflow on SIO changes.

Evidence
  • kunit.py run --arch=arm64 --make_options LLVM=1 --kunitconfig=drivers/dma/apple-sio.kunitconfig at 8e07966 (44 run, 43 passed, 1 skipped):

    Suite Result
    apple-sio-t6030 10/10
    apple-sio-t6041 7/7
    apple-sio-probe 2/2
    apple-sio-boot 6/6
    apple-sio-msg 7/7, the 6 new tag cases included
    apple-sio-terminate 8/8, new (including sio_sleep_bounds_synchronize_test)
    apple_mbox_g17_stall 3 passed, 1 skipped (needs UCLAMP_TASK)

    PROVE_LOCKING and DEBUG_SPINLOCK are on, with no lockdep report.

  • Negative controls:

    • with sio_stop_tx() reporting a stop on a refused TERMINATE, and the late-ISSUE count dropped, sio_terminate_unconfirmed_test and sio_terminate_late_issue_test fail;
    • with sio_stop_held() and sio_wait_retired() giving up after one round (the earlier behaviour), sio_terminate_unconfirmed_test and sio_terminate_ring_retired_test fail;
    • with the bounded early exit removed, sio_sync_bounded_test fails;
    • with sio_pm_prepare() not setting the flag, sio_sleep_bounds_synchronize_test fails.
  • kunit.py run --kunitconfig=drivers/gpu/drm/apple/tests/display.kunitconfig --kconfig_add CONFIG_SOUND=y CONFIG_SND=y CONFIG_DMADEVICES=y CONFIG_APPLE_SIO=y CONFIG_DRM_APPLE_AUDIO=y CONFIG_DRM_APPLE_DCP_T6030_AUDIO=y at 3c3a4bd: 234 run, 233 passed, 1 skipped. This includes apple-dcpaud-release-link 22/22, apple-av-native-audio 18/18 and apple-dcpaud-legacy 5/5.

  • make W=1 drivers/dma/apple-sio.o drivers/gpu/drm/apple/audio.o: no warnings. checkpatch --strict: all eight commits clean.

  • The first CI run stopped at kunit.py's configuration step, because PROVE_LOCKING needs DEBUG_KERNEL. 63b7f02 sets it.

  • CI KUnit apple-sio at fb1af1e (job 139759732253): 39 run, 38 passed, 1 skipped, apple-sio-terminate 3/3.

Thanks to erikwb for reporting these.

…tags

A reply of the SIO firmware names a tag, an endpoint and its type.
sio_recv_msg() only checked that the tag was outstanding. An ACK or
NACK naming another channel than the one its tag's ISSUE went to ran
the ISSUE callback on that other channel. In the old accounting this
took one of that channel's pending ISSUEs, and could advance its
current transfer when the DMA cookies matched, which is common as each
channel numbers its own. In the ring accounting it cleared that
channel's issuing state and advanced its last issued descriptor. The
tag was then freed, so the real ACK of the first channel was dropped.
A STARTED naming any outstanding tag was taken as its ACK, and set the
protocol number.

sio_call() also freed the tag of a call as soon as its 100 ms wait
timed out. The tag on the wire has no generation and the allocator
hands out tags 1 to 15 in turn, so the 15th request after that took
the tag again, and a late reply to the timed-out call was taken for
its reply: a CONFIGURE or TERMINATE answered by another request's ACK
or NACK, or an ISSUE callback run for it.

Bind each tag, when it is handed out, to the endpoint byte of its
request and to the reply it takes: STARTED for a START, an ACK for any
other request, a NACK for any. A reply that does not answer the
request of its tag is dropped with a rate-limited warning, and the tag
stays with its request. A call that times out keeps its tag until its
late reply comes, which then frees the tag and answers nothing else,
or until the firmware is reset (a refused sleep restarts it). A reply
that comes after the timeout, before the call gives up, still answers
the call. While half the tags are kept this way, calls are refused
with -EBUSY, so that the ISSUEs of running channels still get tags.

A spinlock orders a reply against the allocation and release of its
tag, and an ISSUE callback runs after its tag is released, unlocked,
as it may issue again. A request whose send failed gives back its tag
only if a reply did not free it and hand it to another request in the
meantime.

Firmware that answers each request on its own endpoint, in time, sees
no change.

Add KUnit cases: a reply naming another endpoint, or of the wrong
type, is dropped and its tag kept; another channel's ACK leaves a
channel's old and ring ISSUE accounting alone, with the same DMA
cookie on both; a timed-out call keeps its tag through two rounds of
the tag space, and its late reply answers neither a call nor an ISSUE
on the same endpoint; a reply after the timeout but before the give-up
answers the call; calls are refused once half the tags are kept while
ISSUEs get the rest, until a late reply or a reset frees them; and a
failed send leaves a tag that went to another request alone.

Fixes: 5fdca02 ("dmaengine: apple-sio: Add Apple SIO driver")
Signed-off-by: Dj <[email protected]>
The SIO suites (apple-sio-msg, apple-sio-boot, apple-sio-probe,
apple-sio-t6030 and apple-sio-t6041) had no kunitconfig, and the Apple
build workflow neither compiled drivers/dma nor ran on SIO changes, so
no check ran them.

Add drivers/dma/apple-sio.kunitconfig, with spinlock debugging and
lockdep for the tag lock, and list it with the SIO files in
MAINTAINERS. Run it in the KUnit matrix, compile the SIO driver in the
Apple build job, check that the Mac configuration still builds it, and
start the workflow on SIO changes.

Signed-off-by: Dj <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team and RyanTheTide as code owners November 26, 2026 05:49
@github-actions github-actions Bot added area:release Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at 096e5b15: not ready yet

Check Detail
CI at head ok 35 checks passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA 096e5b15, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · every Mac with an SIO (DisplayPort/HDMI audio DMA): M1, M2, M3 Pro, M4, M4 Pro/Max, M5, Neo. The DCP audio change affects native audio links (M3 Pro, M4 Pro/Max, Neo).

Areas: area:display, area:release

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

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 26, 2026
PROVE_LOCKING and DEBUG_SPINLOCK depend on DEBUG_KERNEL, which the
KUnit arm64 configuration does not set, so kunit.py stopped at the
configuration with both options missing. Set it, as the ISP
kunitconfig does.

Signed-off-by: Dj <[email protected]>
@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 26, 2026
…pped

sio_terminate_work() sent TERMINATE, took a NACK as success and only
logged a timeout, waited 500 ms for the transfer's descriptors, and
then freed the transfer whatever came of it. sio_synchronize() returned
after that, so the client could free its buffer while the firmware
still held descriptors pointing at it, and another transfer could take
those descriptor slots.

Free an ended transfer only once the firmware no longer reads its
descriptors: it acknowledged a TERMINATE, after which nothing it holds
is played (as sio_stop_quiet() takes it), or it reported all of them.
A TERMINATE refused or not answered while descriptors are still in
flight is sent again after 500 ms, twice in all. If the channel is
still not stopped, the transfer stays its current one and keeps its
descriptors. Nothing else is issued on the channel, which keeps
refusing a system sleep as busy, and each sio_synchronize() tries to
stop it again. A transfer with nothing in flight is freed whatever
TERMINATE answers.

In the old accounting, an ISSUE acknowledged after the transfer ended
was not counted, so its descriptor looked complete: count it until its
report. A report no longer calls the client back for a transfer it
ended, as in the ring accounting, since a held transfer can outlive
its client.

Firmware that acknowledges TERMINATE sees no change, except that the
client is not called back for a transfer it ended.

Add KUnit cases, with TERMINATE stubbed: a TERMINATE refused or not
answered with descriptors in flight keeps the transfer, its descriptor
slots and the channel, and a queued transfer does not start, until an
acknowledged TERMINATE frees it; with nothing in flight it is freed
anyway; and in the old accounting an ISSUE acknowledged after the end
is in flight until its report, with no client callback.

Fixes: 5fdca02 ("dmaengine: apple-sio: Add Apple SIO driver")
Signed-off-by: Dj <[email protected]>
@DjDeveloperr DjDeveloperr changed the title dmaengine: apple-sio: bind tags to their endpoint and quarantine timed-out tags dmaengine: apple-sio: hold tags and ended transfers until the firmware answers for them Nov 26, 2026
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Nov 26, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

fb1af1e J473 (M2 Mac mini, T8112, batched 0-diff merge onto main) PASS: 200/200 pre-sleep + 1/1 rtc1 s2idle + 20/20 post-sleep silent /dev/zero PCM cycles on external DisplayPort card 8 (0 SIO timeout/terminate/refuse errors vs 0 baseline, 4 apple-sio lines vs 4 baseline), Enforcing, 0 failed, 0 AVC, 0 new audio/SIO/DMA kernel errors; fleet89 restored.

@DjDeveloperr

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Verdict at 8e079667eaa6: ready. The code hasn't changed since I reviewed this head, and the J700 and J516s rows that were owed are now posted.

Blockers: none. My last blocker (the bounded window letting a stream's close free a buffer the firmware still reads) is fixed.

  • No close can land in the bounded window. sleeping is now set in SIO's own .prepare (sio_pm_prepare()) and cleared in its .complete (sio_pm_complete()), both through pm_sleep_ptr(). The PM notifier is gone. In this tree, suspend_prepare() freezes tasks (kernel/power/suspend.c:387) before suspend_devices_and_enter() runs dpm_prepare(), and dpm_complete() runs inside dpm_resume_end() before suspend_finish() thaws (565). So user tasks are frozen for the whole window, and the bounded sio_synchronize() (sio_synchronize_chan()) only meets PM callbacks, which keep their buffers. Hibernation and s2idle go through the same prepare and complete phases with tasks frozen.
  • .complete always clears the flag.
    • sio_pm_prepare() always returns 0. That puts SIO on dpm_prepared_list, and it never asks for direct-complete.
    • Every failure after that goes through dpm_resume_end() → dpm_complete(), which runs .complete for each prepared device: a later device's .prepare, a suspend callback, an early wake, or sio_suspend_late() refusing (Recover_platform → Resume_devices).
    • If the freeze itself fails, no .prepare runs, so the flag is never set.
  • Ordering. The audio device's device_link_add() to SIO (audio.c:2065) moves it after SIO in the PM list (device_reorder_to_tail(), drivers/base/core.c:991). So SIO's .prepare runs before dcpaud_pm_prepare(), and its .complete after the audio device's.

Checked

  • Hardware rows at this exact head (8e079667eaa6):
    • J700 (DP audio through SIO): a test sleep that resumed, loop 10/10 before and after, and 0 SIO error lines.
    • J516s: boot and handshake only, with no HDMI display, and s2idle refused at prepare on main too. 0 SIO error lines.
    • J616s: 200 + 20 cycles across an s2idle on external DisplayPort, 0 TERMINATE retries, and 0 sleep refusals.
    • J473: 200 + 20 cycles across an s2idle, plus an unplug/replug, with 0 TERMINATE retries and 0 sleep refusals.
    • J714s: no regression, though this Mac's DP audio doesn't use SIO.
    • Together these cover the two rows listed under "Not yet", plus a second generation on the shared SIO DMA path.
  • CI: a re-run is in progress. host-tests and kunit pass so far, and the rest (including KUnit apple-sio and apple-build) were still pending when I edited this.
  • Nothing still waits without a bound under link_lock.
    • dcp_pcm_native_sync_stop() uses apple_sio_synchronize_bounded() under the lock (drivers/gpu/drm/apple/audio.c:1377, 1383), and on -EBUSY runs the unbounded dmaengine_synchronize() (1391) only after the lock is dropped.
    • dcpaud_release_link() (1611) uses the bounded call and frees nothing.
    • dcpaud_silence_start()/dcpaud_silence_stop() go through sio_device_config() → sio_set_idle()/sio_clear_idle(). That path takes sync_lock bounded (2155), and sio_clear_idle()'s own stop is bounded. On -EBUSY, dcpaud_idle() keeps idle_set and the silence buffer ("Not removed: the channel may still read the silence.").
    • The other link_lock sections don't reach a synchronize.
  • A sync_lock timeout doesn't drop a buffer in a bounded caller. sio_sync_lock(…, true) (1658) waits at most SIO_SYNC_LOCK_TIMEOUT_MS (177, 1.7 s: the terminate work's two tries, the retired drain, and one TERMINATE plus its report wait). It then returns -EBUSY before touching any transfer. Every bounded caller above either keeps its buffer on -EBUSY or follows with the unbounded call. A held transfer keeps the channel busy, so sio_suspend_late() still refuses the sleep.
  • Across a sleep. dcpaud_pm_prepare() → snd_pcm_suspend_all() → sync_stop runs inside the bounded window, after SIO's .prepare. If an unbounded synchronize is already looping when the sleep starts, it keeps going (its bounded is fixed on entry). That task can't freeze, so the freezer gives up after 20 s and the sleep is aborted rather than hung, before any .prepare runs. That's acceptable.
  • sync_lock is only trylocked under link_lock, so it adds no lock-order edge. tasklet_kill() under sync_lock waits only for tasklets, which can't take mutexes. DRM_APPLE depends on APPLE_SIO || !APPLE_SIO, and the header's stub for !APPLE_SIO falls back to dmaengine_synchronize().
Evidence
  • KUnit at 8e079667eaa6 (drivers/dma/apple-sio.kunitconfig, arm64, LLVM): 44 run, 43 passed, 1 skipped (UCLAMP_TASK). sio_sleep_bounds_synchronize_test passes. Lockdep was on, with no reports.
  • KUnit at 3c3a4bd0bc78 (the DCP side is unchanged since): display.kunitconfig plus SND, DRM_APPLE_AUDIO, DRM_APPLE_DCP_T6030_AUDIO, APPLE_SIO, PROVE_LOCKING: 234 run, 233 passed, 1 skipped, no lockdep reports. The run also prints 19 WARNINGs in tests this PR doesn't touch; main (255761f1d55f) prints the same 19.
  • make W=1 drivers/dma/apple-sio.o (asahi profile, LLVM=1, arm64) at 8e079667eaa6: no warnings. checkpatch.pl --strict on the new commit: clean.

@DjDeveloperr

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

J516s (MacBook Pro 16" M3 Pro, 27.2 stub) row for 8e079667eaa6: PASS. The candidate was main b14959b819cf + #3195 (no other PRs), booted one-shot on the default cmdline, and main b14959b819cf alone was booted as the control. No HDMI display is attached (eDP-1 is the only DRM connector), so this row is boot and handshake only. On both boots, SIO protocol v10 is logged and the SIO DMA controller 289c00000.dma-controller registers. The listed SIO failure lines: 0 with the PR and 0 on main. The sleep step is skipped because s2idle is refused at prepare on the J516s (dwc3-apple, also on main). 0 GPU faults, 0 failed units, and no new kernel errors beyond the MTP HID "no listeners" line the baseline also logs. (An earlier J516s row at fb1af1e4867f passed the same way.)

@DjDeveloperr

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

J714s (MacBook Pro 14" M5 Pro, T6050) final row at 8e079667eaa6: PASS (no regression). On this Mac the SIO DMA path itself isn't exercised; see the first point below.

  • What isn't covered: the J714s's DP audio goes through apple-admac, and no device-tree node references the SIO DMA controller (505e00000.dma-controller). The DMA path (issue, terminate, reports) is therefore not exercised here. The J700 row at this head (DP audio through SIO) covers it.
  • Kernel: 7.3.0-m5-rows-abw, a warm native build of combined candidate 24f15f76484d. That's main 40e5e29cc915 plus drm/asahi: hold an object's backing for every holder of its pages #3193, accel/ane: h16: check admission before importing the HWX and account the copy #3194, this PR at 8e079667eaa6, the media-bounds PRs, ASoC: apple: mca: stop and sync capture DMA before freeing the buffer #3196 and drm/asahi: g17: bound submit syncs, install repeated timeline outputs once, return closed queues' identities at close #3200. Every PR applied cleanly. None of this PR's files differ from 8e079667eaa6 in the candidate, except two that main also changed: Kconfig, where this PR's hunks are intact, and MAINTAINERS, which differs only by main's later lines. The boot used the default command line, headless and silent, and the default kernel was restored afterwards.
  • Earlier heads: fb1af1e4867f ran across two boots with three deep sleeps, and 3c3a4bd0bc78 ran one boot with one deep sleep. Both gave the same results as below.
  • Probe and handshake: SIO protocol v10, bound to apple-sio with 128 DMA channels registered. 0 "starting SIO service", "boot-up parameters", "sending SIO parameter" or "register DMA device" errors.
  • 0x30d SETUP echo: the 0x30d (performance endpoint) parameter is sent only at probe, and the restart after sleep sends no parameters. With this PR, a reply naming any endpoint other than 3 is dropped and the call times out. The probe completed with no timeout, so the firmware echoed it on endpoint 3. There's no direct trace (the kernel has no kprobe events).
  • Deep mem sleep (RTC wake): 1 of 1 at this head. It printed SIO: restarted after the sleep, firmware up, protocol v10, CPU control 0x10. 0 sleep refusals.
  • Counts over the whole boot, the sleep included, of does not answer its request|timed out, tag|not outstanding|refusing calls|ack without|nacked issue|got a NACK|TERMINATE refused|TERMINATE not answered|not stopped, its transfer|terminate descriptor wait timed out|terminate call on chan|still not stopped: 0 on the candidate and 0 on the default kernel. There were also 0 apple-sio or DCP-audio error-level lines.
  • Failed units: only tailscaled.service, the same as on the default boot.
  • Kernel log: 0 WARNING/BUG/Oops. The same boot ran the sync CTS for drm/asahi: g17: bound submit syncs, install repeated timeline outputs once, return closed queues' identities at close #3200. Its "compute publication … gave up" lines are tracked in linux#3235 and don't involve SIO.

When the firmware refused or did not answer TERMINATE with descriptors
still in flight, sio_synchronize() returned anyway. The transfer was
held with its descriptor slots, but the client then freed its buffer,
which the firmware could still read. In the ring accounting, transfers
retired with descriptors that did not complete, on a channel that did
not stop, were left the same way after a WARN.

sio_synchronize() now returns only once the firmware no longer reads
those buffers. A held transfer is freed after an acknowledged
TERMINATE, once its descriptors were reported, or after a firmware
crash, from which nothing more is issued. Retired transfers are freed
once their descriptors completed or the channel stopped. Until then,
TERMINATE is sent again every round, and a channel still not stopped
is reported every 30 rounds. sio_terminate_work() keeps its two bounded
tries, as it runs on the system workqueue.

A held channel no longer outlives sio_synchronize(), so it refuses a
system sleep only while its client waits for it to stop.

Firmware that acknowledges TERMINATE sees no change.

Add KUnit cases: synchronizing waits through refused TERMINATEs until
one is acknowledged; a held transfer is freed once its descriptors are
reported or the firmware crashed; and in the ring accounting retired
transfers are kept through refusals and freed once the channel stops.

Fixes: 5fdca02 ("dmaengine: apple-sio: Add Apple SIO driver")
Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr DjDeveloperr changed the title dmaengine: apple-sio: hold tags and ended transfers until the firmware answers for them dmaengine: apple-sio: hold tags and ended transfers until the firmware is done with them Nov 26, 2026
…uffers

Synchronizing now waits until the channel stops, but it also runs
where no buffer is freed next: in a system sleep's prepare, where the
DisplayPort audio stream is only suspended, and when a display is
unplugged or its processor recovers, where the DCP audio driver holds
its link lock. With firmware that does not stop the channel, the sleep
hung where it used to be refused, and the unplug would hang with that
lock held.

Bound it there. From a system sleep's prepare to its end, as the PM
core notifies them, sio_synchronize() stops the channel once more at
most, and a transfer still not stopped stays held, so
sio_suspend_late() refuses the sleep as before.
apple_sio_synchronize_bounded() does the same, for a caller that keeps
the buffers, and says whether the channel still holds transfers.

A synchronize that waits until the channel stops may then run
concurrently with its client's bounded calls. Synchronizing and setting
or removing the idle transfer now take a lock of the channel. A bounded
caller waits for it as long as synchronizing a channel that stops
takes, and fails with -EBUSY, leaving the channel as it is, while a
synchronize waits for a channel that does not stop.

Firmware that stops the channel when asked sees no change.

Add KUnit cases: a bounded synchronize stops the channel once and keeps
a held or retired transfer, the channel busy; a bounded one that finds
the lock held fails after that time, touching nothing; and the sleep
notifier bounds synchronizing from the prepare to the end.

Fixes: 5fdca02 ("dmaengine: apple-sio: Add Apple SIO driver")
Signed-off-by: DjDeveloperr <[email protected]>
…lock

dcpaud_release_link() and sync_stop's handover to the held link's
silence synchronize the SIO channel with the link lock held. The
display's unplug and its processor's recovery take that lock, and
dcpaud_release_link() also runs in a system sleep's prepare. Neither
frees the stream's buffer.

Synchronize there with apple_sio_synchronize_bounded(): a DMA the
firmware did not stop stays with the channel, and the link is torn
down as before. sync_stop, after which the buffer may be freed, then
waits for such a DMA with dmaengine_synchronize(), without the link
lock.

DRM_APPLE depends on APPLE_SIO || !APPLE_SIO, as for the DART driver:
the native audio links call into the SIO driver.

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

Copy link
Copy Markdown
Contributor

3525449 J473 (M2 Mac mini, T8112, exact-head 0-diff merge onto main) PASS: 200/200 pre-sleep (51.40 s, max 257 ms/cycle vs 50.64 s stock, no stop/close stall) + 1/1 rtc1 s2idle + 20/20 post-sleep (5.14 s, max 257 ms/cycle) silent /dev/zero PCM cycles on external DisplayPort card 8; 0 SIO error patterns (vs 0 baseline), 0 TERMINATE retry log lines, 4 apple-sio lines (vs 4 baseline), Enforcing, 0 failed, 0 AVC, 0 new SIO/DMA/audio kernel errors; fleet89 restored.

Synchronizing is bounded during a system sleep, where streams are only
suspended and keep their buffers. The flag for that came from the PM
notifier, which runs before tasks are frozen and after they are
thawed. A player closing its stream in those windows got the bounded
synchronize, and could free its buffer while the firmware still held
descriptors pointing at it.

Set the flag from the SIO's own prepare and clear it from its complete
instead. Both run with tasks frozen, and the SIO's prepare runs before
those of its DMA clients, which its device links order after it.
Anywhere else, a synchronize waits until the firmware stops the
channel.

Replace the notifier's KUnit case: a synchronize before the SIO's
prepare and after its complete waits through refused TERMINATEs until
one is acknowledged, and only in between is it bounded, leaving the
transfer held.

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

DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

J700 (MacBook Neo, DP audio through SIO) at 8e079667eaa6ffd07f433fc66cf828be09564616: PASS. This was a one-shot boot of a combined candidate with this head merged in: main 255761f plus this PR and other non-overlapping PRs (#3200, #3197/#3199, #3204/#3217, #2888, #3226, #3227, #3231). No external display was connected.

  • Handshake: "SIO protocol v10" and RTKit init once each at boot, as on stock. RTKit init appears again after the test sleep.
  • Card 8 (apple_dcp "Apple USB-C DisplayPort" audio, no sink connected, no samples): a null open/hw_params/prepare/close loop ran 10/10 before and 10/10 after the sleep.
  • One test sleep (rtcwake -m mem, 30 s) resumed on the same boot, with suspend_stats success 1. 0 sleep refusals in normal operation: no apple-sio busy or refusal lines, and no aborted suspend.
  • SIO patterns ("does not answer its request", "timed out, tag", "not outstanding", "refusing calls", "TERMINATE refused/not answered", "not stopped, its transfer", …): 0 on stock, and 0 on the candidate before and after the sleep. 0 apple-sio or DCP-audio error lines.
  • Health: 0 new kernel errors, 0 AVC, 0 failed units. PMU boot-error count 00 on every boot.
Earlier head 35254491603f on J700

No regression on a candidate of the same kind: handshake as on stock, loop 10/10 before and after a test sleep that resumed, and 0 SIO pattern lines.

@RyanTheTide

Copy link
Copy Markdown
Contributor

8e07966 J616s (M4 Pro, T6040, exact head, default cmdline) PASS: apple-sio RTKit v12 / SIO protocol v10 handshake matches stock; 200/200 pre-sleep (115.20 s, max 577 ms/cycle vs 577 ms stock, zero stop/close stall) + 1/1 rtc1 s2idle + 20/20 post-sleep (11.56 s, max 611 ms/cycle) silent /dev/zero S24_LE cycles on external USB-C DisplayPort card 9; 0 SIO/DCP-audio errors, 0 TERMINATE retries, 0 -EBUSY sleep refusals, Enforcing, 0 failed, 0 AVC, stock fleet89 restored. (Note: checked lab J713 T8132 — dma-controller@3ade00000 is status=disabled on its current Stage 2 as well.)

@RyanTheTide

Copy link
Copy Markdown
Contributor

8e07966 J473 (M2 Mac mini, T8112, exact head, default cmdline) PASS: apple-sio RTKit v12 / SIO v10 probe matches stock (4 apple-sio* lines); 200/200 pre-sleep (76.12 s, max 383 ms/cycle, no stop/close stall) + 1/1 rtc1 s2idle + 20/20 post-sleep (7.61 s, max 381 ms/cycle) silent /dev/zero PCM cycles on external USB-C DisplayPort plughw:8,0 + 1/1 simulated card1-DP-2 unplug/replug with stream stopped + 5/5 post-replug cycles OK; 0 SIO/DCP-audio errors, 0 TERMINATE retries, 0 -EBUSY sleep refusals, Enforcing, 0 failed units, 0 AVC, stock fleet89 restored.

@github-actions github-actions Bot added the merge-conflict Conflicts with the base branch (bot) label Nov 27, 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: FINISH, then merge at 8e079667

Blockers:

  1. Merge conflict (CONFLICTING) against main; rebase onto current main (or merge main) and re-run CI (4 checks were cancelled at 8e079667).

Checked:

  • Verified mergeability (CONFLICTING) and existing J473 M2 PASS row at 8e079667.
  • Deferred final diff approval until the conflict against main is resolved and CI finishes green.
Evidence
  • Head 8e079667 vs main: CONFLICTING; CI 29 passed, 4 cancelled.

Forward-merge main. Only apple-build-kunit.yml conflicted: main added
APPLE_CENTAURI_T6050_WIFI to the required-options loop and this branch
added APPLE_SIO there, so the loop keeps both.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Forward-merged main into this branch (merge commit fb303ec, no force push). The only conflict was the required-options loop in apple-build-kunit.yml: main added APPLE_CENTAURI_T6050_WIFI=y and this branch added APPLE_SIO=m, so the loop now has both. apple-sio.c (main's new T8132 compatible) and audio.c (main's T6030 replaced-instance work) merged cleanly.
Tests: on the merge result, drivers/dma/apple-sio.o (built in, with the SIO KUnit tests) and drivers/gpu/drm/apple/audio.o build for arm64 with LLVM=1. The KUnit apple-sio run is left to CI.
Still needed: CI green, including KUnit apple-sio, and App re-review at the merge head. Your driver code is unchanged, so the J473/J616s/J700/J714s rows still apply. Thanks @DjDeveloperr.

@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 fb303ec26989

Blockers: None (wait for queued CI, including KUnit apple-sio, to finish green).

Checked:

  • Forward merge fb303ec26989 of main (MERGEABLE): .github/workflows/apple-build-kunit.yml cleanly retains both APPLE_SIO=m and APPLE_CENTAURI_T6050_WIFI=y and registers the apple-sio KUnit suite (CONFIG_PROVE_LOCKING=y); apple-sio.c preserves main's apple,t8132-sio match and audio.c preserves main's T6030 replaced-instance changes.
  • Full driver audit of drivers/dma/apple-sio.c, drivers/gpu/drm/apple/audio.c, drivers/gpu/drm/apple/Kconfig, and include/linux/dma/apple-sio.h:
    • Tag binding and stale-tag quarantine (sio_alloc_tag, sio_cancel_tag, sio_recv_reply, sio_call_result, sio_release_stale): tags->lock serializes tag allocation, reply matching (endpoint + MSG_STARTED/MSG_ACK/MSG_NACK check), ABA-safe cancellation via held_by[tag] == generation, timeout-vs-reply race closure via try_wait_for_completion(), SIO_MAX_STALE reservation for atomic ISSUEs, and stale-tag release on firmware reset.
    • Quarantined-transfer teardown and bounded/unbounded synchronize (sio_stop_tx, sio_end_tx, sio_stop_held, sio_wait_retired, sio_sync, sio_sync_lock, sio_pm_prepare/sio_pm_complete): prevents freeing DMA buffers still read by firmware while keeping sio_synchronize() bounded during frozen system sleep and under dcpaud->link_lock (dcp_pcm_native_sync_stop() drops &dcpaud->link_lock before falling back to unbounded dmaengine_synchronize()).
    • DRM_APPLE depends on APPLE_SIO || !APPLE_SIO prevents modular-link mismatch when DRM_APPLE=y and APPLE_SIO=m.
  • Existing hardware rows (J473 M2 200 pre-sleep + s2idle + 20 post-sleep + unplug/replug, plus J616s/J700/J714s) stand with unchanged driver logic; apple-sio.o and audio.o build clean for arm64 (LLVM=1).
Evidence
  • Verified sio_recv_reply() releases tags->lock before invoking ack_callback(&sio->channels[sioep], ...) so callbacks can allocate new tags without lock recursion, and sioep == tags->ep[tag] guarantees sioep < sio->nchannels for atomic channel requests.
  • Verified sio_sync_lock() / sio_sync_unlock() wake_up(&siochan->sync_wait) avoids lost wakeups across bounded and unbounded callers.
  • 28 CI checks at fb303ec26989 are queued at review time (0 failures); approve now so merge can proceed once CI goes green.

@RyanTheTide

Copy link
Copy Markdown
Contributor

code-owner ping @DjDeveloperr: closeout merge at fb303ec2. The App approved at this head after the closeout forward-merge/fix. Rows: J473 + J616s + J700 at the pre-merge head; the merge only changes the workflow yml config line. Merging under the 6-point rule 1 h from now, once hosted CI at this head and main CI are green, unless you object.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) labels Nov 29, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train review (non-author) at 096e5b15: approved code, KUnit added. The rows are at 8e07966 (J714s) and earlier heads, and the PR's "Not yet" lists rows at the current code. One exact-head SIO row on J714s (SIO v10 probe, 128 channels, a deep sleep) plus the J473 HDMI-audio regression at this head, and it merges under the 6-point rule. <@422957901716652033>

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at 096e5b15. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J714s(8e07966-same-PR-files)+J473-HDMI-audio;new-merge-bar. (5) There's no blocking review. (6) Dj was pinged here 2460 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit 07cb39a into main Nov 30, 2026
36 checks passed
@RyanTheTide
RyanTheTide deleted the fix/apple-sio-tag-binding branch November 30, 2026 23:08
erikwb added a commit that referenced this pull request Dec 1, 2026
main ended SIO transfers differently (#3195): an ended transfer is freed
only once the firmware no longer reads its descriptors (sio_end_tx(),
sio_release_tx()), and is held with its channel otherwise; synchronize
waits for that (sio_sync()), bounded only from the SIO's prepare to its
complete, under a per-channel lock.

Carry the runtime PM of this branch onto that lifecycle:
- sio_terminate_work() resumes the SIO around sio_end_tx() and hands its
  reference to a next transfer started without one. If the resume fails,
  sio_end_tx() still frees the transfer only once it is known stopped.
- sio_release_tx(), where an ended or held transfer is finally freed,
  drops the channel's transfer reference with its last transfer, and
  aborts issued descriptors when there is no firmware to start them on
  (removal, or stopped), as the old terminate path did.
- sio_stop_quiet() keeps main's result and gains the runtime PM hold and
  the transfer reference release.
- sio_sync() flushes the deferred issue worker before ending anything,
  and kills the tasklet before returning: descriptors aborted with no
  transfer to end complete through it, and dmaengine_synchronize() must
  not return before their callbacks have run.
- A held transfer stays the channel's current one, so it keeps the
  channel busy and its runtime PM reference, and the firmware up.

Tests: initialise the per-channel sync lock in the runtime PM KUnit
fixture; give main's tag fixture an issue worker and a runtime-active,
held device as probe leaves it; extend the sio-rpm-issue host model with
main's held-transfer code and the fields it uses.

Signed-off-by: Erik Bourget <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) area:release Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants