Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4831059imu; Wed, 19 Dec 2018 00:42:38 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xm7uN8FYrNUs36eCUn1nTqBSchE8mmiUeU539oH3iHI0ViKRGQL5bKsACNj4JBduzU4VVb X-Received: by 2002:a17:902:d83:: with SMTP id 3mr18926104plv.43.1545208958071; Wed, 19 Dec 2018 00:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545208958; cv=none; d=google.com; s=arc-20160816; b=aIhWWyT2YPYnUdUFcL2C0VB4k5e4BXtVMEGJQB5tkaWf5ffCtLA07sCadD9cAm7zlO 00KBydSB3bEXEUpq97amZ5UdFl4aNGlLlTeU1AqZHvcUxhRsXVS06D8Cl4BqzZGg9TpQ 5rdmX6aOhMr8pOWnRMApXjmfJDrnmgRJ0ccu2+16zX73iiWjbd+9hjfWCfJE5jsgBp8E m04EJBq7SbPfqHA1yCJeRTjk4H6kOyXGu2rw4W1gHNrh1cZ0UIGzi0v8M/GWr1l9NdJ4 0d05vJVZ67luoAKmiBVKG18hraG7mJdYUBjl1USAuE7HXVuNHLiUs39fWpb4yKD5IYH1 qMUw== 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=xhHRctd/XqQnCYeEth+JKGS9rV5kdfu9x8MbR/nYHqA=; b=jKYHK3iCL02+B18r+XUgmbqzMRrVwOuj52RNwZOhIbZpxXrrPH7c/CHHVwd145Hrzh HJ5aB961TyiVcXxMwAmI3s/GB2ZyU4A45CAaKAoSFgNbGFRB1kU0RF+5zLakvv6Ms2AZ GzM6Ur7zDLFXMxZ6lBnPEktgi0onO8sJ2/8mweJ+i20vfU9lzDtboGfVst2DH+1fnbxt wAklE06NRV6h5bzzOTzlwfA8czAwDpqfdViaPJ3h96+OaHkNaAO6XwRwQoCG6X+urSIa 5Q5Jx2JVVRUVGsFvZ6smq5z5RoLRdwtaHjETLMicwGMxAJKvciGAjozGdVlLRa+Nvk32 0JUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Z3mUSPpM; 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 bh12si15110487plb.353.2018.12.19.00.42.22; Wed, 19 Dec 2018 00:42:38 -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=Z3mUSPpM; 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 S1728265AbeLSISv (ORCPT + 99 others); Wed, 19 Dec 2018 03:18:51 -0500 Received: from mail-yb1-f196.google.com ([209.85.219.196]:41657 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727659AbeLSISu (ORCPT ); Wed, 19 Dec 2018 03:18:50 -0500 Received: by mail-yb1-f196.google.com with SMTP id e124so7541763ybb.8 for ; Wed, 19 Dec 2018 00:18:50 -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=xhHRctd/XqQnCYeEth+JKGS9rV5kdfu9x8MbR/nYHqA=; b=Z3mUSPpMBqrVISWypSsUV3Uk7yalWO+6tVXRckFg0hFhHekN9Go+A8p1WcSRDadDVJ tY73oeOzdvEyF+QrGrIzRpOMpUJ1Kj4CLNTIjopc6pbdSdELm6l8GIbofaNrmjxnkEKz +m5axO0v9jVp+ueBvx7W2goRn5L3Hy/RZQLIQ= 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=xhHRctd/XqQnCYeEth+JKGS9rV5kdfu9x8MbR/nYHqA=; b=nRwYQa3fN4KRDlPkzF2MlshMQoIEPmDX3A3fDF4740nozZudGB0/0zK61jFEXyaHDh uJvtCPGHuCdwOFZmjr8I+zm0y23j5IPKu56gRKiB0aC5yhQ1jdPRNZLYrgABM/LqrnMc 2PNlw4WB3AF9iJSEYwzzNGpaj/2YMLi4d9ZWKom86ASWIst3g9K27WcXDGD8TcfdtY85 vp1o8BDJuV+xOzrWsARJpKNTLjgSh63VWjxIspF2LeeC+5yUh+/4sfYEa/6iMtNKMnWu w/o8dUBdkJ3ZJOkjVXb/bKoOsYWelT1y79RrxFOizaEXcNXTpnZuO7K2sIPOuusy+gI4 oQqw== X-Gm-Message-State: AA+aEWYlwyPEopop/OBZxPxg5BHkJ2BQC6skmVEOZnmeKZkMqWnfdAVq uStLWMS7MUA9Be+slLmgXWHj35gycgg= X-Received: by 2002:a25:8582:: with SMTP id x2mr19249812ybk.199.1545207529609; Wed, 19 Dec 2018 00:18:49 -0800 (PST) Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com. [209.85.219.179]) by smtp.gmail.com with ESMTPSA id o14sm9214421ywo.52.2018.12.19.00.18.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 00:18:48 -0800 (PST) Received: by mail-yb1-f179.google.com with SMTP id d2so7550156ybs.11 for ; Wed, 19 Dec 2018 00:18:47 -0800 (PST) X-Received: by 2002:a25:910f:: with SMTP id v15mr20413719ybl.285.1545207526870; Wed, 19 Dec 2018 00:18:46 -0800 (PST) MIME-Version: 1.0 References: <20181212090917.GA30598@infradead.org> <20181212135440.GA6137@infradead.org> <20181213140329.GA25339@infradead.org> <20181214123624.GA5824@infradead.org> <20181218073847.GA4552@infradead.org> <20181219075150.GA26656@infradead.org> In-Reply-To: <20181219075150.GA26656@infradead.org> From: Tomasz Figa Date: Wed, 19 Dec 2018 17:18:35 +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 Wed, Dec 19, 2018 at 4:51 PM Christoph Hellwig wrote: > > On Tue, Dec 18, 2018 at 06:48:03PM +0900, Tomasz Figa wrote: > > > So as I said you can call dma_alloc_attrs with DMA_ATTR_NON_CONSISTENT > > > in a loop with a suitably small chunk size, then stuff the results into > > > a scatterlist and map that again for the device share with if you don't > > > want a single contigous region. You just have to either deal with > > > non-contigous access from the kernel or use vmap and the right vmap > > > cache flushing helpers. > > > > The point is that you didn't have to do this small chunk loop without > > DMA_ATTR_NON_CONSISTENT, so it's at least inconsistent now and not > > sure why it could be better than just a loop of alloc_page(). > > You have to do it if you want to map the addresses for a second device. > The existing code that deals with dma_alloc_attrs() without DMA_ATTR_NON_CONSISTENT would just call dma_get_sgtable_attrs() like here: https://elixir.bootlin.com/linux/v4.20-rc7/source/drivers/media/common/videobuf2/videobuf2-dma-contig.c#L366 and then dma_map_sg() for the other device like here; https://elixir.bootlin.com/linux/v4.20-rc7/source/drivers/media/common/videobuf2/videobuf2-dma-contig.c#L283 > > > I would advice against new non-consistent users until this series > > > goes through, mostly because dma_cache_sync is such an amazing bad > > > API. Otherwise things will just work at the allocation side, you'll > > > just need to be careful to transfer ownership between the cpu and > > > the device(s) carefully using the dma_sync_* APIs. > > > > Just to clarify, the actual code isn't very likely to surface any time > > soon. so I assume it would be after this series lands. > > > > We will however need an API that can transparently handle both cases > > of contiguous (without IOMMU) and page-by-page allocations (with > > IOMMU) behind the scenes, like the current dma_alloc_attrs() without > > DMA_ATTR_NON_CONSISTENT. > > Is the use case to then share the memory between multiples devices > or just for a single device? The latter case is generally easy, the > former is rather more painful. The former, but the convention has been to assume that the userspace will choose the right (the most constrained typically) device to allocate from or otherwise handle the import failure (e.g. by falling back to copying into a buffer allocated from the importer). Best regards, Tomasz