From patchwork Thu Nov 24 11:20:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 9445249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7B6CD6071C for ; Thu, 24 Nov 2016 11:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6615327D76 for ; Thu, 24 Nov 2016 11:20:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AF4B27E15; Thu, 24 Nov 2016 11:20:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C6C1E27D76 for ; Thu, 24 Nov 2016 11:20:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965132AbcKXLUs (ORCPT ); Thu, 24 Nov 2016 06:20:48 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:54307 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965131AbcKXLUr (ORCPT ); Thu, 24 Nov 2016 06:20:47 -0500 Received: from epcpsbgm2new.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OH502FMU8TW1J20@mailout1.samsung.com> for linux-samsung-soc@vger.kernel.org; Thu, 24 Nov 2016 20:20:42 +0900 (KST) X-AuditID: cbfee61b-f796f6d000004092-07-5836cd0a7892 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id 42.0E.16530.A0DC6385; Thu, 24 Nov 2016 20:20:42 +0900 (KST) Received: from AMDC2765.digital.local ([106.116.147.25]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OH500D6Y8U00G70@mmp1.samsung.com>; Thu, 24 Nov 2016 20:20:42 +0900 (KST) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org Cc: Marek Szyprowski , Joerg Roedel , Krzysztof Kozlowski , Bartlomiej Zolnierkiewicz Subject: [PATCH 4/5] iommu/exynos: Add default_domain check in iommu_attach_device Date: Thu, 24 Nov 2016 12:20:19 +0100 Message-id: <1479986420-30859-5-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1479986420-30859-1-git-send-email-m.szyprowski@samsung.com> References: <1479986420-30859-1-git-send-email-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsVy+t9jAV2us2YRBif7pSw2zljParFgv7VF 5+wN7BbnzwOJGef3MVmsPXKX3YHN48nBeUwem1Z1snlMvrGc0aNvyypGj8+b5AJYo9xsMlIT U1KLFFLzkvNTMvPSbZVCQ9x0LZQU8hJzU22VInR9Q4KUFMoSc0qBPCMDNODgHOAerKRvl+CW 8X/iN+aCaZwViw63sjQwXmHvYuTkkBAwkVj45QIbhC0mceHeeiCbi0NIYCmjxJwXr1lAEkIC vxglmvY6gthsAoYSXW+7wBpEBNwlrv95zgLSwCywgVFi3YwJzCAJYYEQiR0v+sGaWQRUJR58 eAvWwCvgIfHh0EImiG1yEiePTWYFsTkFPCWmb+yHWuYhcWHVW8YJjLwLGBlWMUqkFiQXFCel 5xrlpZbrFSfmFpfmpesl5+duYgQH8jPpHYyHd7kfYhTgYFTi4e0wMYsQYk0sK67MPcQowcGs JMJrcAooxJuSWFmVWpQfX1Sak1p8iNEU6LCJzFKiyfnAKMsriTc0MTcxNzawMLe0NDFSEudt nP0sXEggPbEkNTs1tSC1CKaPiYNTqoFxreOxtrSmUPkWmdXuKvKz+7e7hesJfZi/e8qOB9e7 7hY+1TxqcPZfhCxHxl5x1tByxifrl0RN1OH9uu7j0vfxe4SUH50/MrP58lkWn0f8F5XDE1b9 +7YhdnLzW77Gp22LotTfLt8R/aDs4yRX8aULBS/Pa/6pJxoVY/JkVpJJltkRJjfDy0GWSizF GYmGWsxFxYkAIwokD3oCAAA= X-MTR: 20000000000000000@CPGS Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds default_domain check before calling exynos_iommu_detach_device. This path was intended only to cope with default domains, which are automatically attached by the iommu core, so return error if user tries to attach device, which is already attached to other (non-default) domain. Signed-off-by: Marek Szyprowski --- drivers/iommu/exynos-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 426b1534d4d3..63d9358a6d9c 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -859,8 +859,17 @@ static int exynos_iommu_attach_device(struct iommu_domain *iommu_domain, if (!has_sysmmu(dev)) return -ENODEV; - if (owner->domain) + if (owner->domain) { + struct iommu_group *group = iommu_group_get(dev); + + if (!group || + owner->domain != iommu_group_default_domain(group)) { + iommu_group_put(group); + return -EINVAL; + } + iommu_group_put(group); exynos_iommu_detach_device(owner->domain, dev); + } mutex_lock(&owner->rpm_lock);