Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp4902150pxv; Tue, 29 Jun 2021 19:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCU7pyrC06XIzR1IPdl78wKrqAXcnoVVXm9VLpuBa3Xcipr6W/3HRl2EPclQld0KCpnz8j X-Received: by 2002:a17:906:a20b:: with SMTP id r11mr32667907ejy.221.1625020653764; Tue, 29 Jun 2021 19:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625020653; cv=none; d=google.com; s=arc-20160816; b=RhybK6UMX+ysjT54qUbThvqQgMM6rV4n3BmmllwNk7eapL4PSDRSycbwWSjbxAdqVA boiplnnFqM9ErSAfhhPHIm2Zjj4wVsoEG5hrHRIbBKEd/mKl84Lab5GPm3UFWsRgNB2w /idWmu7EAZo0DgHQcCXN+yr2pLFAFbiGXQ9pVGtwxyjjbheMr+7UlZ+ZT+PmZ0jnHVNA 77Qxgg321Ki9uaB4C3ayIZyfBgdcuXImg/Hs5kYaYAXGkuqpaQmMncQm/t54OG4PNBA5 a3XAao5YFgDCb95d/FnHrag584ZYc8Z1zLsBR8XyvZmD0tniQKokjs94595ODqqMjQHM M5yA== 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=LDKBz8eB3FNsuHIjbGk+IJQ1EcmV1tVx9F7UguzIV7Y=; b=uJz+uMDF5+imO017D4UzOS9IcuZ9kZ4n+F+eXju7Vb7gJM36d/SF2z7RL4Wab9QZYK qHOq8AaaafyrGZTsUoKNLruGLLeu96endOLVxL13TtHDhE9E2B+gm94UNFYKiN1JpmR4 pbjBF/912uGkxd7OmKLatSSV05xdnDeG3Vf0dyEgb+8L0Cym3vGOSoJh049+T7YaSwoM Ams/734/ft22QqPFZsmIepGG7elE9tsR7PYN8Vy8k/+ow4vl0rCdydkAHYhJlUPPYZc6 3jmsAwNRmitYXmVytcgLLOJf8aXBDQUr8Fo3iIuguGdbx6ZknZ3+HBko84SZH4vtCj3j zw0A== 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 l14si7859365edv.526.2021.06.29.19.37.07; Tue, 29 Jun 2021 19:37:33 -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 S232734AbhF3CiR (ORCPT + 99 others); Tue, 29 Jun 2021 22:38:17 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:33855 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232699AbhF3CiO (ORCPT ); Tue, 29 Jun 2021 22:38:14 -0400 X-UUID: 09c797874b1040d0acd9164099f03e60-20210630 X-UUID: 09c797874b1040d0acd9164099f03e60-20210630 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 1464235330; Wed, 30 Jun 2021 10:35:43 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 30 Jun 2021 10:35:42 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 30 Jun 2021 10:35:41 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , Matthias Brugger , Will Deacon , Robin Murphy CC: Krzysztof Kozlowski , Evan Green , Tomasz Figa , Tomasz Figa , , , , , , , , , Nicolas Boichat , , Subject: [PATCH 03/24] iommu/mediatek: Fix 2 HW sharing pgtable issue Date: Wed, 30 Jun 2021 10:34:43 +0800 Message-ID: <20210630023504.18177-4-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210630023504.18177-1-yong.wu@mediatek.com> References: <20210630023504.18177-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 In the this commit 4f956c97d26b ("iommu/mediatek: Move domain_finalise into attach_device"), I overlooked the sharing pgtable case. After that commit, the "data" in the mtk_iommu_domain_finalise always is the data of the current IOMMU HW, If it's sharing pgtable case, here is not right. This patch fix this. In sharing pgable case, we will loop the list to find if there already is the exist domain. this only affect mt2712 which is the only SoC that sharing pgtable. Fixes: 4f956c97d26b ("iommu/mediatek: Move domain_finalise into attach_device") Signed-off-by: Chao Hao Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e06b8a0e2b56..013dbcc87d49 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -390,12 +390,19 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, unsigned int domid) { const struct mtk_iommu_iova_region *region; + struct mtk_iommu_data *tmpdata; - /* Use the exist domain as there is only one pgtable here. */ - if (data->m4u_dom) { - dom->iop = data->m4u_dom->iop; - dom->cfg = data->m4u_dom->cfg; - dom->domain.pgsize_bitmap = data->m4u_dom->cfg.pgsize_bitmap; + /* + * Loop to find if there is already the exist domain. + * Use it when 2 iommu HWs share the pgtable. + */ + for_each_m4u(tmpdata) { + if (!tmpdata->m4u_dom) + continue; + + dom->iop = tmpdata->m4u_dom->iop; + dom->cfg = tmpdata->m4u_dom->cfg; + dom->domain.pgsize_bitmap = tmpdata->m4u_dom->cfg.pgsize_bitmap; goto update_iova_region; } -- 2.18.0