* [PATCH 0/2] mailbox: mtk-cmdq: Fix error resume address and early task completion
@ 2026-12-01 11:26 Jason-JH Lin
2026-12-01 11:26 ` [PATCH 1/2] mailbox: mtk-cmdq: Add mminfra_offset to the error resume address Jason-JH Lin
2026-12-01 11:26 ` [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump Jason-JH Lin
0 siblings, 2 replies; 3+ messages in thread
From: Jason-JH Lin @ 2026-12-01 11:26 UTC (permalink / raw)
To: Jassi Brar, Chun-Kuang Hu, AngeloGioacchino Del Regno
Cc: Matthias Brugger, Jason-JH Lin, Paul-PL Chen, Zi-Hao Huang,
Olivia Wen, Fei Shao, Chen-yu Tsai,
Project_Global_Chrome_Upstream_Group, linux-kernel,
linux-mediatek, linux-arm-kernel
From: Jason-jh Lin <jason-jh.lin@mediatek.com>
This series fixes two problems in the CMDQ mailbox driver's thread irq
handling.
Patch 1 makes the error path use cmdq_convert_gce_addr() when it
resumes the thread at the next task, so mminfra_offset is applied like
in every other write to CMDQ_THR_CURR_ADDR. Without it the thread
resumes from a wrong PC on SoCs with a non-zero mminfra_offset, such as
MT8196.
Patch 2 makes the irq handler wait until GCE has taken the trailing
jump of a finished task before completing it. A client that frees the
task buffer in its callback could otherwise cause an SMMU read fault
when GCE fetches the jump from the freed buffer.
The two patches touch adjacent code in cmdq_task_handle_error() and
need to be applied in this order.
Jason-jh Lin (1):
mailbox: mtk-cmdq: Add mminfra_offset to the error resume address
Olivia Wen (1):
mailbox: mtk-cmdq: Wait for GCE to take the chained jump
drivers/mailbox/mtk-cmdq-mailbox.c | 50 +++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] mailbox: mtk-cmdq: Add mminfra_offset to the error resume address
2026-12-01 11:26 [PATCH 0/2] mailbox: mtk-cmdq: Fix error resume address and early task completion Jason-JH Lin
@ 2026-12-01 11:26 ` Jason-JH Lin
2026-12-01 11:26 ` [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump Jason-JH Lin
1 sibling, 0 replies; 3+ messages in thread
From: Jason-JH Lin @ 2026-12-01 11:26 UTC (permalink / raw)
To: Jassi Brar, Chun-Kuang Hu, AngeloGioacchino Del Regno
Cc: Matthias Brugger, Jason-JH Lin, Paul-PL Chen, Zi-Hao Huang,
Olivia Wen, Fei Shao, Chen-yu Tsai,
Project_Global_Chrome_Upstream_Group, linux-kernel,
linux-mediatek, linux-arm-kernel, stable
From: Jason-jh Lin <jason-jh.lin@mediatek.com>
After an error, cmdq_task_handle_error() moves the thread PC to the
next task with next_task->pa_base >> shift. All other writes of a task
address to CMDQ_THR_CURR_ADDR go through cmdq_convert_gce_addr(), which
also adds mminfra_offset. On SoCs with a non-zero mminfra_offset (e.g.
MT8196, SZ_2G), the thread resumes from the wrong PC after an error.
Use cmdq_convert_gce_addr() here as well.
Fixes: ddb5d0c941c6 ("mailbox: mtk-cmdq: Add mminfra_offset configuration for DRAM transaction")
Cc: stable@vger.kernel.org
Signed-off-by: Jason-jh Lin <jason-jh.lin@mediatek.com>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index f1eb886368cc..191122b4c94f 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -300,7 +300,7 @@ static void cmdq_task_handle_error(struct cmdq_task *task)
next_task = list_first_entry_or_null(&thread->task_busy_list,
struct cmdq_task, list_entry);
if (next_task)
- writel(next_task->pa_base >> cmdq->pdata->shift,
+ writel(cmdq_convert_gce_addr(next_task->pa_base, cmdq->pdata),
thread->base + CMDQ_THR_CURR_ADDR);
cmdq_thread_resume(thread);
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump
2026-12-01 11:26 [PATCH 0/2] mailbox: mtk-cmdq: Fix error resume address and early task completion Jason-JH Lin
2026-12-01 11:26 ` [PATCH 1/2] mailbox: mtk-cmdq: Add mminfra_offset to the error resume address Jason-JH Lin
@ 2026-12-01 11:26 ` Jason-JH Lin
1 sibling, 0 replies; 3+ messages in thread
From: Jason-JH Lin @ 2026-12-01 11:26 UTC (permalink / raw)
To: Jassi Brar, Chun-Kuang Hu, AngeloGioacchino Del Regno
Cc: Matthias Brugger, Jason-JH Lin, Paul-PL Chen, Zi-Hao Huang,
Olivia Wen, Fei Shao, Chen-yu Tsai,
Project_Global_Chrome_Upstream_Group, linux-kernel,
linux-mediatek, linux-arm-kernel
From: Olivia Wen <olivia.wen@mediatek.com>
When a client queues a task on a GCE thread that is still running, the
driver turns the last instruction of the previous task into a jump to
the new one. On the done interrupt, a task is treated as finished as
soon as the thread PC reaches that last instruction, before GCE has
executed the jump.
GCE may still be waiting to fetch the jump when the interrupt is
handled. If the client frees the finished task's buffer in its
callback, GCE then fetches the jump from an unmapped buffer and stops
with an SMMU read fault, and the following tasks are reported as done
although they never ran.
Before completing a task whose PC sits on its trailing jump, poll the
thread PC for up to 20 us until GCE moves past the jump. On timeout,
suspend the thread and move the PC to the next task instead of only
reporting an error. If the task is the last queued one, keep the
thread suspended until the irq handler disables it.
Signed-off-by: Olivia Wen <olivia.wen@mediatek.com>
Signed-off-by: Jason-jh Lin <jason-jh.lin@mediatek.com>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 48 ++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c
index 191122b4c94f..bff8386fe5f8 100644
--- a/drivers/mailbox/mtk-cmdq-mailbox.c
+++ b/drivers/mailbox/mtk-cmdq-mailbox.c
@@ -305,6 +305,50 @@ static void cmdq_task_handle_error(struct cmdq_task *task)
cmdq_thread_resume(thread);
}
+/*
+ * The thread PC (@gce_addr) sits on the trailing JUMP of @task. GCE may not have fetched
+ * that JUMP yet, so make sure the PC leaves @task's buffer before the client is allowed
+ * to free it in its callback.
+ */
+static void cmdq_thread_wait_jump(struct cmdq *cmdq, struct cmdq_thread *thread,
+ struct cmdq_task *task, u32 gce_addr)
+{
+ struct cmdq_task *next_task;
+ u32 pc;
+ dma_addr_t pa;
+
+ /* A suspended thread (e.g. during shutdown) does not fetch anything */
+ if (readl(thread->base + CMDQ_THR_CURR_STATUS) & CMDQ_THR_STATUS_SUSPENDED)
+ return;
+
+ if (!readl_poll_timeout_atomic(thread->base + CMDQ_THR_CURR_ADDR,
+ pc, pc != gce_addr, 1, 20))
+ return;
+
+ /* GCE did not take the JUMP in time, stop it and take the JUMP for it */
+ WARN_ON(cmdq_thread_suspend(cmdq, thread) < 0);
+ if (readl(thread->base + CMDQ_THR_CURR_ADDR) != gce_addr) {
+ cmdq_thread_resume(thread);
+ return;
+ }
+
+ pa = cmdq_revert_gce_addr(pc, cmdq->pdata);
+ dev_err_ratelimited(cmdq->mbox.dev, "GCE thread 0x%x: PC = %pad not jumping after EOC\n",
+ (u32)(thread->base - cmdq->base), &pa);
+
+ /*
+ * For the last task, keep the thread suspended. It is disabled once
+ * the task list becomes empty at the end of the irq handler.
+ */
+ if (list_is_last(&task->list_entry, &thread->task_busy_list))
+ return;
+
+ next_task = list_next_entry(task, list_entry);
+ writel(cmdq_convert_gce_addr(next_task->pa_base, cmdq->pdata),
+ thread->base + CMDQ_THR_CURR_ADDR);
+ cmdq_thread_resume(thread);
+}
+
static void cmdq_thread_irq_handler(struct cmdq *cmdq,
struct cmdq_thread *thread)
{
@@ -342,6 +386,10 @@ static void cmdq_thread_irq_handler(struct cmdq *cmdq,
curr_task = task;
if (!curr_task || curr_pa == task_end_pa - CMDQ_INST_SIZE) {
+ /* PC is on the trailing JUMP of this task */
+ if (curr_task)
+ cmdq_thread_wait_jump(cmdq, thread, task, gce_addr);
+
cmdq_task_exec_done(task, 0);
kfree(task);
} else if (err) {
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 11:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 11:26 [PATCH 0/2] mailbox: mtk-cmdq: Fix error resume address and early task completion Jason-JH Lin
2026-12-01 11:26 ` [PATCH 1/2] mailbox: mtk-cmdq: Add mminfra_offset to the error resume address Jason-JH Lin
2026-12-01 11:26 ` [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump Jason-JH Lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®