Skip to content

Commit 26c6d7d

Browse files
AngeloGioacchino Del Regnogregkh
authored andcommitted
remoteproc: mediatek: Make sure IPI buffer fits in L2TCM
commit 331f91d upstream. The IPI buffer location is read from the firmware that we load to the System Companion Processor, and it's not granted that both the SRAM (L2TCM) size that is defined in the devicetree node is large enough for that, and while this is especially true for multi-core SCP, it's still useful to check on single-core variants as well. Failing to perform this check may make this driver perform R/W operations out of the L2TCM boundary, resulting (at best) in a kernel panic. To fix that, check that the IPI buffer fits, otherwise return a failure and refuse to boot the relevant SCP core (or the SCP at all, if this is single core). Fixes: 3efa0ea ("remoteproc/mediatek: read IPI buffer offset from FW") Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20240321084614.45253-2-angelogioacchino.delregno@collabora.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6420695 commit 26c6d7d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/remoteproc/mtk_scp.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp,
126126
static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw)
127127
{
128128
int ret;
129-
size_t offset;
129+
size_t buf_sz, offset;
130130

131131
/* read the ipi buf addr from FW itself first */
132132
ret = scp_elf_read_ipi_buf_addr(scp, fw, &offset);
@@ -138,6 +138,14 @@ static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw)
138138
}
139139
dev_info(scp->dev, "IPI buf addr %#010zx\n", offset);
140140

141+
/* Make sure IPI buffer fits in the L2TCM range assigned to this core */
142+
buf_sz = sizeof(*scp->recv_buf) + sizeof(*scp->send_buf);
143+
144+
if (scp->sram_size < buf_sz + offset) {
145+
dev_err(scp->dev, "IPI buffer does not fit in SRAM.\n");
146+
return -EOVERFLOW;
147+
}
148+
141149
scp->recv_buf = (struct mtk_share_obj __iomem *)
142150
(scp->sram_base + offset);
143151
scp->send_buf = (struct mtk_share_obj __iomem *)

0 commit comments

Comments
 (0)