Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3348401ybg; Fri, 25 Oct 2019 02:49:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqw/tKicr+LB4GlMZZ+m+3H0ZvgEwa/rW49Fk7UYynRVT8FnruXMw0Hv5UTlVHLvvBdkl6/L X-Received: by 2002:a17:906:314c:: with SMTP id e12mr2492125eje.140.1571996980377; Fri, 25 Oct 2019 02:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571996980; cv=none; d=google.com; s=arc-20160816; b=uSkcHkyZbejm/qywzK3Erlf9C8uxIbDD0vxlVRca8CFaz2JOsFbMzm9Wr+x/5cp380 /2Kx8u5ebQcHEQpZvwglRrJx4e4MoELkDUjiiZNdD/lhfYNgGS/pm6x1mOH/k2ZU0zqs epSFK6VHCAozud1BdcwGPrcSf8DTvfd6KzzJ0/yf7lMHhHDaz2QRe+X/xjxs3FWc+t0z 7Bazr35MnsMM22RzFV+gP8cnokHsZNJlNx3agOW1CmDYI0HCH+4M68DnmQW6qXrgTesB 8BvJWQkKmFartSzcAWMb4Z427SepYkxR+3SH5meb7RB+c/z0dlKtglsLDxifwPuR4/RO lb5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=j2cZXsIxmHq3znKaQQmAvPePSQWc+GCL8fh3KOAKkFw=; b=pB5aU/HnPC7jEOKCP5qWQvj7gtcW2BDbjHVAVOeRU5EWuqan2Wfmtes4YMzZ1EfFi9 UTWrSF9dBEcsCSi0Llx2iY9685H/EkWYzcn8PyqUf3IoVyzKCLkGDlcYODGbRV5zIOtN i+iwdNKplvJNLh4rp4T3uMMKHXX1HY6hHCFBAJCYFURKaMco0tnDvjc5Df5m8059+q4Z 40w3jBzVmLuWkgr5J12NaXgIFVdEi4JaUYmOvwnLRcLu4KTeSHu+y3uaeevQp9DfvXVr /081tyRn94R9HRTc22cnbJ2VrlyOFQdtt4ep5sFeGwpYrgGb50oSGZl1T+1vCjRzBp3o b3dA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n11si916159ejb.240.2019.10.25.02.49.16; Fri, 25 Oct 2019 02:49:40 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393488AbfJXLE3 (ORCPT + 99 others); Thu, 24 Oct 2019 07:04:29 -0400 Received: from foss.arm.com ([217.140.110.172]:47720 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392171AbfJXLE3 (ORCPT ); Thu, 24 Oct 2019 07:04:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0830695D; Thu, 24 Oct 2019 04:04:13 -0700 (PDT) Received: from [192.168.1.123] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 07EA83F71A; Thu, 24 Oct 2019 04:04:10 -0700 (PDT) Subject: Re: [RFC PATCH 1/3] dma-mapping: introduce a new dma api dma_addr_to_phys_addr() To: Laurentiu Tudor , "hch@lst.de" Cc: "joro@8bytes.org" , Ioana Ciocoi Radulescu , "linux-kernel@vger.kernel.org" , "iommu@lists.linux-foundation.org" , "netdev@vger.kernel.org" , Ioana Ciornei , Leo Li , Diana Madalina Craciun , "davem@davemloft.net" , Madalin Bucur References: <20191022125502.12495-1-laurentiu.tudor@nxp.com> <20191022125502.12495-2-laurentiu.tudor@nxp.com> <62561dca-cdd7-fe01-a0c3-7b5971c96e7e@arm.com> <50a42575-02b2-c558-0609-90e2ad3f515b@nxp.com> <20191024020140.GA6057@lst.de> From: Robin Murphy Message-ID: <2b75c349-0ca1-ea7e-6571-28db9f1a8c46@arm.com> Date: Thu, 24 Oct 2019 12:04:07 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-10-24 8:49 am, Laurentiu Tudor wrote: > > > On 24.10.2019 05:01, hch@lst.de wrote: >> On Wed, Oct 23, 2019 at 11:53:41AM +0000, Laurentiu Tudor wrote: >>> We had an internal discussion over these points you are raising and >>> Madalin (cc-ed) came up with another idea: instead of adding this prone >>> to misuse api how about experimenting with a new dma unmap and dma sync >>> variants that would return the physical address by calling the newly >>> introduced dma map op. Something along these lines: >>> * phys_addr_t dma_unmap_page_ret_phys(...) >>> * phys_addr_t dma_unmap_single_ret_phys(...) >>> * phys_addr_t dma_sync_single_for_cpu_ret_phys(...) >>> I'm thinking that this proposal should reduce the risks opened by the >>> initial variant. >>> Please let me know what you think. >> >> I'm not sure what the ret is supposed to mean, but I generally like >> that idea better. > > It was supposed to be short for "return" but given that I'm not good at > naming stuff I'll just drop it. Hmm, how about something like "dma_unmap_*_desc" for the context of the mapped DMA address also being used as a descriptor token? >> We also need to make sure there is an easy way >> to figure out if these APIs are available, as they generally aren't >> for any non-IOMMU API IOMMU drivers. > > I was really hoping to manage making them as generic as possible but > anyway, I'll start working on a PoC and see how it turns out. This will > probably happen sometime next next week as the following week I'll be > traveling to a conference. AFAICS, even a full implementation of these APIs would have to be capable of returning an indication that there is no valid physical address - e.g. if unmap is called with a bogus DMA address that was never mapped. At that point there'sseemingly no problem just implementing the trivial case on top of any existing unmap/sync callbacks for everyone. I'd imagine that drivers which want this aren't likely to run on the older architectures where the weird IOMMUs live, so they could probably just always treat failure as unexpected and fatal either way. In fact, I'm now wondering whether it's likely to be common that users want the physical address specifically, or whether it would make sense to return the original VA/page, both for symmetry with the corresponding map calls and for the ease of being able to return NULL when necessary. Robin.