Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2207397iof; Tue, 7 Jun 2022 23:13:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwr3M/MqAPeZ1ASya/KtvDLkAZTfXNOjfT4qgl/1ANb3Rh+dnf2cKjDIy/LnDzgWbCPtFTz X-Received: by 2002:a17:90b:1e0e:b0:1e3:2eee:3ab9 with SMTP id pg14-20020a17090b1e0e00b001e32eee3ab9mr47992115pjb.158.1654668791845; Tue, 07 Jun 2022 23:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668791; cv=none; d=google.com; s=arc-20160816; b=FrIzZo3il/InmIad6Ivtz3TeCKAAqUpFD5JfYoi6kbq9IoqqncIaQz9TncB7LP1WS2 RQfPxWRk46cAS4qul85dS+5Ldckj3+F/AYuRuhH+6NSJOgL/8TkPW41mrhf6qqHiuEee UQJHSO9bIZNGXx5nFBd8vGHI3DoKV862uayTXoFPpKC+TMKJzaUlk9S61bWMOTCGWszt lNdLq3+tNkB3neTzF5Sc66AlHJ+FFUl7lPkr+3+1EAMXSD5APoGg+JmEyqK9W5oZ56Hq qDkEkxXpyn6utV4vKUukXc2M0/bQPi0SYC51P92V7pTCfwKClrU4ZpHt+7m1LmbRQv5c nYTQ== 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=hW8bDZMFVxmdze9J3peJQSr2h+eBD1zTJp/5wa+cPXE=; b=eiIzgPxEQChUBIDoykk/s8uYSp8ZLWDF+uME4U25742VkWkWXdv5mt7OOGLCbDM4W9 UeXcV4VX8/8HHS7EU3Q5Mt2e53ul8xWsCjFUha8IHdKe4CcP2wBE5iA1aGSRUExuD3ki otAKw0yGAzuIqW5kdZ9/ZVboO0ZS5fTFihtLzl2Va3n8sfMw1jv2civAE0AxXuQ3nL6y u3vh9za5/SiHVVtA17OyGQDwRuYQNURJf8XNMtn4gmU/P9DdiOOZ+EllRgtXF06FCWZM U+Gw0KCQbgh1OtCK6AsfpbdzGrJC5Dz/XJepD+GzKzd372HFPQ0OMiP7q2i4luJlUcJ2 Wa6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BXwW8+D9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id e7-20020a656bc7000000b003fcfdc99472si26460428pgw.739.2022.06.07.23.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:13:11 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BXwW8+D9; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F8B935638C; Tue, 7 Jun 2022 22:35:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390906AbiFHBvx (ORCPT + 99 others); Tue, 7 Jun 2022 21:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383010AbiFGWEv (ORCPT ); Tue, 7 Jun 2022 18:04:51 -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 7905F19593E; Tue, 7 Jun 2022 12:16:17 -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 36217B8233E; Tue, 7 Jun 2022 19:16:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98B4BC385A2; Tue, 7 Jun 2022 19:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629375; bh=dXJ1pkdkNPOA/d6G70SJbl2KnK0Y7faw7WYS0q2pHnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BXwW8+D992L0S+mmb/XR0W9ZD8N8LHscCwk0JFRXQYm4Ks0JA6bIjDRtvOz6QSqy5 epDIe8bTQz9efNn8aLNocK+8mgsiWcSjAN0Euc/GwNYxTZvIv3A8dC+ZJ1wSaHbUpm Gv8IPbV41HTpSyZtBse9lvpf+Pl4gciUOiVhvQf8= 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.18 667/879] iommu/mediatek: Add mutex for m4u_group and m4u_dom in data Date: Tue, 7 Jun 2022 19:03:05 +0200 Message-Id: <20220607165022.211174343@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 81b8db450eac..3413cc98e57e 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 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, @@ -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; + +err_unlock: + mutex_unlock(&data->mutex); + return ret; } static void mtk_iommu_detach_device(struct iommu_domain *domain, @@ -622,6 +628,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(); @@ -630,6 +637,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev) } else { iommu_group_ref_get(group); } + mutex_unlock(&data->mutex); return group; } @@ -910,6 +918,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 b742432220c5..5e8da947affc 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