From patchwork Mon Nov 7 13:06:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 81081 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1002274qge; Mon, 7 Nov 2016 05:08:01 -0800 (PST) X-Received: by 10.98.27.132 with SMTP id b126mr13226542pfb.171.1478524081197; Mon, 07 Nov 2016 05:08:01 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id q9si31248505pfi.45.2016.11.07.05.08.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 05:08:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3jdX-000207-9w; Mon, 07 Nov 2016 13:06:55 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c3jdS-0001rx-Kq for linux-arm-kernel@lists.infradead.org; Mon, 07 Nov 2016 13:06:52 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0OG900DWEWER0W20@mailout2.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Mon, 07 Nov 2016 13:06:27 +0000 (GMT) Received: from eusmges1.samsung.com (unknown [203.254.199.239]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20161107130626eucas1p1015a3ac44abb50b952a264506776c875~Exbt0wNLr0633506335eucas1p1P; Mon, 7 Nov 2016 13:06:26 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges1.samsung.com (EUCPMTA) with SMTP id 34.45.23383.35C70285; Mon, 7 Nov 2016 13:06:27 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246~ExbtOOk3X1245412454eucas1p2v; Mon, 7 Nov 2016 13:06:25 +0000 (GMT) X-AuditID: cbfec7ef-f79e76d000005b57-c2-58207c530bb3 Received: from eusync2.samsung.com ( [203.254.199.212]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id B4.2D.07726.05C70285; Mon, 7 Nov 2016 13:06:24 +0000 (GMT) Received: from AMDC2765.digital.local ([106.116.147.25]) by eusync2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0OG900B1IWEM1NA0@eusync2.samsung.com>; Mon, 07 Nov 2016 13:06:25 +0000 (GMT) From: Marek Szyprowski To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] iommu/dma-iommu: properly respect configured address space size Date: Mon, 07 Nov 2016 14:06:13 +0100 Message-id: <1478523973-8828-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRmVeSWpSXmKPExsWy7djPc7rBNQoRBjvWiVos2G9t0Tl7A7vF psfXWC0u75rDZrH2yF12i4MfnrA6sHk8OTiPyWPNvDWMHpuX1HtMvrGc0aNvyypGj8+b5ALY orhsUlJzMstSi/TtErgy2g+wFpziqthy+j5zA+NTji5GTg4JAROJT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2FEKsUxO4uSxyawTGLkXMDKsYhRJLS3OTc8tNtQrTswtLs1L10vO z93ECAzKbcd+bt7BeGlj8CFGAQ5GJR5eARv5CCHWxLLiytxDjBIczEoivJEVChFCvCmJlVWp RfnxRaU5qcWHGE2Bdk9klhJNzgdGTF5JvKGJobmloZGxhYW5kZGSOG/JhyvhQgLpiSWp2amp BalFMH1MHJxSDYwTz5wLKZH9xKn6L/LSPe6rtvZCDNuehGzyrjdtV2N7HH7K5OiDvqM86+TO P7vSGarE/+XSdbbbX1wqFINvyl+cUzsr72fjzeZN2iZTV81R61Nd4JKTFcn0/cbivwJTdrzp iYvzKFxpOKF51d94g+XWbccN1l18pGGy6Z3/VkamxuMFZYfbhfmVWIozEg21mIuKEwF+0CXy YAIAAA== X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRs=?= =?UTF-8?B?7IK87ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?TWFyZWsgU3p5cHJvd3NraRtTUlBPTC1LZXJuZWwgKFRQKRtT?= =?UTF-8?B?YW1zdW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246 X-RootMTR: 20161107130625eucas1p2dd23c07010b4f3eddb6c6540ed802246 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161107_050650_912236_8650A3FC X-CRM114-Status: GOOD ( 13.83 ) X-Spam-Score: -8.3 (--------) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-8.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [210.118.77.12 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [210.118.77.12 listed in wl.mailspike.net] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.4 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joerg Roedel , Robin Murphy , Marek Szyprowski MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org When one called iommu_dma_init_domain() with size smaller than device's DMA mask, the alloc_iova() will not respect it and always assume that all IOVA addresses will be allocated from the the (base ... dev->dma_mask) range. This patch fixes this issue by taking the configured address space size parameter into account (if it is smaller than the device's dma_mask). Signed-off-by: Marek Szyprowski --- drivers/iommu/dma-iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index c5ab8667e6f2..8b4b72654359 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -212,11 +212,13 @@ static struct iova *__alloc_iova(struct iommu_domain *domain, size_t size, if (domain->geometry.force_aperture) dma_limit = min(dma_limit, domain->geometry.aperture_end); + + dma_limit = min(dma_limit >> shift, (dma_addr_t)iovad->dma_32bit_pfn); /* * Enforce size-alignment to be safe - there could perhaps be an * attribute to control this per-device, or at least per-domain... */ - return alloc_iova(iovad, length, dma_limit >> shift, true); + return alloc_iova(iovad, length, dma_limit, true); } /* The IOVA allocator knows what we mapped, so just unmap whatever that was */