mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason-JH Lin <jason-jh.lin@mediatek.com>
To: Jassi Brar <jassisinghbrar@gmail.com>,
	Chun-Kuang Hu <chunkuang.hu@kernel.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>,
	Jason-JH Lin <jason-jh.lin@mediatek.com>,
	Paul-PL Chen <paul-pl.chen@mediatek.com>,
	Zi-Hao Huang <zi-hao.huang@mediatek.com>,
	Olivia Wen <olivia.wen@mediatek.com>,
	Fei Shao <fshao@chromium.org>, Chen-yu Tsai <wenst@chromium.org>,
	<Project_Global_Chrome_Upstream_Group@mediatek.com>,
	<linux-kernel@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>,
	<linux-arm-kernel@lists.infradead.org>
Subject: [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump
Date: Tue, 1 Dec 2026 19:26:11 +0800	[thread overview]
Message-ID: <20261201112707.644513-3-jason-jh.lin@mediatek.com> (raw)
In-Reply-To: <20261201112707.644513-1-jason-jh.lin@mediatek.com>

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


      parent reply	other threads:[~2026-12-01 11:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201112707.644513-3-jason-jh.lin@mediatek.com \
    --to=jason-jh.lin@mediatek.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=fshao@chromium.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=olivia.wen@mediatek.com \
    --cc=paul-pl.chen@mediatek.com \
    --cc=wenst@chromium.org \
    --cc=zi-hao.huang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®