Received: by 10.192.165.156 with SMTP id m28csp942799imm; Fri, 13 Apr 2018 10:27:25 -0700 (PDT) X-Google-Smtp-Source: AIpwx486xKzNPSf2TQwhL8mjQFtY+WeRPP77EtqC/7ITcX27s22mGfoEuR5W/rwmHA2KizlcNA97 X-Received: by 10.98.172.15 with SMTP id v15mr12319932pfe.129.1523640445217; Fri, 13 Apr 2018 10:27:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523640445; cv=none; d=google.com; s=arc-20160816; b=u8GutDAltNRp6Esu6+8ZUlqHh6iB+IJLjsJtH+ZC/Uj0WVox9PptYCcl0zNaJNSWK1 la0qegKZGlUHg54xE3ILtBYlJwG+MgpEFEF8JUB1TXZz/WedJhsC8teS4jKyfjgVDj0/ Ncj9Gigub040KF/zv180NICZRsMKGYe/90rdqHLPhM492lz91HSU7eyT1epzddiZHukV EIC1LlsRMrtZ/y0Blwr6FDHihJxX6WSgOvHdL1W4p7RnTTyfLQRgk2jDUi/hMZYp2KUj f14jUgz9i6R0QkjvKM3rnZhKtI1Hwbh7Bz792xCnUo8qW4sB3gEbWTsb0NEUxJnOk+RB ZkwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=huqD05CZV2kOOhkCuUwlnJasxklzN7HLhnf4tX6+Hpo=; b=jqgR1susXzFDCrpKS6FuBhmlMeNn73Ik4KO7k78mtN6yQWre3O+UcCwoyWGMKyXqjN IGCMdyCC2h+IU7FIkx+quH+k3M65bYuMbFT+GK8UidIcu4qvg43vrFrXoMJMbbE5hZlO y1idngpxgrD2agSIG79PbqzKBLYmzDY56FJmf9H+jkoK80uXSXsoXlm/x85VLsBIEyl2 C2KNlNX4qtRNRsII6KdsteL/8DVrXEYbu1QS029ofSoaB1CbSnaDMM5fEUYOpkByzURg sKn2eouDMJkSWL76cyJtBy/GIR/UWX7Kjqn5D+JTvqJJBTyaHVppbTVy7vkwGVkUv0K6 wWFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si4533130pgu.263.2018.04.13.10.27.11; Fri, 13 Apr 2018 10:27:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751818AbeDMRZw (ORCPT + 99 others); Fri, 13 Apr 2018 13:25:52 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:56801 "EHLO relay1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750761AbeDMRZv (ORCPT ); Fri, 13 Apr 2018 13:25:51 -0400 X-Originating-IP: 2.224.242.101 Received: from w540.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 2AB5E240002; Fri, 13 Apr 2018 19:25:46 +0200 (CEST) From: Jacopo Mondi To: laurent.pinchart@ideasonboard.com, robin.murphy@arm.com, hch@infradead.org Cc: Jacopo Mondi , ysato@users.sourceforge.jp, dalias@libc.org, iommu@lists.linux-foundation.org, linux-sh@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] base: dma-mapping: Postpone cpu addr translation on mmap() Date: Fri, 13 Apr 2018 19:25:37 +0200 Message-Id: <1523640337-26064-1-git-send-email-jacopo+renesas@jmondi.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Postpone calling virt_to_page() translation on memory locations not guaranteed to be backed by a struct page. Try first to map memory from device's coherent memory pool, then perform translation if that fails. On some architectures, specifically SH when configured with SPARSEMEM memory model, assuming a struct page is always assigned to a memory address lead to unexpected hangs during the virtual to page address translation. This patch fixes that specific issue but applies in the general case too. Suggested-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- It has now been clarified this patch does not resolve the issue, but only mitigate it on platforms where dma_mmap_from_dev_coherent() succeeds and delay page_to_pfn() faulty conversion. A suggested proper solution would be not relying on dma_common_mmap() but require all platforms to implement an mmap methods known to work, as noted by Christoph in v1 review. v1 -> v2: - Save the 'pfn' temp variable performing the page_to_pfn() conversion in the remap_pfn_range() function call as suggested by Christoph. --- drivers/base/dma-mapping.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c index 3b11835..d82566d 100644 --- a/drivers/base/dma-mapping.c +++ b/drivers/base/dma-mapping.c @@ -226,7 +226,6 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, #ifndef CONFIG_ARCH_NO_COHERENT_DMA_MMAP unsigned long user_count = vma_pages(vma); unsigned long count = PAGE_ALIGN(size) >> PAGE_SHIFT; - unsigned long pfn = page_to_pfn(virt_to_page(cpu_addr)); unsigned long off = vma->vm_pgoff; vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); @@ -234,12 +233,11 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret)) return ret; - if (off < count && user_count <= (count - off)) { + if (off < count && user_count <= (count - off)) ret = remap_pfn_range(vma, vma->vm_start, - pfn + off, + page_to_pfn(virt_to_page(cpu_addr)) + off, user_count << PAGE_SHIFT, vma->vm_page_prot); - } #endif /* !CONFIG_ARCH_NO_COHERENT_DMA_MMAP */ return ret; -- 2.7.4