Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2850409pxb; Mon, 17 Jan 2022 07:02:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJx53PmkKPfN1YRJ07NY2H3xh5kD+dRdGw/QFka1nB4uLV28tb050zwvZ4kor9m783rIAIeA X-Received: by 2002:a17:90a:7e81:: with SMTP id j1mr25626602pjl.24.1642431743122; Mon, 17 Jan 2022 07:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642431743; cv=none; d=google.com; s=arc-20160816; b=FVorzozQkeYTcVoXL04GybNIbstpFS1M2yVjolRApj/U5No4aQ6G0Kd8gt0eVdJI4T TPHJwLtqtHcyjLQSRMMG6ojIwNU3Ls0lwMuzAo85C+DCisjZxWV60gXvkd2Gq2NLQOPv MWWuwzNc2AWyZb+eKinm6p0dA8kmVzHc13AftgizkFvYhcm0JY2VfDistCXwQDhcqYlY 27vN1RqML+55nV+30mObm0Ofx7DHOkwQEmW4/t55FexAvNKrkfnLyOE1omB0Pu3rPDrw 2oUaczRy5oxkOtDWu1MEECzpWfwoGu2lEx6/IXs7mPKgZ9evM8MItn0pIMFxQa3ib+Nx UEeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=gKoEtGsXH6TRILGCL88jjOSlD52kiJTGhHf8aMRcQQE=; b=GzLgA4LdKyKNqulU/mz7kkpYQPjg9zhNIJ9uaILxhdkwdu/nkzYu4Oai7zOnhJ1Cxx tmvf6BIFl+Eob6ZBIQMh+ekxdHypy7Cuja7KnhKjnZiy+TX4GrrPBlyF1YUVxJnmnd1c WlEdH7X4m3234CIGG19LY2AgvtKciNpHu2TNzsMXLEt2zE9yEOuPGfdYPOwuH63SVkqo tTTucCv2HIO5inokjvmwVddJHDKoyxyFI+ABVZXPAs7CFV6js+87LWqmgtdy//1hhGmi MHDTZRGAtwF8tVHcInSGMwCJcahEhzy+EdjEADIERCnVKE4X9+vkuFkoyNyKIMhOU0Sp 41Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h14si14772455pgm.837.2022.01.17.07.02.09; Mon, 17 Jan 2022 07:02:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232982AbiAQHGH (ORCPT + 99 others); Mon, 17 Jan 2022 02:06:07 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:44694 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S234975AbiAQHF4 (ORCPT ); Mon, 17 Jan 2022 02:05:56 -0500 X-UUID: b2d5fe270a95426890fa5f4ae9e99ab6-20220117 X-UUID: b2d5fe270a95426890fa5f4ae9e99ab6-20220117 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2078910753; Mon, 17 Jan 2022 15:05:53 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 17 Jan 2022 15:05:51 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 15:05:49 +0800 From: Yong Wu To: Matthias Brugger , Hans Verkuil , Joerg Roedel , Rob Herring , Krzysztof Kozlowski , David Airlie , "Mauro Carvalho Chehab" CC: Evan Green , Robin Murphy , Tomasz Figa , Will Deacon , , , , , , , , , Matthias Kaehlcke , , , , , , Daniel Vetter , Chun-Kuang Hu , Philipp Zabel , Tiffany Lin , "Dafna Hirschfeld" , Hsin-Yi Wang , Eizan Miyamoto , , Frank Wunderlich , , , , AngeloGioacchino Del Regno Subject: [PATCH v10 02/13] iommu/mediatek-v1: Free the existed fwspec if the master dev already has Date: Mon, 17 Jan 2022 15:04:59 +0800 Message-ID: <20220117070510.17642-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220117070510.17642-1-yong.wu@mediatek.com> References: <20220117070510.17642-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the iommu master device enters of_iommu_xlate, the ops may be NULL(iommu dev is defered), then it will initialize the fwspec here: [] (dev_iommu_fwspec_set) from [] (iommu_fwspec_init+0xbc/0xd4) [] (iommu_fwspec_init) from [] (of_iommu_xlate+0x7c/0x12c) [] (of_iommu_xlate) from [] (of_iommu_configure+0x144/0x1e8) BUT the mtk_iommu_v1.c only supports arm32, the probing flow still is a bit weird. We always expect create the fwspec internally. otherwise it will enter here and return fail. static int mtk_iommu_create_mapping(struct device *dev, struct of_phandle_args *args) { ... if (!fwspec) { .... } else if (dev_iommu_fwspec_get(dev)->ops != &mtk_iommu_ops) { >>>>>>>>>>Enter here. return fail.<<<<<<<<<<<< return -EINVAL; } ... } Thus, Free the existed fwspec if the master device already has fwspec. This issue is reported at: https://lore.kernel.org/linux-mediatek/trinity-7d9ebdc9-4849-4d93-bfb5-429dcb4ee449-1626253158870@3c-app-gmx-bs01/ Reported-by: Frank Wunderlich Tested-by: Frank Wunderlich # BPI-R2/MT7623 Signed-off-by: Yong Wu Acked-by: Joerg Roedel Acked-by: AngeloGioacchino Del Regno --- drivers/iommu/mtk_iommu_v1.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c index be22fcf988ce..1467ba1e4417 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -425,6 +425,15 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev) struct mtk_iommu_data *data; int err, idx = 0; + /* + * In the deferred case, free the existed fwspec. + * Always initialize the fwspec internally. + */ + if (fwspec) { + iommu_fwspec_free(dev); + fwspec = dev_iommu_fwspec_get(dev); + } + while (!of_parse_phandle_with_args(dev->of_node, "iommus", "#iommu-cells", idx, &iommu_spec)) { -- 2.18.0