Received: by 10.213.65.68 with SMTP id h4csp2905687imn; Mon, 9 Apr 2018 10:56:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Z07h+G4/LIK4mRzsvXXDo1GS/rWOjtGE6WpAZEMehNnzmcNQikA5R1VvqEUHrKlTOWRiC X-Received: by 2002:a17:902:5497:: with SMTP id e23-v6mr9871401pli.308.1523296593755; Mon, 09 Apr 2018 10:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523296593; cv=none; d=google.com; s=arc-20160816; b=cdIdmQ/HsRseRfr8dGyxIoKov3Tt+Hzq7uo+5SSaapfZqPrSMmAgXIeGlQzK0nRNgd 3ojO9QuxDZjNW/RXjlKcrA0tQrXXYAy4VQ0dyuvJsW+5Zanfd6Tj/tMXjyM3inYtFm/b ULjBn1MdFttRzlLSfXLprcB9YJH/jcsWRpP1h7i1kUOQgD3Ju12q7MT4RKFMPzwHtUpR YGf+Pd3QupMefWIsNWHnqx4AhzCz0j13AoXQaNIBoTvgNlX4W4tYzt3nX1RC3KU3WW5J xU7fCSxTruWEqCPHnBJta9bmeyJ8qssNozqC3C1+KHoV9BxdA4V16On4tBJCzglbssE0 vABA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=crIAKrNHZIeVslz/u6j72RdB+VkUetvy3HZvL+G7PpI=; b=A9KXagGdpb/dKk5Q3vVXYG+GgcKEVq5OXnLSBCd8fK8hKqKszr6xKVMY26mbeMMkIy mfStt/8wsquO5MDMcun9ewPxKhzaIAgEm9Ms9aXHXmhD+WkwRc4Ka8ilzT2VNqEVqC8P NHjcTG/oQQ3yUWFG3+TRguHfB5nc8Ty+eAqA1W/inSH0XM2mG4qEMEpb4Qzc8gLjzhQi rJAZxH6RYEFKwjmH0fP1ZNEMMlPtt8VppS7lynVHOxp7Lg4S+bWSKqkxVs5r/E3ohmkS ukTpgm041iaUSA3fLQDf8GA8t98DkKoSxD1kzWagAWLfDSzmE68vucOvo7huwFLsnzJW Nvcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CgTwg+AS; 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 i1si520305pgc.229.2018.04.09.10.55.56; Mon, 09 Apr 2018 10:56:33 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=CgTwg+AS; 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 S1752718AbeDIRxG (ORCPT + 99 others); Mon, 9 Apr 2018 13:53:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49326 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751942AbeDIRxE (ORCPT ); Mon, 9 Apr 2018 13:53:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=crIAKrNHZIeVslz/u6j72RdB+VkUetvy3HZvL+G7PpI=; b=CgTwg+ASqitSXsYDRxeMg+865 Epqd6nmQ8VLnUC+DyR+SGGN2yoQE4hWNxYKSupNQh4CcZSAV6DVkMTpOAAKhEKFFemOZvUiDvI1h5 MBydjUFuUagayOVEQUVGKEudYU5ev6DIAgCVjadXtOnCeO2xb3Jib+5nQskQEiCwjsqfs1uuy4ecp noL97gCT6I0Sq5UaZNAFyNZ7qsFReW5sH1x1zPNYNC166dTLZ04Tp8kpyuTI0gR7i0HHCy3+y2H82 LA9akTnpXZIRPT0qzbFcOAX6X4v7ZwKIN9RQGTqyTiSYDtLYhOPYeeVL8DFV2kZbGtlnhiU5NH3wQ LAu3JvYOQ==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1f5ayJ-0003KE-Qm; Mon, 09 Apr 2018 17:52:51 +0000 Date: Mon, 9 Apr 2018 10:52:51 -0700 From: Christoph Hellwig To: Jacopo Mondi Cc: laurent.pinchart@ideasonboard.com, robin.murphy@arm.com, dalias@libc.org, ysato@users.sourceforge.jp, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, iommu@lists.linux-foundation.org Subject: Re: [PATCH] base: dma-mapping: Postpone cpu addr translation on mmap() Message-ID: <20180409175251.GA5426@infradead.org> References: <1523293148-18726-1-git-send-email-jacopo+renesas@jmondi.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1523293148-18726-1-git-send-email-jacopo+renesas@jmondi.org> User-Agent: Mutt/1.9.2 (2017-12-15) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 09, 2018 at 06:59:08PM +0200, Jacopo Mondi wrote: > I'm still a bit puzzled on what happens if dma_mmap_from_dev_coherent() fails. > Does a dma_mmap_from_dev_coherent() failure guarantee anyhow that the > successive virt_to_page() isn't problematic as it is today? > Or is it the > if (off < count && user_count <= (count - off)) > check that makes the translation safe? It doesn't. I think one major issue is that we should not simply fall to dma_common_mmap if no method is required, but need every instance of dma_map_ops to explicitly opt into an mmap method that is known to work. > #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; > + unsigned long pfn; > > vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); > > @@ -235,6 +235,7 @@ int dma_common_mmap(struct device *dev, struct vm_area_struct *vma, > return ret; > > if (off < count && user_count <= (count - off)) { > + pfn = page_to_pfn(virt_to_page(cpu_addr)); > ret = remap_pfn_range(vma, vma->vm_start, > pfn + off, > user_count << PAGE_SHIFT, Why not: ret = remap_pfn_range(vma, vma->vm_start, page_to_pfn(virt_to_page(cpu_addr)) + off, and save the temp variable?