Message ID | 20230317085541.20447-3-yong.wu@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp229426wrt; Fri, 17 Mar 2023 02:10:21 -0700 (PDT) X-Google-Smtp-Source: AK7set9cyxue3Dd+TrfDj/35HkqoAf1dTdSE08mkpMHWxb0b1vk9etY2jbr9WgDXu/usdRLVWsfz X-Received: by 2002:a17:90b:358b:b0:237:40a5:77cb with SMTP id mm11-20020a17090b358b00b0023740a577cbmr5507749pjb.1.1679044221160; Fri, 17 Mar 2023 02:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679044221; cv=none; d=google.com; s=arc-20160816; b=t4DvamiEPbp3Ph4KPYDQvK0OyAOroKFXvdB3FKdMIyAYmfzTybjWWLm9ba3UEgs9zA yanLLtuc03deuRIR27dzR+KHQWWp2Kq9j+6hVNodmMuHAnzwFtHLeJpXN7sSzKxHov8q snAW6OAk2dMs7QYFQ5PZyQQwkwG6wngNuKOlFGAzPBq3sN9AQwM7mRgt4XBMWs0HgHd+ APa06opTxN74qyDBmlu3F1uFIsKwYfHn0u2WXd5O5kUpP24mPFjUapo6Oh2jG784lEN3 SQPRaJmAtUzRcBa3CC1vagsUsSHRcM+GTbpoKOWF54Bkvg3a+L30ZKXxj2XBY05X4Rxj UH8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fldchiudSIbV/7hMpcrPDkPnL9MLz8Oy+/j3QfLCNIU=; b=pvAKxOE6LXm5hQSY4A96+ZAEkDIKtuM1pKwoMj/N7C+jTQgS+Ht195EYS7KyILX1RC LYn1YZlveKBfoTUyt+tY6kFkQD1KACxe7hp2WttkLtgbBUjhfSGWLz7E79/kPCstJ9z4 PkAcS+lpky6XLbqIPqjW1gSLGQbPzXlR+r65viG02w11X7onS5vUKFGBC3xtUfNgKJaX V+aujqj1TH2h6CeWDOfZ9jDDUOoblajqX6Paumm6pNNHyCSD8LG7cFZJ/kBKYcZLmmEY BAtNBxZWtxcAqLNQ65VTPhUYlHTR1F1Y8mah/gdFkn0rSoYj1c/4+nNTRzHLbgigYv1q zAGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=aoIYkRB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a17090acf1400b0023d982fb7ecsi7276877pju.75.2023.03.17.02.10.08; Fri, 17 Mar 2023 02:10:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=aoIYkRB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231519AbjCQI5x (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Fri, 17 Mar 2023 04:57:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231515AbjCQI51 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 17 Mar 2023 04:57:27 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 061C775849; Fri, 17 Mar 2023 01:56:51 -0700 (PDT) X-UUID: 9ef8262ec4a111edbd2e61cc88cc8f98-20230317 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=fldchiudSIbV/7hMpcrPDkPnL9MLz8Oy+/j3QfLCNIU=; b=aoIYkRB4ICw3vIJryGZHHVb4+rc/H6RSM6idDzdFlFxETHbw2HCS/lRKJ48Er4Er9p1F8sH4rIWTCJlx6itpPIBJLsFPGfelo6ZDFWXcQwEy/QCUznHdRzuk44K38uF8Cf4mX9O3Rcb03DC6w4P7bOcW1TPuCoUV79SsAU7doLw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.21,REQID:da9b7b1c-43dc-4f25-aed9-bac277c6cc37,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.21,REQID:da9b7b1c-43dc-4f25-aed9-bac277c6cc37,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:83295aa,CLOUDID:0f3e1cf6-ddba-41c3-91d9-10eeade8eac7,B ulkID:230317165638E285ZD18,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-UUID: 9ef8262ec4a111edbd2e61cc88cc8f98-20230317 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from <yong.wu@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 420804674; Fri, 17 Mar 2023 16:56:35 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Fri, 17 Mar 2023 16:56:34 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Fri, 17 Mar 2023 16:56:33 +0800 From: Yong Wu <yong.wu@mediatek.com> To: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, Rob Herring <robh+dt@kernel.org>, Matthias Brugger <matthias.bgg@gmail.com> CC: Robin Murphy <robin.murphy@arm.com>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Yong Wu <yong.wu@mediatek.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, <iommu@lists.linux.dev>, <linux-mediatek@lists.infradead.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <mingyuan.ma@mediatek.com>, <yf.wang@mediatek.com>, <jianjiao.zeng@mediatek.com>, <chengci.xu@mediatek.com> Subject: [PATCH v9 2/7] iommu/mediatek: Fix two IOMMU share pagetable issue Date: Fri, 17 Mar 2023 16:55:36 +0800 Message-ID: <20230317085541.20447-3-yong.wu@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230317085541.20447-1-yong.wu@mediatek.com> References: <20230317085541.20447-1-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760605473342895740?= X-GMAIL-MSGID: =?utf-8?q?1760605473342895740?= |
Series |
MT8188 IOMMU SUPPORT
|
|
Commit Message
Yong Wu
March 17, 2023, 8:55 a.m. UTC
From: "Chengci.Xu" <chengci.xu@mediatek.com> Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is VDO-IOMMU. The 2 MM IOMMU HWs share pagetable don't work in this case: a) VPP-IOMMU probe firstly. b) VDO-IOMMU probe. c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). d) The master in another domain probe. No matter it is vdo or vpp. Then it still create a new pagetable in step d). The problem is "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) enter, it still create a new one. In this patch, we create a new variable "share_dom" for this share pgtable case, it should be helpful for readable. and put all the share pgtable logic in the mtk_iommu_domain_finalise. In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU from its dtsi node sequence, we don't see this issue in it. Prepare for mt8188. Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com> Signed-off-by: Yong Wu <yong.wu@mediatek.com> --- drivers/iommu/mtk_iommu.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
Comments
Il 17/03/23 09:55, Yong Wu ha scritto: > From: "Chengci.Xu" <chengci.xu@mediatek.com> > > Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. > > We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is VDO-IOMMU. > The 2 MM IOMMU HWs share pagetable don't work in this case: > a) VPP-IOMMU probe firstly. > b) VDO-IOMMU probe. > c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). > d) The master in another domain probe. No matter it is vdo or vpp. > Then it still create a new pagetable in step d). The problem is > "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) enter, it > still create a new one. > > In this patch, we create a new variable "share_dom" for this share > pgtable case, it should be helpful for readable. and put all the share > pgtable logic in the mtk_iommu_domain_finalise. > > In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU > from its dtsi node sequence, we don't see this issue in it. Prepare for > mt8188. > > Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com> > Signed-off-by: Yong Wu <yong.wu@mediatek.com> I'm not sure whether this is *not* a fix... if a specific platform wasn't affected, this may still be a logic mistake... to be cautious, I would still add a Fixes tag to this one. Otherwise, I would reword the commit title and remove the "Fix" word, so that it would look something like... iommu/mediatek: Prepare for pagetables domain sharing I'm sorry for noticing that only at v9, but the previous versions had a bit more stuff to address and couldn't really focus on analyzing this one. If there's anything I've misunderstood about this patch, please feel free to explain. Regards, Angelo
On Fri, 2023-03-17 at 10:34 +0100, AngeloGioacchino Del Regno wrote: > Il 17/03/23 09:55, Yong Wu ha scritto: > > From: "Chengci.Xu" <chengci.xu@mediatek.com> > > > > Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. > > > > We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is > > VDO-IOMMU. > > The 2 MM IOMMU HWs share pagetable don't work in this case: > > a) VPP-IOMMU probe firstly. > > b) VDO-IOMMU probe. > > c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). > > d) The master in another domain probe. No matter it is vdo or > > vpp. > > Then it still create a new pagetable in step d). The problem is > > "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) > > enter, it > > still create a new one. > > > > In this patch, we create a new variable "share_dom" for this share > > pgtable case, it should be helpful for readable. and put all the > > share > > pgtable logic in the mtk_iommu_domain_finalise. > > > > In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU > > from its dtsi node sequence, we don't see this issue in it. Prepare > > for > > mt8188. > > > > Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com> > > Signed-off-by: Yong Wu <yong.wu@mediatek.com> > > I'm not sure whether this is *not* a fix... if a specific platform > wasn't > affected, this may still be a logic mistake... to be cautious, I > would > still add a Fixes tag to this one. I think you are right. If we need add the Fixes tag, it should fix this one: 645b87c190c9 ("iommu/mediatek: Fix 2 HW sharing pgtable issue"). Before I thought the code flow was changed a lot. I added the bank structure and removed the mtk_iommu.h, I'm a bit afraid that this fix patch can not be applied clean, then it will introduce confuse when applying to the previous version for the maintainers. Meanwhile, After mt8195, mt8186/mt6795/m8365/6795 were merged in upstream. All of them don't have this sharing case, thus I thought this fix it is not so necessary. What's your opinion? and should I send this one separately if I add the fixes tag? > Otherwise, I would reword the commit title and remove the "Fix" word, > so > that it would look something like... > > iommu/mediatek: Prepare for pagetables domain sharing > > I'm sorry for noticing that only at v9, but the previous versions had > a bit > more stuff to address and couldn't really focus on analyzing this > one. > > If there's anything I've misunderstood about this patch, please feel > free > to explain. > > Regards, > Angelo >
Il 21/03/23 07:50, Yong Wu (吴勇) ha scritto: > On Fri, 2023-03-17 at 10:34 +0100, AngeloGioacchino Del Regno wrote: >> Il 17/03/23 09:55, Yong Wu ha scritto: >>> From: "Chengci.Xu" <chengci.xu@mediatek.com> >>> >>> Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. >>> >>> We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, another is >>> VDO-IOMMU. >>> The 2 MM IOMMU HWs share pagetable don't work in this case: >>> a) VPP-IOMMU probe firstly. >>> b) VDO-IOMMU probe. >>> c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). >>> d) The master in another domain probe. No matter it is vdo or >>> vpp. >>> Then it still create a new pagetable in step d). The problem is >>> "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) >>> enter, it >>> still create a new one. >>> >>> In this patch, we create a new variable "share_dom" for this share >>> pgtable case, it should be helpful for readable. and put all the >>> share >>> pgtable logic in the mtk_iommu_domain_finalise. >>> >>> In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU >>> from its dtsi node sequence, we don't see this issue in it. Prepare >>> for >>> mt8188. >>> >>> Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com> >>> Signed-off-by: Yong Wu <yong.wu@mediatek.com> >> >> I'm not sure whether this is *not* a fix... if a specific platform >> wasn't >> affected, this may still be a logic mistake... to be cautious, I >> would >> still add a Fixes tag to this one. > > I think you are right. If we need add the Fixes tag, it should fix this > one: 645b87c190c9 ("iommu/mediatek: Fix 2 HW sharing pgtable issue"). > > Before I thought the code flow was changed a lot. I added the bank > structure and removed the mtk_iommu.h, I'm a bit afraid that this fix > patch can not be applied clean, then it will introduce confuse when > applying to the previous version for the maintainers. > > Meanwhile, After mt8195, mt8186/mt6795/m8365/6795 were merged in > upstream. All of them don't have this sharing case, thus I thought this > fix it is not so necessary. > > What's your opinion? and should I send this one separately if I add the > fixes tag? > Well, it would be nicer to send it separately but, realistically, the described issue does *not* happen on the previous kernel releases for the supported SoCs... so it's not necessary to split this. Add the Fixes tag and send this again inside of this series, that's going to be fine. Thanks! Angelo
diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index e0264d5f1c9a..9802e5c1a625 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -258,6 +258,8 @@ struct mtk_iommu_data { struct device *smicomm_dev; struct mtk_iommu_bank_data *bank; + struct mtk_iommu_domain *share_dom; /* For 2 HWs share pgtable */ + struct regmap *pericfg; struct mutex mutex; /* Protect m4u_group/m4u_dom above */ @@ -624,15 +626,14 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, struct mtk_iommu_data *data, unsigned int region_id) { + struct mtk_iommu_domain *share_dom = data->share_dom; const struct mtk_iommu_iova_region *region; - struct mtk_iommu_domain *m4u_dom; - - /* Always use bank0 in sharing pgtable case */ - m4u_dom = data->bank[0].m4u_dom; - if (m4u_dom) { - dom->iop = m4u_dom->iop; - dom->cfg = m4u_dom->cfg; - dom->domain.pgsize_bitmap = m4u_dom->cfg.pgsize_bitmap; + + /* Always use share domain in sharing pgtable case */ + if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE) && share_dom) { + dom->iop = share_dom->iop; + dom->cfg = share_dom->cfg; + dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap; goto update_iova_region; } @@ -662,6 +663,9 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom, /* Update our support page sizes bitmap */ dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap; + if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE)) + data->share_dom = dom; + update_iova_region: /* Update the iova region for this domain */ region = data->plat_data->iova_region + region_id; @@ -712,7 +716,9 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, /* Data is in the frstdata in sharing pgtable case. */ frstdata = mtk_iommu_get_frst_data(hw_list); + mutex_lock(&frstdata->mutex); ret = mtk_iommu_domain_finalise(dom, frstdata, region_id); + mutex_unlock(&frstdata->mutex); if (ret) { mutex_unlock(&dom->mutex); return ret;