Received: by 10.223.176.46 with SMTP id f43csp4161797wra; Tue, 23 Jan 2018 05:21:34 -0800 (PST) X-Google-Smtp-Source: AH8x224gJxhIKlx3In6PQ8mlRpbQnWYdDrrv5MzkifmsNgpNs+16Wc0YQar8j3gKB6JptCs0oBro X-Received: by 10.98.34.27 with SMTP id i27mr10409943pfi.43.1516713694247; Tue, 23 Jan 2018 05:21:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516713694; cv=none; d=google.com; s=arc-20160816; b=SAjX2tGYyAw9vFTxvuecqBMLhX/NeMw6RlOuiBmlWt5p5dXbqiWPj0N2IRbZxl/lW6 qQt00ahT/Sh3S3wHTILf7fqbQRQEiVXSP2DV9YFr2RGsqkP9arYTAY8TCgAwQCwsKiBE HziOptUsdlA2Kd+dXslPZwNtDMd7CbYzhX0s3KXtgnf3H03meekVFlh/hDLje1T9YZUC B7pnS1rpt9OdjYEkCDx5QMQSTdLjy8VW81aUc7jBRMV1ZbM9Gxn8BwQK0xVhEkpyvaqW Cq/M0TWd91dsuO5mEAzdzp2gOM6beq0dVcBnoP7Rk8F5Z1dDJEjDeC/Ed67gbT7vo70e kW6Q== 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=Sch/j+9LmthaZcMzh/l0/j0rHIpKEerJtoXIgAxULlE=; b=OxadXhwdGCE3QJNQ3fpzWCqauxU3iquvK0ldpKnvOHAPtdEyTkngbUQZ5S+hl+2AD3 Hz9B9w0y0VGHbUbVSwi42PK3uyEenmC/Ag2a2hn0j5sXXAHZmoSxj0J8MnkGW0LX9U7G jvauyo2+1A34iMMmnsAV7itdPYR8siGdCXEhaSlJ0WfAex/I44DHj27sYyBSTNaaazCH 58vWPvsMGI6lKX927DAYiLZiS25UQhBzKN/Nn3+fQW8ZulWH4M77mbJwRE8JKqGUt/Zu 75Dg6713vVmJB2RDQM4069/pEuoQAU4OdVCxTW1bf9mZW6Gj/3gXnq8qaFZ1NHrxjJoe nkxg== 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 m2-v6si4813644pli.761.2018.01.23.05.21.20; Tue, 23 Jan 2018 05:21:34 -0800 (PST) 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 S1752543AbeAWNUi (ORCPT + 99 others); Tue, 23 Jan 2018 08:20:38 -0500 Received: from verein.lst.de ([213.95.11.211]:57396 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752244AbeAWNUf (ORCPT ); Tue, 23 Jan 2018 08:20:35 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id 5463B68C35; Tue, 23 Jan 2018 14:20:33 +0100 (CET) Date: Tue, 23 Jan 2018 14:20:33 +0100 From: Christoph Hellwig To: Florian Fainelli Cc: Christoph Hellwig , Florian Fainelli , Rob Herring , Jim Quinlan , "linux-kernel@vger.kernel.org" , Bjorn Helgaas , Catalin Marinas , Will Deacon , Brian Norris , Russell King , Robin Murphy , Jonas Gorski , Lorenzo Pieralisi , Mark Rutland , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Linux-MIPS , linux-pci@vger.kernel.org, Kevin Cernekee , Ralf Baechle , bcm-kernel-feedback-list@broadcom.com, Gregory Fong , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" Subject: Re: [PATCH v4 4/8] PCI: brcmstb: Add dma-range mapping for inbound traffic Message-ID: <20180123132033.GA21438@lst.de> References: <1516058925-46522-1-git-send-email-jim2101024@gmail.com> <1516058925-46522-5-git-send-email-jim2101024@gmail.com> <20180118073123.GA15766@lst.de> <20180118152331.GA24461@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 19, 2018 at 11:47:54AM -0800, Florian Fainelli wrote: > How can this work well in the context of a loadable module for instance? > For MIPS, this would mean that we have to override phys_to_dma() and > dma_to_phys() in the platform that is *susceptible* to use this PCIe > controller (arch/mips/bmips) which is fine, but there, we essentially > need to find a way to make this dynamic based on whether the PCIe > controller is loaded or not. > > As you might have seen from this patch, what needs to be done is highly > dependent on the processor architecture and its memory controller > physical memory map, so I don't see how we are in any better situation > if we need to replicate 3 times across MIPS, ARM and ARM64 how the > addresses need to be mangled. > > Are you suggesting we somehow decouple the memory mangling part into a > portion that can be built into the kernel image (so phys_to_dma() and > dma_to_phys() is resolved at vmlinux link time) and can be selected by > different architectures that need it? If so, yikes. On architectures with crazy PCIe controllers (this seems to include mips, arm, arm64 and x86 thanks to the weird SOCs) we will need a a few different memory maps, yes. Take a look at arch/x86/pci/sta2x11-fixup.c, preferably from a tree where the worst issues are fixed: http://git.infradead.org/users/hch/misc.git/blob/refs/heads/dma-direct-all:/arch/x86/pci/sta2x11-fixup.c Overriding phys_to_dma and dma_to_phys is required if you need to support swiotlb, and chances are with a broken PCIe controller on arm64 or mips64 you eventuall will. This sta2x11 code should probably be lifted to common code in one form or another eventually, althought it will need another fair round of cleanups for now. > I can see value in having a generic mechanism, ala X86_DMA_REMAP > allowing architectures to have the ability to override phys_to_dma() and > dma_to_phys() but right now, especially if we look at > arch/x86/pci/sta2x11-fixup.c this really appears to be quite messy and > equally ugly than stacking operations... > > What is the actual problem you want to avoid with the stacking of DMA > operations, is it because it becomes harder to audit, or are there are > other reasons? Audit, consolidate into a single dma-direct implementation and properly support swiotlb out of the box.