Repository navigation
drm/apple: dptxep: don't refill a stalled port with HPD requests - #3360
DjDeveloperr wants to merge 9 commits into
Conversation
On a J316c (M1 Max, external display processor on firmware 13.5) the DPTX port stopped answering after an s2idle: an HPD low timed out, and every later call on the port timed out or failed with -ENOSPC. The log held only the timeouts. What the host saw of the endpoint at that point tells a firmware that stopped reading its queue from one that was never told about the command, but it was printed only for the T6030 external processor. A doorbell the mailbox failed to deliver was not reported at all, except on firmware 14.7 and native26. On the first timeout of a stall (until the service's next reply), report once: - the service's command slots, and how many hold timed-out commands; - the TX ring pointers and how many bytes the firmware has not read yet, and the RX ring pointers; - how many doorbells in a row the mailbox did not deliver, and why; - whether RTKit runs or has crashed. Say when a timed-out command is answered after all, and how long after it was queued: that tells a slow firmware from a stopped one. Say once, until the next reply, that a service has no free command slot left, rather than only the caller's -ENOSPC. dcp_send_message() now returns the mailbox result and warns, rate limited, on every firmware. A lost doorbell is only counted: its entry stays in the ring, and the next doorbell carries a later write pointer that covers it. Nothing here reads the coprocessor: the rings are host memory. Signed-off-by: DjDeveloperr <hey@djdev.me>
A command that times out keeps its slot and its buffers until the firmware answers it: the reply names the slot and lands in the command's buffer, so neither can be reused before then (afk_recv_handle_reply()). That keeps late replies safe, but a caller that repeats a call the firmware does not answer takes one more of the service's 16 slots each time. The Type-C SAFE transition does that with a DPTX port's HPD low. dcp_typec_route_prepare() lowers HPD through dcp_dptx_disconnect_oob() and fails the transition when the HPD low times out. The port stays safe_pending, the port controller retries the transition, and every retry and every later cable event lowers HPD again. On a J316c whose external display processor had stopped reading its queue (firmware 13.5, after an s2idle), all 16 slots of the port ended up held by unanswered HPD lows, with 2048 unread bytes in its TX ring. From then on the port refused every call with -ENOSPC until a reboot. A copy queued behind an identical request that is still unanswered does nothing: no other call was queued on the service in between, so the firmware takes it right after the first, with the same input. Add afk_service_call_unanswered(), which tells whether the call queued last on a service is this one, with the same input, and timed out unanswered. dptxport_set_hpd_timeout() then returns -ETIMEDOUT at once, as the first request did, without sending a copy. The other HPD level, and any other call, is sent as before, and so is the same request once the firmware has answered. The slots of commands that did time out are not reclaimed, so late replies stay safe. This does not bring back a port whose firmware has stopped; it keeps the stall from taking every slot of the port. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Non-author review at
|
There was a problem hiding this comment.
Verdict: Code approved at a4fa8d3fe580. Hardware evidence remains open.
The suppression test checks the live slot bitmap, tag, completion state and command bytes while holding the service lock. It leaves a different HPD level eligible and does not retry a doorbell with uncertain delivery. Hosted Apple build, KUnit and host tests pass. Before merge, record the J316c external-DP suspend/replug row and the requested 13.5 and 27.x peers. This avoids slot exhaustion after the stall; the original firmware stall remains a separate diagnosis.
|
We carry this PR in our J716c (M5 Max, T6050) daily kernel. When an external display processor stops answering its DPTX port (such as after sleep/resume), repeated Type-C retries previously queued duplicate unanswered HPD requests until all 16 AFK command slots were exhausted, leaving the port jammed without surfacing the underlying AFK stall. Carried in our J716c daily kernel as protection against DPTX AFK slot exhaustion and to log stall diagnostics; running cleanly in daily use. |
The selftest EPIC service stub in edid.py takes both sides' fields: main's defer_start and started, and this branch's stall_reported, full_reported and last-call record. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merged On the merged tree:
Still owed before merge: an independent approval, and the rows in Not yet: J316c external DP with s2idle and replug, plus a second generation. Our J414s (M2 Pro) can take the second-generation row, and J714s covers the 27.x |
|
Hardware row on the 16-inch M1 Max MacBook Pro (J316c, T6001), at head efd42a1: skipping the external-DP row — this machine currently has no external display attached, so the 3x s2idle + 3x replug sequence can't run. The internal panel (eDP-1) is the only connected connector. Will rerun if a display gets attached. |
Main now returns the error of an undelivered doorbell from afk_send_ret() to the caller, keeps the slot and buffers of the published command itself, and logs the failed call. A command that times out has had its doorbell delivered. That replaces what this branch did with an int afk_send(), a dcp_send_message() that returns the mailbox result, and a count of undelivered doorbells. The rest of the report (slots, late replies, the first stall only) is not needed for the fix. Keep only the HPD check. The apple-afk-stall KUnit suite stubbed the second afk_send() and goes with it. The host tests run the real sender instead. Signed-off-by: DjDeveloperr <hey@djdev.me>
With the stall report and the doorbell count gone, nothing conflicts: afk_send_ret(), dcp_send_message_ret() and the transmit admission are main's, and the branch adds the HPD check. Signed-off-by: DjDeveloperr <hey@djdev.me>
The check that keeps an HPD request from being queued behind its own unanswered copy also skipped the copy's doorbell. Main now fails a command whose doorbell the mailbox did not deliver, and holds its slot like that of a timed-out one. Skipping every repeat of such a request would leave it without a doorbell until some other call is queued on the endpoint, and a port in a Type-C SAFE retry queues no other call. A request the firmware did read, but never answered, would also never be sent again. Match the request only while the TX ring still holds unread entries, and ring the doorbell again for it. Every retry then pokes the firmware as before, but takes no slot. Use main's transmit admission, and leave a call that the sender would refuse to the sender, so its error stays the same. The slot of the command queued last is enough to find it: a set slot bit means that it was not reused since. Run the check and the sender together in the host tests, for a request that timed out and for one whose doorbell was lost. Signed-off-by: DjDeveloperr <hey@djdev.me>
The ring pointers tell whether the firmware still reads its queue, but they were logged only for the T6030 external processor. The J316c stall was on a T600x one (firmware 13.5), where the log held nothing but timeouts. The snapshot reads host memory and RTKit's state, not the coprocessor, so log it for every processor. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merged
|
There was a problem hiding this comment.
Verdict: MERGE at 444bc2b
Checked: Ran the exact-head AFKV2 send and DPTX HPD controls with ASan and UBSan. Repeated identical HPD requests for a still-unread ring entry ring the doorbell again without spending another slot, including after the original doorbell was lost. A drained ring, different HPD payload, and refused TX admission retain the regular send path. The separate apple-dcp fixture issue from the base has been fixed on main in #4019.
afk_service_call_ring_unread() leaves a call that the sender would refuse to the sender, but it checked only a part of what the sender checks. It also rang while the firmware-27 sleep gate (sleep_v27_closed) is closed, when nothing may reach the firmware, and read the ring pointers without checking that the ring is set up. Check both, as afk_send_epic_token() does. The test covers both, and that with both HPD levels unread only the one queued last is taken for a repeat. It passed before with last_slot never recorded, where the second HPD low of low, high, low is dropped. Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
The endpoint ring check does not show that this HPD entry is unread. If firmware has consumed the HPD command without replying and another service has an unread entry on the same endpoint, the old HPD slot still matches and the ring pointers differ. This returns ETIMEDOUT without queuing the requested HPD retry. The fast path needs evidence that the matching HPD entry itself remains unread.
afk_service_call_ring_unread() took any unread entry in the endpoint's TX ring for the call's. If the firmware had read the HPD request without answering it, and another service's entry was still unread, the request was not sent again. Count the bytes the host has published in the ring, and note for each command where its entry ends. The entry is unread if fewer bytes follow it than the firmware has not read. Unlike a ring offset, that also tells it from one that lies in the same place a lap later. The test puts another service's entry behind the request, read and unread, at every place in the ring. Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict at e09a113e0dbb: merge once the rows below pass. A comment, because the PR and the last push are ours. Someone else has to approve this head.
Fixed here
e09a113e0dbb: the point raised at8c1bd117f567is right. The check looked at the endpoint's ring, not at the HPD entry. A request the firmware had read without answering, with another service's entry unread, was not sent again. The host now counts the bytes it publishes in the ring and notes for each command where its entry ends. Only a call whose own entry is unread is matched, and an entry in the same place a lap later is not mistaken for it.8c1bd117f567: the helper said it leaves to the sender what the sender would refuse, but it also rang while the firmware-27 sleep gate (sleep_v27_closed) is closed, and read the ring pointers withouttxbfr.ready. Both are checked now.- The tests passed with
last_slotnever recorded, where the second low of low, high, low is dropped. They now cover low, high, low, with the other level unread, answered, and at every place in the ring.
Read
- HPD edges: only the call queued last on that port's service is compared, level included. Another level, port or command goes to the sender.
- A rebooted processor has a new or emptied service, and ring positions are relative to the write pointer.
- Dead or off:
stopping,tx_paused,rx_paused, crash, quiesce and the sleep gate refuse, and RTKit refuses a stopped endpoint. - Locks: the slot under
service->lock, the ring undertx_lockandep->lockas the sender,dma_rmb()before the pointers. The buffer can't go while its slot bit is set.
Checked: on main 5d5060423c0e, CI host-tests image: --only afk 13/13, dptx 11/11, dcp 103/103, and the same families with #2097 and #3398 merged (13, 11, 111). 11 mutants of the new check are killed. W=1 of drivers/gpu/drm/apple/: 0 C warnings, KUnit suites built, not run. checkpatch clean. Merges cleanly with main, #2097 and #3398. Not run: no boot, no hardware.
Rows left at this head
- J773g, DP-3: boot, 10 replugs, 3x DPMS, 2x s2idle, 2x deep sleep. Picture back each time, AFK timeout lines as base.
- Peer T6050 (J716c): external display, 3 sleeps, 3 replugs, 0
-ENOSPC. Our J714s has no external display. - Peer J316c: external DP on USB-C, 5x s2idle, 3 replugs. If it stalls, one HPD slot at most, no
-ENOSPC, ring line pasted.
RyanTheTide
left a comment
There was a problem hiding this comment.
The per-entry ring arithmetic fixes my prior case. One synchronization issue remains: the retry helper reads cmd->tx_end unconditionally under service->lock, even when waits is false because the first caller still owns the slot. The first caller writes tx_end outside that lock. An overlapping retry can therefore race with that write. Read tx_end only when waits is true, or move the write under the same lock.
There was a problem hiding this comment.
Verdict: FINISH at e09a113
Failure: In afk.c, a retry can run while the original command still owns the slot with cmd->completion set. The retry predicate rejects the active slot, then reads cmd->tx_end unconditionally at line 3673. The original sender writes the same slot's tx_end at line 3930 outside service->lock. The retry's lock only protects the reader, so an overlapping retry gives the conflicting unguarded read/write Ryan reported. Read the end position only after the predicate confirms that the previous sender released the slot, or protect the writer with the same lock.
Checked: The per-command byte position fixes the earlier false retry suppression. The exact AFK sender passed under ASan and UBSan, including another service's unread entry and a full ring lap. The concurrency finding comes from the two exact call paths.
What: On a J316c (M1 Max), the external display processor (firmware 13.5) stopped answering its DPTX port after an s2idle. The Type-C SAFE retries then kept sending HPD lows. Each one that timed out kept one of the port's 16 AFK command slots, until every call on the port failed with
-ENOSPC. With this change, an HPD request identical to the port's last one, which the firmware has not read yet, is not queued again: only its doorbell is rung again. The ring pointers of a timed-out command are now logged for every processor, so the stall itself can be traced.Tested: no Mac at this head yet. Host only:
apple-afkv2passes with gcc and clang under ASan and UBSan, and--only afk13/13,--only dptx11/11.--only dcpis 102/103: threeapple-dcpunits don't compile, and fail the same way onmain37a630623169alone, since #4013. With the merge onto5fe340ace(before #4013)--only dcpwas 103/103.drivers/gpu/drm/apple/builds for arm64 at W=1 with 0 warnings, also with the display, parser and fabric KUnit suites, which are built, not run here (DRM_APPLE doesn't build under UML). checkpatch --strict is clean on the three new commits.Risk: two-way · every Mac with a DCP (shared AFK code). The HPD change only acts after an HPD request has gone unanswered while the TX ring still holds unread entries. The new log line only prints on a command timeout.
Not yet:
Details
How the slots run out (current
main)dcp_typec_route_prepare()(dcp-fabric.c) handles SAFE. It setssafe_pendingand callsdcp_dptx_disconnect_oob(), which sendsdptxport_set_hpd(port, false)and returns its error. A timed-out HPD low fails the mux change, and the port stayssafe_pending=1,safe_finish_ready=0.-ETIMEDOUTas a failed update.cd321x_retry_revalidation()retries up to 3 more times per event, and every later event (resume revalidation, partner change) starts another series. Each attempt re-enters the prepare and lowers HPD again.afk_send_command_common(), a command that timed out, or whose doorbell was lost after it was published, keeps its slot and its buffers (free_on_ack, no waiter) until the firmware answers. This is correct: the reply names the slot and is written into the command's buffer. But each repeat takes one more slot, and after 16 every call fails with-ENOSPC.The fix.
afk_service_call_ring_unread()looks at the command queued last on a service. If it is the same call with the same input, has no answer and no waiter, and the TX ring still holds unread entries, it rings the doorbell again and returns true.dptxport_set_hpd_timeout()then returns-ETIMEDOUTat once, as the first request did, without queuing a copy. A copy would do nothing: nothing else was queued on the port in between.This does not bring back a port whose firmware has stopped. It keeps the stall from taking every slot, so the failure stays a timeout, and a firmware that resumes has one request to answer, not 16.
What main already does.
main(#3321) returns the error of a lost doorbell fromafk_send_ret()to the caller and keeps the published command's slot. The earlier version of this branch did the first part a second way (int afk_send(),int dcp_send_message(), a doorbell counter) and is gone, with its stall report and theapple-afk-stallKUnit suite built on it.failed to complete: -110with notimed out afterline before it).TX r/win the timeout log tells whether the firmware still reads its queue, andrunning/crashedwhether RTKit is up.The J316c stall. Both endpoints of the same processor stopped: 0x29 (audio OPEN, the first timeout) and 0x2a (DPTX). That points at the coprocessor or its mailbox, not at the AV service. On this path (T600x dcpext, not
dcp->external),dcp_platform_suspend()closes audio and keeps the domains on throughdevice_set_wakeup_path().dcp_platform_resume()then opens audio again, and that OPEN is the call that timed out first.Related PRs
DCPDP13Serviceon endpoint 0x28 for firmware 27.x. That is not this path.Route deferral (
-61), not changed here.-ENODATAcomes fromdcp_modes_dup()in the route-follow prepare. The pipeline that owns the port's route has no admitted mode catalog for that connector. On a J316c, each Type-C port has two candidate pipelines (dcpext1, then dcpext0). The log fits this: the connector was on dcpext0's CRTC (289c00000.dcp) while dcpext1 (28cc00000.dcp, the processor that later stalled) owned the route.apple_crtc_atomic_enable()invalidates the CRTC's mode and sends a notify-only hotplug, so DRM keeps the CRTC active and the connector connected with nothing scanned out. Recovery is the owner's READY hotplug:dcp_hotplug()→dcp_retrain_active_crtc()resets the CRTC once the catalog arrives. When the owner's firmware is the one that stalled, that READY never comes. No separate code defect was found there.Evidence
On main
37a630623169:0b35d733b33d,a4fa8d3fe580andefd42a16294e: the earlier version.09938fa53392drm/apple: afk: drop the stall report and the doorbell count75450d09821fmerge of main, no conflict left after itea49e8fa4095drm/apple: dptxep: ring again for an unread HPD request444bc2b0e386drm/apple: afk: log the rings of every command that times outAgainst main the branch changes 6 files:
afk.c,afk.h,dptxep.cand three host-test files.Host tests ran in the pinned
host-testscontainer image.extract-send.pyruns the realafk_send_command_common(), reply path andafk_service_call_ring_unread()on a legacy ring:extract-hpd.pychecks thatdptxport_set_hpd_timeout()sends no copy and returns-ETIMEDOUT.Build: arm64, clang 23, CONFIG_DRM_APPLE=m.
afk.oanddptxep.oalso build at W=1 at the merge commit and at each commit after it.