From patchwork Thu Oct 20 07:22:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 78419 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp639049qge; Thu, 20 Oct 2016 00:23:51 -0700 (PDT) X-Received: by 10.98.213.132 with SMTP id d126mr18629021pfg.182.1476948231252; Thu, 20 Oct 2016 00:23:51 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yk1si36569458pab.231.2016.10.20.00.23.51; Thu, 20 Oct 2016 00:23:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751012AbcJTHXp (ORCPT + 14 others); Thu, 20 Oct 2016 03:23:45 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:21928 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751350AbcJTHXi (ORCPT ); Thu, 20 Oct 2016 03:23:38 -0400 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OFC005EK4JCGS20@mailout3.w1.samsung.com>; Thu, 20 Oct 2016 08:23:36 +0100 (BST) Received: from eusmges3.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161020072335eucas1p1fa9d90e1d723a1abda7fb71b89409c22~-LJOtqViL1037610376eucas1p1o; Thu, 20 Oct 2016 07:23:35 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3.samsung.com (EUCPMTA) with SMTP id ED.53.11330.7F078085; Thu, 20 Oct 2016 08:23:35 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20161020072334eucas1p2a159a25a2875611eff208381ebdb2e84~-LJN6-bxX3245932459eucas1p2J; Thu, 20 Oct 2016 07:23:34 +0000 (GMT) X-AuditID: cbfec7f2-f79556d000002c42-b5-580870f78d88 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 54.BD.10494.2D078085; Thu, 20 Oct 2016 08:22:58 +0100 (BST) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OFC0074C4J1JF30@eusync2.samsung.com>; Thu, 20 Oct 2016 08:23:34 +0100 (BST) From: Marek Szyprowski To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Joerg Roedel , Inki Dae , Kukjin Kim , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz , "Rafael J. Wysocki" , Mark Brown , "Luis R. Rodriguez" , Greg Kroah-Hartman , Tomeu Vizoso , Lukas Wunner , Kevin Hilman , Tobias Jakobi , Tomasz Figa Subject: [PATCH v5 5/7] iommu/exynos: Rework and fix internal locking Date: Thu, 20 Oct 2016 09:22:51 +0200 Message-id: <1476948173-21093-6-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1476948173-21093-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzVSa0hTYRju3Tln57icnTaxDyuJRf3oYlkSH3ZHpdOPyD+R9KdGHpw0neyo aGC4rKnr4trUVl6SUoN5K5MxV2ZN2TJN84b2Y15SSwxJUok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lNGizOnL7FatK3+wGqxatcfRou+tZfYHIQ9nhycx+Sx4+4SRo+ds+6ye2xa 1cnmsX/uGnaPyTeWM3r8O8buseVqO4tH35ZVjB6fN8l5zGjfxhrAHeVmk5GamJJapJCal5yf kpmXbqsUGuKma6GkkJeYm2qrFKHrGxKkpFCWmFMK5BkZoAEH5wD3YCV9uwS3jDXHEgsOi1Uc /z+XuYFxsnAXIyeHhICJxJf7p5ggbDGJC/fWs3UxcnEICSxhlFjQco8Fwmliknj7fCc7SBWb gKFE19susCoRgUZGiW1bJ7KDOMwCz1gkFvzYBpTh4BAWcJVonKoA0sAioCrROGkGC0iYV8BD YvIRZ4htchInj01mBbE5BTwldq/pZQaxhYBK3m9cxziBkXcBI8MqRpHU0uLc9NxiI73ixNzi 0rx0veT83E2MwMjbduznlh2MXe+CDzEKcDAq8fBmnGOPEGJNLCuuzD3EKMHBrCTCeyyHI0KI NyWxsiq1KD++qDQntfgQoynQTROZpUST84FJIa8k3tDE0NzS0MjYwsLcyEhJnHfqhyvhQgLp iSWp2ampBalFMH1MHJxSDYzT/ksVHdkRq2C2Loc9Pv/SxHuXG05kCm1Jq/y68WhRRM3MGzGu F4IeVbe97P+5pHO20YMfrJPWrHIuLeqWz46L6rWbJfM5u//p4uQ9GUmJl8TPyL5wsTfave1x rMhaV4ml69hznLbOPT5/+5b6GZ+eXXr3/oius9MFnZbjDG9Fdh8tDF1jumq5EktxRqKhFnNR cSIAg8svB9ICAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161020072334eucas1p2a159a25a2875611eff208381ebdb2e84 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161020072334eucas1p2a159a25a2875611eff208381ebdb2e84 X-RootMTR: 20161020072334eucas1p2a159a25a2875611eff208381ebdb2e84 References: <1476948173-21093-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org This patch reworks locking in the exynos_iommu_attach/detach_device functions to ensure that all entries of the sysmmu_drvdata and exynos_iommu_owner structure are updated under the respective spinlocks, while runtime pm functions are called without any spinlocks held. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 28e570b53672..a959443e6f33 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -731,10 +731,12 @@ static void exynos_iommu_domain_free(struct iommu_domain *iommu_domain) spin_lock_irqsave(&domain->lock, flags); list_for_each_entry_safe(data, next, &domain->clients, domain_node) { + spin_lock(&data->lock); __sysmmu_disable(data); data->pgtable = 0; data->domain = NULL; list_del_init(&data->domain_node); + spin_unlock(&data->lock); } spin_unlock_irqrestore(&domain->lock, flags); @@ -772,17 +774,22 @@ static void exynos_iommu_detach_device(struct iommu_domain *iommu_domain, if (!has_sysmmu(dev) || owner->domain != iommu_domain) return; + list_for_each_entry(data, &owner->controllers, owner_node) { + __sysmmu_disable(data); + pm_runtime_put(data->sysmmu); + } + spin_lock_irqsave(&domain->lock, flags); list_for_each_entry_safe(data, next, &domain->clients, domain_node) { - __sysmmu_disable(data); + spin_lock(&data->lock); data->pgtable = 0; data->domain = NULL; list_del_init(&data->domain_node); - pm_runtime_put(data->sysmmu); + spin_unlock(&data->lock); } + owner->domain = NULL; spin_unlock_irqrestore(&domain->lock, flags); - owner->domain = NULL; dev_dbg(dev, "%s: Detached IOMMU with pgtable %pa\n", __func__, &pagetable); @@ -803,18 +810,22 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, if (owner->domain) exynos_iommu_detach_device(owner->domain, dev); + spin_lock_irqsave(&domain->lock, flags); list_for_each_entry(data, &owner->controllers, owner_node) { + spin_lock(&data->lock); data->pgtable = pagetable; data->domain = domain; + list_add_tail(&data->domain_node, &domain->clients); + spin_unlock(&data->lock); + } + owner->domain = iommu_domain; + spin_unlock_irqrestore(&domain->lock, flags); + + list_for_each_entry(data, &owner->controllers, owner_node) { pm_runtime_get_sync(data->sysmmu); __sysmmu_enable(data); - - spin_lock_irqsave(&domain->lock, flags); - list_add_tail(&data->domain_node, &domain->clients); - spin_unlock_irqrestore(&domain->lock, flags); } - owner->domain = iommu_domain; dev_dbg(dev, "%s: Attached IOMMU with pgtable %pa\n", __func__, &pagetable);