From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20F46C433DF for ; Thu, 20 Aug 2020 10:31:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F146F20658 for ; Thu, 20 Aug 2020 10:31:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="QFNCCjnh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731645AbgHTKbY (ORCPT ); Thu, 20 Aug 2020 06:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729134AbgHTKbS (ORCPT ); Thu, 20 Aug 2020 06:31:18 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06DE1C061757 for ; Thu, 20 Aug 2020 03:31:18 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id f24so1882124ejx.6 for ; Thu, 20 Aug 2020 03:31:17 -0700 (PDT) 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=FU3+CiJFzLHmOFDuQMwlaisWRGuHRN+5AV6txupwZrU=; b=QFNCCjnhRiVXX1RwHJMrjJrm3FMIDmNx/PgDGVaGoYPr2orRHBTBO48N0vE/bjgnJ+ SYuYytDiRhiYZtZgJZ7z4/4vPKus2MwWgTKmnlMmLZQ4o8gAgDqGKHg0dO0uTStdh95b tHYxvzFh9iEVHBmlKA/EhqmNwNT52r2I3xUhk= 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=FU3+CiJFzLHmOFDuQMwlaisWRGuHRN+5AV6txupwZrU=; b=WG6rJyeswGhQttUYv/EkRKc2/AB1fCXKuAoZvm6M+xlTNFNHJRMXOuEdZ6qoP1QYqJ YgdC74vO7jW/T4FP9ipydv79zORRWqkkJDE5lljk2bWBfT9YhHVeBaT1f3/M+pY3wevg tmPNOkWYvjQvDY7hiNaQQO4v3u3xFY/yHCWg65mkurBrEUfaJuMGClRJXtKXgezS/vNB +8qupQJbTqjyVI/zlPSHZX9Lfk8PQoV0yoCbIJma7Str4Bvi8vBreqp4pgUpFOk+j1zy kJM5RkJGaNNJGJahLpkgIGSKET3jkznR5lWPO2FrgEvEA1PmVxVQKYcyHAkDTwpdj4GB Td8w== X-Gm-Message-State: AOAM532kqGvcrexVSm/AjB+HmgsC5XZhJSumcUqOQxHFy6ULmFRYVP+A 8NH/5Qc63ucQj1XVDNd35yzMs8Do6XBGtJ3B X-Google-Smtp-Source: ABdhPJx6TKPk7ik8DsEutpdZybj3pjhtcenNJ+yM+CBtA9W//rOSoo/zttLSmGT4ko/7bHay2BfXAg== X-Received: by 2002:a17:906:d8b6:: with SMTP id qc22mr2759584ejb.468.1597919475294; Thu, 20 Aug 2020 03:31:15 -0700 (PDT) Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com. [209.85.218.47]) by smtp.gmail.com with ESMTPSA id y13sm1051086eds.64.2020.08.20.03.31.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Aug 2020 03:31:15 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id kq25so1896897ejb.3 for ; Thu, 20 Aug 2020 03:31:14 -0700 (PDT) X-Received: by 2002:a5d:6744:: with SMTP id l4mr2717742wrw.105.1597919084826; Thu, 20 Aug 2020 03:24:44 -0700 (PDT) MIME-Version: 1.0 References: <20200819065555.1802761-1-hch@lst.de> <20200819065555.1802761-6-hch@lst.de> <62e4f4fc-c8a5-3ee8-c576-fe7178cb4356@arm.com> <2b32f1d8-16f7-3352-40a5-420993d52fb5@arm.com> <20200820050214.GA4815@lst.de> In-Reply-To: <20200820050214.GA4815@lst.de> From: Tomasz Figa Date: Thu, 20 Aug 2020 12:24:31 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 05/28] media/v4l2: remove V4L2-FLAG-MEMORY-NON-CONSISTENT To: Christoph Hellwig Cc: Robin Murphy , alsa-devel@alsa-project.org, linux-ia64@vger.kernel.org, Linux Doc Mailing List , nouveau@lists.freedesktop.org, linux-nvme@lists.infradead.org, Linux Kernel Mailing List , "James E.J. Bottomley" , linux-mm@kvack.org, Marek Szyprowski , linux-samsung-soc , Joonyoung Shim , linux-scsi@vger.kernel.org, Kyungmin Park , Ben Skeggs , Matt Porter , Linux Media Mailing List , Tom Lendacky , Pawel Osciak , Mauro Carvalho Chehab , "list@263.net:IOMMU DRIVERS" , Joerg Roedel , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , Thomas Bogendoerfer , linux-parisc@vger.kernel.org, netdev@vger.kernel.org, Seung-Woo Kim , linux-mips@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Aug 20, 2020 at 7:02 AM Christoph Hellwig wrote: > > On Wed, Aug 19, 2020 at 03:07:04PM +0100, Robin Murphy wrote: > >> FWIW, I asked back in time what the plan is for non-coherent > >> allocations and it seemed like DMA_ATTR_NON_CONSISTENT and > >> dma_sync_*() was supposed to be the right thing to go with. [2] The > >> same thread also explains why dma_alloc_pages() isn't suitable for the > >> users of dma_alloc_attrs() and DMA_ATTR_NON_CONSISTENT. > > > > AFAICS even back then Christoph was implying getting rid of NON_CONSISTENT > > and *replacing* it with something streaming-API-based - i.e. this series - > > not encouraging mixing the existing APIs. It doesn't seem impossible to > > implement a remapping version of this new dma_alloc_pages() for > > IOMMU-backed ops if it's really warranted (although at that point it seems > > like "non-coherent" vb2-dc starts to have significant conceptual overlap > > with vb2-sg). > > You can alway vmap the returned pages from dma_alloc_pages, but it will > make cache invalidation hell - you'll need to use > invalidate_kernel_vmap_range and flush_kernel_vmap_range to properly > handle virtually indexed caches. > > Or with remapping you mean using the iommu do de-scatter/gather? Ideally, both. For remapping in the CPU sense, there are drivers which rely on a contiguous kernel mapping of the vb2 buffers, which was provided by dma_alloc_attrs(). I think they could be reworked to work on single pages, but that would significantly complicate the code. At the same time, such drivers would actually benefit from a cached mapping, because they often have non-bursty, random access patterns. Then, in the IOMMU sense, the whole idea of videobuf2-dma-contig is to rely on the DMA API to always provide device-contiguous memory, as required by the hardware which only has a single pointer and size. > > You can implement that trivially implement it yourself for the iommu > case: > > { > merge_boundary = dma_get_merge_boundary(dev); > if (!merge_boundary || merge_boundary > chunk_size - 1) { > /* can't coalesce */ > return -EINVAL; > } > > > nents = DIV_ROUND_UP(total_size, chunk_size); > sg = sgl_alloc(); > for_each_sgl() { > sg->page = __alloc_pages(get_order(chunk_size)) > sg->len = chunk_size; > } > dma_map_sg(sg, DMA_ATTR_SKIP_CPU_SYNC); > // you are guaranteed to get a single dma_addr out > } > > Of course this still uses the scatterlist structure with its annoying > mix of input and output parametes, so I'd rather not expose it as > an official API at the DMA layer. The problem with the above open coded approach is that it requires explicit handling of the non-IOMMU and IOMMU cases and this is exactly what we don't want to have in vb2 and what was actually the job of the DMA API to hide. Is the plan to actually move the IOMMU handling out of the DMA API? Do you think we could instead turn it into a dma_alloc_noncoherent() helper, which has similar semantics as dma_alloc_attrs() and handles the various corner cases (e.g. invalidate_kernel_vmap_range and flush_kernel_vmap_range) to achieve the desired functionality without delegating the "hell", as you called it, to the users? Best regards, Tomasz