From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ABF943064A9 for ; Wed, 31 Dec 2025 23:39:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767224342; cv=none; b=Q921hCZpaRIRwBYwGPKfXBSmrzdClB0TY8HBW94sX1jUzR3bGh9m1x0YGkvr1RS2wyKnCQ8OZfwd7B1df9rsct3BlPW9Kd34hgZ590N5M07Qhf04SL52ugn+YE80MeIUrwQlXOpwK4Y+iqVowWpUvHgR0wI7SJb7638IA1WC72g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767224342; c=relaxed/simple; bh=dQ92F5m0cvYQ0BIrNzodFYLQ9eaMQPsnd9ZIArx1ccY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YtlxR9cu1pLS+0VkCE6vsN3sp6j2XK20CGmVcB/h9xd+4Lkj+i5aSS3Ai8v3HPI1fk1pmTiuU4C9h8pXRmW305F9VHOU2ETTpXnT8v6nhoosOIa0eQQf7BzWjG1qmh+7C+sdLxcGRBm2luQ15X0r68GQqtcQejZqHUBxyIONWPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mHp69jhj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mHp69jhj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 920FAC113D0; Wed, 31 Dec 2025 23:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767224341; bh=dQ92F5m0cvYQ0BIrNzodFYLQ9eaMQPsnd9ZIArx1ccY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mHp69jhjFimVfaDp1n5o+COGaGo7mfEgRWsmIlJqmvcnmFoAGcqeX0di9WpS0trDc M3ynu3zYx+gPjFWVP9bHhClBAQA0wLiSuguT1nf+Rk5795ITXM3AyvBsKMeMV1PjsR rXuMhsNYYO8Ve8PwAo3TtmQlArev9lIPNWADneDWpsxwfX86j12USxqRoC/P2yI6RE SQjq3MOYlAzdj17YjLodiKfkTYpx3oTccx9OAExzaZpC9OML5MFaUTA5i6Qw0TD/ei VoNBZ39eHPHwwie72xiD7GEZ83MtwnJGHAyFVxZvMuK01od8I0Px5kf2oaEb9TxYJ3 +oun2fxIPLPrA== From: Sasha Levin To: stable@vger.kernel.org Cc: Yong Wu , Guenter Roeck , AngeloGioacchino Del Regno , Matthias Brugger , Joerg Roedel , Sasha Levin Subject: [PATCH 6.1.y 1/2] iommu/mediatek: Improve safety for mediatek,smi property in larb nodes Date: Wed, 31 Dec 2025 18:38:57 -0500 Message-ID: <20251231233858.3696664-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025122941-reluctant-exhale-a49f@gregkh> References: <2025122941-reluctant-exhale-a49f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Yong Wu [ Upstream commit 6cde583d5352818a51985b32a960cdde85ab3821 ] No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb nodes. Suggested-by: Guenter Roeck Signed-off-by: Yong Wu Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Matthias Brugger Link: https://lore.kernel.org/r/20221018024258.19073-6-yong.wu@mediatek.com Signed-off-by: Joerg Roedel Stable-dep-of: de83d4617f9f ("iommu/mediatek: fix use-after-free on probe deferral") Signed-off-by: Sasha Levin --- drivers/iommu/mtk_iommu.c | 53 +++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index d4cb09b2e267..773cbd63ed5c 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -1046,7 +1046,7 @@ static const struct component_master_ops mtk_iommu_com_ops = { static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **match, struct mtk_iommu_data *data) { - struct device_node *larbnode, *smicomm_node, *smi_subcomm_node; + struct device_node *larbnode, *frst_avail_smicomm_node = NULL; struct platform_device *plarbdev, *pcommdev; struct device_link *link; int i, larb_nr, ret; @@ -1058,6 +1058,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m return -EINVAL; for (i = 0; i < larb_nr; i++) { + struct device_node *smicomm_node, *smi_subcomm_node; u32 id; larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i); @@ -1098,27 +1099,47 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m goto err_larbdev_put; } + /* Get smi-(sub)-common dev from the last larb. */ + smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0); + if (!smi_subcomm_node) { + ret = -EINVAL; + goto err_larbdev_put; + } + + /* + * It may have two level smi-common. the node is smi-sub-common if it + * has a new mediatek,smi property. otherwise it is smi-commmon. + */ + smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); + if (smicomm_node) + of_node_put(smi_subcomm_node); + else + smicomm_node = smi_subcomm_node; + + /* + * All the larbs that connect to one IOMMU must connect with the same + * smi-common. + */ + if (!frst_avail_smicomm_node) { + frst_avail_smicomm_node = smicomm_node; + } else if (frst_avail_smicomm_node != smicomm_node) { + dev_err(dev, "mediatek,smi property is not right @larb%d.", id); + of_node_put(smicomm_node); + ret = -EINVAL; + goto err_larbdev_put; + } else { + of_node_put(smicomm_node); + } + component_match_add(dev, match, component_compare_dev, &plarbdev->dev); platform_device_put(plarbdev); } - /* Get smi-(sub)-common dev from the last larb. */ - smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0); - if (!smi_subcomm_node) + if (!frst_avail_smicomm_node) return -EINVAL; - /* - * It may have two level smi-common. the node is smi-sub-common if it - * has a new mediatek,smi property. otherwise it is smi-commmon. - */ - smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0); - if (smicomm_node) - of_node_put(smi_subcomm_node); - else - smicomm_node = smi_subcomm_node; - - pcommdev = of_find_device_by_node(smicomm_node); - of_node_put(smicomm_node); + pcommdev = of_find_device_by_node(frst_avail_smicomm_node); + of_node_put(frst_avail_smicomm_node); if (!pcommdev) return -ENODEV; data->smicomm_dev = &pcommdev->dev; -- 2.51.0