Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4167067pxb; Tue, 25 Jan 2022 05:01:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJze2f5a/FdJs2wgfccLrBhDtb3IA74zXpZzQwiZ9mQCF9UAWfPUrdDa94JTOYIolqPdM9Qx X-Received: by 2002:a17:902:8ec6:b0:14a:c625:eb2d with SMTP id x6-20020a1709028ec600b0014ac625eb2dmr18771430plo.26.1643115699484; Tue, 25 Jan 2022 05:01:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643115699; cv=none; d=google.com; s=arc-20160816; b=l7Cu+K6S/ICi28PG3+86HVla3jXispi2kXenqAQAh2oLQwhsaWrCzWVt0ZbAPfFico j7ErXbc1Amfi8LmCahoGb2KqZ7C1zgpbyUWUgz5tZvCxgTLYNwqNTF41d9EgoV8cN/pl 3FZBCH3gikGfItCXixXQEkts5CKH2+QcCRjacX+0NcKoIQBHWXZi3wq4BbQeP8iMwHbF UPCYcrE715nutoTbhpEuDrD3MMdaFezrufUFx8PLoQsVT6nJgfpLER2vJN3LgnXxDaeC p8XUnOFXd6FXLacTudESWNoRnXopIqK3nQwRTI/ITIWrMl/uCuKiP4zCF3wsXwS5UWwK Tckg== 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=zfZtnQvX2gViLxSBJx1G62zwtuelTWxAxM1f7VadFuI=; b=eXvdFWsTd2XPa3PrR5ruMsVmNCyO2FQ3jBDN6pma0Y8g6c+vFoR8S1QfszYYe3+ekN lC8TrDdo8YgF2ZtQA9y4BdmbY+W5OsMWpVlr/vBU/7P+s2D/g3RU0jRB0HKzk0xHFfiV 9A4lzn1DTIlfeRdSkNi0MUibqQ277cM2PZ2fnoGZIMEOeZy2idwxw5kcf8CbsIlqt2YU lZLBENe6hvdPgSmTdrPo6Fz05b8iD7V8RcBgjTGci/qbaSr/us1gAPegiljAmF45hmKK 9Vq9KxhjTDgbR6taPtC2bzzDkLQklVHJt8U7E6tHsvG6k3R8PDz03p3VwiAoeSG1j+bE e5WQ== 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 lp2si284486pjb.124.2022.01.25.05.01.26; Tue, 25 Jan 2022 05:01:39 -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 S1454701AbiAYJAn (ORCPT + 99 others); Tue, 25 Jan 2022 04:00:43 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:37260 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1454127AbiAYI5r (ORCPT ); Tue, 25 Jan 2022 03:57:47 -0500 X-UUID: 11643d176e644c1d89b3094aaee55cdb-20220125 X-UUID: 11643d176e644c1d89b3094aaee55cdb-20220125 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 1064192246; Tue, 25 Jan 2022 16:57:43 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) 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; Tue, 25 Jan 2022 16:57:42 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 25 Jan 2022 16:57:40 +0800 From: Yong Wu To: Joerg Roedel , Rob Herring , "Matthias Brugger" , Will Deacon CC: Robin Murphy , Krzysztof Kozlowski , Tomasz Figa , , , , , , , Hsin-Yi Wang , , , , , , "AngeloGioacchino Del Regno" , , , , Subject: [PATCH v4 06/35] iommu/mediatek: Add mutex for m4u_group and m4u_dom in data Date: Tue, 25 Jan 2022 16:56:05 +0800 Message-ID: <20220125085634.17972-7-yong.wu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220125085634.17972-1-yong.wu@mediatek.com> References: <20220125085634.17972-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 Add a mutex to protect the data in the structure mtk_iommu_data, like ->"m4u_group" ->"m4u_dom". For the internal data, we should protect it in ourselves driver. Add a mutex for this. This could be a fix for the multi-groups support. Fixes: c3045f39244e ("iommu/mediatek: Support for multi domains") Signed-off-by: Yunfei Wang Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 13 +++++++++++-- drivers/iommu/mtk_iommu.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index ec2c387abf60..095736bfb7b4 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -464,15 +464,16 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, dom->data = data; } + mutex_lock(&data->mutex); if (!data->m4u_dom) { /* Initialize the M4U HW */ ret = pm_runtime_resume_and_get(m4udev); if (ret < 0) - return ret; + goto data_unlock; ret = mtk_iommu_hw_init(data); if (ret) { pm_runtime_put(m4udev); - return ret; + goto data_unlock; } data->m4u_dom = dom; writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, @@ -480,9 +481,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, pm_runtime_put(m4udev); } + mutex_unlock(&data->mutex); mtk_iommu_config(data, dev, true, domid); return 0; + +data_unlock: + mutex_unlock(&data->mutex); + return ret; } static void mtk_iommu_detach_device(struct iommu_domain *domain, @@ -592,6 +598,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) if (domid < 0) return ERR_PTR(domid); + mutex_lock(&data->mutex); group = data->m4u_group[domid]; if (!group) { group = iommu_group_alloc(); @@ -600,6 +607,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) } else { iommu_group_ref_get(group); } + mutex_unlock(&data->mutex); return group; } @@ -874,6 +882,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, data); + mutex_init(&data->mutex); ret = iommu_device_sysfs_add(&data->iommu, dev, NULL, "mtk-iommu.%pa", &ioaddr); diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h index f81fa8862ed0..f413546ac6e5 100644 --- a/drivers/iommu/mtk_iommu.h +++ b/drivers/iommu/mtk_iommu.h @@ -80,6 +80,8 @@ struct mtk_iommu_data { struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */ + struct mutex mutex; /* Protect m4u_group/m4u_dom above */ + struct list_head list; struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX]; }; -- 2.18.0