Received: by 10.213.65.68 with SMTP id h4csp2596680imn; Mon, 9 Apr 2018 06:10:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Dzf9x3LqqJAFWM3zQhIk8QzQusLzPEDjT7BGIEPvMb2VZkc2iC6+HDAhgL7PVpYWmnc03 X-Received: by 2002:a17:902:2c03:: with SMTP id m3-v6mr3192940plb.192.1523279427046; Mon, 09 Apr 2018 06:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523279427; cv=none; d=google.com; s=arc-20160816; b=fJQG1GSABE51RDLkwqV2m3C6FcpOClaaIcNzPzknN4pL65XXK7jfRsIhXAlz9voNWN dE+Uk+lWYctoq6PSot/Ve7PMo9Pb2R1vRenI4mS5dSUnoMkqP6VgZzrG+VxT2oEDWuNL Vts2GtUNENNkKz8Bk85ZQLM6XjmHEx3Nmlm88KSSCgv1XJBVKKZ5eiTazhZU3hAyPBJX wGycw1c29WGH+PVV/PAM3rCFl8o0ZZrKJtwYsWr3z/AkYgQhAmLYX5PKrhm9FeCWIyXh kYrpLpMYF4I3BmSqtb2NF0sr3nvGSM/sIsLnxqI4wK2fla11i3nl9klRLsBnynXcowfk kIKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=nYSaeViODjw/ALEEMDIfAx36ohh+7zBzvevahe2U/xk=; b=P1or0Jt8PI/8yTUiNMOMuKG1lspfygIemn7uw+THJxYMXJ/PdEKhlsf0li0vGpQCru +LvBR2vvgcUfHBc8Avuotx4cqowFXAezhnCk01vnFpFApxlskZAoPXpql85hosFTUMGU 3WE6YHz6+Y8Uh+J4MigTz37/ABHfLCNus92HO8qY/po2bXwZzvfZAdRINtGy11gpOKO3 r3J+UAlTIHg4T51p0Q/LvgChY/0POj6rku1o/9LsssRF1njn2qbD7wwY2H8+uVVtXS7N 0Joe4PKgsnV6dnHxJjYxa+yDnP0OTFv1m9FCSFW9PjTjxS5uhs7ts2VENkBv5OfdV6Lm FKHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=BVScfYpM; 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 c20si181855pfi.18.2018.04.09.06.09.50; Mon, 09 Apr 2018 06:10:26 -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=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=BVScfYpM; 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 S1752137AbeDINGP (ORCPT + 99 others); Mon, 9 Apr 2018 09:06:15 -0400 Received: from galahad.ideasonboard.com ([185.26.127.97]:35167 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752081AbeDINGO (ORCPT ); Mon, 9 Apr 2018 09:06:14 -0400 Received: from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 08A37200BF; Mon, 9 Apr 2018 15:03:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1523279019; bh=uw8SSuaGm1fKH2lFIypllmBMFUPZLZ+wGtb0VSZBEik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BVScfYpM+sEDNAyTMfXuXHz2s5nRMcxeRCzWJ3EkJ/tm97rC512jgU2uQyhF7nurf JuAGF9SLR0kW/klYBmQv6fIVj/kY2I4LD725H7CqC9SmyVhFJ9r+gE6pfeTTNmosHa hsPPSEhUsV43/1OwUu3MCU06tZ4G7z19Ed/PcVBU= From: Laurent Pinchart To: Robin Murphy Cc: jacopo mondi , Jacopo Mondi , ysato@users.sourceforge.jp, dalias@libc.org, geert@linux-m68k.org, linux-renesas-soc@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-sh@vger.kernel.org Subject: Re: [RFC v2 2/2] base: dma-mapping: Postpone page_to_pfn() on mmap() Date: Mon, 09 Apr 2018 16:06:15 +0300 Message-ID: <2555020.mSAUJ9kk90@avalon> Organization: Ideas on Board Oy In-Reply-To: <7da3f31e-e4ad-7f1a-e66c-0d3e0fb8b27d@arm.com> References: <1510679286-6988-1-git-send-email-jacopo+renesas@jmondi.org> <20180409072547.GU20945@w540> <7da3f31e-e4ad-7f1a-e66c-0d3e0fb8b27d@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Monday, 9 April 2018 14:11:22 EEST Robin Murphy wrote: > On 09/04/18 08:25, jacopo mondi wrote: > > Hi Robin, Laurent, > > > > a long time passed, sorry about this. > > > > On Wed, Nov 15, 2017 at 01:38:23PM +0000, Robin Murphy wrote: > >> On 14/11/17 17:08, Jacopo Mondi wrote: > >>> On SH4 architecture, with SPARSEMEM memory model, translating page to > >>> pfn hangs the CPU. Post-pone translation to pfn after > >>> dma_mmap_from_dev_coherent() function call as it succeeds and make page > >>> translation not necessary. > >>> > >>> This patch was suggested by Laurent Pinchart and he's working to submit > >>> a proper fix mainline. Not sending for inclusion at the moment. > >> > >> Y'know, I think this patch does have some merit by itself - until we know > >> that cpu_addr *doesn't* represent some device-private memory which is not > >> guaranteed to be backed by a struct page, calling virt_to_page() on it is > >> arguably semantically incorrect, even if it might happen to be benign in > >> most cases. > > > > I still need to carry this patch in my trees to have a working dma memory > > mapping on SH4 platforms. My understanding from your comment is that > > there may be a way forward for this patch, do you still think the same? > > Have you got any suggestion on how to improve this eventually for > > inclusion? > > As before, the change itself does seem reasonable; it might be worth > rewording the commit message in more general terms rather than making it > sound like an SH-specific workaround (which I really don't think it is), > but otherwise I'd say just repost it as a non-RFC patch. I actually can't remember any better fix I would have in mind, so this looks good to me :-) I agree with Robin, the commit message should be reworded. Robin's explanation of why virt_to_page() should be postponed until we know that cpu_addr represents memory that is guaranteed to be backed by a struct page is a good starting point. You can mention SH4 as an example of an architecture that will crash when calling virt_to_page() in such a case, but the fix isn't specific to SH4. > >>> Suggested-by: Laurent Pinchart > >>> Signed-off-by: Jacopo Mondi > >>> --- > >>> > >>> drivers/base/dma-mapping.c | 3 ++- > >>> 1 file changed, 2 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c > >>> index e584edd..73d64d3 100644 > >>> --- a/drivers/base/dma-mapping.c > >>> +++ b/drivers/base/dma-mapping.c > >>> @@ -227,8 +227,8 @@ 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; > >>> + unsigned long pfn; > >>> > >>> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); > >>> > >>> @@ -236,6 +236,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, -- Regards, Laurent Pinchart