Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp312541lqp; Thu, 21 Mar 2024 01:46:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3EUggu9DaQIJI93cXAlyb1CbS27QD8S5f1KU7JsB/Pg/MzSdT59mkPp0gjVUnKaI75qJ3I1u4emEzqRf79fHbBnUtuNOObMm0EUlDGg== X-Google-Smtp-Source: AGHT+IE7aLENrgUPXJ8XohQ8RtMBo3QHVn8rPjBHEpjHi8DSFr/nt83+MI9qDHyiYLmzUAjPFreH X-Received: by 2002:a05:6214:1d2e:b0:696:51aa:8a6a with SMTP id f14-20020a0562141d2e00b0069651aa8a6amr2088864qvd.18.1711010809131; Thu, 21 Mar 2024 01:46:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711010809; cv=pass; d=google.com; s=arc-20160816; b=k0fdJwaiM73XBPkkf5Gxz4BzsYhWu4t6mgf8dR5O2shLKC7KVQBCP6d0bc/f9N3xiY uRNWJEG1HgOoAmq8IvT+J7g3l9JmbSAIeiE0B4gppKB60Y3PXGrb6nCwdG+4vfPPvhGN FrBKFj9lO/xIZrSwvXLSJSctSzJDmQ0tcrAn5HtDCj2mnMlUiXo88DMzx2FX5ASZ8uCm FMtMbRVKiXSm1OzuNI8b8qpzARbTT3ftrWV64p/znsU1MOtRLwpbKMzbXisaTfaKawaC B7gNi635ocg+7b1wUuIKX9pMtj5t5eELWW38KPQOkOW6tBsYeWappF7or1fsP+m7I6iQ hKnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ddqYUChVCWVYq1Iy43zQymIAj2h/oUbeJaD3Fbheqxs=; fh=paRSa/Rd7IxtF+5+pZI2G+TKlQUEk4rWEuOAHek/xn4=; b=g9OY2Xr9c6gyVjlWexNEbOIJmnQo0ZY2zxUyLyoD5pg1FYHKlwsR7iGUfFw1dGM0Ge p/hnYRrC7s/9iFsUSkqHh9wW+DNcBvb84hbF35cFEJnfDdhEqHhFbk1pxxXJLLX8xmQd SWiY7xfOORj2p/UKGrKmHRNKODvFMDOvVJcZKTSwoAfgowxEyWN8jFU+jMIJqR07penO b/c03XwOlAw3zBa1tbrdDjOK3fbf5p002jlfq9W1MhHn5vZa4SfokL2q5G+4WGZSoEXi QK9vrzHk5n/T95geTwNk9z2/jq7l+nMdrp9MfMGpLppp1CVWflBzub8jWoWDtBEgfvOk H0SA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=1fp7acZm; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-109810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 10-20020a0562140cca00b00690bc7c1d63si15096139qvx.232.2024.03.21.01.46.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 01:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-109810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=1fp7acZm; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-109810-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-109810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id CBBDB1C20D56 for ; Thu, 21 Mar 2024 08:46:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97625381B9; Thu, 21 Mar 2024 08:46:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="1fp7acZm" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33FE51B274; Thu, 21 Mar 2024 08:46:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711010795; cv=none; b=jDwVAvGZ0hJu9vmplzJraopBrZDli714odqmwgG9lTkk2K5QSWXu0epTWLuyz2HqqALdFZzJmF3O+rITJTb7Iiq2ylNqO5EnXgGwc0bIu9ImVidjITNleB0Rh2SFlc40Gw///19fjUke9Y0SES//NlgGFNY17rcxpeyUstZtRC4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711010795; c=relaxed/simple; bh=NqcCQoYTi7w39yHeqdyYgH/AKTtHB2Xu9qukGQne7yA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=guYnwyyTZ2sVh5zk6bBZgRjweh7rlkyhOErvXYwOTRZGjnqxU7fdURGK2pYC2my3pBYz3k54tEd2MjeYy/mONDyYCNdhrN2JNRwi+JlFbDWue4waxo4naqcgxEsuh4iyn/lmz/gWnip5nygP0C3r+KE5Zm9ETQOVvuKKtgFhsNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=1fp7acZm; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1711010792; bh=NqcCQoYTi7w39yHeqdyYgH/AKTtHB2Xu9qukGQne7yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1fp7acZmBXCpRsY5BNXvVpvO/H+tZY7F6WB7B0Qay39vTKhh+BKJF42sh6kdvM8aE F913/i597FGqp+xvQvdVzofeVzjSbaAD4PP9kokEPNlGsWgYNX6oz0117rxvXMVZEY LV/bUVKfAavpu+/JbLjWUM8ftpCGKYDXvxwddipwPA+r+NUvabFVgiHlQowucYj9Rh lEbMZ+A53zFJW7skNmG5nFKMqVwvW5oeCyeftgV5lL8BkedpG1B8dl1dl1JEhboy/z m1HY1blLw+mw7PhAuz25pFgj9j0NnjP4Exx8VrBAMDHTNkeG/OYNjxhQ0bMyw/WqrS Co0oCbYYS2axw== Received: from IcarusMOD.eternityproject.eu (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A31E137820EF; Thu, 21 Mar 2024 08:46:31 +0000 (UTC) From: AngeloGioacchino Del Regno To: mathieu.poirier@linaro.org Cc: andersson@kernel.org, matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, tzungbi@kernel.org, tinghan.shen@mediatek.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, wenst@chromium.org, kernel@collabora.com Subject: [PATCH 1/2] remoteproc: mediatek: Make sure IPI buffer fits in L2TCM Date: Thu, 21 Mar 2024 09:46:13 +0100 Message-ID: <20240321084614.45253-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321084614.45253-1-angelogioacchino.delregno@collabora.com> References: <20240321084614.45253-1-angelogioacchino.delregno@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 oeprations 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: 3efa0ea743b7 ("remoteproc/mediatek: read IPI buffer offset from FW") Signed-off-by: AngeloGioacchino Del Regno --- drivers/remoteproc/mtk_scp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c index a35409eda0cf..67518291a8ad 100644 --- a/drivers/remoteproc/mtk_scp.c +++ b/drivers/remoteproc/mtk_scp.c @@ -132,7 +132,7 @@ static int scp_elf_read_ipi_buf_addr(struct mtk_scp *scp, static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw) { int ret; - size_t offset; + size_t buf_sz, offset; /* read the ipi buf addr from FW itself first */ ret = scp_elf_read_ipi_buf_addr(scp, fw, &offset); @@ -144,6 +144,14 @@ static int scp_ipi_init(struct mtk_scp *scp, const struct firmware *fw) } dev_info(scp->dev, "IPI buf addr %#010zx\n", offset); + /* Make sure IPI buffer fits in the L2TCM range assigned to this core */ + buf_sz = sizeof(*scp->recv_buf) + sizeof(*scp->send_buf); + + if (scp->sram_size < buf_sz + offset) { + dev_err(scp->dev, "IPI buffer does not fit in SRAM.\n"); + return -EOVERFLOW; + } + scp->recv_buf = (struct mtk_share_obj __iomem *) (scp->sram_base + offset); scp->send_buf = (struct mtk_share_obj __iomem *) -- 2.44.0