From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=60.244.123.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796124435; b=Ygvpg+crIE2PVUuY51rT4gf9TVLrDoBsuwPG0OCGAZx61JD5TM15X0U0RAUn4jYKxDyl tajXJolyMnhd0wxfDlYojmNEB2o4zairXgbZvF+b9QXwHT1tRWvgwq8SnYlRmiO5g56xn xX2Ve0bRUADuUh1fV3ddsqWesy7pAyymkoIjlF8OdlLliL3a0mnqht/OKOB6pREInXUoS MWqM7NpkMLmIwh+nUX6NoAtONPFkeaW3Ljyyv0IMg8kg7mksZ6cXbb2Zq7+iJhlTTUP5t ASP+wNqHmtRrg0cCdKJ3QkUW9/0AsChbSysiIl0XJCagxLlXg085fUXkh2w8ugabfXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796124435; h=DMARC-Filter:X-UUID:DKIM-Signature:X-CID-P-RULE:X-CID-O-INFO: X-CID-META:X-CID-BVR:X-CID-BAS:X-CID-FACTOR:X-CID-RHF:X-UUID:Received: Received:Received:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding: Content-Type:X-MTK; bh=2GOH8dEQeJKH83sYnDX+7Q1+pESVzatPRzHzpWq6+BU=; b=jDAx6m1x25AV/qv2s9Byewx4X5dw1wxFkXqP926C5IfyGmDipg0O1KPgE9PQe1+EekJs G4871vw2XKUsfI+HRZdEGCiTa6GqKeeCT7YJtXhSTwAo+XVn3RUX/nc+CZOxW6BtR9f6i ag7YW0lDX17sXGLKD9AgAo6EniHVBj/jIFj9Qc12oVxS1tALZP7YNZDp+6LQstO3tKfHD emaJSIkzTVSHxFFdWEOxLBUCLDUyjmQFD1cvYV37SN9AKCq/6du0Cl1dF4UpGT3Xo5PuI MRKUDazcKw+ahoO+RG89ET6+nwDulPnLZ6EAUvI4zCbt7zcR9Uc3r6pgUGseh/pHLng== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=XRfk89zG; arc=none smtp.remote-ip=60.244.123.138 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2487B606A329 for ; Tue, 1 Dec 2026 11:27:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2487B606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256 header.s=dk header.b=XRfk89zG X-UUID: 2552cc1aed7a11f1b9cf3d4034dccee2-20261201 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=2GOH8dEQeJKH83sYnDX+7Q1+pESVzatPRzHzpWq6+BU=; b=XRfk89zGbKvVEmzoKKlJrBlRvJPK9WEM3VElpznsmxv/wGxvNRQP9s5Ys1ITriP5FiuF5IkFrmuuaPw036Igrj0ARSO42GvvErTk4l+/0t4oTKqNWObASVOn+jGgDmmZoJYNcaMKSiKW4h3vioP7nbgtGzlp+YFi4sACOqOdi64=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.21,REQID:ae1e0ef0-9744-400c-a22f-07fab611f1e6,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:1,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:1 X-CID-META: VersionHash:b0318ac,CLOUDID:38770967-4b51-4c95-bb1b-80ac6aad9c96,B ulkID:nil,BulkQuantity:0,SF:81|82|102|836|865|888|898,TC:-5,Content:0|15|5 0|99,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0 ,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 2552cc1aed7a11f1b9cf3d4034dccee2-20261201 Received: from mtkmbs09n2.mediatek.inc [(172.21.101.94)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1601448742; Tue, 01 Dec 2026 19:27:09 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N1.mediatek.inc (172.21.101.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Tue, 1 Dec 2026 19:27:07 +0800 Received: from mtksitap99.mediatek.inc (10.233.130.16) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.2562.56 via Frontend Transport; Tue, 1 Dec 2026 19:27:07 +0800 From: Jason-JH Lin 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 , , , , Subject: [PATCH 2/2] mailbox: mtk-cmdq: Wait for GCE to take the chained jump Date: Tue, 1 Dec 2026 19:26:11 +0800 Message-ID: <20261201112707.644513-3-jason-jh.lin@mediatek.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20261201112707.644513-1-jason-jh.lin@mediatek.com> References: <20261201112707.644513-1-jason-jh.lin@mediatek.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N From: Olivia Wen 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 Signed-off-by: Jason-jh Lin --- 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