Received: by 10.213.65.68 with SMTP id h4csp3583746imn; Tue, 10 Apr 2018 01:02:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx49+ZEJiB6tvaggEg/r24bdgCEUkHPdLT200WOIp6LFOrEPZ8mJBsKWfFiFMfvwO4mtTG0Em X-Received: by 2002:a17:902:7b97:: with SMTP id w23-v6mr7922484pll.45.1523347347263; Tue, 10 Apr 2018 01:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523347347; cv=none; d=google.com; s=arc-20160816; b=lDXYR8Y4mT7d1173KGTR0jFkO1RNykmTmKkLktPx30VG5+AWtjCYTtJUZYJGPMlfoW gPHfNljLduV7ntImVgIML3IDkmCVDhefVr+9L2mSoGjVzgoluEmyGU5kwsHWEjm/H79h idrPxYQhyNqPaEMS/XFDpBrsMYJPMUVCV6CRnMhZp1HyIw0PE7CfKUYqWQdgMleIOwEg fl1vKNvnfyPxTRntKZujQrv36h3mhCvorVPd65pN84d/LbzDp0AoIxdDeS0bdp5ugCAJ IuKUEjAb1TSXp2NltuhoG56uDfqXxeuMMpDaVKyIEbkv6ioocdVZkR/4klA4HCcHfSoS NB8w== 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:arc-authentication-results; bh=svI0yGN3hhESITYU60PwFADnLNCNGPN5jWSwLOO/LyI=; b=u3jV23JLSErO18n4mHu51JO4T7UyS+13NlcACVXeKyIxy7xNjI8EZyNNHUMa+gRvZ4 4Kx51XlWdHkzVlQSv6fKLkMHjdie/1aHwSidz8WHYqGMvfqIqgE2l5re38o97oAQ9ftK ePvT+96hYOKBrjXS7ZWoSRWSuWR9SeaWL7fEdwNSqMfjWWCOd3IZB0kC9FkCgGxDv8qJ eHy2FOKKCM5Tu1BHMZ73vGEZ26WYXgpp4l+IbBCysw6L7LGFOJw/5wMAHHv77JC0qhGw PXn+rllBDg0T6xDFapvTevOw1xpQQ1d4GNr1Cucs2DF+2bDdX5zVzsbmBIV5IN/7oeX8 yP2A== 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 h9si1622072pfn.237.2018.04.10.01.01.50; Tue, 10 Apr 2018 01:02:27 -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 S1752489AbeDJH57 (ORCPT + 99 others); Tue, 10 Apr 2018 03:57:59 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:53895 "EHLO relay3-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752369AbeDJH55 (ORCPT ); Tue, 10 Apr 2018 03:57:57 -0400 X-Originating-IP: 2.224.242.101 Received: from w540 (unknown [2.224.242.101]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A34DC60003; Tue, 10 Apr 2018 09:57:53 +0200 (CEST) Date: Tue, 10 Apr 2018 09:57:52 +0200 From: jacopo mondi To: Christoph Hellwig Cc: Jacopo Mondi , 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: <20180410075752.GB20945@w540> References: <1523293148-18726-1-git-send-email-jacopo+renesas@jmondi.org> <20180409175251.GA5426@infradead.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="n5G3y24fV3/VEqbx" Content-Disposition: inline In-Reply-To: <20180409175251.GA5426@infradead.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --n5G3y24fV3/VEqbx Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Hi Christoph, On Mon, Apr 09, 2018 at 10:52:51AM -0700, Christoph Hellwig wrote: > 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. I see.. this patch thus just postpones the problem... > > > #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? Sure, it's better... Should I send a v2 or considering your above comment this patch is just a mitigation and should be ditched in favour of a proper solution (which requires a much more considerable amount of work though)? Thanks j --n5G3y24fV3/VEqbx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJazG6AAAoJEHI0Bo8WoVY86H0P/2SMs4laMyttAVmvylDfTO4w p8rssvBm/Qt20vZDkznGlLX2++8JAY4AMtdwjEvx+RrJHzvvjoziIYEIguZFv1IA 8sM/N2i7+4KpHeJsUJtQ0ckcxbxyGXZsz2BOMsUFtmsa0lo0U0B1W9mCfpxaj5sn MApicnmKxUBlfbbFzgoug4+l2bdOWkWtO1Es6t9Ky08kUySfcHq38InjrnyOGC3V ERjohSe5N8+FMzySnnpDQ2tqkCJ03vOrQa4WG301fsLADrkWzQ6qmItfyfIe3k2X 8A8VScaqG1u2p4yNUoJfmfKvGWkEmiiz6rqyesOVQHkCmmrDNyT+lpZsejpWg/qQ HhG7f8q72CxMY4vsj8j2o5fSc9LNplVabEAGCOBDvU+S4SQcWTapnMhGv1hEXNzW P3eMzDTcLQwmRoOHd1ZLkRKVtpWanH5UZQYsnLIg2dtz3j2x5JGE9N7W7CeMWsyn 9nGmY47qBvnNszGNY5R/wBTzaiPzbsFM0uKfW9eeedxHwb3yR1S+f7qeBKHm/H7u rpUPOYU6GaJyxfjUUE+t+dFJYKrUf3VTxMCbViEAZBu5HgG9LiveADvSLyNPxJec tMkTMv2Tplq9GxiFDNB+nZGlr7DwMpoWc/5qZg+v0TshwdtLony7cdtD0Us+Gg9t oe7/84v/+s4N7PLfgU6I =BwgV -----END PGP SIGNATURE----- --n5G3y24fV3/VEqbx--