From patchwork Tue Feb 16 14:40:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 62033 Delivered-To: patches@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1703731lbl; Tue, 16 Feb 2016 06:41:30 -0800 (PST) X-Received: by 10.140.180.130 with SMTP id b124mr17755989qha.77.1455633690450; Tue, 16 Feb 2016 06:41:30 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 47si40899280qgd.35.2016.02.16.06.41.30; Tue, 16 Feb 2016 06:41:30 -0800 (PST) Received-SPF: pass (google.com: domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=linaro-mm-sig-bounces@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 17612618D9; Tue, 16 Feb 2016 14:41:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id E1AB1617C4; Tue, 16 Feb 2016 14:40:56 +0000 (UTC) X-Original-To: linaro-mm-sig@lists.linaro.org Delivered-To: linaro-mm-sig@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 71D35617C4; Tue, 16 Feb 2016 14:40:54 +0000 (UTC) Received: from mailout4.w1.samsung.com (mailout4.w1.samsung.com [210.118.77.14]) by lists.linaro.org (Postfix) with ESMTPS id 7137D61705 for ; Tue, 16 Feb 2016 14:40:52 +0000 (UTC) Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O2N004OXA42QE20@mailout4.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Tue, 16 Feb 2016 14:40:50 +0000 (GMT) X-AuditID: cbfec7f5-f79b16d000005389-ec-56c334f2dbb7 Received: from eusync2.samsung.com ( [203.254.199.212]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id BB.28.21385.2F433C65; Tue, 16 Feb 2016 14:40:50 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O2N009ERA3YAL40@eusync2.samsung.com>; Tue, 16 Feb 2016 14:40:50 +0000 (GMT) From: Marek Szyprowski To: iommu@lists.linux-foundation.org Date: Tue, 16 Feb 2016 15:40:31 +0100 Message-id: <1455633632-16873-2-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <1455633632-16873-1-git-send-email-m.szyprowski@samsung.com> References: <1455633632-16873-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmphluLIzCtJLcpLzFFi42I5/e/4Fd1PJofDDE590rTYOGM9q8WC/dYW nbM3sFt8ufKQyWLtkbvsDqweTw7OY/K4/e8xs8fkG8sZPfq2rGIMYInisklJzcksSy3St0vg yjiwYTNrwRn+iovLH7I3ML7m6WLk5JAQMJE4uPQWO4QtJnHh3nq2LkYuDiGBpYwSx9tamEAS QgJNTBJd/XkgNpuAoUTX2y42EFtEQEVi1s7FLCANzAIrGSU2frsINklYIFbiwffVYEUsAqoS jb2rGUFsXgEPiRmPZzJCbJOT+P9yBdACDg5OAU+JrT/VIHZ5SHzc/ohtAiPvAkaGVYyiqaXJ BcVJ6blGesWJucWleel6yfm5mxghYfN1B+PSY1aHGAU4GJV4eDe4HgoTYk0sK67MPcQowcGs JML77xVQiDclsbIqtSg/vqg0J7X4EKM0B4uSOO/MXe9DhATSE0tSs1NTC1KLYLJMHJxSDYyn swMub2acpqzOdXf9M5/X6dEVc5wc5rvtfdHqdOqb572I06u2vg37lsfFe8f0WOjij8ybnbsW sQooee4Qjjn32O2meY/vvTXb9TT9DLac/8UgwClR/mr6yQ3nAz79fKg0UfKieyXHFsFvqh1u 2Q53rj0oD/ff93/dhvuT/Y8xXcpftXU196xOJZbijERDLeai4kQAVySW9xcCAAA= Cc: linaro-mm-sig@lists.linaro.org, Joerg Roedel , Bartlomiej Zolnierkiewicz Subject: [Linaro-mm-sig] [PATCH 1/2] iommu: call detach also for default_domain before attaching to new one X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: "Linaro-mm-sig" This patch ensures that devices attached to the default_domain will be first detached from it before attaching to new domain. To avoid forward declaration, __iommu_attach_group() function has been moved to new place in the source code. Signed-off-by: Marek Szyprowski --- drivers/iommu/iommu.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0e3b009..db231ad 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1198,22 +1198,6 @@ static int iommu_group_do_attach_device(struct device *dev, void *data) return __iommu_attach_device(domain, dev); } -static int __iommu_attach_group(struct iommu_domain *domain, - struct iommu_group *group) -{ - int ret; - - if (group->default_domain && group->domain != group->default_domain) - return -EBUSY; - - ret = __iommu_group_for_each_dev(group, domain, - iommu_group_do_attach_device); - if (ret == 0) - group->domain = domain; - - return ret; -} - int iommu_attach_group(struct iommu_domain *domain, struct iommu_group *group) { int ret; @@ -1235,6 +1219,28 @@ static int iommu_group_do_detach_device(struct device *dev, void *data) return 0; } +static int __iommu_attach_group(struct iommu_domain *domain, + struct iommu_group *group) +{ + int ret; + + if (group->default_domain && group->domain != group->default_domain) + return -EBUSY; + + if (group->default_domain && group->default_domain == group->domain) { + __iommu_group_for_each_dev(group, group->domain, + iommu_group_do_detach_device); + group->domain = NULL; + } + + ret = __iommu_group_for_each_dev(group, domain, + iommu_group_do_attach_device); + if (ret == 0) + group->domain = domain; + + return ret; +} + static void __iommu_detach_group(struct iommu_domain *domain, struct iommu_group *group) {