Repository navigation
drm/apple: afk: limit the compact replies waiting to be sent - #2937
Conversation
Every compact service call from the firmware gets a reply buffer of the call's size, which is queued on the endpoint's ordered transmit queue. A reply can wait there for transmit ring space for up to five seconds while the receive worker keeps taking calls, and nothing limits how many replies, or how many bytes of them, are queued in the meantime. A firmware that keeps calling while it does not drain its ring makes the queue grow without bound. Count the payload bytes of the replies that are queued and not yet sent, under the endpoint lock, and take a call only while its reply fits. The room is AFK_COMPACT_MESSAGE_MAX, the largest single message, which is also what the receive side holds in assembly: one call of any valid size is always taken when nothing is queued, and the short calls the display services receive stay far below it. A call beyond that is dropped with a rate-limited warning before its buffer is allocated and before the service handler runs, so it is not counted as a pending job either. The reply worker returns the room once the send has finished or failed, which covers the queue flush at teardown as well. A dropped call, like one whose reply buffer cannot be allocated, is never answered, which the firmware sees the same way as a reply that failed to send. With the coordinated sleep transport, mark the endpoint so that sleep does not proceed, as the reply worker already does for a failed send. Add a KUnit case that stalls the transmit queue, feeds calls until the room is used up and checks that later calls are dropped until the queue has drained, and that a dropped call holds off the coordinated sleep. Signed-off-by: Ryan Murray <[email protected]>
|
Review at 33f05ac.
Rows owed at this head (none posted): an external display with hotplug on J713 and on a desktop with 26.x DCP firmware; one coordinated s2r cycle on a v27_sleep_transport Mac, to show that sleep is not poisoned in normal use. |
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at 33f05ac891c96fe7bb61bde2c6fed3bc9050afb6.
Checklist Summary
- §1 No model gating: Pass — applies uniformly to compact service calls;
v27_sleep_transportis an existing transport capability flag. - §2 Production-ready: Pass — no new parameters or workarounds.
- §3 Safety: Pass —
afk_recv_handle_compact_call()already enforcespayload_size >= sizeof(*request_desc) + sizeof(*call) > 0, so zero-byte calls cannot bypass the byte cap;afk_compact_reply_reserve()uses overflow-safe subtraction underep->lock; both budget-drop (afk.c:1210) andkvzalloc-failure (afk.c:1216) paths now callafk_compact_call_unanswered()to setsleep_poisonedunderep->lockwhenv27_sleep_transportis active;afk_compact_reply_worker()releases the reserved bytes on both success and failure, anddestroy_workqueue(tx_wq)drains queued replies cleanly on teardown. - §4 Clean-room & attribution: Pass — human author/committer (
Ryan Murray <[email protected]>) and humanSigned-off-by:, zero AI trailers in commit. - §5 Evidence: Pending — KUnit
afk_compact_call_reply_budget_testpasses (51/52, 1 unrelated skip), but hardware rows are still owed (external display with hotplug on J713 / 26.x DCP desktop + coordinated s2r on av27_sleep_transportMac to confirm normal operation does not poison sleep). - §6 Naming: Pass.
- CI (at review time):
host-testsgreen.
Non-blocking Nits
drivers/gpu/drm/apple/afk.c:1163-1168: two consecutiveif (ret)blocks inafk_compact_reply_worker()can be folded into one block.- The
kvzallocOOM poison path (afk.c:1214-1217) is verified by inspection but not directly exercised by KUnit.
Verdict
COMMENT — 0 code/policy blockers and CI is green; waiting on the owed §5 hardware rows before approval.
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at 33f05ac891c9. The byte budget is released by the reply worker and exhaustion poisons the prepared sleep path where applicable. The current J473 does not bind its DCP, so a clean boot there does not exercise this callback. Add an admitted J473 27.2 display hotplug/DPMS row alongside a J413 13.5 path that uses the affected transport, and confirm sleep clears the pending-reply state after unwind.
There was a problem hiding this comment.
Formal §1–§6 pre-PR re-review at 33f05ac891c96fe7bb61bde2c6fed3bc9050afb6 against live integration/aurora (70a00e583b03).
Status & Code Assessment (0 code, CI, or attribution blockers)
- Not superseded: Live
integration/aurora(drivers/gpu/drm/apple/afk.c:1175-1259,afk.h:575) still has unbounded compact reply queuing and does not poison coordinated sleep on OOM/drop. - §1 No model gating: Pass — applies uniformly to compact service calls;
v27_sleep_transportis an existing transport capability flag. - §2 Production-ready & §3 Safety: Pass —
afk_recv_handle_compact_call()requirespayload_size >= sizeof(*request_desc) + sizeof(*call) > 0andep->tx_wqbefore reserving, so zero-byte calls cannot bypass the budget.afk_compact_reply_reserve()uses overflow-safe subtraction underep->lock(irqsave); budget-drop andkvzallocfailure both callafk_compact_call_unanswered()to setep->sleep_poisonedunderep->lockwhenv27_sleep_transportis active.afk_compact_reply_worker()setssleep_poisoned(on send failure) and releasescompact_reply_bytesbeforeatomic_dec_return_release(&r->ep->sleep_jobs)andkvfree(r); teardown (afk_quiesce()) destroysep->wqbeforeep->tx_wq, draining all queued replies cleanly.
- §4 Clean-room & attribution: Pass — commit
33f05ac891c9carries human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only, zero AI trailers;Assisted-by:is in the PR body. - §6 Naming & Live CI: Pass —
host-testsis COMPLETED / SUCCESS on33f05ac891c9, and QEMU arm64 KUnit (afk_compact_call_reply_budget_test) passes. - Non-blocking nit: The two consecutive
if (ret)blocks inafk_compact_reply_worker()(afk.c:1163-1168) can be folded into one.
Blocker Holding APPROVE / MERGETRAIN-LINUX4
- §5 Hardware test & regression rows missing: Zero hardware rows have been posted yet (
### Hardware rowsstill lists fleet82 one-shot boots on M1 Pro, M2, J616s, J473 asPending). Please post exact-head hardware evidence on the default cmdline exercising the compact-EPIC display path (including external display hotplug/DPMS on a host whose DCP binds this path, plus a coordinated S2R cycle on av27_sleep_transportMac confirming normal operation does not poison sleep and clears pending reply state cleanly) with §5 regression numbers (0 SELinux denials, 0 failed units, 0 new kernel errors).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 33f05ac891c9: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: one boot at this head on one of the pending Macs (M1 Pro, M2, J616s or J473) with the compact-EPIC display path in use (internal panel, plus an external display where there is one) and no AFK errors.
Checked: no Apple material, no gates. The compact replies waiting to be sent are bounded. CI green.
Superseded by the review at 33f05ac
|
|
Compact service calls from the DCP firmware each get a reply buffer, queued on the endpoint's ordered transmit workqueue. A reply can wait there for ring space while the receive side keeps taking calls, and nothing limited how many replies were queued.
Change
ep->lockand capped atAFK_COMPACT_MESSAGE_MAX, the largest single message (also what the receive side holds in assembly). Any one valid call is always taken when nothing is queued. A call beyond the cap is dropped with a rate-limited warning before anything is allocated or the handler runs.v27_sleep_transport) the endpoint is now markedsleep_poisonedon both paths, as the reply worker already does when a send fails, so a coordinated sleep does not proceed with a call outstanding.No parameters, no chip/board/firmware gates.
Testing
integration/auroraa7638d5 + this commit:apple-epic-parserand the rest of the C group, 52 run, 51 passed, 1 skipped (apple_g17_rx_util_min_test, needsCONFIG_UCLAMP_TASK).afk_compact_call_reply_budget_teststalls the transmit queue, fills the budget, checks that later calls are dropped until the queue drains, and (new) that a dropped call setssleep_poisonedwith the sleep transport on. With the two new poison calls removed it FAILS atafk-parser-test.c:259.Still to run
Hardware rows
Pending: one-shot boots of fleet82 + this series on the default cmdline (M1 Pro, M2, J616s, J473), compared with the same rows on the production kernel. They will be added here.
Reviewer detail
afk_compact_call_unanswered()takesep->lock(irqsave) and setssleep_poisonedonly whenep->dcp->v27_sleep_transport; the worker's failed-send path now uses the same helper (no behaviour change there).afk_compact_reply_reserve()/_release()run underep->lock. A dropped call is not counted insleep_jobs. The worker releases the reply's bytes after the send whether it succeeded or failed; teardown (destroy_workqueue(tx_wq)) drains through the worker, so the count returns to zero.