Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2190898iof; Tue, 7 Jun 2022 22:41:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMr+aSN3WJm+LFT2Un7ijltQQEp3DlA35tIZWhlGnSkmVNAQ0o7zu9xuslRsQIUYN8Awtc X-Received: by 2002:a63:2010:0:b0:3fc:180e:e49 with SMTP id g16-20020a632010000000b003fc180e0e49mr27995888pgg.197.1654666908481; Tue, 07 Jun 2022 22:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666908; cv=none; d=google.com; s=arc-20160816; b=SxA6M9bBd/nPc8mXYAlLg3ELjcwyJntSMt8C23ZCm84yU00Jg9xrjqxlOLBHcih8el 0nFjjF/bV4G0F5Fo0ZRIbrpMEnfu9KnaOyXq1bTj4vyYVWvKDaGd9ATagJx2pWnAFyan zdFF7HsvKspuAfmBdUgiHMmqWvpN88EQPYCauY5KZ+qD4B6lifTgoH8NF2icm0a9+EBk v8GAaHSjriGuXMjaHJxSQVIFIS3dRMbiAhmpem9DzsSugMf3bQI6F8XgXIBizL+AHLIQ 118BSu7OxBtOkkUoRaKX8Uw5/160HufdWztReHUidcZdocirydIGDJ2TPlLyMAYDUUXd vklg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OyiZ9Y6GkgY0vyMJLAWqG+WhCuP6GdCGDu3/N+Z9Hzg=; b=P0bmXG2iLsYV8tp/joEAt+Yg1j1V6LhgmgziOAJxxrw/p+vyC0t1qR8rmRPV+5sG2d XqgbxajSU/bxfhEfLFqiZGAdE6M+3pYeA10Mmt+dYKEzNnOJmantZJkm/c2KV1hrWwHy apSCXxzRz1PywxkMSplJVaofBFqCEjesGRjWQLpNaKU9k5G53lwSMAGIcnLRRDoVIT60 KND8dUNIHSmFMnRgZ7PWxTP0L1qb8FUa3LNw5xhrDPo9Jjo8sGtiXLXydSrF8AHR30eB 48XZ2+blPmGRisnm3+LDPIoZkyOdzH79nqwBxV4HvldSpEw73eMCwtjaX3ukCJk/ekp7 CX8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yRT5AMx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pv2-20020a17090b3c8200b001e33af25e04si23914063pjb.108.2022.06.07.22.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:41:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yRT5AMx5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B4802AC558; Tue, 7 Jun 2022 22:07:24 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379981AbiFGVaK (ORCPT + 99 others); Tue, 7 Jun 2022 17:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377838AbiFGUeI (ORCPT ); Tue, 7 Jun 2022 16:34:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E79571E7AF8; Tue, 7 Jun 2022 11:36:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 302C4B8233E; Tue, 7 Jun 2022 18:36:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88FF8C385A2; Tue, 7 Jun 2022 18:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654626969; bh=1fnCYEHFdDXiebIMF3JIQlXednadZc3hyC/x3Lsi5wA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yRT5AMx5Dua92RtYwUqTSeLf6E5I16GaWq4Yqca04p07/5MPt4sw0mXjKGsIPu402 kRWAe1ReeGt1gzTTkSqX5k0oA/S9fpyXEM/XkeNrGg+BduXLZd40MoeAc3uCb8TtmM Q9GG27ujrcbEdqI9IzjJfu8qjCLBeDqLEqit4vjk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yunfei Wang , Yong Wu , AngeloGioacchino Del Regno , Matthias Brugger , Joerg Roedel , Sasha Levin Subject: [PATCH 5.17 571/772] iommu/mediatek: Add mutex for m4u_group and m4u_dom in data Date: Tue, 7 Jun 2022 19:02:43 +0200 Message-Id: <20220607165005.779832757@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Yong Wu [ Upstream commit 0e5a3f2e630b28e88e018655548212ef8eb4dfcb ] 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 Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Matthias Brugger Link: https://lore.kernel.org/r/20220503071427.2285-8-yong.wu@mediatek.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- 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 b9d690327eae..9b3ded518f83 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -469,15 +469,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 err_unlock; ret = mtk_iommu_hw_init(data); if (ret) { pm_runtime_put(m4udev); - return ret; + goto err_unlock; } data->m4u_dom = dom; writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK, @@ -485,9 +486,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; + +err_unlock: + mutex_unlock(&data->mutex); + return ret; } static void mtk_iommu_detach_device(struct iommu_domain *domain, @@ -627,6 +633,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(); @@ -635,6 +642,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) } else { iommu_group_ref_get(group); } + mutex_unlock(&data->mutex); return group; } @@ -909,6 +917,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.35.1