Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1604964imu; Thu, 13 Dec 2018 19:20:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/UIsgFEwIsw8Aj0Ewq0pS30GHKpHJ170MzRAjSI/uBr5GNdxsukGRgdOxXRKLmwRgueTtAj X-Received: by 2002:a63:1f1c:: with SMTP id f28mr1271211pgf.193.1544757626921; Thu, 13 Dec 2018 19:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544757626; cv=none; d=google.com; s=arc-20160816; b=NJob6Uo3W75RSRgpOb6t/JUB6eF1qFqL6WK7QXcKNyC+0uZJLasFcaEgFHdB9Gxfle WJbSZOxpv/6nllQBLckIP//16RwV+kpSp2AURyWfwpgAJFSTg+uv+Hwdc2N70hZiwZI7 NfmuGI7bSRVebdFvX7DX5EgPCntkbx2RM7dmM5ZdJtqIsfLmKO9uhnXHrmcABLy3Bl6C rnzItw3KQSnu7NsPuptV8en/JwCLqm4gu+7HdkTd7E5sAse0oGLcTW28h5xkh7p56PEt ArtVSZ9hNZhBITOJ+yDCuqobTM8ZN5nyiqkPe4/GiXIUVJ3tEsVDYEP2YzSCHNaiWtl1 F6hA== 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 :in-reply-to:references:mime-version:dkim-signature; bh=6chvDpYuKOUdNKAhe8SqsSGz5gKVHREizTUjW93gBBA=; b=fVdw2WragjYH40QO5o6Jkr73rHBm5nM4mpW0wvUFbceDixDTE3Bq+8Geg/D3gBAEZd qUxuphSgvq9UsfC+v4ObEwh4qk+ayi5tq2F/yw25jC92dCVDnvhfoGdYXgzuLGpsSxRO EAKuILP7mZJ6I63dB1PQKodYjr5pjBOa2rZPoym0krklDoHd1CkzNSCr6RWIKCcLTykd V08RxwB1BIS3vjeMAKrYT0Rgws7DTWQNW4u1JBXt1m8TYx5NqicxJV+P8nA5QvdMcxvS HE8TC5+qixf9XatNy7P54GKJf53CMSNnFKHtVQgJzV5eKzpEKAnL9NPxZWC1Jvn2cahy dmyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IGSSdUc6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si2946501plt.5.2018.12.13.19.20.11; Thu, 13 Dec 2018 19:20:26 -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; dkim=pass header.i=@chromium.org header.s=google header.b=IGSSdUc6; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbeLNDTW (ORCPT + 99 others); Thu, 13 Dec 2018 22:19:22 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:36089 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725949AbeLNDTW (ORCPT ); Thu, 13 Dec 2018 22:19:22 -0500 Received: by mail-yw1-f68.google.com with SMTP id i73so578083ywg.3 for ; Thu, 13 Dec 2018 19:19:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6chvDpYuKOUdNKAhe8SqsSGz5gKVHREizTUjW93gBBA=; b=IGSSdUc6+P3lkRXfOyEfw7/1isV/6KpGPmHELrENxMdUc1FplkWRDfhO2ubD52uRYD E8LBvKkk24JMp5/qxdO5aW11YgW57cMtQuiQRRamCy2xj/6J+q82hbEl6f9hDxEE78fr ZY/h5FK5Hox0VeSHXp5IuvafDSDqjQihnqX9M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6chvDpYuKOUdNKAhe8SqsSGz5gKVHREizTUjW93gBBA=; b=qu6gpA9A9Wbpmy4aCq8u1O3Puo3blXpCqca9pw7AJadV4T6363Ynx51kI2BrqqmZik tgLjx8I0/3NWFOKF+3xS/FERqiL8cPQ6ZdSfg+oA4OXEY+5IX1Xjb3M36B66J8FSNtdh iHRcR4+pF6OgmN/rOKBzZsl6kFW/bahACcgyKH/poKeeIVYqrdPozzTJF6ez/Kd29Low oOLNZMPZfX6vB52lyVcJvPL+eAGMUCaNPJF9bR/Dp0Ve3Zr1cP03hls5p6QqJIGb/baD XpqOKlIHe4GQwP1x2LkjK+MvV6WeFSsrQ2gSuyjWQMK/1GKec8jYetdijUdUqvboyRz0 ph/A== X-Gm-Message-State: AA+aEWYXBosveeRxxUqhMz8oW7I9+wOl1fPI9uIJy80g5j53MCdOQ92K 7QQXgL1cCiQLckjEnXQESJo1/t3/1v4= X-Received: by 2002:a0d:e887:: with SMTP id r129mr1506949ywe.54.1544757560668; Thu, 13 Dec 2018 19:19:20 -0800 (PST) Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com. [209.85.219.173]) by smtp.gmail.com with ESMTPSA id q24sm1188655ywa.95.2018.12.13.19.19.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Dec 2018 19:19:20 -0800 (PST) Received: by mail-yb1-f173.google.com with SMTP id e124so1713401ybb.8 for ; Thu, 13 Dec 2018 19:19:20 -0800 (PST) X-Received: by 2002:a25:84c6:: with SMTP id x6mr1366869ybm.293.1544757170391; Thu, 13 Dec 2018 19:12:50 -0800 (PST) MIME-Version: 1.0 References: <20180821170629.18408-1-matwey@sai.msu.ru> <20180821170629.18408-3-matwey@sai.msu.ru> <2213616.rQm4DhIJ7U@avalon> <20181207152502.GA30455@infradead.org> <20181212090917.GA30598@infradead.org> <20181212135440.GA6137@infradead.org> <20181213140329.GA25339@infradead.org> In-Reply-To: <20181213140329.GA25339@infradead.org> From: Tomasz Figa Date: Fri, 14 Dec 2018 12:12:38 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 2/2] media: usb: pwc: Don't use coherent DMA buffers for ISO transfer To: Christoph Hellwig Cc: Laurent Pinchart , "Matwey V. Kornilov" , Linux Media Mailing List , Linux Kernel Mailing List , "Matwey V. Kornilov" , Alan Stern , Ezequiel Garcia , hdegoede@redhat.com, Hans Verkuil , Mauro Carvalho Chehab , rostedt@goodmis.org, mingo@redhat.com, Mike Isely , Bhumika Goyal , Colin King , Kieran Bingham , keiichiw@chromium.org 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 Thu, Dec 13, 2018 at 11:03 PM Christoph Hellwig wrote: > > On Thu, Dec 13, 2018 at 12:13:29PM +0900, Tomasz Figa wrote: > > Putting aside the problem of memory without struct page, one thing to > > note here that what is a contiguous DMA range for device X, may not be > > mappable contiguously for device Y and it would still need something > > like a scatter list to fully describe the buffer. > > I think we need to define contiguous here. > > If the buffer always is physically contiguous, as it is in the currently > posted series, we can always map it with a single dma_map_single call > (if the hardware can handle that in a single segment is a different > question, but out of scope here). Are you sure the buffer is always physically contiguous? At least the ARM IOMMU dma_ops [1] and the DMA-IOMMU dma_ops [2] will simply allocate pages without any continuity guarantees and remap the pages into a contiguous kernel VA (unless DMA_ATTR_NO_KERNEL_MAPPING is given, which makes them return an opaque cookie instead of the kernel VA). [1] http://git.infradead.org/users/hch/misc.git/blob/2dbb028e4a3017e1b71a6ae3828a3548545eba24:/arch/arm/mm/dma-mapping.c#l1291 [2] http://git.infradead.org/users/hch/misc.git/blob/2dbb028e4a3017e1b71a6ae3828a3548545eba24:/drivers/iommu/dma-iommu.c#l450 > > If on the other hand we have multiple discontiguous physical address > range that are mapped using the iommu and vmap this interface doesn't > work anyway. > > But in that case you should just do multiple allocations and then use > dma_map_sg coalescing on the hardware side, and vmap [1] if really > needed. I guess for this we want to gurantee that dma_alloc_attrs > with the DMA_ATTR_NON_CONSISTENT allows virt_to_page to be used on > the return value, which the currently posted implementation does, > although I'm a it reluctant about the API guarantee. > > > > Do we already have a structure that would work for this purposes? I'd > > assume that we need something like the existing scatterlist but with > > page links replaced with something that doesn't require the memory to > > have struct page, possibly just PFN? > > The problem is that just the PFN / physical address isn't enough for > most use cases as you also need a kernel virtual address. But moving > struct scatterlist to store a pfn instead of a struct page would be > pretty nice for various reasons anyway. > > > > > > > > > It would also be great to use that opportunity to get rid of all the > > > code duplication of almost the same dmabug provides backed by the > > > DMA API. > > > > Could you sched some more light on this? I'm curious what is the code > > duplication you're referring to. > > It seems like a lot of the dmabuf ops are just slight various of > dma_alloc + dma_get_sttable + dma_map_sg / dma_unmap_sg. There must be > a void to not duplicate that over and over. Device/kernel/userspace maps/unmaps shouldn't really be exporter-specific indeed, as long as one provides a uniform way of describing a buffer and then have dma_map_*() work on that. Possibly a part that manages the CPU cache maintenance either. There is still some space for some special device caches (or other synchronization), though. > > [1] and use invalidate_kernel_vmap_range and flush_kernel_vmap_range > to manually take care of cache flushing.