Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1121109ybt; Tue, 7 Jul 2020 08:14:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYdLPf+A2JSJiIWLMIjAb5tVAvk/yRk9Bbob61ns8rwrguWGTIdpJZJi+foSiXpuED31yw X-Received: by 2002:a05:6402:888:: with SMTP id e8mr63927404edy.210.1594134872188; Tue, 07 Jul 2020 08:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594134872; cv=none; d=google.com; s=arc-20160816; b=EtWtBI2IL8eqiCd4ekxBz+ZqAL/r7K4Z5UZWldoJqa84SFm7jmCi4OrUXCwrBD2Mra 1LKTmxjbhyn48oyxGJr2gO5M9KaeYBFRKU/8r49thj0goffji7pL8UWyj7I3SRTp+19M HRCwYIMyEVpmhsqmA0EgGsnC5kkHJfePHEGRUHdsWRxftRQBm8C9EcBPhaNwVkqs0BtV gZQKM0S5oZkOQyj1kI/vyXhm6mvLnwCgPR6O50NKCcg1zUilOGsJEbcgmA9UxlCSNQRB 80dpfa49f3mJFuHNbAMA91fsCWO86XBWa7Mzs8LaWNxGapI6Rl33wvOAdSZlktlYM5ri bBwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=AtkFyIwIZV2gX5nd4LzKkAK+dWtQ6jgEWzRJlxK6MNQ=; b=eBrxt6v2DEMVFvDgQCBXtt0aY1QWXQk5GuprUkI+u6DfycwfFpwIWPRCIkiHR8Alqy Q6A1TzXhNuhZJ2YgiPIVBala3A2jAu9p4HKDvuH23aTqSFxeTAQ9WeBpQsClOp4J0PGE b8LA90ruZoLAMcE7DsbyI3WG8qpOQt13Yph2AEnxjIZ5JBk5r5aGTBObZygK5oGBW7g4 sQUC1pf+jX4qHtmUXIv+tn9ZUJ9NhuDr5qq9P9KMR0NjVr2aNska9QIlrLO9EQ4uLBFy kpXzdX1Ik+/00NxYb3StWvvCKakrSO3UuHF/8iF5F9juQT2KfkdpPqCbixr9k6EvwL1T xYew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s21si17655662edi.268.2020.07.07.08.14.07; Tue, 07 Jul 2020 08:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728669AbgGGPLU (ORCPT + 99 others); Tue, 7 Jul 2020 11:11:20 -0400 Received: from smtp8.emailarray.com ([65.39.216.67]:34512 "EHLO smtp8.emailarray.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728661AbgGGPLS (ORCPT ); Tue, 7 Jul 2020 11:11:18 -0400 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 Cc: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= , Magnus Karlsson , iommu@lists.linux-foundation.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200707064730.GA23602@lst.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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