Received: by 10.192.165.148 with SMTP id m20csp1787121imm; Thu, 26 Apr 2018 02:11:13 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrK35Ja/uwxNL7K+CXa8ivXNmkBMmWB0kpN1m5Ut20OPN0A27i5xaL4d5b+wjoQwOsGlEDY X-Received: by 10.101.69.2 with SMTP id n2mr3421868pgq.95.1524733873381; Thu, 26 Apr 2018 02:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524733873; cv=none; d=google.com; s=arc-20160816; b=INTigRVRxDjR5+jHgSdUEYN9aist+PYF1PsTKKPlgUgmt9Yd1vijLI2F2cG3I48Fln q6BLIxzRybistotuYsftPMr8dlRwFuWo3FNvr+ZP9eNRPhI2ZYZjr7wBFSSNIAivzzdG J40qvoz6RgEtOab+6Za97ziQ2SEnb17wYaVY6bYpGCAeUdQPs4dAUoiB2/YTtZ2z0p6o qquZuQD+rjhxH3e2u27tNeKdPqHy9R9EUG4L1G4V8rFQFaQxVKMBeMUH2ZZ7p72/YVNZ 5cAc6HjObwkg26IO55oOKwpxnjRWAxzTjGGZNpW9axYlElyEAYZvQfu4/8mxQg7hCWbw m6sA== 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:dkim-signature:arc-authentication-results; bh=x0eYgZWUDsAGgBukafbVFmeNDo9Nf7ofCkjzPrrZT+U=; b=vdb8j1DMHvziNULq7K7AZ8mNronyGFI9iGud0/6Ayf8RqXrLR3TMoXiXAbSCoTzO6k GBuM4kyQtwwUeIbm3uMVolj2w1+GCzbhs6CM0BSGWXObzDzkyGsw3OSLyywMvQQlBfB9 sWG+9uJLUCZmrrtMj4qPHBRiK/c5bpbdQuG0Rh9nmdRzjFihQWDNvioHTs1wA/Eiqpx5 EWaAcvLB/2SgPm8KJk/Q02kGl+mJe4LGBuAzUMKxatj2ofl9H/q4Ro4qHgR70iJ8PpmI cXzmn59O8loHOg9QzMErXH3MDvOhhGyou7+8fkPDvOQ+aJofCMCeNf0mk3Yrt8XToF8f 9mOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Rtk2Snbw; 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 l129si14020479pgl.485.2018.04.26.02.10.58; Thu, 26 Apr 2018 02:11:13 -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=Rtk2Snbw; 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 S1754364AbeDZJJy (ORCPT + 99 others); Thu, 26 Apr 2018 05:09:54 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:43168 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753780AbeDZJJt (ORCPT ); Thu, 26 Apr 2018 05:09:49 -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:Cc:To:From:Date:Sender:Reply-To: 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=x0eYgZWUDsAGgBukafbVFmeNDo9Nf7ofCkjzPrrZT+U=; b=Rtk2SnbwuzdaAs0QJ2b7pxViT TiaG6SyqYJP1tJZMf9MPA16P2Cy+wQy50382J5ipeV3j8XSv7aj0sPj72dqWjGF5Ud5IOdn23KUWo loGACyGNj8+lUc4vBf24vA3V5feySl0iRf9ABAFi6XwxLGRXuZF3vOb6JGq4HQ/dtlvlLgzfa0rqk aUOI+Mcy0dItOwwLSqBSKt88yuqPQWDAEISv6YKyeg+W2n+bDf3F7z0Ilvxb7LOz4D/bnErRzceqB zGdj/5BqrT7eXnY0YH7fJPi3yfRnzeXBEL0g2Xr5VGYcOfglrYXoGiAtmXCdIZAOzSB5jXxTqAvxs w0jsAadcg==; Received: from hch by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fBcuM-00079H-TF; Thu, 26 Apr 2018 09:09:42 +0000 Date: Thu, 26 Apr 2018 02:09:42 -0700 From: Christoph Hellwig To: Daniel Vetter Cc: Christoph Hellwig , Thierry Reding , 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" , iommu@lists.linux-foundation.org, Linux ARM Subject: Re: noveau vs arm dma ops Message-ID: <20180426090942.GA18811@infradead.org> References: <20180425054855.GA17038@infradead.org> <20180425064335.GB28100@infradead.org> <20180425074151.GA2271@ulmo> <20180425085439.GA29996@infradead.org> <20180425100429.GR25142@phenom.ffwll.local> <20180425153312.GD27076@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Apr 25, 2018 at 11:35:13PM +0200, Daniel Vetter wrote: > > 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. I'm pretty sure I've seen some oddly low dma masks in GPU drivers. E.g. duplicated in various AMD files: adev->need_dma32 = false; dma_bits = adev->need_dma32 ? 32 : 40; r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits)); if (r) { adev->need_dma32 = true; dma_bits = 32; dev_warn(adev->dev, "amdgpu: No suitable DMA available.\n"); } synopsis: drivers/gpu/drm/bridge/synopsys/dw-hdmi-i2s-audio.c: pdevinfo.dma_mask = DMA_BIT_MASK(32); drivers/gpu/drm/bridge/synopsys/dw-hdmi.c: pdevinfo.dma_mask = DMA_BIT_MASK(32); drivers/gpu/drm/bridge/synopsys/dw-hdmi.c: pdevinfo.dma_mask = DMA_BIT_MASK(32); etnaviv gets it right: drivers/gpu/drm/etnaviv/etnaviv_gpu.c: u32 dma_mask = (u32)dma_get_required_mask(gpu->dev); But yes, the swiotlb hackery really irks me. I just have some more important and bigger fires to fight first, but I plan to get back to the root cause of that eventually. > > >> - 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. That url doesn't seem to work currently. But I am talking about the thread titled '[RFC] common non-cache coherent direct dma mapping ops' > 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. Which sounds like the right thing to do to me. > 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). Simple cma_alloc() doesn't do anything about cache handling, it just is a very dumb allocator for large contiguous regions inside a big pool. I'm not the CMA maintainer, but in general I'd love to see an EXPORT_SYMBOL_GPL slapped onto cma_alloc/release and drivers use that were needed. Using that plus dma_map*/dma_unmap* sounds like a much saner interface than dma_alloc_attrs + DMA_ATTR_NON_CONSISTENT or DMA_ATTR_NO_KERNEL_MAPPING. You don't happen to have a pointer to that previous discussion? > 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. As long as we stay away from the dma coherent allocations separating them is fine, and I'm working towards it. dma coherent allocations on the other hand are very hairy beasts, and provide by very different implementations depending on the architecture, or often even depending on the specifics of individual implementations inside the architecture. So for your GPU/media case it seems like you'd better stay away from them as much as you can.