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=-0.7 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,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 D9460C433E2 for ; Tue, 7 Jul 2020 15:11:30 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8C6020771 for ; Tue, 7 Jul 2020 15:11:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8C6020771 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 8DC2D88F30; Tue, 7 Jul 2020 15:11:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Jq25EKuugNU3; Tue, 7 Jul 2020 15:11:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 8DA9488B67; Tue, 7 Jul 2020 15:11:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 83D81C07FF; Tue, 7 Jul 2020 15:11:29 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id BA590C016F for ; Tue, 7 Jul 2020 15:11:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id A580C88B67 for ; Tue, 7 Jul 2020 15:11:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jgGoTGxS9NUo for ; Tue, 7 Jul 2020 15:11:27 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp8.emailarray.com (smtp8.emailarray.com [65.39.216.67]) by whitealder.osuosl.org (Postfix) with ESMTPS id 88F8D88F06 for ; Tue, 7 Jul 2020 15:11:27 +0000 (UTC) Received: (qmail 99413 invoked by uid 89); 7 Jul 2020 15:11:12 -0000 Received: from unknown (HELO localhost) (amxlbW9uQGZsdWdzdmFtcC5jb21AMTYzLjExNC4xMzIuMw==) (POLARISLOCAL) by smtp8.emailarray.com with SMTP; 7 Jul 2020 15:11:12 -0000 Date: Tue, 7 Jul 2020 08:11:09 -0700 From: Jonathan Lemon To: Christoph Hellwig Subject: Re: [PATCH 1/4] dma-mapping: add a new dma_need_sync API Message-ID: <20200707151109.qui5uzzzq4dihfie@bsd-mbp> References: <20200629130359.2690853-1-hch@lst.de> <20200629130359.2690853-2-hch@lst.de> <20200706194227.vfhv5o4lporxjxmq@bsd-mbp.dhcp.thefacebook.com> <20200707064730.GA23602@lst.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200707064730.GA23602@lst.de> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, bpf@vger.kernel.org, =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Tue, Jul 07, 2020 at 08:47:30AM +0200, Christoph Hellwig wrote: > On Mon, Jul 06, 2020 at 12:42:27PM -0700, Jonathan Lemon wrote: > > On Mon, Jun 29, 2020 at 03:03:56PM +0200, Christoph Hellwig wrote: > > > Add a new API to check if calls to dma_sync_single_for_{device,cpu} are > > > required for a given DMA streaming mapping. > > > > > > +:: > > > + > > > + bool > > > + dma_need_sync(struct device *dev, dma_addr_t dma_addr); > > > + > > > +Returns %true if dma_sync_single_for_{device,cpu} calls are required to > > > +transfer memory ownership. Returns %false if those calls can be skipped. > > > > Hi Christoph - > > > > Thie call above is for a specific dma_addr. For correctness, would I > > need to check every addr, or can I assume that for a specific memory > > type (pages returned from malloc), that the answer would be identical? > > You need to check every mapping. E.g. this API pairs with a > dma_map_single/page call. For S/G mappings you'd need to call it for > each entry, although if you have a use case for that we really should > add a dma_sg_need_sync helper instea of open coding the scatterlist walk. My use case is setting up a pinned memory area, and caching the dma mappings. I'd like to bypass storing the DMA addresses if they aren't needed. For example: setup() { if (dma_need_sync(dev, addr, len)) { kvmalloc_array(...) cache_dma_mappings(...) } dev_get_dma(page) { if (!cache) return page_to_phys(page) return dma_cache_lookup(...) The reason for doing it this way is that the page in question may be backed by either system memory, or device memory such as a GPU. For the latter, the GPU provides a table of DMA addresses where data may be accessed, so I'm unable to use the dma_map_page() API. -- Jonathan _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu