From patchwork Fri Mar 31 11:02:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9655899 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 284A160351 for ; Fri, 31 Mar 2017 11:03:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 169A62860C for ; Fri, 31 Mar 2017 11:03:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0956B28653; Fri, 31 Mar 2017 11:03: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham 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 2FEA72860C for ; Fri, 31 Mar 2017 11:03:33 +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: 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: In-Reply-To:List-Owner; bh=4unI6qLKGylB2wo8O6+dh3XyMnvTdn9q8FYuq8vu6Rw=; b=CG iWeSL+ddDUYtBvv5kUqeFtVYWtkGQD7IgbSX5OqK3FfHScwKKj/X/1QBG7mlP+tc+Vl6Kycg5yCb6 1bamMc4+hwbrCl4Ux2qw8UEKLJlNmrdY5/tr/mwx7zU31TFwenvZ/4UN2GiTtv+YaKhhmvYJsyMKI G5xxBUP9BAdZrwYQK98noqU1xdYqRo3Kr43XOHy9FIxA6JpPf/XciRI9CkB3wur0llNdiqEDy8A5Z 0zIhexj1x0P/WARih3/hsOOPYqqqmEg6S7V669LxxPI7lm+x3tWLytTHKIQyRYe8PX1VNIRZ5+RNR U1JrHyKFqdsrrvxra5zc02KO1XASqGcg==; 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 1ctuL6-0003Es-DK; Fri, 31 Mar 2017 11:03:32 +0000 Received: from mailout3.w1.samsung.com ([210.118.77.13]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctuL2-0003D5-CE for linux-arm-kernel@lists.infradead.org; Fri, 31 Mar 2017 11:03:30 +0000 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ONO009G9EP16I30@mailout3.w1.samsung.com> for linux-arm-kernel@lists.infradead.org; Fri, 31 Mar 2017 12:03:01 +0100 (BST) Received: from eusmges2.samsung.com (unknown [203.254.199.241]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20170331110301eucas1p2d14c72990025bf2fc91561a1a0e5d0b8~w8pEB_g6D2405324053eucas1p2l; Fri, 31 Mar 2017 11:03:01 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2.samsung.com (EUCPMTA) with SMTP id 9B.D2.04459.4673ED85; Fri, 31 Mar 2017 12:03:01 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20170331110300eucas1p1535f003de554a9f6e1db56eb47630885~w8pDbGAHx2059320593eucas1p18; Fri, 31 Mar 2017 11:03:00 +0000 (GMT) X-AuditID: cbfec7f1-f796e6d00000116b-35-58de37641b42 Received: from eusync1.samsung.com ( [203.254.199.211]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 60.85.20206.6773ED85; Fri, 31 Mar 2017 12:03:18 +0100 (BST) Received: from AMDC2768.DIGITAL.local ([106.120.43.17]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ONO0084IEOZW0B0@eusync1.samsung.com>; Fri, 31 Mar 2017 12:03:00 +0100 (BST) From: Andrzej Hajda To: Catalin Marinas , linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] arm64/dma-mapping: fix DMA_ATTR_FORCE_CONTIGUOUS mmaping code Date: Fri, 31 Mar 2017 13:02:51 +0200 Message-id: <1490958171-2303-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsWy7djPc7qp5vciDFanWtxad47VYuOM9awW 75f1MFrMnT2J0WLBfmuLTY+vsVqsPXKX3eLghyesFi8/nmBx4PRYM28No8fEs7oem5fUe0y+ sZzRo2/LKsYA1igum5TUnMyy1CJ9uwSujOlXHzAXzBSouPR3EVMD42reLkZODgkBE4nV1w8z QthiEhfurWfrYuTiEBJYyijxZF07M4TzmVFiTX87axcjB1jH2yeZEPFljBJX595hhHD+M0pM nreEBWQUm4CmxN/NN9lAbBGBUIkbXTvBxjILrGKSuH3mLBNIQlggWOLz7GlgNouAqsTJKQ/A bF4BJ4nX81eyQdwkJ3HzXCfYGRICj9kknl86ygxxhqzEpgPMEDUuEm1/3kHZwhKvjm9hh7Bl JC5P7maB6O1mlPjUf4IdwpnCKPHvwwyoDmuJw8cvsoLYzAJ8EpO2TYdawCvR0SYEUeIhsWXH dSYI21Hi0/rFYK1CArES6358YpvAKL2AkWEVo0hqaXFuemqxkV5xYm5x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llh9TXuZpt9f9NG7K+vLX/zuXr7G6ZLF9xNx/XBU2i191+rkoKbEUZyQa ajEXFScCAJ+RLt1qAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170331110300eucas1p1535f003de554a9f6e1db56eb47630885 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRvsgrw=?= =?UTF-8?B?7ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRtTYW1z?= =?UTF-8?B?dW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170331110300eucas1p1535f003de554a9f6e1db56eb47630885 X-RootMTR: 20170331110300eucas1p1535f003de554a9f6e1db56eb47630885 References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170331_040328_559662_5F77CAA5 X-CRM114-Status: GOOD ( 16.12 ) 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: Geert Uytterhoeven , Bartlomiej Zolnierkiewicz , Will Deacon , Andrzej Hajda , iommu@lists.linux-foundation.org, Robin Murphy , Marek Szyprowski 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 In case of DMA_ATTR_FORCE_CONTIGUOUS allocations vm_area->pages is invalid. __iommu_mmap_attrs and __iommu_get_sgtable should not use it and take advantage of contiguous nature of the allocation. Fixes: 44176bb ("arm64: Add support for DMA_ATTR_FORCE_CONTIGUOUS to IOMMU") Signed-off-by: Andrzej Hajda --- Hi Robin, Geert, In this version of the patch I have replaced temporal pages and iommu_dma_mmap with remap_pfn_range or rather its simplified version vm_iomap_memory. Unfortunately I have not find nice helper for sgtable creation, so I left sg allocation inside _iommu_mmap_attrs. As the fixing of DMA_ATTR_FORCE_CONTIGUOUS related crashes has higher priority I have focused only on it in this patch. Regards Andrzej --- arch/arm64/mm/dma-mapping.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index f7b5401..41c7c36 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -703,6 +703,10 @@ static int __iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) return ret; + if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) + return vm_iomap_memory(vma, + page_to_phys(vmalloc_to_page(cpu_addr)), size); + area = find_vm_area(cpu_addr); if (WARN_ON(!area || !area->pages)) return -ENXIO; @@ -715,8 +719,19 @@ static int __iommu_get_sgtable(struct device *dev, struct sg_table *sgt, size_t size, unsigned long attrs) { unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT; - struct vm_struct *area = find_vm_area(cpu_addr); + struct vm_struct *area; + + if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { + int ret = sg_alloc_table(sgt, 1, GFP_KERNEL); + + if (!ret) + sg_set_page(sgt->sgl, vmalloc_to_page(cpu_addr), + PAGE_ALIGN(size), 0); + return ret; + } + + area = find_vm_area(cpu_addr); if (WARN_ON(!area || !area->pages)) return -ENXIO;