Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3796667imu; Mon, 14 Jan 2019 09:10:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN46hL3QXcTqnBG9W6cXEvQoni/Mb4pujIBR1wYtlNfYr+JNcxB4qmL8npIF2Zkd3uk6ZTWw X-Received: by 2002:a63:cc12:: with SMTP id x18mr23649827pgf.33.1547485831529; Mon, 14 Jan 2019 09:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547485831; cv=none; d=google.com; s=arc-20160816; b=tk9w8JDtyNvK3ysqZpR2RoDY29TN9C/261KrL1dhGV+YX8L8T4DZyxJgvYGT5kqM4o 7aDQ2PSAwyQMHnuSFK1aEbqEdF3Ad8O4tAkuaakRf/Wg5m3r6mLEm9u5jKgDWv0gsmo+ GxH+c393dtESkvZccu21EICzbae6OUAKlWtTHJfVA0EpmQfA8f7fgk8bX99ZbOjFasAr mA/x2LfJH8kqrNLqFKzg1c0PplOXr9KAdDc18No0ErWx+HRmnCo8KrHEHVMegXgU4y2b fTIcEup/+v6MmODPFqYJ3Yv9rHX2syxd4EiU2WGQ8SS5r10nDEiXj2vVQO6S95YVlHUY KQtg== 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; bh=Ici3nqFMbmyNYx9vUn7FTrfY9/fZs6My/hRI25rGTwA=; b=wwgWXo+6EL5eVgpInyu25N7HognG6MtTFOUV6bIDUpk0AaOtGjp2kxLNpYMRMZHDdZ s3VbgDHPiK6dvLiTBIHqqaC+Q25veE2pcaBnFeyz6ZGl1aFsMeYYX4Dcjy83hF5EahrN LBF3TRBoZZJRGh9Dd/G/uKL7KvBxYpjAjXLodrGpptcUldrBC7JmY5wlOXQyBt9w3jFF /gEpkyB9lBeaFmKW5WaQrBBOfQShoK9mPgWoudxkQInPPmGb8E72WMwtAKYb7vuW+UNy XqA6SSuVGjOvjkBC2IHsY4+0FksRq1atSKk32qJVzrpDGxIAWGMcsBa3pGzyIZX3AFN5 LjZw== 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 bc3si719932plb.130.2019.01.14.09.10.15; Mon, 14 Jan 2019 09:10:31 -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 S1726803AbfANRI5 (ORCPT + 99 others); Mon, 14 Jan 2019 12:08:57 -0500 Received: from verein.lst.de ([213.95.11.211]:47826 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbfANRI5 (ORCPT ); Mon, 14 Jan 2019 12:08:57 -0500 Received: by newverein.lst.de (Postfix, from userid 2407) id 0861268D93; Mon, 14 Jan 2019 18:08:56 +0100 (CET) Date: Mon, 14 Jan 2019 18:08:55 +0100 From: Christoph Hellwig To: Robin Murphy Cc: Christoph Hellwig , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Niklas =?iso-8859-1?Q?S=F6derlund?= , Russell King , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Mauro Carvalho Chehab , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Subject: Re: [PATCH 1/3] dma-mapping: remove the default map_resource implementation Message-ID: <20190114170855.GA7485@lst.de> References: <20190111181731.11782-1-hch@lst.de> <20190111181731.11782-2-hch@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 Mon, Jan 14, 2019 at 01:12:33PM +0000, Robin Murphy wrote: > Ignoring the offset was kind of intentional there, because at the time I > was primarily thinking about it in terms of the Keystone 2 platform where > the peripherals are all in the same place (0-2GB) in both the bus and CPU > physical address maps, and only the view of RAM differs between the two > (2-4GB vs. 32-34GB). However, on something like BCM283x, the peripherals > region is also offset from its bus address in the CPU view, but at a > *different* offset relative to that of RAM. I was more thinking of the PCIe P2P case, where we need to apply a consistent offset to translate between the CPU and the bus view. But this isn't really used for PCIe P2P, so I guess keeping the original sematics might be a better idea. That being said the videobuf code seems to rely on these offsets, so we might be between a rock and a hard place. > Fortunately, I'm not aware of any platform which has a DMA engine behind an > IOMMU (and thus *needs* to use dma_map_resource() to avoid said IOMMU > blocking the slave device register reads/writes) and also has any nonzero > offsets, and AFAIK the IOMMU-less platforms above aren't using > dma_map_resource() at all, so this change shouldn't actually break > anything, but I guess we have a bit of a problem making it truly generic > and robust :( Note that we don't actually use the code in this patch for ARM/ARM64 platforms with IOMMUs, as both the ARM and the ARM64 iommu code have their own implementations of ->map_resource that actually program the iommu (which at least for the PCIe P2P case would be wrong). > Is this perhaps another shove in the direction of overhauling > dma_pfn_offset into an arbitrary "DMA ranges" lookup table? It is long overdue anyway. >> addr = ops->map_resource(dev, phys_addr, size, dir, attrs); > > Might it be reasonable to do: > > if (!dma_is_direct(ops) && ops->map_resource) > addr = ops->map_resource(...); > else > addr = dma_direct_map_resource(...); > > and avoid having to explicitly wire up the dma_direct callback elsewhere? No, I absolutely _want_ the callback explicitly wired up. That is the only way to ensure we actually intentionally support it and don't just get a default that often won't work. Same issue for ->mmap and ->get_sgtable.