From patchwork Mon Nov 14 10:08:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 82040 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp932632qge; Mon, 14 Nov 2016 02:10:53 -0800 (PST) X-Received: by 10.98.166.70 with SMTP id t67mr34481312pfe.132.1479118253139; Mon, 14 Nov 2016 02:10:53 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o20si21634477pgn.236.2016.11.14.02.10.52; Mon, 14 Nov 2016 02:10:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933399AbcKNKKn (ORCPT + 26 others); Mon, 14 Nov 2016 05:10:43 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:24828 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753915AbcKNKJR (ORCPT ); Mon, 14 Nov 2016 05:09:17 -0500 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OGM008TKMVDV600@mailout1.w1.samsung.com>; Mon, 14 Nov 2016 10:09:13 +0000 (GMT) Received: from eusmges5.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161114100913eucas1p1009f3ab9badfd98ec96f84c58a6232b9~G4h_nVeMW2318423184eucas1p1L; Mon, 14 Nov 2016 10:09:13 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges5.samsung.com (EUCPMTA) with SMTP id AE.4F.19540.84D89285; Mon, 14 Nov 2016 10:09:12 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161114100912eucas1p18aed36d2573319e00bd232b0eedf9489~G4h96AypX2318423184eucas1p1I; Mon, 14 Nov 2016 10:09:12 +0000 (GMT) X-AuditID: cbfec7f5-f79ce6d000004c54-da-58298d48d17c Received: from eusync4.samsung.com ( [203.254.199.214]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id CB.22.10494.C2D89285; Mon, 14 Nov 2016 10:08:45 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OGM00IDHMV2LBA0@eusync4.samsung.com>; Mon, 14 Nov 2016 10:09:12 +0000 (GMT) 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, Joerg Roedel Cc: Marek Szyprowski , 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 v7 5/7] iommu/exynos: Rework and fix internal locking Date: Mon, 14 Nov 2016 11:08:10 +0100 Message-id: <1479118092-1365-6-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1479118092-1365-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAAzWSa0hTcRjG/e9cdtQWh030jzdiIaihZST+lyFFRgciyD6kFFQjD/M2L5tK FqIZ3lZe0kTzEqauaF6Wm81NTM3LNA3vlhUmpWK3ka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t7gx4SmjxZnTl1gt2lZ/YLVYtesPo0Xf2ktsDsIeTw7OY/LYcXcJo8fOWXfZPTat 6mTz2D93DbvH5BvLGT3+HWP32HK1ncWjb8sqRo/Pm+Q8ZrRvYw3gjnKzyUhNTEktUkjNS85P ycxLt1UKDXHTtVBSyEvMTbVVitD1DQlSUihLzCkF8owM0ICDc4B7sJK+XYJbRt+2pawFO8Uq 7i+5ytzA2CncxcjJISFgIrH67QJWCFtM4sK99WwgtpDAEkaJ5hPVXYxcQHYTk8SKbweYQBJs AoYSXW+72EASIgKLGSUaDk1hBHGYBY6xSCzuOcgMUiUs4CrxZ+pCMJtFQFXi4sUTYDavgLvE lX8foNbJSZw8NhnM5hTwkJj7+RMLxGp3iauX9zNPYORdwMiwilEktbQ4Nz232EivODG3uDQv XS85P3cTIzD6th37uWUHY9e74EOMAhyMSjy8HfkaEUKsiWXFlbmHGCU4mJVEeJV7NCOEeFMS K6tSi/Lji0pzUosPMZoCHTWRWUo0OR+YGPJK4g1NDM0tDY2MLSzMjYyUxHmnfrgSLiSQnliS mp2aWpBaBNPHxMEp1cC4PZp7PbfUoseKqpkfPF49czRnFazXMZBnrO/f+XR509lMNgOFnD+c zU2zrFWU+N65PN984O9lhdtRMmoGymH3K4rmn0rZo/x2il9jdbL7Dzu9//lih7f31HTcc/63 wlC396rBL702B7b0YPV3nc7/I6ND38gJPS/vyG9gqTifVWDadHLKSSWW4oxEQy3mouJEAIcr EJbUAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161114100912eucas1p18aed36d2573319e00bd232b0eedf9489 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: 20161114100912eucas1p18aed36d2573319e00bd232b0eedf9489 X-RootMTR: 20161114100912eucas1p18aed36d2573319e00bd232b0eedf9489 References: <1479118092-1365-1-git-send-email-m.szyprowski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 28e570b..a959443 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);