Received: by 10.192.165.148 with SMTP id m20csp1213405imm; Wed, 25 Apr 2018 14:38:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx4++A/RIfHOj0BWnmqmP1sNX+RNI/30hBOu3isW4apWG7zDUKw3RDR6D3D6tdkLkRp1z0mFX X-Received: by 10.98.247.17 with SMTP id h17mr28974927pfi.165.1524692289780; Wed, 25 Apr 2018 14:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524692289; cv=none; d=google.com; s=arc-20160816; b=mt7hoZNUBBALTgRsXpmCVEkKrtsP+U99bnoky+FEfJEDgv59YErzkLDTTElxVcQk2X u+QD85zW38gZvf7ImOxhyZZ+3saSmW3Cc4RvP/69Lts8/Y+BdSuOXX3obz/9xAfenJm5 0Go7eAmn8kbbCXPf/e84teaiZ5DzjJKNncW2QbBnhn7LKP4a8BOLAGX8D7lk0twasv7J m8cMhzjRAc1sYAr+JbbalWPGKS2nPxTJoGykILIMoFMGmFHcFRoaGXgMx/Fe6/tWVUhz GVQQZ7Gb2c9vOZuCtp4PPpbO6WU0wMOxfFDggHOtUITwrg5SE818h3JapE4jwuH492P8 NcRg== 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=QtQreAv+lu4bpj/scvYB02zrY7NKZlxcOttrwNRT6Zs=; b=DWaq0FmTTeJfvsD5fUKTviRb6pfcvLXlH0rQDufeYMgCo3vzE9Veaza4+zyzwnya5H PizwDufP0nzYKEDHlKm9AR6ehmEgjkGQ6KJ6dVgIIxCASbEKekUHGc1CAyrunwjgsfjJ fsFxGZKsgVLqkUBMxYhWe23Jp8uW+FwC8oBlgdKFMFc4TlkrtWhEolfXxFYMm+JHiwML 4aIxXh2onOBzfNcL4pAKauPH6ydHqEUsTKUVXyMjXlPJEKJiDp2K0BScGBKfBTBOz/95 rQeSQtYiXTRksDYA9vw+fkwPosbMouhXG+P8yewXfd8eM2asP2/nWF8088kInwi9X3L+ smvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=J/eqwIpw; 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 v85si14352831pgb.120.2018.04.25.14.37.55; Wed, 25 Apr 2018 14:38:09 -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=J/eqwIpw; 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 S1753494AbeDYVfT (ORCPT + 99 others); Wed, 25 Apr 2018 17:35:19 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:55408 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751852AbeDYVfP (ORCPT ); Wed, 25 Apr 2018 17:35:15 -0400 Received: by mail-it0-f65.google.com with SMTP id 144-v6so7180828iti.5 for ; Wed, 25 Apr 2018 14:35:15 -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=QtQreAv+lu4bpj/scvYB02zrY7NKZlxcOttrwNRT6Zs=; b=J/eqwIpw97gLbHBQCLXjGLnRxJ0g7AHem+X9DEgXzbP3EyP8mrZH8TJOtNYnQJv9ph Fej8GslI0+2hsqQHG6fKYa4qy4mFtrTGSkTR3XdK8s4uNgYQP0t/WxrwBmnbWkluwkoN GcfZ8Blo7kRfIxbre3wzgG31zz3e8bqSipygA= 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=QtQreAv+lu4bpj/scvYB02zrY7NKZlxcOttrwNRT6Zs=; b=tnwexoIZapyzXNJZtZIMyYijdLg5rYpuYhEPbYwPnzIe5RKCpFwBoVp6I2abx3KyBx XsGWnrk4R7B5mhPtVSn80NPcIzWSomKmxsuQMMOK/JEp41N2FBxBPn2xjphZ7IrHID8T 2HrwusS6xNIY9/1I5DZkgSlcDBkCG95DxA1Cn5F3R42tIpMukvwKQYHZdLLnGHrutIEN g2pAbVcyr8kkTLiGb3iZF2sIYul5KXAl8ca3AlFIjyBRsg3rEoXr5/PmH8Amg9e7q/5S FEP2UvdefyiOe6YT/g+y9sb067jCNxmmhaB/R4G1BWwDl6nKXjHGCDtFYkWIN0L9OdU0 xCbg== X-Gm-Message-State: ALQs6tDmUBk5sJCWWqIEaV69Laq6siY8N+CrusCou8Mb9Rt6tKnj1hU1 Ov/eTcaut6y0wSI+RXMeJ3DSHaGHBfU0F3aso++UXg== X-Received: by 2002:a24:b310:: with SMTP id e16-v6mr21836535itf.58.1524692114452; Wed, 25 Apr 2018 14:35:14 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:f0d3:0:0:0:0:0 with HTTP; Wed, 25 Apr 2018 14:35:13 -0700 (PDT) X-Originating-IP: [2a02:168:5635:0:39d2:f87e:2033:9f6] In-Reply-To: <20180425153312.GD27076@infradead.org> References: <20180420152111.GR31310@phenom.ffwll.local> <20180424184847.GA3247@infradead.org> <20180425054855.GA17038@infradead.org> <20180425064335.GB28100@infradead.org> <20180425074151.GA2271@ulmo> <20180425085439.GA29996@infradead.org> <20180425100429.GR25142@phenom.ffwll.local> <20180425153312.GD27076@infradead.org> From: Daniel Vetter Date: Wed, 25 Apr 2018 23:35:13 +0200 X-Google-Sender-Auth: clLW9LOvJLz6ewemqlwmJZjZzyU Message-ID: Subject: Re: noveau vs arm dma ops To: Christoph Hellwig Cc: Thierry Reding , =?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" , iommu@lists.linux-foundation.org, Linux ARM 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 Wed, Apr 25, 2018 at 5:33 PM, Christoph Hellwig wrote: > On Wed, Apr 25, 2018 at 12:04:29PM +0200, Daniel Vetter wrote: >> > Coordinating the backport of a trivial helper in the arm tree is not >> > the end of the world. Really, this cowboy attitude is a good reason >> > why graphics folks have such a bad rep. You keep poking into random >> > kernel internals, don't talk to anoyone and then complain if people >> > are upset. This shouldn't be surprising. >> >> Not really agreeing on the cowboy thing. The fundamental problem is that >> the dma api provides abstraction that seriously gets in the way of writing >> a gpu driver. Some examples: > > So talk to other people. Maybe people share your frustation. Or maybe > other people have a way to help. > >> - We never want bounce buffers, ever. dma_map_sg gives us that, so there's >> hacks to fall back to a cache of pages allocated using >> dma_alloc_coherent if you build a kernel with bounce buffers. > > get_required_mask() is supposed to tell you if you are safe. However > we are missing lots of implementations of it for iommus so you might get > some false negatives, improvements welcome. It's been on my list of > things to fix in the DMA API, but it is nowhere near the top. I hasn't come up in a while in some fireworks, so I honestly don't remember exactly what the issues have been. But commit d766ef53006c2c38a7fe2bef0904105a793383f2 Author: Chris Wilson Date: Mon Dec 19 12:43:45 2016 +0000 drm/i915: Fallback to single PAGE_SIZE segments for DMA remapping and the various bits of code that a $ git grep SWIOTLB -- drivers/gpu turns up is what we're doing to hack around that stuff. And in general (there's some exceptions) gpus should be able to address everything, so I never fully understood where that's even coming from. >> - dma api hides the cache flushing requirements from us. GPUs love >> non-snooped access, and worse give userspace control over that. We want >> a strict separation between mapping stuff and flushing stuff. With the >> IOMMU api we mostly have the former, but for the later arch maintainers >> regularly tells they won't allow that. So we have drm_clflush.c. > > The problem is that a cache flushing API entirely separate is hard. That > being said if you look at my generic dma-noncoherent API series it tries > to move that way. So far it is in early stages and apparently rather > buggy unfortunately. I'm assuming this stuff here? https://lkml.org/lkml/2018/4/20/146 Anyway got lost in all that work a bit, looks really nice. >> - dma api hides how/where memory is allocated. Kinda similar problem, >> except now for CMA or address limits. So either we roll our own >> allocators and then dma_map_sg (and pray it doesn't bounce buffer), or >> we use dma_alloc_coherent and then grab the sgt to get at the CMA >> allocations because that's the only way. Which sucks, because we can't >> directly tell CMA how to back off if there's some way to make CMA memory >> available through other means (gpus love to hog all of memory, so we >> have shrinkers and everything). > > If you really care about doing explicitly cache flushing anyway (see > above) allocating your own memory and mapping it where needed is by > far the superior solution. On cache coherent architectures > dma_alloc_coherent is nothing but allocate memory + dma_map_single. > On non coherent allocations the memory might come through a special > pool or must be used through a special virtual address mapping that > is set up either statically or dynamically. For that case splitting > allocation and mapping is a good idea in many ways, and I plan to move > towards that once the number of dma mapping implementations is down > to a reasonable number so that it can actually be done. Yeah the above is pretty much what we do on x86. dma-api believes everything is coherent, so dma_map_sg does the mapping we want and nothing else (minus swiotlb fun). Cache flushing, allocations, all done by the driver. On arm that doesn't work. The iommu api seems like a good fit, except the dma-api tends to get in the way a bit (drm/msm apparently has similar problems like tegra), and if you need contiguous memory dma_alloc_coherent is the only way to get at contiguous memory. There was a huge discussion years ago about that, and direct cma access was shot down because it would have exposed too much of the caching attribute mangling required (most arm platforms need wc-pages to not be in the kernel's linear map apparently). Anything that separate these 3 things more (allocation pools, mapping through IOMMUs and flushing cpu caches) sounds like the right direction to me. Even if that throws some portability across platforms away - drivers who want to control things in this much detail aren't really portable (without some serious work) anyway. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch