From patchwork Thu Apr 11 18:47:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B1C61805 for ; Thu, 11 Apr 2019 18:48:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5195D288BB for ; Thu, 11 Apr 2019 18:48:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44EB728CE8; Thu, 11 Apr 2019 18:48:56 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 607E12847B for ; Thu, 11 Apr 2019 18:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lXx1Jy7/SPHfkq7KoxTB1LeAmBxPzgSjKXJdrAPUXYs=; b=bFc43oXPHFCJ3h WxMr7K+vewXZ5VKhKLSWzeqrGtO2a8uyjrDUyn7qUq8ova3ACXPL/8VK/VDS2lIOUWuUym9QtLC/Z 9KyZr9TCuye3YEifjyY+l1ytT15hEHNIIOE6Wt1T6Sa0ULyxo7wCTvj/1Jy4dT4UddbU14Wytpc7m EGC36tIdoLpAoBAHlYReUrpXPVF3ZRfrMky1ojnPZsdnOkTdPpC08ob5CfFjgWgCb3mXUOOoMLPGv JKBpJVcI3Dso7EK8EHBtS5H0lvrHw7RGiIelBMi9r8ml2xRFeAx5GZ4SrUixDMg9rT1GOQRXv+RbF Z7Hg5GMjUNidOERdBoMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEekk-000217-G6; Thu, 11 Apr 2019 18:48:50 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEekb-0001qZ-Up for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:48:46 +0000 Received: by mail-ed1-x544.google.com with SMTP id x14so6168496eds.1 for ; Thu, 11 Apr 2019 11:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n4yA9kbM0Q0ne12+8XH1tmRl7xUq0Nxej0JIzN1JreU=; b=HhLRfjxa79ZXKH5Hm8L2aKT5z3CmMLkQ1hyD+3gm0L+cfNfIvDgelJWfxehXaiUn4Y EkF9gkxnlO93eoGKTba94wUgLy7OfxfoyXfgHFMfOz970JFQNSpbpCpNsCFn7HtN7O40 NWkXG8RmRxSbsm4e2gqjxNMWlPfUCAyg83uwOmwu7FGFCSIAGA9guCvwNSkQH1KBpG/Y h//oHsGzUj3Tgh6XZHgK0LH3I0eOWxrK9QiLxUXmIle8X/wI8Y5iRWaBwfJqE998wg6r tuBMhiydbpGnMMzEk+6L4N4IAJS5KdIM+jixwDWZT83OzvHA08bZhe0vhFW2+SXVd2Ud G5sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n4yA9kbM0Q0ne12+8XH1tmRl7xUq0Nxej0JIzN1JreU=; b=cz9adfwAcPfsowrcXFsSu7Im92R3HlKkRQeveXlqTy0cFvgv1fpplzzHWNebqCNmDI nGaa7G7b3QskVhml3mV5IstBbpJUFxgbObMocqLxtCLTYeaQ2R69W5THJzuMxBKUqY7M p4ha7VJpDyPDAxExznRtUUJapzPLeKoilDkYOkDjkZjJpyKnJi8XpEzPavcfID+uTEvy ZcW379Rb3NtQ3wOuM3VaqPySFNvhVdKBXFFtev9h9K4qx29iI6Q78EaTQr4ShvweJ8v/ U6TOyzPo3KsMiXB1Xp9P3VSPJ0Df9+KimwuGBkF0JRhLkZ2kDgX/dCoG0yU7P3zjQ9OQ 9Z2A== X-Gm-Message-State: APjAAAU76zHHQqu/ypy7KFvmSFRPfziNeSE9I9xm2Sp2O8nIzOdlHy+u eIuf54XnSIfMHLEipfREwrgniA== X-Google-Smtp-Source: APXvYqzMIqAsWo8mz5RO//d9/Q380vAGnatUNo+w1xdSz2URAp829inx6rjeeNWbisHhqhaffsUlNg== X-Received: by 2002:aa7:dd11:: with SMTP id i17mr7148462edv.220.1555008520271; Thu, 11 Apr 2019 11:48:40 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.48.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:48:39 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 1/9] iommu/dma-iommu: Add iommu_map_atomic Date: Thu, 11 Apr 2019 19:47:30 +0100 Message-Id: <20190411184741.27540-2-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114842_461023_FDFB26CD X-CRM114-Status: GOOD ( 22.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The iommu ops .map function (or the iommu_map function which calls it) was always supposed to be sleepable (according to Joerg's comment in this thread: https://lore.kernel.org/patchwork/patch/977520/ ) and so should probably have had a "might_sleep()" since it was written. However currently the dma-iommu api can call iommu_map in an atomic context, which it shouldn't do. This doesn't cause any problems because any iommu driver which uses the dma-iommu api uses gfp_atomic in it's iommu_ops .map function. But doing this wastes the memory allocators atomic pools. Add a new function iommu_map_atomic, use it in the dma-iommu api and add “might_sleep()” to the iommu_map function. After this change all drivers which use the dma-iommu api need to implement the new iommu ops .map_atomic function. For the moment just reuse the driver's iommus ops .map function for .map_atomic. Signed-off-by: Tom Murphy --- drivers/iommu/arm-smmu-v3.c | 1 + drivers/iommu/arm-smmu.c | 1 + drivers/iommu/dma-iommu.c | 6 ++--- drivers/iommu/exynos-iommu.c | 1 + drivers/iommu/iommu.c | 46 +++++++++++++++++++++++++++++----- drivers/iommu/ipmmu-vmsa.c | 1 + drivers/iommu/mtk_iommu.c | 1 + drivers/iommu/qcom_iommu.c | 1 + drivers/iommu/rockchip-iommu.c | 1 + include/linux/iommu.h | 22 ++++++++++++++++ 10 files changed, 72 insertions(+), 9 deletions(-) diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index d3880010c6cf..c64ba333c05a 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -2055,6 +2055,7 @@ static struct iommu_ops arm_smmu_ops = { .domain_free = arm_smmu_domain_free, .attach_dev = arm_smmu_attach_dev, .map = arm_smmu_map, + .map_atomic = arm_smmu_map, .unmap = arm_smmu_unmap, .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c index 045d93884164..836ec6d0bba5 100644 --- a/drivers/iommu/arm-smmu.c +++ b/drivers/iommu/arm-smmu.c @@ -1691,6 +1691,7 @@ static struct iommu_ops arm_smmu_ops = { .domain_free = arm_smmu_domain_free, .attach_dev = arm_smmu_attach_dev, .map = arm_smmu_map, + .map_atomic = arm_smmu_map, .unmap = arm_smmu_unmap, .flush_iotlb_all = arm_smmu_flush_iotlb_all, .iotlb_sync = arm_smmu_iotlb_sync, diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 77aabe637a60..1a4bff3f8427 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -590,7 +590,7 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, sg_miter_stop(&miter); } - if (iommu_map_sg(domain, iova, sgt.sgl, sgt.orig_nents, prot) + if (iommu_map_sg_atomic(domain, iova, sgt.sgl, sgt.orig_nents, prot) < size) goto out_free_sg; @@ -648,7 +648,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, if (!iova) return DMA_MAPPING_ERROR; - if (iommu_map(domain, iova, phys - iova_off, size, prot)) { + if (iommu_map_atomic(domain, iova, phys - iova_off, size, prot)) { iommu_dma_free_iova(cookie, iova, size); return DMA_MAPPING_ERROR; } @@ -809,7 +809,7 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, * We'll leave any physical concatenation to the IOMMU driver's * implementation - it knows better than we do. */ - if (iommu_map_sg(domain, iova, sg, nents, prot) < iova_len) + if (iommu_map_sg_atomic(domain, iova, sg, nents, prot) < iova_len) goto out_free_iova; return __finalise_sg(dev, sg, nents, iova); diff --git a/drivers/iommu/exynos-iommu.c b/drivers/iommu/exynos-iommu.c index 05c6bc099d62..bf1281aa12bc 100644 --- a/drivers/iommu/exynos-iommu.c +++ b/drivers/iommu/exynos-iommu.c @@ -1332,6 +1332,7 @@ static const struct iommu_ops exynos_iommu_ops = { .attach_dev = exynos_iommu_attach_device, .detach_dev = exynos_iommu_detach_device, .map = exynos_iommu_map, + .map_atomic = exynos_iommu_map, .unmap = exynos_iommu_unmap, .iova_to_phys = exynos_iommu_iova_to_phys, .device_group = generic_device_group, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 33a982e33716..1eaf0aed0aff 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1582,8 +1582,8 @@ static size_t iommu_pgsize(struct iommu_domain *domain, return pgsize; } -int iommu_map(struct iommu_domain *domain, unsigned long iova, - phys_addr_t paddr, size_t size, int prot) +int __iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot, bool is_atomic) { const struct iommu_ops *ops = domain->ops; unsigned long orig_iova = iova; @@ -1620,8 +1620,12 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova, pr_debug("mapping: iova 0x%lx pa %pa pgsize 0x%zx\n", iova, &paddr, pgsize); + if (is_atomic) + ret = ops->map_atomic(domain, iova, paddr, pgsize, + prot); + else + ret = ops->map(domain, iova, paddr, pgsize, prot); - ret = ops->map(domain, iova, paddr, pgsize, prot); if (ret) break; @@ -1641,8 +1645,22 @@ int iommu_map(struct iommu_domain *domain, unsigned long iova, return ret; } + +int iommu_map(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot) +{ + might_sleep(); + return __iommu_map(domain, iova, paddr, size, prot, false); +} EXPORT_SYMBOL_GPL(iommu_map); +int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot) +{ + return __iommu_map(domain, iova, paddr, size, prot, true); +} +EXPORT_SYMBOL_GPL(iommu_map_atomic); + static size_t __iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size, bool sync) @@ -1717,8 +1735,9 @@ size_t iommu_unmap_fast(struct iommu_domain *domain, } EXPORT_SYMBOL_GPL(iommu_unmap_fast); -size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, - struct scatterlist *sg, unsigned int nents, int prot) +size_t __iommu_map_sg(struct iommu_domain *domain, unsigned long iova, + struct scatterlist *sg, unsigned int nents, int prot, + bool is_atomic) { size_t len = 0, mapped = 0; phys_addr_t start; @@ -1729,7 +1748,9 @@ size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, phys_addr_t s_phys = sg_phys(sg); if (len && s_phys != start + len) { - ret = iommu_map(domain, iova + mapped, start, len, prot); + ret = __iommu_map(domain, iova + mapped, start, + len, prot, is_atomic); + if (ret) goto out_err; @@ -1757,8 +1778,21 @@ size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, return 0; } + +size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, + struct scatterlist *sg, unsigned int nents, int prot) +{ + return __iommu_map_sg(domain, iova, sg, nents, prot, false); +} EXPORT_SYMBOL_GPL(iommu_map_sg); +size_t iommu_map_sg_atomic(struct iommu_domain *domain, unsigned long iova, + struct scatterlist *sg, unsigned int nents, int prot) +{ + return __iommu_map_sg(domain, iova, sg, nents, prot, true); +} +EXPORT_SYMBOL_GPL(iommu_map_sg_atomic); + int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, phys_addr_t paddr, u64 size, int prot) { diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 9a380c10655e..c2e0cdb9e784 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c @@ -931,6 +931,7 @@ static const struct iommu_ops ipmmu_ops = { .attach_dev = ipmmu_attach_device, .detach_dev = ipmmu_detach_device, .map = ipmmu_map, + .map_atomic = ipmmu_map, .unmap = ipmmu_unmap, .flush_iotlb_all = ipmmu_iotlb_sync, .iotlb_sync = ipmmu_iotlb_sync, diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c index de3e02277b70..ed8f768f46b6 100644 --- a/drivers/iommu/mtk_iommu.c +++ b/drivers/iommu/mtk_iommu.c @@ -497,6 +497,7 @@ static const struct iommu_ops mtk_iommu_ops = { .attach_dev = mtk_iommu_attach_device, .detach_dev = mtk_iommu_detach_device, .map = mtk_iommu_map, + .map_atomic = mtk_iommu_map, .unmap = mtk_iommu_unmap, .flush_iotlb_all = mtk_iommu_iotlb_sync, .iotlb_sync = mtk_iommu_iotlb_sync, diff --git a/drivers/iommu/qcom_iommu.c b/drivers/iommu/qcom_iommu.c index 8cdd3f059513..26100487642d 100644 --- a/drivers/iommu/qcom_iommu.c +++ b/drivers/iommu/qcom_iommu.c @@ -591,6 +591,7 @@ static const struct iommu_ops qcom_iommu_ops = { .attach_dev = qcom_iommu_attach_dev, .detach_dev = qcom_iommu_detach_dev, .map = qcom_iommu_map, + .map_atomic = qcom_iommu_map, .unmap = qcom_iommu_unmap, .flush_iotlb_all = qcom_iommu_iotlb_sync, .iotlb_sync = qcom_iommu_iotlb_sync, diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c index 77d4bd93fe4b..d24bc2413d49 100644 --- a/drivers/iommu/rockchip-iommu.c +++ b/drivers/iommu/rockchip-iommu.c @@ -1124,6 +1124,7 @@ static const struct iommu_ops rk_iommu_ops = { .attach_dev = rk_iommu_attach_device, .detach_dev = rk_iommu_detach_device, .map = rk_iommu_map, + .map_atomic = rk_iommu_map, .unmap = rk_iommu_unmap, .add_device = rk_iommu_add_device, .remove_device = rk_iommu_remove_device, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index ffbbc7e39cee..75559918d9bd 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -166,6 +166,7 @@ struct iommu_resv_region { * @attach_dev: attach device to an iommu domain * @detach_dev: detach device from an iommu domain * @map: map a physically contiguous memory region to an iommu domain + * @map_atomic: same as map but can be called from an atomic context * @unmap: unmap a physically contiguous memory region from an iommu domain * @flush_iotlb_all: Synchronously flush all hardware TLBs for this domain * @iotlb_range_add: Add a given iova range to the flush queue for this domain @@ -199,6 +200,8 @@ struct iommu_ops { void (*detach_dev)(struct iommu_domain *domain, struct device *dev); int (*map)(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); + int (*map_atomic)(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot); size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, size_t size); void (*flush_iotlb_all)(struct iommu_domain *domain); @@ -295,12 +298,17 @@ extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); extern struct iommu_domain *iommu_get_dma_domain(struct device *dev); extern int iommu_map(struct iommu_domain *domain, unsigned long iova, phys_addr_t paddr, size_t size, int prot); +extern int iommu_map_atomic(struct iommu_domain *domain, unsigned long iova, + phys_addr_t paddr, size_t size, int prot); extern size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size); extern size_t iommu_unmap_fast(struct iommu_domain *domain, unsigned long iova, size_t size); extern size_t iommu_map_sg(struct iommu_domain *domain, unsigned long iova, struct scatterlist *sg,unsigned int nents, int prot); +extern size_t iommu_map_sg_atomic(struct iommu_domain *domain, + unsigned long iova, struct scatterlist *sg, + unsigned int nents, int prot); extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova); extern void iommu_set_fault_handler(struct iommu_domain *domain, iommu_fault_handler_t handler, void *token); @@ -469,6 +477,13 @@ static inline int iommu_map(struct iommu_domain *domain, unsigned long iova, return -ENODEV; } +static inline int iommu_map_atomic(struct iommu_domain *domain, + unsigned long iova, phys_addr_t paddr, + size_t size, int prot) +{ + return -ENODEV; +} + static inline size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) { @@ -488,6 +503,13 @@ static inline size_t iommu_map_sg(struct iommu_domain *domain, return 0; } +static inline size_t iommu_map_sg_atomic(struct iommu_domain *domain, + unsigned long iova, struct scatterlist *sg, + unsigned int nents, int prot) +{ + return 0; +} + static inline void iommu_flush_tlb_all(struct iommu_domain *domain) { } From patchwork Thu Apr 11 18:47:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5F7317E0 for ; Thu, 11 Apr 2019 18:49:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD178288BB for ; Thu, 11 Apr 2019 18:49:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C058428CDF; Thu, 11 Apr 2019 18:49:19 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 61123288BB for ; Thu, 11 Apr 2019 18:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zo2BSp3U7KdImbuZDzg6+U/9R+QWOQw/2cDTnp55JvM=; b=mTRPh++J2fyLr2C+jFQVGvXdSN lObTwbdOC0quEzqJDVorNhl5uKIycJXspeNIVPOX3xERPt1v45ZXdfsCZ2Z2L64nwzo1aobxWLOwf 03FQHN82BIPuNt5SbeYofspwgrXLsDlUSxydEOWCSPjXKK59aTz2pK/CENX8CKFUWKekKukGVtoKS 0kaVz4/CBjE9051+VL/SNHOxd6wTYirL102PbgFnPePHaayFf0oaWufBcTJf1NkOCRRleuYgJCyKx bkFD7QSsN4XAnUSaAHi8w2wKfLFV+3cFz8v2paA4cgO4NJGEbnlfEE4R7RnE7TzGVpTBjidkSLrOM +YsuXMXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEel7-0002Rb-5v; Thu, 11 Apr 2019 18:49:13 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEeko-000254-Au for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:04 +0000 Received: by mail-ed1-x541.google.com with SMTP id x14so6169027eds.1 for ; Thu, 11 Apr 2019 11:48:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6jV061f41NQwb8JTG8oXH2FoN+EzpljlUI1gqzDD5mU=; b=LB8fzaJxGq1UE+kpvHkDhu+B7IYs10PuyLyxZ03R2k40h38528mg8DNtw5CvvGGUEC 4dNobAdGceLj4W3cf/sfNIbHYYnxPug8x3dHbMQMr2kBWb4l2K/d40OgBWHu7LGBSrMM s+LiuJL7CxNF9g9cw4QCmZ7DPjTrADiA+PibC+2h5HaxTFrd/3KF3OxCtBPyIfkaGijI w27pVFIysfKxbHH1Oa9xGIwlfToSd/gcWJ+6qScvI3KsfWoRcLhGTSa83G90H5wmgs26 LzzyBPinYyZ0Vrq04CSUH9OmCRpgSwAiWliiYd80JUgr4JUSA6+IIwLoCw9dkVOlrsoq r3CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6jV061f41NQwb8JTG8oXH2FoN+EzpljlUI1gqzDD5mU=; b=n3iwWim+k3ea8dcb6O64hCFjCYDTamEeEw85WSZOc3JQfdgha7WWMrcdg7tWW+R+I2 supDYPdqSR39E2ZI8FiQxdJYxYKpeDPojSC4ZSCn9Rlq6CYHdzYOnijLnlUuG0rUXj3U ZolrJrn82yyHCmq/zsk+C8T5fYaTADfOIwRQqEJgNHRPlGkH8KFjkFb2GrIzUUMkDqxh ch3VqMHwO54qJpcqYgbrMlx85AzXNa1b/irInHchPO7r76Of3ytYIP7DbJUY2Esj/pgu NAcqd4U5D9hQDVNWzB22htOZQYvnE7aJBhQ06K869v94EZ5ybGts4bO+C0K94dpy2/Ah MJbg== X-Gm-Message-State: APjAAAVYQD8Udv9vxZf+FR9r5ZuuvVUoAcxOKBGcaH2FF56HZj61Um8A K+2SmREJNCXQ5n9l3jzQi+FDeg== X-Google-Smtp-Source: APXvYqxuoTpmggkOjj92suBw5a7aMbe3r0ArbtvwTV09yEmPy8J3qtmyATEWD+DKwUJEiX7Kcbu32A== X-Received: by 2002:a17:906:5e0d:: with SMTP id n13mr27817212eju.37.1555008532896; Thu, 11 Apr 2019 11:48:52 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.48.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:48:52 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 2/9] iommu/dma-iommu: Add function to flush any cached not present IOTLB entries Date: Thu, 11 Apr 2019 19:47:31 +0100 Message-Id: <20190411184741.27540-3-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114854_811740_62D191EC X-CRM114-Status: GOOD ( 15.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Both the AMD and Intel drivers can cache not present IOTLB entries. To convert these drivers to the dma-iommu api we need a generic way to flush the NP cache. IOMMU drivers which have a NP cache can implement the .flush_np_cache function in the iommu ops struct. I will implement .flush_np_cache for both the Intel and AMD drivers in later patches. The Intel np-cache is described here: https://software.intel.com/sites/default/files/managed/c5/15/vt-directed-io-spec.pdf#G7.66452 And the AMD np-cache is described here: https://developer.amd.com/wordpress/media/2012/10/34434-IOMMU-Rev_1.26_2-11-09.pdf#page=63 Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 10 ++++++++++ include/linux/iommu.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 1a4bff3f8427..cc5da30d6e58 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -594,6 +594,9 @@ struct page **iommu_dma_alloc(struct device *dev, size_t size, gfp_t gfp, < size) goto out_free_sg; + if (domain->ops->flush_np_cache) + domain->ops->flush_np_cache(domain, iova, size); + *handle = iova; sg_free_table(&sgt); return pages; @@ -652,6 +655,10 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, iommu_dma_free_iova(cookie, iova, size); return DMA_MAPPING_ERROR; } + + if (domain->ops->flush_np_cache) + domain->ops->flush_np_cache(domain, iova, size); + return iova + iova_off; } @@ -812,6 +819,9 @@ int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, if (iommu_map_sg_atomic(domain, iova, sg, nents, prot) < iova_len) goto out_free_iova; + if (domain->ops->flush_np_cache) + domain->ops->flush_np_cache(domain, iova, iova_len); + return __finalise_sg(dev, sg, nents, iova); out_free_iova: diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 75559918d9bd..47ff8d731d6a 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -173,6 +173,7 @@ struct iommu_resv_region { * @iotlb_sync_map: Sync mappings created recently using @map to the hardware * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush * queue + * @flush_np_cache: Flush the non present entry cache * @iova_to_phys: translate iova to physical address * @add_device: add device to iommu grouping * @remove_device: remove device from iommu grouping @@ -209,6 +210,8 @@ struct iommu_ops { unsigned long iova, size_t size); void (*iotlb_sync_map)(struct iommu_domain *domain); void (*iotlb_sync)(struct iommu_domain *domain); + void (*flush_np_cache)(struct iommu_domain *domain, + unsigned long iova, size_t size); phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); int (*add_device)(struct device *dev); void (*remove_device)(struct device *dev); From patchwork Thu Apr 11 18:47:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896655 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4EEB117E0 for ; Thu, 11 Apr 2019 18:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334B3288BB for ; Thu, 11 Apr 2019 18:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 267E728CDF; Thu, 11 Apr 2019 18:49:30 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C945C288BB for ; Thu, 11 Apr 2019 18:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=xDq8I2qSEHdSA2NaYpHv2dWG70/WM7TpmP8301AIgqM=; b=opJzVMoHVLElqYSgh6Iod0vbAW YFZ1D5t1lUL0Eqb2i6N0ChNDrT+m5VIOr5i3pekUMpukRdtIQzoFsFSCu+bzoM4A5hVtE2i3d55hh NPfhQ0Xhz1A8Ni0o44rnyAT7YEV3g/juZ4kP4Ap3293sWfA3KQiaWXyYymmfp7XFXEqWfLhuKtVBE z/mZAjM0ci+rJQBEv9HUjEgWcJtS294DJ5efHjWGHo0UphCcdccGqMooOPCtGeegqJl+8eGHbR5xI N/k/LlpldoW7xOQp1x6P2jgUBSJeM6THij+hXHoZNGxxrzRZaCJc5ST8v+TiRkgQKlCPn3Ul4sg4Z suAHQCgA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelG-0002hD-RN; Thu, 11 Apr 2019 18:49:22 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEeks-0002BJ-Vi for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:07 +0000 Received: by mail-ed1-x544.google.com with SMTP id w3so6123144edu.10 for ; Thu, 11 Apr 2019 11:48:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AUkwsqPqLpOQmNdW6Zo0mGf3wmD2BJmU+zJegMbV/Cw=; b=QBMldSGXvc5UwIGLNlY32ptO/VQea8opvEhsRdSzFj4NeN+2G0brH1f/8UVXoDmFzp vgXq8kR+NdanSwtvOTUwpCkm2QCKmWJ4W86KO5tQnP14gTIyY6jfmkyqnM3PIjU1mTrt RDRIQ3bZewU8rrugmcD7S8kRSviGvRiF9zV4bsr6eB83nCXNebkP2SIudff9lbHkRgMS jtauEkPGJgc+fdQv9IWyCVoKtXmY9AvPYOF2tkN2bpTztPvH+bZN2z5g44aD0CJPVIjp Jfs1P1M2x6/FXn9kRoiH7d82Jzo159phG6Ce+OItl5XQo6MoCtkdx/N7GlvqiQu50XsS 3gtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AUkwsqPqLpOQmNdW6Zo0mGf3wmD2BJmU+zJegMbV/Cw=; b=YBA38p27hb8U/Rp8lh+nn+Rv7RaDMRcnl/1a4PknIbfGlFn/zO0f8LGsdPS+CCAyCw jg2I7OepxbP1Zz/+sxOVmiip2VFoLazrPlUiE16RoUQ/IYjsKxF3RJZCoxRTyjyQWC7D HwO0WN/4hUK8HIzPECi9VsB4WPs7HZ9IJ8tk4JQ0kpg8T/yFeGiH2Za3UDymrEnSMYf/ KhQBotIcCaafgyq+wfqAuhTCuBYFpBLTgXK7iqC7LHUv9EUpEOhFkKktQtIsCqhstzjT 8Iq254v6L16FqXwxVM0w+9rHEcG/uNXuIKYbivurWBpa5kNlaRQAxjCRZo1bAaprAFxE MxIw== X-Gm-Message-State: APjAAAWKoQSUVMRQrgCaGKDOsbBvzuYJ5Sl2KzBjT0Jjl80dPmqv0BAY 4isofcWOcPaNeOOTAzhem4eUhg== X-Google-Smtp-Source: APXvYqzL/CeoYgUz/dL+UCoRPB57kS8k+K0AU3mwSjtkIW0qzE0UGCl3M97UgeKZ/ZqnWNSSEOk5sg== X-Received: by 2002:a17:906:f0f:: with SMTP id z15mr12761935eji.125.1555008537548; Thu, 11 Apr 2019 11:48:57 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.48.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:48:57 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 3/9] iommu/dma-iommu: Add iommu_dma_copy_reserved_iova, iommu_dma_apply_resv_region to the dma-iommu api Date: Thu, 11 Apr 2019 19:47:32 +0100 Message-Id: <20190411184741.27540-4-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114859_464797_CD7D1838 X-CRM114-Status: GOOD ( 14.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP To convert the AMD iommu driver to the dma-iommu we need to wrap some of the iova reserve functions. Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index cc5da30d6e58..613d181e78a9 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -162,6 +162,33 @@ void iommu_put_dma_cookie(struct iommu_domain *domain) } EXPORT_SYMBOL(iommu_put_dma_cookie); +static struct iova *iommu_dma_reserve_iova(struct iommu_domain *domain, + dma_addr_t iova_lo, dma_addr_t iova_hi) +{ + struct iommu_dma_cookie *cookie = domain->iova_cookie; + struct iova_domain *iovad = &cookie->iovad; + unsigned long order = __ffs(domain->pgsize_bitmap); + + return reserve_iova(iovad, iova_lo >> order, iova_hi >> order); +} + +void iommu_dma_copy_reserved_iova(struct iova_domain *from, + struct iommu_domain *to) +{ + struct iommu_dma_cookie *cookie = to->iova_cookie; + struct iova_domain *to_iovad = &cookie->iovad; + + copy_reserved_iova(from, to_iovad); +} + +void iommu_dma_apply_resv_region(struct device *dev, + struct iommu_domain *domain, struct iommu_resv_region *region) +{ + dma_addr_t end = region->start + region->length - 1; + + WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL); +} + /** * iommu_dma_get_resv_regions - Reserved region driver helper * @dev: Device from iommu_get_resv_regions() diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index e760dc5d1fa8..c527ded5c41c 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -23,6 +23,7 @@ #ifdef CONFIG_IOMMU_DMA #include #include +#include #include int iommu_dma_init(void); @@ -57,6 +58,12 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int prot); +/* These are wrappers around some iova functions */ +void iommu_dma_apply_resv_region(struct device *dev, + struct iommu_domain *domain, struct iommu_resv_region *region); +void iommu_dma_copy_reserved_iova(struct iova_domain *from, + struct iommu_domain *to); + /* * Arch code with no special attribute handling may use these * directly as DMA mapping callbacks for simplicity From patchwork Thu Apr 11 18:47:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EF0F1805 for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F248287DB for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E41128D1B; Thu, 11 Apr 2019 18:50:07 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BC20287DB for ; Thu, 11 Apr 2019 18:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3yINTe8z3AWpIpVt83S78GEnSgXmj/etD1X2qZ4hedE=; b=gEi+prRsvyP7l/C+eeZirxcmuS UuSEkGRp8TEY3SEU6okVe7LpR2V6FxwuKG5C5w9bcsQg3vO04WEypCWuBAD04yodYf3Tk1xyjh2aJ G1eGPS5uaPyoHn0c1wCaxsZZP0YHdcB69DE99/fTFsvnJPrBY4FfdDATKj2kVUcWq9rQfiJroYwGq yKuPEAwVy8iUSEbbkYa2JUEt7m8aul40QRvdLhrpmk31B+dd5WTQBcpbfNiNVrZj6hhfwOyiA8SD7 DLdVMeA0D6c1qBch6spXtoWfJ9GTxP/ibLXLYmWAPbEEMwGMijAzKjCoMSwxD06b7udqoq80jBnRV kZ4VeTVw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEels-0003K1-Dl; Thu, 11 Apr 2019 18:50:00 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEekx-0002Id-Mk for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:21 +0000 Received: by mail-ed1-x543.google.com with SMTP id s39so6160115edb.2 for ; Thu, 11 Apr 2019 11:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yoJ8L21VfG+7EiXp/r/AWsB982DfY9O3RZBK5Kp8sB8=; b=ZqsZwWNrSw+xqySh9ZjBwb+L6eYpx0X4qksRNIOZU8mg1TOpLf9O0fXmV0r6aHL2fZ 3MfvzFGrJstIHcy1Po8voTQFYh8EpRq1/E82o6IVwvbNi70AX9ZsnmIDFYU6mz9IgKtS dYq2HbKPb0HAXgobjaNdmeDR8NvJmumSeiwwulVBya5cl5NYPDrIwZ2Tv3gVZLFW7Ova tsj1dT55hh6+YaiULDGzVztJQZPedQIn3i7JLnjvyt1OWAKoMUr4a3U/hvmoA6UDpVts xZLLAyc0d3/bS++XMrG4Q+Bewl65uvasxMRMjuBIQJx//ij8nSqueitAqBQHl/yYVNfY 09hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yoJ8L21VfG+7EiXp/r/AWsB982DfY9O3RZBK5Kp8sB8=; b=V94lFLtSMqLikazQGdHFIPGTGVd4z8pl/8vK67I9diTcBAFKMyzjqzTPtP9E4UgO1B T8ZMnYWL5w4txxAajif5nnuMk01iUEMBu4mTzASm11Mjb48VGLviHnNgvZInaQEebQxm xHxzUhnk7IG/rTD0TSKzAFEHzA0VH6OadkLZS5Ix0Y86CdrIWXwAsOEZsGAJAVBeiFa1 peXiqsBNUatvHY3MSFP9pa42AtYkbX/pC58uVXRCCyNbvw/MDTR7t+JaHdrewHFXbMXa 8qIjJKOBniK3pshudF3ay0uuFwx+6ceubxqe1kxfz8y1xPd223g9K/j9bkXQj37g2SZz xodA== X-Gm-Message-State: APjAAAWWwImeGtKP9hWZdh/gTX+reg+bvF5uN4xs0MCofWODnTt+Xbdt NhOgfcpt2a/LdSzDo3BPB8np4Q== X-Google-Smtp-Source: APXvYqzhcIOArLgPaFIotHVPB4LMHAtfaoxhteXVLtNCkA9H3EacRfD1/rKtcbt7o0ew6bGKIbXfPg== X-Received: by 2002:a17:906:d1da:: with SMTP id bs26mr28530697ejb.149.1555008542329; Thu, 11 Apr 2019 11:49:02 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:01 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 4/9] iommu/dma-iommu: Add iommu_dma_map_page_coherent Date: Thu, 11 Apr 2019 19:47:33 +0100 Message-Id: <20190411184741.27540-5-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114903_991919_E5928D3F X-CRM114-Status: GOOD ( 16.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add iommu_dma_map_page_coherent function to allow mapping pages through the dma-iommu api using the dev->coherent_dma_mask mask instead of the dev->dma_mask mask Signed-off-by: Tom Murphy --- drivers/iommu/dma-iommu.c | 25 ++++++++++++++++++++----- include/linux/dma-iommu.h | 3 +++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 613d181e78a9..0128370f8b88 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -663,7 +663,8 @@ int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) } static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, - size_t size, int prot, struct iommu_domain *domain) + size_t size, int prot, struct iommu_domain *domain, + dma_addr_t dma_limit) { struct iommu_dma_cookie *cookie = domain->iova_cookie; size_t iova_off = 0; @@ -674,7 +675,7 @@ static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, size = iova_align(&cookie->iovad, size + iova_off); } - iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); + iova = iommu_dma_alloc_iova(domain, size, dma_limit, dev); if (!iova) return DMA_MAPPING_ERROR; @@ -693,7 +694,19 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int prot) { return __iommu_dma_map(dev, page_to_phys(page) + offset, size, prot, - iommu_get_dma_domain(dev)); + iommu_get_dma_domain(dev), dma_get_mask(dev)); +} + +dma_addr_t iommu_dma_map_page_coherent(struct device *dev, struct page *page, + unsigned long offset, size_t size, int prot) +{ + dma_addr_t dma_mask = dev->coherent_dma_mask; + + if (!dma_mask) + dma_mask = dma_get_mask(dev); + + return __iommu_dma_map(dev, page_to_phys(page) + offset, size, prot, + iommu_get_dma_domain(dev), dma_mask); } void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size, @@ -883,7 +896,7 @@ dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys, { return __iommu_dma_map(dev, phys, size, dma_info_to_prot(dir, false, attrs) | IOMMU_MMIO, - iommu_get_dma_domain(dev)); + iommu_get_dma_domain(dev), dma_get_mask(dev)); } void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, @@ -910,7 +923,9 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, if (!msi_page) return NULL; - iova = __iommu_dma_map(dev, msi_addr, size, prot, domain); + iova = __iommu_dma_map(dev, msi_addr, size, prot, domain, + dma_get_mask(dev)); + if (iova == DMA_MAPPING_ERROR) goto out_free_page; diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h index c527ded5c41c..185ff8500841 100644 --- a/include/linux/dma-iommu.h +++ b/include/linux/dma-iommu.h @@ -55,6 +55,9 @@ int iommu_dma_mmap(struct page **pages, size_t size, struct vm_area_struct *vma) dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int prot); +dma_addr_t iommu_dma_map_page_coherent(struct device *dev, + struct page *page, unsigned long offset, + size_t size, int prot); int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int prot); From patchwork Thu Apr 11 18:47:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90A271515 for ; Thu, 11 Apr 2019 18:50:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 776B628D31 for ; Thu, 11 Apr 2019 18:50:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B82328DB9; Thu, 11 Apr 2019 18:50:24 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D7D828D31 for ; Thu, 11 Apr 2019 18:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p91NT/xIlilinPDf0UOH4MYp4EZv7RgtJbBwUBdVoPE=; b=uTBvD6mioqYUx13pm+PKUlCmR8 /WQJD7AZ77Rwv8dN5xefN2BPgMQ8Xw+8BzYN6i5KcaNF6xJSHe22H3uLtlE+buIgcKTYZBjsRJAMT CJAHNqbPzNC1+L4fW794WLBXR3/pCY+bf+eksXoUhHS7LtjzlQmt7bDcmEwdzTKQ+2iWYVzEcZ5VA 4lRMMaE0CvX/E8hPIy3Tj3tw6GOzV/jyFJotf7RwLAfLDldZpPEwnFXcGQO1MOHo4wYdUDWp4EAuP 3Ia1GFPN0bryy7VGk5RAgO607xo0mwGvBNL3Jvy5wCpvCVLvuZS+G1rvD4EnoXbiNTRRbASJD10Md AxJvTYaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEem9-0004nk-CG; Thu, 11 Apr 2019 18:50:17 +0000 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEel2-0002NJ-DA for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:29 +0000 Received: by mail-ed1-x544.google.com with SMTP id o26so6112859edv.12 for ; Thu, 11 Apr 2019 11:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0ptM0TW5MEf0wZjhcNVg+kVepdW4r8Z6tyROfJJShQo=; b=Kz0209+sKNZfmB0yWwNPjjrMA+GYb4rsz3YQ+7qzCBKV0K8VKU+rELf+Zl1rDwGfGG UDqhVf2LzXA6K1Mp+V7RE4dqFrJsHX5w+JbTNVOgDNMqnsvq1/Svzxa1O30Nwx4bNza7 xhOejAKAbe35ytPwR0TZVkNIacGaIechwtfh4zN2DCFIKQ4M9BguB3dgKppQ9rukI4fk jwu4Kh6E1Kp4KE4cvVyzWTm9dLB+7BauhZN2nsIMnKgsjVX0U/GpqN2Ak+4MJtwQ7Rct vag21Of0Bv8JJEz+PXrI7LQkFSMnYl4wWcIJZDQCt3rzHh/G7O3Wjvfv8J/dr1KSZ6iE ULLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0ptM0TW5MEf0wZjhcNVg+kVepdW4r8Z6tyROfJJShQo=; b=IWaLoS9+r0KHjOn1TJyPDlFEO6H8mcj9t4JKPEpRsz+B18is/pCjw9SuqdYA0+YA2Q 52/ajmr8EC4ErwOxrB1Dc1QHBIBTsvbrSEFB++6emvOcZZL8SFSckPQMxiT4omGsmqFV Gnibeih4XdqkRQe2jDLrr4JasBNsCTg3lKk75ypCi0qD+kdJAWeQ/Ko4/pzaA0AtaDcn /+tkACPAJW1ioyBCfLMPNhbkZ318bQk8fqXKPxz44iu7QcmbQZ96MpfVPhb3TPobuk8c WP4Zzdx6IofOaPHQkH9mkU9XGLITf1h59ryAaDVYi3lm5m7m9KawPDR6Wj7iXu5JEvz/ AKPg== X-Gm-Message-State: APjAAAVFN/ThsjbMtvIHeslBSJ8hcbowhueCP3s9nS4Z0Gok6sKBXgyq pKn2Nu0+B9fgyb2QlHHdbCpuVA== X-Google-Smtp-Source: APXvYqxPgBo+MMzWroNLnpmi2H77XJDBCOGidMozjjYD68K8alQvz4uZiMPtc7ZU8Kl0PrPPn+MeYg== X-Received: by 2002:a05:6402:558:: with SMTP id i24mr26522920edx.51.1555008547040; Thu, 11 Apr 2019 11:49:07 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:06 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 5/9] iommu/amd: Implement .flush_np_cache Date: Thu, 11 Apr 2019 19:47:34 +0100 Message-Id: <20190411184741.27540-6-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114908_787529_E883572E X-CRM114-Status: GOOD ( 14.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Implement flush_np_cache for the AMD iommu driver. This allows the amd iommu non present cache to be flushed if amd_iommu_np_cache is set. Signed-off-by: Tom Murphy --- drivers/iommu/amd_iommu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index b319e51c379b..2d4ee10626b4 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1319,6 +1319,18 @@ static void domain_flush_devices(struct protection_domain *domain) device_flush_dte(dev_data); } +static void amd_iommu_flush_np_cache(struct iommu_domain *domain, + unsigned long iova, size_t size) +{ + struct protection_domain *dom = to_pdomain(domain); + + if (unlikely(amd_iommu_np_cache)) { + domain_flush_pages(dom, iova, size); + domain_flush_complete(dom); + } +} + + /**************************************************************************** * * The functions below are used the create the page table mappings for @@ -3263,6 +3275,7 @@ const struct iommu_ops amd_iommu_ops = { .flush_iotlb_all = amd_iommu_flush_iotlb_all, .iotlb_range_add = amd_iommu_iotlb_range_add, .iotlb_sync = amd_iommu_flush_iotlb_all, + .flush_np_cache = amd_iommu_flush_np_cache, }; /***************************************************************************** From patchwork Thu Apr 11 18:47:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 432751669 for ; Thu, 11 Apr 2019 18:50:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F4D728D9D for ; Thu, 11 Apr 2019 18:50:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2379928DB0; Thu, 11 Apr 2019 18:50: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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0CD128D9D for ; Thu, 11 Apr 2019 18:50:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=aCogju79xMuQhWbe/Bl5JSxOhVU1mXYcuQuCqTgFF/0=; b=lqhKJp1U3duKgB b/7EOK+l+2Xft4paoHLgMVNe1hLbY/dFMq5K55gBqtI9hDbPHxbQiBFLXBbRYAf9am1e8UDdRjR90 jt4Ictplbx4do0mCv2xUblVe8j39QrY5eFogIjvahq2sUVFrI/TLGbChRn3PAm2p1t3f1KdRgejVF nlUMgqiz7TjLqhR+Lm8RB8q0lUWQMKIBqmVbjPY3zE5J4SOJtx+ix0ex/jlgO5UxG39n4y8PIA1b1 BJGHDakYXqrSEX4Mk4i7Iso2pEch9wduF/kFdSaJ4TJlv/l+2tR1UWP15S/trV7yE4XfZ9Of0q4D+ z2vUnTmKDXZMSP0aql+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEemX-0005IE-Gx; Thu, 11 Apr 2019 18:50:41 +0000 Received: from mail-ed1-x542.google.com ([2a00:1450:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEel7-0002Td-AM for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:41 +0000 Received: by mail-ed1-x542.google.com with SMTP id u57so5509280edm.3 for ; Thu, 11 Apr 2019 11:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lX2MVOfiam4gxtJM5rz0M+xQIQGKu992FM3+lagPerc=; b=eQ4Yac+opjGEBMpNwcIhE+BWp72NvMbMpxtmojUTpE9/rOYjMILcbpoRJOSkm78WBk Aff06hpFM7720IPoJiqJyT63C+/E8qw6EX81NozIpVIX1tteropdJH6LFlD3Eh/+bnxp TqdoMoiwgIxQtWMiOGAc90uv+qOUf34JAI/T0ybJD/E7UmC1cFWzDvL9PTwU99FOa2Cq uBtmAEg9IcB2Z+rtiVJG0Mt+tgtzmiJ3TreKGg24TfCmsdd0CwQJXJinK6O+48LvF5v/ TMCo/yA7WVatb4O5GCP0DxBkXEFa1ZseoyB+vX5EoAJETdaxDHDXc+uPIuWnEbhC9q2H SvUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lX2MVOfiam4gxtJM5rz0M+xQIQGKu992FM3+lagPerc=; b=XuM8EANsViCq4t1l8OgpiHWWpwzfqRhy4flWdagF576RBH8SII4ewnAnlDMAhQUs7a ygwVU3nTOO7Z5/QCfTL345yyGqcRPep9ZUOw++Uu53H3NxJGbYK1P4fyQzhINz275b+g aVf3cxVGXk9tMG8s/4JI0v7sLAkIerYoOGIIo8B+j624eM7FqKcQjRz+KRnH1mnR+Z4w KhybC4C8gw21kQEq5cSrPBNHpudXOLKlQpg6vhMYHYxc6QLEIHQCQEkbxGaBkP9pGheG qQ+9DzWppc/+rfQ5+ZfSEOt2WlBVWc1L7+Sru9uDYGCIQk8t1VgSiWPogPl6+E4Q6+ck gv+Q== X-Gm-Message-State: APjAAAWYwisNoVcrhCQA/Z17d7l5Ajlia/J+odc6oKgJ7/Q4lko2dRSs 0zEFiDl9w98JBC1wQGLrAic/+w== X-Google-Smtp-Source: APXvYqw1ZpBKkZJS1pdF6BGZGDt7JAfIqiI9pMC84S3fxuGG7Kvy3jG4mkJy+S81q/cfVwljARoScw== X-Received: by 2002:aa7:d954:: with SMTP id l20mr32634023eds.156.1555008551931; Thu, 11 Apr 2019 11:49:11 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:11 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 6/9] iommu/amd: Implement map_atomic Date: Thu, 11 Apr 2019 19:47:35 +0100 Message-Id: <20190411184741.27540-7-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114914_035726_99032D0B X-CRM114-Status: GOOD ( 16.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of using a spin lock I removed the mutex lock from both the amd_iommu_map and amd_iommu_unmap path as well. iommu_map doesn’t lock while mapping and so if iommu_map is called by two different threads on the same iova region it results in a race condition even with the locks. So the locking in amd_iommu_map and amd_iommu_unmap doesn't add any real protection. The solution to this is for whatever manages the allocated iova’s externally to make sure iommu_map isn’t called twice on the same region at the same time. Signed-off-by: Tom Murphy --- drivers/iommu/amd_iommu.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 2d4ee10626b4..b45e0e033adc 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3089,12 +3089,12 @@ static int amd_iommu_attach_device(struct iommu_domain *dom, return ret; } -static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, - phys_addr_t paddr, size_t page_size, int iommu_prot) +static int __amd_iommu_map(struct iommu_domain *dom, unsigned long iova, + phys_addr_t paddr, size_t page_size, int iommu_prot, + gfp_t gfp) { struct protection_domain *domain = to_pdomain(dom); int prot = 0; - int ret; if (domain->mode == PAGE_MODE_NONE) return -EINVAL; @@ -3104,11 +3104,21 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, if (iommu_prot & IOMMU_WRITE) prot |= IOMMU_PROT_IW; - mutex_lock(&domain->api_lock); - ret = iommu_map_page(domain, iova, paddr, page_size, prot, GFP_KERNEL); - mutex_unlock(&domain->api_lock); + return iommu_map_page(domain, iova, paddr, page_size, prot, gfp); +} - return ret; +static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova, + phys_addr_t paddr, size_t page_size, int iommu_prot) +{ + return __amd_iommu_map(dom, iova, paddr, page_size, iommu_prot, + GFP_KERNEL); +} + +static int amd_iommu_map_atomic(struct iommu_domain *dom, unsigned long iova, + phys_addr_t paddr, size_t page_size, int iommu_prot) +{ + return __amd_iommu_map(dom, iova, paddr, page_size, iommu_prot, + GFP_ATOMIC); } static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova, @@ -3262,6 +3272,7 @@ const struct iommu_ops amd_iommu_ops = { .attach_dev = amd_iommu_attach_device, .detach_dev = amd_iommu_detach_device, .map = amd_iommu_map, + .map_atomic = amd_iommu_map_atomic, .unmap = amd_iommu_unmap, .iova_to_phys = amd_iommu_iova_to_phys, .add_device = amd_iommu_add_device, From patchwork Thu Apr 11 18:47:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB2F317E0 for ; Thu, 11 Apr 2019 18:49:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ACC4288D3 for ; Thu, 11 Apr 2019 18:49:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CF7B28A07; Thu, 11 Apr 2019 18:49:51 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B399C288D3 for ; Thu, 11 Apr 2019 18:49:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=f/EMb8/kPiHQrSfsEmEcwvl+XVOt0GUFimOGChGyQsk=; b=dHS3OJfLDaAAgrD1qELZBFF1TK 8gv1krg3blzWLnjBPec8pPYaDUqIep1Z3dnQlleaqtv1JF8WlT7oy9x0cRwP/YGbvF9HcSCzdIg44 G6dftg0Jd+8HDltYMY1moXx2X7X1nWMo7cTqkjY/6blYY+iO4SmhriC5BOTmlNDWIbkCUD/UKgjKW BIPDpPU3T577+hjnTbOpOOACoVPSIyv5dkXBWlDydn3v+AxNoABSL2tO79lojOkHHunkvYz4DKs9t DQ3s/u/azsn8DyyLKWCNoA1pLodvxL4Iq6lPAS/kNcbJcO8frMoKj+a6jdIc1TP3rC4Oz4Y9EBNrv NW09jYAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelh-0003AA-5u; Thu, 11 Apr 2019 18:49:49 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelH-0002gj-3J for linux-arm-kernel@bombadil.infradead.org; Thu, 11 Apr 2019 18:49:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=h4NTbwpzCv6yGyNv0iD8bNRgN2z2J8QjAYzKFda07OQ=; b=NpjtxH1Ix92N9dQ8ZqQL9Mz5q y2WqsiZzhdv5Sk6DtHerEVHmwPT8CArb/gKiQNTu8eaOrWy/sQYkw2AU0zd89mCUkBfkbd7gFKij4 OIA0/7X+tJ2Rxc7usbYMxB33ANd/RU7lD98mJ/wUlWfF/spmeQ5l1i95WVgE23d5RzDAT7ZRGSIeG kSzFK3gF7Z9WCauLvLx8pKrekHs93blP7QwUMMAGQHxXCt6+t4wmTfAGOH2pmrOhj05U1zPTPzMFk +H+z/oW4NiznqY+ENrDCjsGPf2nxmmjTwMD6+iepy5K5V0V5eE8Dcd3xq3K1QIoSWYqWgkQrKtfAg RJFKIZgnQ==; Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelD-0003cG-KJ for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:21 +0000 Received: by mail-ed1-x541.google.com with SMTP id u57so5509515edm.3 for ; Thu, 11 Apr 2019 11:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h4NTbwpzCv6yGyNv0iD8bNRgN2z2J8QjAYzKFda07OQ=; b=XmDArHBqr3lcdwiD6rmDPJRrqBJX1smBT6QSTA2zzebiEMqn8UHCyGmgPzWi6atDRP PPUqmOGZYXS23R7Ffooko6LD7qj6HcfZPk0svG1qlEfih5yv1ge96oJLIsCqu83GWIXF fFHKmEUgNre/+8pORg56gg+YLbsw7/yz0pu3XRA4ZWqdbuqPvZl8lQN5tYR2Au1L2hT5 igQqnGL7YIapccrpw4JKLDDC6E2iYOHKdL2mhqwUn6fNR6HmbSsje5e87puCLeQBvOF7 qJ1AZEmghQioW31glddOQqlmAOHRJBc2Gufce5uL/GHbS7h6Ym95OptpDOHCVcqAvJgm WlwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h4NTbwpzCv6yGyNv0iD8bNRgN2z2J8QjAYzKFda07OQ=; b=ka3JAcH7nY6cjWWeuoEQYMnlY3nxpd2qtV9gPaBRPeliDYSIzv19VB5C2RM81HzWrl QpOB4xMmV73cv6YZpAlLOxGx0jdcwNJybGVmm6UpFdRjkcmi4K4X6ZsPCZ3ZHe8BVasj MhCj9cKPpoLZnk1woZ/gfIme9z1c9vMO4GBP1mQLQwaCGyIhmWTLYwyXnWSeQt6PW+df nnSxw81Sj4OpQTXepx8xvoS35SV/zaolIICwOKTQdJYJcM1abJIGAohYxdDQKM6hq25k qGroTsz6tD9eyuGVcOcpZG8LMcwqlNdLy6BTVvau3TGe8rwmd/vzI6XIrz+bAbsBqd1K Hehg== X-Gm-Message-State: APjAAAWb5wSGMQ/MyS5JM8VHA6fbRGRoNzwp8eprzTCZVKDPvbefifJ8 ha1M7UAGAlyw0MmsByTfEaXlLg== X-Google-Smtp-Source: APXvYqxbd4FvXCjbDMq5Fsg2btmgtwj7DZO42a/09ctUdEBj5tqSF7sGN2ToxCvtNcAbEs1PDoduJQ== X-Received: by 2002:a50:93a6:: with SMTP id o35mr33093218eda.245.1555008557237; Thu, 11 Apr 2019 11:49:17 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:16 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 7/9] iommu/amd: Use the dma-iommu api Date: Thu, 11 Apr 2019 19:47:36 +0100 Message-Id: <20190411184741.27540-8-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_144919_790480_F451BA0F X-CRM114-Status: GOOD ( 29.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Convert the AMD iommu driver to use the dma-iommu api. Signed-off-by: Tom Murphy --- drivers/iommu/Kconfig | 1 + drivers/iommu/amd_iommu.c | 217 +++++++++++++------------------------- 2 files changed, 77 insertions(+), 141 deletions(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index 6f07f3b21816..cc728305524b 100644 --- a/drivers/iommu/Kconfig +++ b/drivers/iommu/Kconfig @@ -136,6 +136,7 @@ config AMD_IOMMU select PCI_PASID select IOMMU_API select IOMMU_IOVA + select IOMMU_DMA depends on X86_64 && PCI && ACPI ---help--- With this option you can enable support for AMD IOMMU hardware in diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index b45e0e033adc..218faf3a6d9c 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -1845,21 +1846,21 @@ static void iova_domain_flush_tlb(struct iova_domain *iovad) * Free a domain, only used if something went wrong in the * allocation path and we need to free an already allocated page table */ -static void dma_ops_domain_free(struct dma_ops_domain *dom) +static void dma_ops_domain_free(struct protection_domain *domain) { - if (!dom) + if (!domain) return; - del_domain_from_list(&dom->domain); + del_domain_from_list(domain); - put_iova_domain(&dom->iovad); + iommu_put_dma_cookie(&domain->domain); - free_pagetable(&dom->domain); + free_pagetable(domain); - if (dom->domain.id) - domain_id_free(dom->domain.id); + if (domain->id) + domain_id_free(domain->id); - kfree(dom); + kfree(domain); } /* @@ -1867,37 +1868,46 @@ static void dma_ops_domain_free(struct dma_ops_domain *dom) * It also initializes the page table and the address allocator data * structures required for the dma_ops interface */ -static struct dma_ops_domain *dma_ops_domain_alloc(void) +static struct protection_domain *dma_ops_domain_alloc(void) { - struct dma_ops_domain *dma_dom; + struct protection_domain *domain; + u64 size; - dma_dom = kzalloc(sizeof(struct dma_ops_domain), GFP_KERNEL); - if (!dma_dom) + domain = kzalloc(sizeof(struct protection_domain), GFP_KERNEL); + if (!domain) return NULL; - if (protection_domain_init(&dma_dom->domain)) - goto free_dma_dom; + if (protection_domain_init(domain)) + goto free_domain; - dma_dom->domain.mode = PAGE_MODE_3_LEVEL; - dma_dom->domain.pt_root = (void *)get_zeroed_page(GFP_KERNEL); - dma_dom->domain.flags = PD_DMA_OPS_MASK; - if (!dma_dom->domain.pt_root) - goto free_dma_dom; + domain->mode = PAGE_MODE_3_LEVEL; + domain->pt_root = (void *)get_zeroed_page(GFP_KERNEL); + domain->flags = PD_DMA_OPS_MASK; + if (!domain->pt_root) + goto free_domain; - init_iova_domain(&dma_dom->iovad, PAGE_SIZE, IOVA_START_PFN); + domain->domain.pgsize_bitmap = AMD_IOMMU_PGSIZES; + domain->domain.type = IOMMU_DOMAIN_DMA; + domain->domain.ops = &amd_iommu_ops; + if (iommu_get_dma_cookie(&domain->domain) == -ENOMEM) + goto free_domain; - if (init_iova_flush_queue(&dma_dom->iovad, iova_domain_flush_tlb, NULL)) - goto free_dma_dom; + size = 0;/* Size is only required if force_apperture is set */ + if (iommu_dma_init_domain(&domain->domain, IOVA_START_PFN << PAGE_SHIFT, + size, NULL)) + goto free_cookie; /* Initialize reserved ranges */ - copy_reserved_iova(&reserved_iova_ranges, &dma_dom->iovad); + iommu_dma_copy_reserved_iova(&reserved_iova_ranges, &domain->domain); - add_domain_to_list(&dma_dom->domain); + add_domain_to_list(domain); - return dma_dom; + return domain; -free_dma_dom: - dma_ops_domain_free(dma_dom); +free_cookie: + iommu_put_dma_cookie(&domain->domain); +free_domain: + dma_ops_domain_free(domain); return NULL; } @@ -2328,6 +2338,26 @@ static struct iommu_group *amd_iommu_device_group(struct device *dev) return acpihid_device_group(dev); } +static int amd_iommu_domain_get_attr(struct iommu_domain *domain, + enum iommu_attr attr, void *data) +{ + switch (domain->type) { + case IOMMU_DOMAIN_UNMANAGED: + return -ENODEV; + case IOMMU_DOMAIN_DMA: + switch (attr) { + case DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE: + *(int *)data = !amd_iommu_unmap_flush; + return 0; + default: + return -ENODEV; + } + break; + default: + return -EINVAL; + } +} + /***************************************************************************** * * The next functions belong to the dma_ops mapping/unmapping code. @@ -2509,21 +2539,15 @@ static dma_addr_t map_page(struct device *dev, struct page *page, enum dma_data_direction dir, unsigned long attrs) { - phys_addr_t paddr = page_to_phys(page) + offset; - struct protection_domain *domain; - struct dma_ops_domain *dma_dom; - u64 dma_mask; + int prot = dir2prot(dir); + struct protection_domain *domain = get_domain(dev); - domain = get_domain(dev); if (PTR_ERR(domain) == -EINVAL) - return (dma_addr_t)paddr; + return (dma_addr_t)page_to_phys(page) + offset; else if (IS_ERR(domain)) return DMA_MAPPING_ERROR; - dma_mask = *dev->dma_mask; - dma_dom = to_dma_ops_domain(domain); - - return __map_single(dev, dma_dom, paddr, size, dir, dma_mask); + return iommu_dma_map_page(dev, page, offset, size, prot); } /* @@ -2532,16 +2556,11 @@ static dma_addr_t map_page(struct device *dev, struct page *page, static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - struct protection_domain *domain; - struct dma_ops_domain *dma_dom; - - domain = get_domain(dev); + struct protection_domain *domain = get_domain(dev); if (IS_ERR(domain)) return; - dma_dom = to_dma_ops_domain(domain); - - __unmap_single(dma_dom, dma_addr, size, dir); + iommu_dma_unmap_page(dev, dma_addr, size, dir, attrs); } static int sg_num_pages(struct device *dev, @@ -2578,77 +2597,10 @@ static int map_sg(struct device *dev, struct scatterlist *sglist, int nelems, enum dma_data_direction direction, unsigned long attrs) { - int mapped_pages = 0, npages = 0, prot = 0, i; - struct protection_domain *domain; - struct dma_ops_domain *dma_dom; - struct scatterlist *s; - unsigned long address; - u64 dma_mask; - int ret; - - domain = get_domain(dev); + struct protection_domain *domain = get_domain(dev); if (IS_ERR(domain)) return 0; - - dma_dom = to_dma_ops_domain(domain); - dma_mask = *dev->dma_mask; - - npages = sg_num_pages(dev, sglist, nelems); - - address = dma_ops_alloc_iova(dev, dma_dom, npages, dma_mask); - if (address == DMA_MAPPING_ERROR) - goto out_err; - - prot = dir2prot(direction); - - /* Map all sg entries */ - for_each_sg(sglist, s, nelems, i) { - int j, pages = iommu_num_pages(sg_phys(s), s->length, PAGE_SIZE); - - for (j = 0; j < pages; ++j) { - unsigned long bus_addr, phys_addr; - - bus_addr = address + s->dma_address + (j << PAGE_SHIFT); - phys_addr = (sg_phys(s) & PAGE_MASK) + (j << PAGE_SHIFT); - ret = iommu_map_page(domain, bus_addr, phys_addr, PAGE_SIZE, prot, GFP_ATOMIC); - if (ret) - goto out_unmap; - - mapped_pages += 1; - } - } - - /* Everything is mapped - write the right values into s->dma_address */ - for_each_sg(sglist, s, nelems, i) { - s->dma_address += address + s->offset; - s->dma_length = s->length; - } - - return nelems; - -out_unmap: - dev_err(dev, "IOMMU mapping error in map_sg (io-pages: %d reason: %d)\n", - npages, ret); - - for_each_sg(sglist, s, nelems, i) { - int j, pages = iommu_num_pages(sg_phys(s), s->length, PAGE_SIZE); - - for (j = 0; j < pages; ++j) { - unsigned long bus_addr; - - bus_addr = address + s->dma_address + (j << PAGE_SHIFT); - iommu_unmap_page(domain, bus_addr, PAGE_SIZE); - - if (--mapped_pages == 0) - goto out_free_iova; - } - } - -out_free_iova: - free_iova_fast(&dma_dom->iovad, address >> PAGE_SHIFT, npages); - -out_err: - return 0; + return iommu_dma_map_sg(dev, sglist, nelems, dir2prot(direction)); } /* @@ -2659,20 +2611,11 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist, int nelems, enum dma_data_direction dir, unsigned long attrs) { - struct protection_domain *domain; - struct dma_ops_domain *dma_dom; - unsigned long startaddr; - int npages = 2; - - domain = get_domain(dev); + struct protection_domain *domain = get_domain(dev); if (IS_ERR(domain)) return; - startaddr = sg_dma_address(sglist) & PAGE_MASK; - dma_dom = to_dma_ops_domain(domain); - npages = sg_num_pages(dev, sglist, nelems); - - __unmap_single(dma_dom, startaddr, npages << PAGE_SHIFT, dir); + iommu_dma_unmap_sg(dev, sglist, nelems, dir, attrs); } /* @@ -2684,7 +2627,6 @@ static void *alloc_coherent(struct device *dev, size_t size, { u64 dma_mask = dev->coherent_dma_mask; struct protection_domain *domain; - struct dma_ops_domain *dma_dom; struct page *page; domain = get_domain(dev); @@ -2695,7 +2637,6 @@ static void *alloc_coherent(struct device *dev, size_t size, } else if (IS_ERR(domain)) return NULL; - dma_dom = to_dma_ops_domain(domain); size = PAGE_ALIGN(size); dma_mask = dev->coherent_dma_mask; flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32); @@ -2715,9 +2656,8 @@ static void *alloc_coherent(struct device *dev, size_t size, if (!dma_mask) dma_mask = *dev->dma_mask; - *dma_addr = __map_single(dev, dma_dom, page_to_phys(page), - size, DMA_BIDIRECTIONAL, dma_mask); - + *dma_addr = iommu_dma_map_page_coherent(dev, page, 0, size, + dir2prot(DMA_BIDIRECTIONAL)); if (*dma_addr == DMA_MAPPING_ERROR) goto out_free; @@ -2739,7 +2679,6 @@ static void free_coherent(struct device *dev, size_t size, unsigned long attrs) { struct protection_domain *domain; - struct dma_ops_domain *dma_dom; struct page *page; page = virt_to_page(virt_addr); @@ -2749,9 +2688,8 @@ static void free_coherent(struct device *dev, size_t size, if (IS_ERR(domain)) goto free_mem; - dma_dom = to_dma_ops_domain(domain); - - __unmap_single(dma_dom, dma_addr, size, DMA_BIDIRECTIONAL); + iommu_dma_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, + attrs); free_mem: if (!dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT)) @@ -2948,7 +2886,6 @@ static struct protection_domain *protection_domain_alloc(void) static struct iommu_domain *amd_iommu_domain_alloc(unsigned type) { struct protection_domain *pdomain; - struct dma_ops_domain *dma_domain; switch (type) { case IOMMU_DOMAIN_UNMANAGED: @@ -2969,12 +2906,11 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type) break; case IOMMU_DOMAIN_DMA: - dma_domain = dma_ops_domain_alloc(); - if (!dma_domain) { + pdomain = dma_ops_domain_alloc(); + if (!pdomain) { pr_err("Failed to allocate\n"); return NULL; } - pdomain = &dma_domain->domain; break; case IOMMU_DOMAIN_IDENTITY: pdomain = protection_domain_alloc(); @@ -2993,7 +2929,6 @@ static struct iommu_domain *amd_iommu_domain_alloc(unsigned type) static void amd_iommu_domain_free(struct iommu_domain *dom) { struct protection_domain *domain; - struct dma_ops_domain *dma_dom; domain = to_pdomain(dom); @@ -3008,8 +2943,7 @@ static void amd_iommu_domain_free(struct iommu_domain *dom) switch (dom->type) { case IOMMU_DOMAIN_DMA: /* Now release the domain */ - dma_dom = to_dma_ops_domain(domain); - dma_ops_domain_free(dma_dom); + dma_ops_domain_free(domain); break; default: if (domain->mode != PAGE_MODE_NONE) @@ -3278,9 +3212,10 @@ const struct iommu_ops amd_iommu_ops = { .add_device = amd_iommu_add_device, .remove_device = amd_iommu_remove_device, .device_group = amd_iommu_device_group, + .domain_get_attr = amd_iommu_domain_get_attr, .get_resv_regions = amd_iommu_get_resv_regions, .put_resv_regions = amd_iommu_put_resv_regions, - .apply_resv_region = amd_iommu_apply_resv_region, + .apply_resv_region = iommu_dma_apply_resv_region, .is_attach_deferred = amd_iommu_is_attach_deferred, .pgsize_bitmap = AMD_IOMMU_PGSIZES, .flush_iotlb_all = amd_iommu_flush_iotlb_all, From patchwork Thu Apr 11 18:47:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25D9B922 for ; Thu, 11 Apr 2019 18:51:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07CAB28D1B for ; Thu, 11 Apr 2019 18:51:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0602328DB4; Thu, 11 Apr 2019 18:51:05 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6995D28D9D for ; Thu, 11 Apr 2019 18:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=YmOyh8g0AgR7SFBK6cbkK5qtTZkXX5dyWkjOyEfcJs4=; b=aifF6DasrQibnsJdtI6vUl3L// SpDYKDPELVaekHZm//2tjp4EahZDOLLZXBrB+IPzcQXoyok7PMZBKSAvYMfZMbGX/RI3ge18PmGG5 WHuCfiO0q+X6GikKX/CoLXIwfUodndAVygOb/R/nmFPYTsyyRid0gzdiZw04/aH595xapKWIhZMiu TUlB2u2erDdTzP3YZkq9yLs8+qyBVrn7AaK53qd+c2Xq1LDk65Ejow7cRsTomMUkfymZ7wCtEOqra rgVfgl/V66T5O4VTjaYl0newWO88VObp8/gu9+NcKSCg9otHlySAZdpB19qznCsmCnAAi13pvWULU BgIWWoCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEemn-0005cL-W9; Thu, 11 Apr 2019 18:50:58 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelH-0002iG-Ru for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:48 +0000 Received: by mail-ed1-x543.google.com with SMTP id w3so6124200edu.10 for ; Thu, 11 Apr 2019 11:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+wIWsBlpHNvqt41NAQAGAJ7H8cITKPcnmYAF2btwAb0=; b=e1cnSn2PK0vQqM4MAMrrXLaTpi+hjQMUA4RONp5/QufCiGQabRY3c40vjmfM6/tVvu dHm2QgZxsJQxyaRWei+pLoeWXOIeJGMqxUsAwfq5xicNbDht5hsH9B9U3PksM/0Z1XVx 7s29y5FnFW4RWp/4CUJywws1z5EA5sMdlVoxCo4ZXNuPJ+tPQk+TA/k5mdqED7+a6wOY ojT9K4KRqkO48HqTHgwak30pwg5Ii15hz3/L1EDeCE9YwFGUkkD/OfSFwHUQ6zuwiQy2 4V/6bFAxvGfBhu6p6kUL2Oheb1GFC38Y0NuBIgjcvwkq28NKMZtTWCL3BpGsOTRkDHE0 NSdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+wIWsBlpHNvqt41NAQAGAJ7H8cITKPcnmYAF2btwAb0=; b=mZfcxGUfsVhNEKg3Rxjl1JD2RhlHMo3yB9gEjyKPK4DWKPot2zF3iJppLBUF/21FJt bZb9IeU9ApVyC7XaI5rgr6IQkDZu9w2P+t/dKopL46Z/UEWm/ocACTttnZWdk9RPythC g0Vg8rrWB0c685ZHb1F8ATs6dCSkOTnHPDi/rzlTWuJexP/5td5ligxOlKYUESsY8fD6 JibNs1Fi0uHVy0vpnpuDNWP7uQYYzvEs86TjkSarDEyFMiE8WtsHn8s0xTr7LBY8Mw0E dyIHgVMBFd0E2edxL9JflKe7DImE2B6ySMF3jxRWuRTb12GmmYl4j6J00Ip5cut1/1Ox WHug== X-Gm-Message-State: APjAAAWQMVTgVQ4pgdPjc7949osreWinQxKX4aGE7z+iizPn26fasb2r rfPJ9C8Gx4Qh1z3/dH4rxrsQ/A== X-Google-Smtp-Source: APXvYqzgvOx+i4FlVrymlvrfw2T19AcnP3BMR2H3Nrx4Vhr9zqZaB5+5yb9dg9dURDNKxHOHDD/v1A== X-Received: by 2002:a17:906:4c92:: with SMTP id q18mr28345302eju.16.1555008562323; Thu, 11 Apr 2019 11:49:22 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:21 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 8/9] iommu/amd: Clean up unused functions Date: Thu, 11 Apr 2019 19:47:37 +0100 Message-Id: <20190411184741.27540-9-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_114924_512674_40D4F0AA X-CRM114-Status: GOOD ( 20.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Now that we are using the dma-iommu api we have a lot of unused code. This patch removes all that unused code. Signed-off-by: Tom Murphy --- drivers/iommu/amd_iommu.c | 209 -------------------------------------- 1 file changed, 209 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 218faf3a6d9c..02b351834a3b 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -116,18 +116,6 @@ struct kmem_cache *amd_iommu_irq_cache; static void update_domain(struct protection_domain *domain); static int protection_domain_init(struct protection_domain *domain); static void detach_device(struct device *dev); -static void iova_domain_flush_tlb(struct iova_domain *iovad); - -/* - * Data container for a dma_ops specific protection domain - */ -struct dma_ops_domain { - /* generic protection domain information */ - struct protection_domain domain; - - /* IOVA RB-Tree */ - struct iova_domain iovad; -}; static struct iova_domain reserved_iova_ranges; static struct lock_class_key reserved_rbtree_key; @@ -201,12 +189,6 @@ static struct protection_domain *to_pdomain(struct iommu_domain *dom) return container_of(dom, struct protection_domain, domain); } -static struct dma_ops_domain* to_dma_ops_domain(struct protection_domain *domain) -{ - BUG_ON(domain->flags != PD_DMA_OPS_MASK); - return container_of(domain, struct dma_ops_domain, domain); -} - static struct iommu_dev_data *alloc_dev_data(u16 devid) { struct iommu_dev_data *dev_data; @@ -1280,12 +1262,6 @@ static void domain_flush_pages(struct protection_domain *domain, __domain_flush_pages(domain, address, size, 0); } -/* Flush the whole IO/TLB for a given protection domain */ -static void domain_flush_tlb(struct protection_domain *domain) -{ - __domain_flush_pages(domain, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, 0); -} - /* Flush the whole IO/TLB for a given protection domain - including PDE */ static void domain_flush_tlb_pde(struct protection_domain *domain) { @@ -1689,43 +1665,6 @@ static unsigned long iommu_unmap_page(struct protection_domain *dom, return unmapped; } -/**************************************************************************** - * - * The next functions belong to the address allocator for the dma_ops - * interface functions. - * - ****************************************************************************/ - - -static unsigned long dma_ops_alloc_iova(struct device *dev, - struct dma_ops_domain *dma_dom, - unsigned int pages, u64 dma_mask) -{ - unsigned long pfn = 0; - - pages = __roundup_pow_of_two(pages); - - if (dma_mask > DMA_BIT_MASK(32)) - pfn = alloc_iova_fast(&dma_dom->iovad, pages, - IOVA_PFN(DMA_BIT_MASK(32)), false); - - if (!pfn) - pfn = alloc_iova_fast(&dma_dom->iovad, pages, - IOVA_PFN(dma_mask), true); - - return (pfn << PAGE_SHIFT); -} - -static void dma_ops_free_iova(struct dma_ops_domain *dma_dom, - unsigned long address, - unsigned int pages) -{ - pages = __roundup_pow_of_two(pages); - address >>= PAGE_SHIFT; - - free_iova_fast(&dma_dom->iovad, address, pages); -} - /**************************************************************************** * * The next functions belong to the domain allocation. A domain is @@ -1827,21 +1766,6 @@ static void free_gcr3_table(struct protection_domain *domain) free_page((unsigned long)domain->gcr3_tbl); } -static void dma_ops_domain_flush_tlb(struct dma_ops_domain *dom) -{ - domain_flush_tlb(&dom->domain); - domain_flush_complete(&dom->domain); -} - -static void iova_domain_flush_tlb(struct iova_domain *iovad) -{ - struct dma_ops_domain *dom; - - dom = container_of(iovad, struct dma_ops_domain, iovad); - - dma_ops_domain_flush_tlb(dom); -} - /* * Free a domain, only used if something went wrong in the * allocation path and we need to free an already allocated page table @@ -2437,100 +2361,6 @@ static int dir2prot(enum dma_data_direction direction) return 0; } -/* - * This function contains common code for mapping of a physically - * contiguous memory region into DMA address space. It is used by all - * mapping functions provided with this IOMMU driver. - * Must be called with the domain lock held. - */ -static dma_addr_t __map_single(struct device *dev, - struct dma_ops_domain *dma_dom, - phys_addr_t paddr, - size_t size, - enum dma_data_direction direction, - u64 dma_mask) -{ - dma_addr_t offset = paddr & ~PAGE_MASK; - dma_addr_t address, start, ret; - unsigned int pages; - int prot = 0; - int i; - - pages = iommu_num_pages(paddr, size, PAGE_SIZE); - paddr &= PAGE_MASK; - - address = dma_ops_alloc_iova(dev, dma_dom, pages, dma_mask); - if (!address) - goto out; - - prot = dir2prot(direction); - - start = address; - for (i = 0; i < pages; ++i) { - ret = iommu_map_page(&dma_dom->domain, start, paddr, - PAGE_SIZE, prot, GFP_ATOMIC); - if (ret) - goto out_unmap; - - paddr += PAGE_SIZE; - start += PAGE_SIZE; - } - address += offset; - - if (unlikely(amd_iommu_np_cache)) { - domain_flush_pages(&dma_dom->domain, address, size); - domain_flush_complete(&dma_dom->domain); - } - -out: - return address; - -out_unmap: - - for (--i; i >= 0; --i) { - start -= PAGE_SIZE; - iommu_unmap_page(&dma_dom->domain, start, PAGE_SIZE); - } - - domain_flush_tlb(&dma_dom->domain); - domain_flush_complete(&dma_dom->domain); - - dma_ops_free_iova(dma_dom, address, pages); - - return DMA_MAPPING_ERROR; -} - -/* - * Does the reverse of the __map_single function. Must be called with - * the domain lock held too - */ -static void __unmap_single(struct dma_ops_domain *dma_dom, - dma_addr_t dma_addr, - size_t size, - int dir) -{ - dma_addr_t i, start; - unsigned int pages; - - pages = iommu_num_pages(dma_addr, size, PAGE_SIZE); - dma_addr &= PAGE_MASK; - start = dma_addr; - - for (i = 0; i < pages; ++i) { - iommu_unmap_page(&dma_dom->domain, start, PAGE_SIZE); - start += PAGE_SIZE; - } - - if (amd_iommu_unmap_flush) { - domain_flush_tlb(&dma_dom->domain); - domain_flush_complete(&dma_dom->domain); - dma_ops_free_iova(dma_dom, dma_addr, pages); - } else { - pages = __roundup_pow_of_two(pages); - queue_iova(&dma_dom->iovad, dma_addr >> PAGE_SHIFT, pages, 0); - } -} - /* * The exported map_single function for dma_ops. */ @@ -2563,32 +2393,6 @@ static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size, iommu_dma_unmap_page(dev, dma_addr, size, dir, attrs); } -static int sg_num_pages(struct device *dev, - struct scatterlist *sglist, - int nelems) -{ - unsigned long mask, boundary_size; - struct scatterlist *s; - int i, npages = 0; - - mask = dma_get_seg_boundary(dev); - boundary_size = mask + 1 ? ALIGN(mask + 1, PAGE_SIZE) >> PAGE_SHIFT : - 1UL << (BITS_PER_LONG - PAGE_SHIFT); - - for_each_sg(sglist, s, nelems, i) { - int p, n; - - s->dma_address = npages << PAGE_SHIFT; - p = npages % boundary_size; - n = iommu_num_pages(sg_phys(s), s->length, PAGE_SIZE); - if (p + n > boundary_size) - npages += boundary_size - p; - npages += n; - } - - return npages; -} - /* * The exported map_sg function for dma_ops (handles scatter-gather * lists). @@ -3166,19 +2970,6 @@ static void amd_iommu_put_resv_regions(struct device *dev, kfree(entry); } -static void amd_iommu_apply_resv_region(struct device *dev, - struct iommu_domain *domain, - struct iommu_resv_region *region) -{ - struct dma_ops_domain *dma_dom = to_dma_ops_domain(to_pdomain(domain)); - unsigned long start, end; - - start = IOVA_PFN(region->start); - end = IOVA_PFN(region->start + region->length - 1); - - WARN_ON_ONCE(reserve_iova(&dma_dom->iovad, start, end) == NULL); -} - static bool amd_iommu_is_attach_deferred(struct iommu_domain *domain, struct device *dev) { From patchwork Thu Apr 11 18:47:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Murphy X-Patchwork-Id: 10896691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE7C31515 for ; Thu, 11 Apr 2019 18:50:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9376B28DCD for ; Thu, 11 Apr 2019 18:50:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87C9F28DD1; Thu, 11 Apr 2019 18:50:35 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 37A7928DCD for ; Thu, 11 Apr 2019 18:50:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=d+V9YBt3FhFX4eO06BUU0ZvUws0j4ZSHHgdufjZGTHM=; b=OQqNSqYqD2J34qji9EUe7c/C4h fzhQOKi43Ac+wm5ZzG7ehhQ0Y8Pi7yZQPtIHVE5UmXwhe5ESAgD70S//oPJJ7AmRBugia0QZFGDfu rtHX8ZAld6Pg2m8+26+zOk8mlbPkT8NwtrIuXO7SZOcKTVSxiDYnMqKM/0J/tvvBordACYOZz5K8W a8n8pL3lEDj/eBNzGM1BJ44DhGsJ675Fbhgt0yq/Z3C5suqw6P08lC80+qD4bOU8RLW31K+izwXFn kQ7mH+0ZyElG9WwAz+wG00IH1xBpcb1xZkhZonZpW5pAZ+XValtgUf52mF0QQ6Yr23dn5rL5rvhpo o6hiTL4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEemK-000527-CW; Thu, 11 Apr 2019 18:50:28 +0000 Received: from merlin.infradead.org ([205.233.59.134]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelQ-0002tB-5X for linux-arm-kernel@bombadil.infradead.org; Thu, 11 Apr 2019 18:49:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DMnZhta68iAX33CpRchMA+yMZHDHOGcPtQBVqQabrNw=; b=UD8Y6qB7WZHW/zSK2Do43pxGk jkGVNpY+vIMt7FOP07j9nG9BXQMEdIQAfvAQQv4qXHxL6vYnB+EOlLZBctRfBN9mru4BRA478HVjk NpCNGQWjs3uQhGrUs/trArizagA0S15K0ybkwPwHwsYQhdsVIDH5u12rUj6ZGD1VWqRzcvJqqZ5BI 0U2CHdCfCo0N6w6gr0I7othFcDVii9678C4k/ZJgGbyMxeBap/tvD8Yw20RHI1Vb0w2cNGGRSRrjG 2U/WWIl97xP/j3mwaqCRK6qC2JZ4ANdHtjhxPEUdy4NEa/okhR1zP0vm5yV9GzoJBaTyQvfvLi69b yQM08WjPQ==; Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hEelN-0003dl-SJ for linux-arm-kernel@lists.infradead.org; Thu, 11 Apr 2019 18:49:30 +0000 Received: by mail-ed1-x541.google.com with SMTP id x14so6170547eds.1 for ; Thu, 11 Apr 2019 11:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DMnZhta68iAX33CpRchMA+yMZHDHOGcPtQBVqQabrNw=; b=KrxWIEikxDdZvLu8UnFVjW0EcG/PU1SormZHDInUdtOAg+J8UeRfz2zXDqrYBYevOn JwyWhZgYwU6QtoPuE0mXZ1Oe5eYGnMUIagbCpUNbdwOBGj5GuTN3H7Op5ODJ3yxVBy4a HJv3vGEEQWldc4EKVLOm7+5le7P2BEiIWuDF1OhwdjSym2xlj9kWG98u6Ge2wHvP8QAZ tWipMQtzFYHT0eFwweBjtWhr2X29dn3Z6GXvM4PStsLb8BJAl2VsSyrgiCcO2JqfpiLQ mZIfb9bKl4Awxr45GpXcPVoobD3hUoYj2Adz7S2v77C2kyg4y/sYDgRpJl/SvI0brDXa u9JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DMnZhta68iAX33CpRchMA+yMZHDHOGcPtQBVqQabrNw=; b=kf/FgUXGtk6QUg8AzdvVXWY1iHWtMVcU8KQGHG3oBCnTMd0vILVczNRrjBA8HBeDUK 6jzxhqyrL9M1pQilFryeGFZ10uc4FZrxnjNKtO6Aya33tzjoefWYn1kF62fafAXkDAeC ZzJRXh8YGtoQu1KvBEp9kc7MGcrXACmQgfwI5dPx89vzrBDS9BAAp3vreNzs7e+bAbPL rdz5/LtrGs2VTWyNTJKY1YCTDnwWUOXFr87B5G3B8iijYv5QCavh8QOO+RcQ1Ta4ZIL3 qU0Nf4k4Vwvyldrq7wiXS/3Tapsp5pz2Gs/JE7Qk6IdmsljiLVfjv4x/Zy0jjAfznpGn 3DmQ== X-Gm-Message-State: APjAAAVHHedBfaaBY5FXNZkK2tSerCj26fgZz1ljOKelx4goLVDYuetA Z3+oQfThfT30ZMxt+KJx9NmkDw== X-Google-Smtp-Source: APXvYqxGXfYCaCRlvVgksxX9b5Eab0yr+jZV0UQmnyepRxSCDJinf+ClgjALBi9ceksiejLlB/1QXw== X-Received: by 2002:a17:906:e285:: with SMTP id gg5mr27392064ejb.229.1555008568161; Thu, 11 Apr 2019 11:49:28 -0700 (PDT) Received: from localhost.localdomain ([80.233.32.123]) by smtp.gmail.com with ESMTPSA id b10sm1285130edi.28.2019.04.11.11.49.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 11:49:27 -0700 (PDT) From: Tom Murphy To: iommu@lists.linux-foundation.org Subject: [PATCH 9/9] iommu/amd: Add allocated domain to global list earlier Date: Thu, 11 Apr 2019 19:47:38 +0100 Message-Id: <20190411184741.27540-10-tmurphy@arista.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190411184741.27540-1-tmurphy@arista.com> References: <20190411184741.27540-1-tmurphy@arista.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190411_144929_986199_AD250BE8 X-CRM114-Status: GOOD ( 16.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , jamessewart@arista.com, Will Deacon , David Brown , Marek Szyprowski , linux-samsung-soc@vger.kernel.org, dima@arista.com, Joerg Roedel , Krzysztof Kozlowski , linux-rockchip@lists.infradead.org, Kukjin Kim , Andy Gross , Marc Zyngier , linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Tom Murphy , linux-kernel@vger.kernel.org, murphyt7@tcd.ie, Rob Clark , Robin Murphy MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP dma_ops_domain_free() expects domain to be in a global list. Arguably, could be called before protection_domain_init(). Signed-off-by: Dmitry Safonov Signed-off-by: Tom Murphy --- drivers/iommu/amd_iommu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 02b351834a3b..bfb021d656aa 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1801,8 +1801,12 @@ static struct protection_domain *dma_ops_domain_alloc(void) if (!domain) return NULL; - if (protection_domain_init(domain)) - goto free_domain; + if (protection_domain_init(domain)) { + kfree(domain); + return NULL; + } + + add_domain_to_list(domain); domain->mode = PAGE_MODE_3_LEVEL; domain->pt_root = (void *)get_zeroed_page(GFP_KERNEL); @@ -1824,8 +1828,6 @@ static struct protection_domain *dma_ops_domain_alloc(void) /* Initialize reserved ranges */ iommu_dma_copy_reserved_iova(&reserved_iova_ranges, &domain->domain); - add_domain_to_list(domain); - return domain; free_cookie: