Received: by 10.192.165.148 with SMTP id m20csp5037174imm; Tue, 24 Apr 2018 12:33:41 -0700 (PDT) X-Google-Smtp-Source: AIpwx4++Ifj9hX8QZct4LVSXoN7JXucrUOohUR39ARxwMFUm/R4vIyESR4CT3/cbQQsFwd7/dU3v X-Received: by 2002:a17:902:780d:: with SMTP id p13-v6mr26262176pll.281.1524598421365; Tue, 24 Apr 2018 12:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524598421; cv=none; d=google.com; s=arc-20160816; b=0QCrpZEhjUKTq5nU80jnIw8vGNqpoag3ec0BDP8CaIxfWmfOYtziLvXsf3Iq5O0R5F Qw3O128DBP9tmu8SyvIx9o2MQ3aDHu/u9ZlGpVMv4kehyv5Zqiad6HHzbflej3JLwsAI aNhQe5/FsCi6NRVTn8za17YshW/z20NhzeiX55fKiwBpCfKAiiZtybRHB7bC7oypETvk iieBP4VD+iwXLUXlddM9L8FxC6ISYCXm23R+cYMQkF6yu4fTMT0TKa5+wUWRlbviXgcX tubINuMSA2cJhKOZoxmPvt4Drx1kEh1TyYC9L0x9vF2PqC193i98H4QFVGgY8qWUJAXs +m0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=shAokbM5veu5kAp6q0+wG7PfEvvV2/ocIkys1tSt4Wc=; b=kZbIix03WrCUBq6BtIyvb0TDSmT50Fh9gD3YEdMHkPY9SnxX63EsGt2N5N+xyXSWEA 35bV5Q0bg23PEwY3d1WIqbMvpNFCpMLXoDPvOajcRbxh2XMYgxcpQpM7aGF1duG+yJ4x ACLLErdx5wc2USmq/A3m3jW91KUxNVGg1E7V8iPZuQrH2KgvDIB3D/xoY/H2qdnX1vR/ 4kKk7MpAFDMsoUR2jhDe+7BZdGEAKOru5rl8CtpB2+iuBNVCCVLYjbbQ3aLc/ngYdnz9 K6vwzKVaYMJGa8ujB2/AqScJOVsn5pQ+fvZRAay9t32rFxJD7VKD9s/CNxHUZuqLsDtm 1WZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=e5fQQ0Ud; 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 33-v6si14097232pll.332.2018.04.24.12.33.27; Tue, 24 Apr 2018 12:33:41 -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=@ffwll.ch header.s=google header.b=e5fQQ0Ud; 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 S1752441AbeDXTcZ (ORCPT + 99 others); Tue, 24 Apr 2018 15:32:25 -0400 Received: from mail-io0-f169.google.com ([209.85.223.169]:39669 "EHLO mail-io0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751095AbeDXTcV (ORCPT ); Tue, 24 Apr 2018 15:32:21 -0400 Received: by mail-io0-f169.google.com with SMTP id r9-v6so8028795iod.6 for ; Tue, 24 Apr 2018 12:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=shAokbM5veu5kAp6q0+wG7PfEvvV2/ocIkys1tSt4Wc=; b=e5fQQ0UdXUQol+JoIuCjk11qb7lNMwR/vmlTY7fHLDf0K30yyOQglapvJqMjFwT83o X68w38iAQ8KIhbScU5HJHyhF4bMC1RlGqdygqpVWeTolbVqtS8QL6hq/L0ddhuJcGNs5 9Nf21YVtMteydrh5mG9AjQxgd4zYU+9T0NvvM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=shAokbM5veu5kAp6q0+wG7PfEvvV2/ocIkys1tSt4Wc=; b=BnTzYc7PCNplVYKOlgYoXA+X29D/HReJKswMxD+h51MSHWFHnJZ16IvsrICSfhWlrT iose3WznjTnDuo4kQC++SLTdfHT5S7R4tkBJCZEgznRy4dpccfa9Z3NUvmFPtOCv27UM wypxotmu6JtXqmhiZn2DSn9p2nRp/MUJjwZ1HH8m+nolokm4EtvzBuwfE/hctxdZrJZq zQLiTjoDsvCjo1YVtd/WCSzru1NrAA3R1SxA0x5E5zIGJu48nsVjTpoG5Jn4lKhYWjIy 2Od4HYBjWu2OmeEbPYqicgBk7DfFUyih1vnJS98LUUQjdkHghRMJZSMRj1X/ET9pSUX+ s6Ag== X-Gm-Message-State: ALQs6tBmIz6+Wio/aEOEBx7o+w+tiRZnWBiHqWnhEHtSx7ExWq1Zmet8 vS1po/9JMV5bHB4OxBOGNGlIDk0QtBzdWbYos6FXqA== X-Received: by 2002:a6b:c582:: with SMTP id v124-v6mr27990335iof.55.1524598340883; Tue, 24 Apr 2018 12:32:20 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:5b42:0:0:0:0:0 with HTTP; Tue, 24 Apr 2018 12:32:20 -0700 (PDT) X-Originating-IP: [2a02:168:5635:0:39d2:f87e:2033:9f6] In-Reply-To: <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> <20180424184847.GA3247@infradead.org> From: Daniel Vetter Date: Tue, 24 Apr 2018 21:32:20 +0200 X-Google-Sender-Auth: Weph1xNq63TwgBmoR0fV0oTioX4 Message-ID: Subject: Re: [Linaro-mm-sig] [PATCH 4/8] dma-buf: add peer2peer flag To: Christoph Hellwig Cc: =?UTF-8?Q?Christian_K=C3=B6nig?= , "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" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 24, 2018 at 8:48 PM, Christoph Hellwig wrote: > 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. Out of curiosity, how much virtual flushing stuff is there still out there? At least in drm we've pretty much ignore this, and seem to be getting away without a huge uproar (at least from driver developers and users, core folks are less amused about that). And at least for gpus that seems to have been the case since forever, or at least since AGP was a thing 20 years ago: AGP isn't coherent, so needs explicit cache flushing, and we have our own implementations of that in drivers/char/agp. Luckily AGP died 10 years ago, so no one yet proposed to port it all over to the iommu framework and hide it behind the dma api (which really would be the "clean" way to do this, AGP is simply an IOMMU + special socket dedicated for the add-on gpu). > 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. Yeah I think that should work. dma_get_sgtable is a pretty nasty layering violation. > - 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. Yeah the dma-buf exporter always knows what kind of backing storage it is dealing with, and for which struct device it should set up a new view. Hence can make sure that it calls the right functions to establish a new mapping, whether that's dma_map_sg, dma_map_resource or the new dma_alloc_remap (instead of the dma_get_sgtable layering mixup). The importer doesn't know. >> 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. Well the idea was to have 1 interface to allow all drivers to share buffers with anything else, no matter how exactly they're allocated. dma-buf has all the functions for flushing, so you can have coherent mappings, non-coherent mappings and pretty much anything else. Or well could, because in practice people hack up layering violations until it works for the 2-3 drivers they care about. On top of that there's the small issue that x86 insists that dma is coherent (and that's true for most devices, including v4l drivers you might want to share stuff with), and gpus really, really really do want to make almost everything incoherent. The end result is pretty epic :-) -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch