From patchwork Thu Apr 16 14:41:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C3=98rjan_Eide?= X-Patchwork-Id: 6226661 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7102E9F1C4 for ; Thu, 16 Apr 2015 14:44:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BF582037B for ; Thu, 16 Apr 2015 14:44:40 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A696E2034B for ; Thu, 16 Apr 2015 14:44:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yil1y-0000Og-8j; Thu, 16 Apr 2015 14:44:38 +0000 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Yil1w-0000IA-Ab for linux-rockchip@lists.infradead.org; Thu, 16 Apr 2015 14:44:37 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by uk-mta-7.uk.mimecast.lan; Thu, 16 Apr 2015 15:41:54 +0100 Received: from e106893-lin.trondheim.arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 16 Apr 2015 15:41:53 +0100 From: =?UTF-8?q?=C3=98rjan=20Eide?= To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org Subject: [PATCH 2/2] ARM: DMA: Use vm_pgoff for IOMMU mmap Date: Thu, 16 Apr 2015 16:41:52 +0200 Message-Id: <1429195312-25898-2-git-send-email-orjan.eide@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429195312-25898-1-git-send-email-orjan.eide@arm.com> References: <1429195312-25898-1-git-send-email-orjan.eide@arm.com> MIME-Version: 1.0 X-OriginalArrivalTime: 16 Apr 2015 14:41:53.0699 (UTC) FILETIME=[7B1EF730:01D07853] X-MC-Unique: iKibjb-wRzKmoNVEoxl5ow-3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150416_074436_756646_D8BEF834 X-CRM114-Status: GOOD ( 10.69 ) X-Spam-Score: -2.3 (--) Cc: djkurtz@chromium.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP arm_iommu_mmap_attrs() ignores the page offset in vma->vm_pgoff that was specified in the mmap call. Any user of dma_mmap_* will get an unexpected result when the device uses the IOMMU DMA ops. Some DRM driver that use dma_mmap_* seems to depend on it ignoring vma->vm_pgoff. Both the Samsung Exynos DRM driver before v3.18, and the current Rockchip DRM driver, use the page offset to pass GEM cookies that are used to look up the GEM buffers and then call dma_mmap_attrs() with the cookie value still in vma->vm_pgoff. rockchip_gem_mmap_buf() in drivers/gpu/drm/rockchip/rockchip_drm_gem.c still does this. It should be fixed before fixing arm_iommu_mmap_attrs(). Signed-off-by: Ørjan Eide Reviewed-by: Daniel Kurtz Tested-by: Daniel Kurtz --- arch/arm/mm/dma-mapping.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index c274476..07d571b 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1364,6 +1364,9 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, { unsigned long uaddr = vma->vm_start; unsigned long usize = vma->vm_end - vma->vm_start; + unsigned long nr_vma_pages = usize >> PAGE_SHIFT; + unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; + unsigned long off = vma->vm_pgoff; struct page **pages = __iommu_get_pages(cpu_addr, attrs); vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); @@ -1371,6 +1374,11 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma, if (!pages) return -ENXIO; + if (off >= nr_pages || nr_vma_pages > (nr_pages - off)) + return -ENXIO; + + pages += off; + do { int ret = vm_insert_page(vma, uaddr, *pages++); if (ret) {