From adbab6a1d1b46cbaebf905c5fde67bb7d4477005 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 20 Nov 2026 00:32:14 +1100 Subject: [PATCH] drm/apple: stop the J613 DCPLink when a call is abandoned dcp_v26_link_call() was copied from the T6030 14.7 DCPLink client before two fixes landed there, and the 26.6 copy kept the old exits. When a call times out, fails its reply check, or a callback handler fails, it returns with the link still running and calls[nested].active still set. dcp_v26_call() then marks the session failed and nothing pumps the link again, but dcp_v26_link_receive() keeps accepting the late reply and every later callback and queues a kmalloc'd copy of each, up to the 32-event limit. The same happens when a queued notification fails while draining before an outer call, and when a nested call finds no callback to answer. link_fail() woke the waiters but left the queued copies on a list nothing would dequeue again. Port Chris Kearney's 14.7 fixes, commit d203ba4fbaa0 ("drm/apple: stop the T6030 DCPLink when a call is abandoned") and commit 90139dcfa979 ("drm/apple: stop the T6030 DCPLink when a call fails before submit"): stop the link on every return that gives up on a call, clear the abandoned call's active flag so the receive path drops whatever arrives for it, and free the queued events in link_fail() under the lock. An event a caller has already dequeued is no longer on the list. The callers already treat any failed call as the end of the session (dcp_v26_call() latches v26->failed, "recovery requires a reboot"), so nothing that worked before stops working. The firmware buffers and the RPC memory are still kept until reboot. This code runs only with the J613 (apple,t8122-dcp) 25G83 DCP firmware. The -EBUSY retry before submit is unchanged: it re-drains a callback that arrived between the drain and the submit, bounded by the call deadline. Fixes: aa504d6de3db ("drm: apple: add the J613 v26 display backend and guarded coldplug") Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/iomfb_v26_6_link.c | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/apple/iomfb_v26_6_link.c b/drivers/gpu/drm/apple/iomfb_v26_6_link.c index 36d9a6d38691e..3b5c0d08f5c62 100644 --- a/drivers/gpu/drm/apple/iomfb_v26_6_link.c +++ b/drivers/gpu/drm/apple/iomfb_v26_6_link.c @@ -63,9 +63,17 @@ struct dcp_v26_event { /* Called with the lock held. */ static void link_fail(struct dcp_v26_link *link) { + struct dcp_v26_event *e, *next; + if (!link->failed) dev_err(link->dev, "DCP link stopped; firmware buffers are kept until reboot\n"); link->failed = true; + /* Nothing dequeues events from a failed link. */ + list_for_each_entry_safe(e, next, &link->events, list) { + list_del(&e->list); + kfree(e); + } + link->event_count = 0; wake_up(&link->wait); } @@ -409,6 +417,7 @@ int dcp_v26_link_pump(struct dcp_v26_link *link, unsigned long timeout, /* * Calls @tag and handles the callbacks that arrive until its reply, and, for * a non-zero @completion_id, until the swap-complete callback for that swap. + * A call that fails once submitted, including by timing out, stops the link. * Must not be called concurrently with itself or dcp_v26_link_pump(), except * from inside a callback handler. */ @@ -443,6 +452,10 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, ret = dcp_v26_link_pump(link, 0, callback, cookie); if (ret) { kfree(packet); + /* The caller gives up on the session: stop queueing. */ + mutex_lock(&link->lock); + link_fail(link); + mutex_unlock(&link->lock); return ret; } } @@ -450,6 +463,7 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, mutex_lock(&link->lock); nested = link->callback_depth != 0; if (nested && !link->callback_count) { + link_fail(link); mutex_unlock(&link->lock); kfree(packet); return -EPROTO; @@ -471,8 +485,10 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, struct dcp_v26_event *e = link_next_event(link, max_t(long, deadline - jiffies, 0)); struct apple_dcp_link_rpc_header *h; - if (IS_ERR(e)) - return PTR_ERR(e); + if (IS_ERR(e)) { + ret = PTR_ERR(e); + goto abandon; + } h = (void *)e->data; if (e->kind == DCP_V26_EVENT_REPLY) { if (replied || e->size != size || e->message != expected || @@ -494,9 +510,16 @@ int dcp_v26_link_call(struct dcp_v26_link *link, u32 tag, const void *input, } kfree(e); if (ret) - return ret; + goto abandon; if (replied && (!completion_id || completed == completion_id)) return 0; } - return -ETIMEDOUT; + ret = -ETIMEDOUT; +abandon: + /* The firmware may still answer: queue nothing for a call nobody waits for. */ + mutex_lock(&link->lock); + link->calls[nested].active = false; + link_fail(link); + mutex_unlock(&link->lock); + return ret; }