Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1122847ybt; Tue, 7 Jul 2020 08:16:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5pxH5pxNdjvjhEZHYcPaZg0jaNYpSTIsgWj4vPsb6JZ6WsQWTJAJmXelsq+jnFqAEkKS+ X-Received: by 2002:aa7:dc46:: with SMTP id g6mr57373445edu.194.1594134990048; Tue, 07 Jul 2020 08:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594134990; cv=none; d=google.com; s=arc-20160816; b=Zz2J1PZ+PEyJzun1BbvDtqXiXblgb7dkdu7y5h77jIwceE4xbEwLKIqRMZBXG4Wgox fB3y2McD5KMo+17Gf3Bkbr0d1D4geJLf/5vbH9be6kmBvwa8Np6mVY4p0pTNUaDkjaUs nn+4cprejOuk0YkrGu/yg9F/kwkiFjOriLVq1eAQZaiGV7GNZWw9mZDUsWTSBWNPrWJY nICME7Wmnjww0whxk/6YZAMrLSk5PJ1Z1yG5MWQadk6q5/+B2SjNAgWJ3inMDzo8hbMS c2l4htM2vsgq4JYWq/fvrlXZ8KfdUuYUFyJSmJFbMeqbQNDbVmxskZ1hZp7QEgSZ6VDg 9zEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=e8FcFLpjKCsDo3PJmdcIEy8e31xC8ysfVlIdQGjLo6o=; b=cyPiLVHDJiSf3rqJE70eO4rPD0ifdYU1hDsInOrQ79I0vrYT98kmq35MBYRBygsOH6 jHfp4fujxFOS5s+1sP0TQbJecpOu+IutYPvXwybf4ioMpi+4wPZg4DDuau/pExxASUSb tISuUE+hyqH/nxNJz+3ma2LrZVH3GVKmDxvAgI1kbN6nUNebATL5f4VwnuHoUdLRNHwq Nw3rO/+5E2fd5EIE9+wU6znvKG2+goda+pQAjy+qwkjM8wVINQpibCpD1E73uw8N56xV zzcs7t7drh6hWQIP6IfONkDafdR+24B8J8wuZS/FIhmqobdom9KU3p7w66AAA3k24JG1 Y17w== 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 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.16.07; Tue, 07 Jul 2020 08:16:30 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728609AbgGGPPQ (ORCPT + 99 others); Tue, 7 Jul 2020 11:15:16 -0400 Received: from verein.lst.de ([213.95.11.211]:59269 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728747AbgGGPOr (ORCPT ); Tue, 7 Jul 2020 11:14:47 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id E6E5268AFE; Tue, 7 Jul 2020 17:14:41 +0200 (CEST) Date: Tue, 7 Jul 2020 17:14:40 +0200 From: Christoph Hellwig To: Jonathan Lemon Cc: Christoph Hellwig , =?iso-8859-1?Q?Bj=F6rn_T=F6pel?= , 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: <20200707151440.GA23816@lst.de> References: <20200629130359.2690853-1-hch@lst.de> <20200629130359.2690853-2-hch@lst.de> <20200706194227.vfhv5o4lporxjxmq@bsd-mbp.dhcp.thefacebook.com> <20200707064730.GA23602@lst.de> <20200707151109.qui5uzzzq4dihfie@bsd-mbp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200707151109.qui5uzzzq4dihfie@bsd-mbp> User-Agent: Mutt/1.5.17 (2007-11-01) 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:11:09AM -0700, Jonathan Lemon wrote: > > 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. dma_need_sync doesn't tell you if the unmap needs the dma_addr_t. I've been think about replacing CONFIG_NEED_DMA_MAP_STATE with a runtime for a while, which would give you exattly what you need. For now it isn't very useful as there are very few configs left that do not have CONFIG_NEED_DMA_MAP_STATE set.