From patchwork Tue Jan 31 20:16:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nate Watterson X-Patchwork-Id: 9548415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EFF460415 for ; Tue, 31 Jan 2017 20:23:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FA452838C for ; Tue, 31 Jan 2017 20:23:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 342DE2838E; Tue, 31 Jan 2017 20:23:29 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 C71592838C for ; Tue, 31 Jan 2017 20:23:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cYexb-0007xP-Ob; Tue, 31 Jan 2017 20:23:27 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cYew8-0006qz-F1 for linux-arm-kernel@bombadil.infradead.org; Tue, 31 Jan 2017 20:21:56 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cYew3-0005m1-EW for linux-arm-kernel@lists.infradead.org; Tue, 31 Jan 2017 20:21:54 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4B69860AA5; Tue, 31 Jan 2017 20:21:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485894089; bh=AOSjUi2GXL+js2n9dbbjwkoQDznKycAxuZIfaFAmNTE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dipJaAB6aHBaDvvJ3abgV1lPYejvwbdLhUG9nLfSs5D7VDic8CVomWd7mycftu5po GyCr78NKJNT8mOk8kJpz8E0niX3T9eX5pny37O6cbl1aANUDAP1Rd234/3NeEnE63w NfHjU9VTqqBhLP2OF9n17jUaov/DZACARHxi9+hc= Received: from ssd-mint172.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nwatters@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 7BAB860C18; Tue, 31 Jan 2017 20:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1485894086; bh=AOSjUi2GXL+js2n9dbbjwkoQDznKycAxuZIfaFAmNTE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ZyPqzKy8Hi0iYnwVWQDqDGO4lbcEJ2aW3698bpWJ9XRu4jVCZp3I7B9uPPgiC00Zs 1DE2WaD6+/VY/ClIDgzkVZv+f8McCHBXKDXtGYnF0w/YJIs2ZLuYpioRBRT5xAXozb CnB2fN8ju1TsgFc8YgybjJ1kW4utrdT0tLcq0+h0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7BAB860C18 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=nwatters@codeaurora.org From: Nate Watterson To: Catalin Marinas , Will Deacon , Robin Murphy , Joerg Roedel , Geert Uytterhoeven , Jisheng Zhang , Nate Watterson , Marek Szyprowski , Lorenzo Pieralisi , Krzysztof Kozlowski , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] arm64/dma-mapping: validate dma_masks against IORT defined limits Date: Tue, 31 Jan 2017 15:16:01 -0500 Message-Id: <1485893763-20671-2-git-send-email-nwatters@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485893763-20671-1-git-send-email-nwatters@codeaurora.org> References: <1485893763-20671-1-git-send-email-nwatters@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170131_202151_805668_3CDEF0CF X-CRM114-Status: GOOD ( 18.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: , 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 Some drivers set the dma_mask of client devices based solely on values read from capability registers which may not account for platform specific bus address width limitations. Fortunately, the ACPI IORT table provides a way to report the effective number of address bits a device can use to access memory. This information, when present, is used to supplement the checks already being done in dma_supported() to avoid setting overly generous dma_masks. Signed-off-by: Nate Watterson --- arch/arm64/mm/dma-mapping.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index e040827..467fd23 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -347,6 +348,12 @@ static int __swiotlb_get_sgtable(struct device *dev, struct sg_table *sgt, static int __swiotlb_dma_supported(struct device *hwdev, u64 mask) { + int dma_limit; + + dma_limit = iort_get_memory_address_limit(hwdev); + if (dma_limit >= 0 && DMA_BIT_MASK(dma_limit) < mask) + return 0; + if (swiotlb) return swiotlb_dma_supported(hwdev, mask); return 1; @@ -784,6 +791,17 @@ static void __iommu_unmap_sg_attrs(struct device *dev, iommu_dma_unmap_sg(dev, sgl, nelems, dir, attrs); } +static int __iommu_dma_supported(struct device *hwdev, u64 mask) +{ + int dma_limit; + + dma_limit = iort_get_memory_address_limit(hwdev); + if (dma_limit >= 0 && DMA_BIT_MASK(dma_limit) < mask) + return 0; + + return iommu_dma_supported(hwdev, mask); +} + static struct dma_map_ops iommu_dma_ops = { .alloc = __iommu_alloc_attrs, .free = __iommu_free_attrs, @@ -799,7 +817,7 @@ static void __iommu_unmap_sg_attrs(struct device *dev, .sync_sg_for_device = __iommu_sync_sg_for_device, .map_resource = iommu_dma_map_resource, .unmap_resource = iommu_dma_unmap_resource, - .dma_supported = iommu_dma_supported, + .dma_supported = __iommu_dma_supported, .mapping_error = iommu_dma_mapping_error, };