Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp175295pxb; Tue, 28 Sep 2021 18:39:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPj5XyPRGuGt1LofjbM2fywfLiB4VHvcfR2bcV1Rnu99ySWmijUDmVF1AYZTnldFUtdDbx X-Received: by 2002:a50:dace:: with SMTP id s14mr11722884edj.369.1632879595789; Tue, 28 Sep 2021 18:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632879595; cv=none; d=google.com; s=arc-20160816; b=Q5B3TFKGputGIDhcUv33UQFPYRX4yjBU4hPCtQ/YPBOuY2W8ufsdMOtciO9k3ePDRc 8ehv8EEqIo94IuWN9M0xi5E/6UyDdCRZCcmbY5pbPvdulWJy45lx9WT97FYORgDN8UMj j3+bsUXfd9HT/718u/SdwXoMpV7bXa5TqRCb0dYZMQCKsOvrSopmNSDsXiz5b4S4IspM SjgveglpyCGfI6VvpUYjeoTRSnp1vK8150fVp7sOenZVHyAUVVweN1YKFf0uw3foqPGT savUC8ze+e2yxRe7sP5lTOTsS1scbOt8tHGPjsPEwBnR0OPNBvHJwiTOweAOXNb2VqRw YisA== 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=wETCUU0wEv6aTBg7eiOZ9oZbK9NuDn3AUSVDehcxSYA=; b=05lpsg+ZZ3oPrvvcHcvWi0qIvAeu5pfHs3+WcxK2BpMAPufhnI4fWanAmQrtLc2r3c j6GkmGEdNaN5xEAqNc9e3CszSZmOOyJQGRJ+Icrw1EB+aAXTWjRy1UwVpzZBVcJb5dM5 J8PNLUFo9wbT3K+fPV85zXsy1Zu90OhWa5CPRjn2T3iLoTwUj4sH0ZVQGly5R4ZWdwJ2 +MBlyHjZuUM0CvUWi5b1vzrVO1vcLzavvctX52/+ug27Ur77woGCqRBOkxk2NNSXS9Vz ogw77rqTWAq9CQhoQ0EiDYQcCb4gfVXDYFflLcr+m03aezXDX6VmBzEATqpFw92sLr/Z 6dKQ== 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 ox7si890719ejb.360.2021.09.28.18.39.32; Tue, 28 Sep 2021 18:39:55 -0700 (PDT) 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 S243658AbhI2Bje (ORCPT + 99 others); Tue, 28 Sep 2021 21:39:34 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:35872 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232041AbhI2Bjd (ORCPT ); Tue, 28 Sep 2021 21:39:33 -0400 X-UUID: fb0079a0a98b4a8e8b1016da144587f0-20210929 X-UUID: fb0079a0a98b4a8e8b1016da144587f0-20210929 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 181317399; Wed, 29 Sep 2021 09:37:49 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Wed, 29 Sep 2021 09:37:47 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 29 Sep 2021 09:37:46 +0800 From: Yong Wu To: Matthias Brugger , 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 Subject: [PATCH v8 02/12] iommu/mediatek-v1: Free the existed fwspec if the master dev already has Date: Wed, 29 Sep 2021 09:37:09 +0800 Message-ID: <20210929013719.25120-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210929013719.25120-1-yong.wu@mediatek.com> References: <20210929013719.25120-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 Signed-off-by: Yong Wu --- 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