Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6599349pxv; Thu, 29 Jul 2021 19:55:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4BILCyYNr4B+LefQzXaY3PPqPf5XvjqjOBb8NIHuPvMrVwoZXtoSOJ4mLKU57wsM5I472 X-Received: by 2002:aa7:de98:: with SMTP id j24mr307007edv.139.1627613758921; Thu, 29 Jul 2021 19:55:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627613758; cv=none; d=google.com; s=arc-20160816; b=zFiJieyxaEaSniHZNzP6fkB/2wJWQtQkoqvSsHym3OWntU4GFw8seIFfAuEKWUIg+9 66Og67U4Ruh/8FaE3dkagvY0YETJjWk0+BmkipmnUOemu55I6Qw3QVk9DhiOhplDleLB fKt1IGX9LSv/OqyjdbKyphPnzVyWUkV4mFoB6RSNJoP7LzyJ8lpYsOT0eC1V/kCJ7q1k BtWF4PLmAkxbO+qdmtS45FZgVotqjPKoF9kZ4FZLdJ6N1VG/zn2xyE8obaACNRBtKTNU skw9Jbo2v+N4y5BM5ksJZFsL+FJjv26fFKeRfRN73NK7f4c0usMpZSB18Nj6TNEq9+En tOHw== 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=zycEJLhByTO0CTeAJFvH56cIqzPSPibHH91n8/WPpkk=; b=KHDm/4lK7Vbt0bCMmn23anCNCw+m0lEd0NzEN6eS/a3j8LDmyG0+IgLdKCBnVhIkFo oZpT7uqEdi5DAcRIFQty05NRGgBFMweGtYp/pmGTePy4AMUG+SQSQeGK+f7wHWK5+4ti VFIgIaqjtvokvYsw3E8X6I7oiIZFKF7rTlfjCQ8nDTDmHcp5VYSmxt55A0aK9ZjGJqkA 0+QOLqc8Qm8AO4LaRqSKkk/nSKNpropChxgWY5LHA3vtxF3CWo5mKU0PXABwGyHevEHe diBP7JHNijX0xqYSPPmTK8osMcainKamH9vBPXZooyXtYsCjz0QZXdDHuwFcDiDOgfzu /FPw== 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 y13si355402eds.482.2021.07.29.19.55.36; Thu, 29 Jul 2021 19:55:58 -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 S234443AbhG3Cxz (ORCPT + 99 others); Thu, 29 Jul 2021 22:53:55 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:46830 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S233918AbhG3Cxy (ORCPT ); Thu, 29 Jul 2021 22:53:54 -0400 X-UUID: 4ad6bef9094743928928c97372254832-20210730 X-UUID: 4ad6bef9094743928928c97372254832-20210730 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 504441517; Fri, 30 Jul 2021 10:53:48 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 30 Jul 2021 10:53:46 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 30 Jul 2021 10:53:42 +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 , , , , , , , , , Nicolas Boichat , Matthias Kaehlcke , , , , , , , Daniel Vetter , Chun-Kuang Hu , Philipp Zabel , Xia Jiang , Tiffany Lin , Dafna Hirschfeld , Hsin-Yi Wang , Eizan Miyamoto , , Frank Wunderlich Subject: [PATCH v7 02/12] iommu/mediatek-v1: Free the existed fwspec if the master dev already has Date: Fri, 30 Jul 2021 10:52:28 +0800 Message-ID: <20210730025238.22456-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210730025238.22456-1-yong.wu@mediatek.com> References: <20210730025238.22456-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 --- No need fix tag, since it is ok before this cleanup patchset. the issue may be revealed by the patch adding probe_defer what adjust the device probing sequency. --- 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 778e66f5f1aa..6861eeab182d 100644 --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -426,6 +426,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 if the dev already has, + * 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