Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4167070pxb; Tue, 25 Jan 2022 05:01:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJywxGK/yu/HnTvGSMGyNPaEXwFYiJjwON7A/rkPIrwkblXp633vjWwB7qMGa0SQ5cs7FxmU X-Received: by 2002:a17:90b:4c43:: with SMTP id np3mr3425928pjb.88.1643115699569; 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=v7OfPNuem4sZOiJibHtLw0gGJOp2dw0Efwejm0qNVBOvNT6yE/+ETRAltAd9lXV/Nr NTjtk8XpLWdg03vF382IznQVqyrg38vjjEGisfEo28uU0UL+/cxB6Sv86hDUeg3XYDxZ cEyN3iQIl/9JSlwScP/hKTYcxL12BIM3Ee2sfdlrsyuUUPPvgCmzB0Qr4vRc1CSJDcPk M/vIL6kS+mktgW6Xq/lyOIhTDXE2cunHNWnlnUwPwGAajmyFHDtKMzS9jmW5AI/G2b6R y6HYSLtRmTipZKmQzNE6M0l3LzGdBKeSQSL+8oMhsAPAylLaJm4r3/iEdXGHTme4FEXC a/1w== 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=GJacX3bQQmNd9PhV1wek+qTqUcIu6KI4S5/5iyLupoY=; b=OKWT2iBWTMFSy2cI7pH9Z5qwhsPkEipsJ8vv+ryM/qCrqnOitBlW7vHzCkTWmMDnSf j0q0IbHSpv18WjdAWynRoLjE7UHjUng8XBbH3BvBkVx57Ias7+oZIyhgO/qo4iH8iImh MjYQGsIK02p5m8JUcs1Tb7OWKDkkboWCdMVJD65069VGo26WJadWUu/lpZNnHOUv+vJs y18pa1+4EpOFGUE0TFgjc3o8t0pM7O4KYWp1SoyuiZj7klRh0xqXkkhYqcTpA+2Ia/SJ uF3tLJFJ3dtI5iUph2OGG/ohHqXFFc0dlsPQiknc4UfqZQCmTA24ISBfApRY2Gbo9xIb U8OA== 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 pc7si302110pjb.3.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 S1454738AbiAYJAt (ORCPT + 99 others); Tue, 25 Jan 2022 04:00:49 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:59672 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1454175AbiAYI56 (ORCPT ); Tue, 25 Jan 2022 03:57:58 -0500 X-UUID: 62db39b6e7844cd9b6e3a7573406f297-20220125 X-UUID: 62db39b6e7844cd9b6e3a7573406f297-20220125 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 271611354; Tue, 25 Jan 2022 16:57:52 +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:51 +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:49 +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 07/35] iommu/mediatek: Add mutex for data in the mtk_iommu_domain Date: Tue, 25 Jan 2022 16:56:06 +0800 Message-ID: <20220125085634.17972-8-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 Same with the previous patch, add a mutex for the "data" in the mtk_iommu_domain. Just improve the safety for multi devices enter attach_device at the same time. We don't get the real issue for this. Signed-off-by: Yong Wu --- drivers/iommu/mtk_iommu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index 095736bfb7b4..e6e4ee471867 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -128,6 +128,8 @@ struct mtk_iommu_domain { struct mtk_iommu_data *data; struct iommu_domain domain; + + struct mutex mutex; /* Protect "data" in this structure */ }; static const struct iommu_ops mtk_iommu_ops; @@ -434,6 +436,7 @@ static struct iommu_domain *mtk_iommu_domain_alloc(unsigned type) dom = kzalloc(sizeof(*dom), GFP_KERNEL); if (!dom) return NULL; + mutex_init(&dom->mutex); return &dom->domain; } @@ -455,14 +458,19 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain, if (domid < 0) return domid; + mutex_lock(&dom->mutex); if (!dom->data) { /* Data is in the frstdata in sharing pgtable case. */ frstdata = mtk_iommu_get_m4u_data(); - if (mtk_iommu_domain_finalise(dom, frstdata, domid)) + ret = mtk_iommu_domain_finalise(dom, frstdata, domid); + if (ret) { + mutex_unlock(&dom->mutex); return -ENODEV; + } dom->data = data; } + mutex_unlock(&dom->mutex); mutex_lock(&data->mutex); if (!data->m4u_dom) { /* Initialize the M4U HW */ -- 2.18.0