Received: by 10.192.165.148 with SMTP id m20csp4995482imm; Tue, 24 Apr 2018 11:50:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx49Or0kYPrv+adBC7zyaHwRKtx8btddNT58U5ql/Dxt08d5CtJMZF9GHq+RqLcw/5jChchQR X-Received: by 2002:a17:902:781:: with SMTP id 1-v6mr19798650plj.150.1524595824135; Tue, 24 Apr 2018 11:50:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524595824; cv=none; d=google.com; s=arc-20160816; b=Zj10SkuW34RYdHTMOjSjGSEV76FaGGdnRMqzQW9V4wq+AIj9aQUJjIhQrz1GdNSOqN kPIhUWf09+hNFZCOpViilLV/xXzPeVO4aJ0jXnWUoztOsZ/uZaogTbDW9S/Jb1D+/bMX h1rmVSM+qp7n4NHzLuBjyJkEj5ATSiW3BJGd/bMFC/zQ7n7toL1XMIIiVYa97OBU6qhf rovuCcJ1QlweFxHBRnpHfKrV34fUqgiduccLn0BZIm/iDrROSJPqiWLxCn/5Q6xCGAZY YYu40WbMwNU/lDDE3pSxLEVu4pUTWCVreY493Apto1VuwQlgEGMYcqDWoujZ/5vGEvs8 NUFw== 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:to :from:date:dkim-signature:arc-authentication-results; bh=aRNGFxBYjkbbQ65QtnFXGb38TJIJLM/PCPsCA1EQlX8=; b=pqggkZlnfeZ6rNb5fRVzEycPip1ml/f0Scs8nvEmE9kWNXijwCxtd9SWHgoeqvkfPS kIOm/EWBWlb3PQAgxVNO++YF6E7SknvTGBBkxX+N5Cwg9AeYG1s+kxISdfr0L89wKG63 yNOKR9XJ/UoELFmPsy8HwzevbTm2ZYe5kmZYFQ3XSB776mfTohFEUY5+p1aB3uJ+dD/3 Ydfpyo97dH5rpBw6EeizGzy6X6IxN+/GNmgzW+W7QCS1FkjfokCLmUe4DRtWiEJYjr+O LkAfl1Ijl+lUVpSKnZdNZgShYSfVQumkpOLqb972rY6kIP0L4d/4Ti3/lU6VF8VdL4cR Ubjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=XpccBJS2; 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 f5si6918361pgc.37.2018.04.24.11.50.10; Tue, 24 Apr 2018 11:50:24 -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=XpccBJS2; 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 S1752532AbeDXSs6 (ORCPT + 99 others); Tue, 24 Apr 2018 14:48:58 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50130 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751980AbeDXSsu (ORCPT ); Tue, 24 Apr 2018 14:48:50 -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:To:From:Date:Sender:Reply-To:Cc: 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=aRNGFxBYjkbbQ65QtnFXGb38TJIJLM/PCPsCA1EQlX8=; b=XpccBJS2dJNMVFKO70VhAZN6J 7MG0ZmasUm/XMRPuBw56Dw1wJQ1XIBgdQ497jS+46p7lp/1SVjPiah1sjNbZtu+jdtR+vt7Xeb2ot 2i5niK5z147xsSItbG/P8SiFNw4h7A4DLIyovDVp3DAo1hrmOIsfMdDVWa/Zn4sFupFXATv4K9OPj Qm45+zoW2U6/G/i76ct5d1cQLfj4pXSzV//JGGbnEwj5AjeFR4R319tjgSpXjIJUnOYaW4N8g1WT8 sBhMXo+MAkZMtU9LRNVqRz1dRFU0Dvj2okQ/dbEGQjKkv9Ly52mL9zYL7pj3HoBLHclPLFZvvCR8K zpXZE2eUA==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fB2zf-00079w-CS; Tue, 24 Apr 2018 18:48:47 +0000 Date: Tue, 24 Apr 2018 11:48:47 -0700 From: Christoph Hellwig To: Christoph Hellwig , Christian =?iso-8859-1?Q?K=F6nig?= , "moderated list:DMA BUFFER SHARING FRAMEWORK" , Linux Kernel Mailing List , amd-gfx list , Jerome Glisse , dri-devel , Dan Williams , Logan Gunthorpe , "open list:DMA BUFFER SHARING FRAMEWORK" Subject: Re: [Linaro-mm-sig] [PATCH 4/8] dma-buf: add peer2peer flag Message-ID: <20180424184847.GA3247@infradead.org> References: <20180403180832.GZ3881@phenom.ffwll.local> <20180416123937.GA9073@infradead.org> <20180419081657.GA16735@infradead.org> <20180420071312.GF31310@phenom.ffwll.local> <3e17afc5-7d6c-5795-07bd-f23e34cf8d4b@gmail.com> <20180420101755.GA11400@infradead.org> <20180420124625.GA31078@infradead.org> <20180420152111.GR31310@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180420152111.GR31310@phenom.ffwll.local> 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 Fri, Apr 20, 2018 at 05:21:11PM +0200, Daniel Vetter wrote: > > At the very lowest level they will need to be handled differently for > > many architectures, the questions is at what point we'll do the > > branching out. > > Having at least struct page also in that list with (dma_addr_t, lenght) > pairs has a bunch of benefits for drivers in unifying buffer handling > code. You just pass that one single list around, use the dma_addr_t side > for gpu access (generally bashing it into gpu ptes). And the struct page > (if present) for cpu access, using kmap or vm_insert_*. We generally > ignore virt, if we do need a full mapping then we construct a vmap for > that buffer of our own. Well, for mapping a resource (which gets back to the start of the discussion) you will need an explicit virt pointer. You also need an explicit virt pointer and not just page_address/kmap for users of dma_get_sgtable, because for many architectures you will need to flush the virtual address used to access the data, which might be a vmap/ioremap style mapping retourned from dma_alloc_address, and not the directly mapped kernel address. Here is another idea at the low-level dma API level: - dma_get_sgtable goes away. The replacement is a new dma_alloc_remap helper that takes the virtual address returned from dma_alloc_attrs/coherent and creates a dma_addr_t for the given new device. If the original allocation was a coherent one no cache flushing is required either (because the arch made sure it is coherent), if the original allocation used DMA_ATTR_NON_CONSISTENT the new allocation will need dma_cache_sync calls as well. - you never even try to share a mapping retourned from dma_map_resource - instead each device using it creates a new mapping, which makes sense as no virtual addresses are involved at all. > So maybe a list of (struct page *, dma_addr_t, num_pages) would suit best, > with struct page * being optional (if it's a resource, or something else > that the kernel core mm isn't aware of). But that only has benefits if we > really roll it out everywhere, in all the subsystems and drivers, since if > we don't we've made the struct pages ** <-> sgt conversion fun only worse > by adding a 3 representation of gpu buffer object backing storage. I think the most important thing about such a buffer object is that it can distinguish the underlying mapping types. While dma_alloc_coherent, dma_alloc_attrs with DMA_ATTR_NON_CONSISTENT, dma_map_page/dma_map_single/dma_map_sg and dma_map_resource all give back a dma_addr_t they are in now way interchangable. And trying to stuff them all into a structure like struct scatterlist that has no indication what kind of mapping you are dealing with is just asking for trouble.