Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2694044yba; Mon, 22 Apr 2019 11:14:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2DIOCVewN3o114lxswUwSNeV4LO4Zxt11Jbp9Fd491nglFipmWTjFF8xq+Kf/OJRU++EE X-Received: by 2002:a63:6fcd:: with SMTP id k196mr20052145pgc.238.1555956876570; Mon, 22 Apr 2019 11:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555956876; cv=none; d=google.com; s=arc-20160816; b=oxXVXo8IuT9UTGaOaSr5pujYAy/TDB4n2X6EgOpcrr/cL3881Lz+a+7y3WQvclIrl9 TKBNXxWdZ5t5NBZX9mQcpwAOtfu5OezGAKU53USi3AiUJFpDf9S9HiDJnl4U+l/eMM9Q 0WP6ObiX4UP9jes0QSDVQuoTRWSjybNWN8ulDSvISFnU7GeK76MObCZzUhjkaPIcUu3N NnxLCpvaXJQKerFWoNY42Hico47HCH3Fi8/l6P1tP8zJ8NL7K1xC6vqKMeZqizaK/q15 2mP84H3UT8OnNTWDKx7HKSMN3X24blCXFqarB0M4uBirQle3uysBrATSQsssdZY0aJ1f okDg== 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=rKMz5Pxf82UzXh/BbA5mQip5vZyvu2JLUr0gjjNjNq0=; b=lTcWK87XVCkEEtKS6wBUzN9z1da9nNwWtsNX0nUaQxvJVdBIbaMOc73XjCXd3yp8Qj 0yv3lVWpWrQEuFm0NLpsxsvO9HtkEWTrRVml/DKiiYX4Qu3cI5suzTqy4uly78IVatUE LvlH/iFcakyD6TOt7AlhDAKviajyuEWPkK1oQkZkOZdfvGwRJKgrK5oPIM9xbcLWrZtg afZjEOjxjYgRxB9CF6Bez9raxTomkHVEt6l8GMd9ZJsHxFVVf95KPlw2VtY0uFcgaVwZ xC/9MmjI8HMrXwNFj2rOf/O4+k/RQXlYqXzM1CdMhepqpTVfbEmQhf8ooYujAEsILeTX UtjA== 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 gn14si13458197plb.7.2019.04.22.11.14.21; Mon, 22 Apr 2019 11:14:36 -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 S1728619AbfDVSLV (ORCPT + 99 others); Mon, 22 Apr 2019 14:11:21 -0400 Received: from verein.lst.de ([213.95.11.211]:41053 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728309AbfDVSLU (ORCPT ); Mon, 22 Apr 2019 14:11:20 -0400 Received: by newverein.lst.de (Postfix, from userid 2407) id 1434668AFE; Mon, 22 Apr 2019 20:11:01 +0200 (CEST) Date: Mon, 22 Apr 2019 20:11:00 +0200 From: Christoph Hellwig To: laurentiu.tudor@nxp.com Cc: hch@lst.de, robin.murphy@arm.com, m.szyprowski@samsung.com, iommu@lists.linux-foundation.org, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] dma-mapping: create iommu mapping for newly allocated dma coherent mem Message-ID: <20190422181100.GB32490@lst.de> References: <20190422165125.21704-1-laurentiu.tudor@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190422165125.21704-1-laurentiu.tudor@nxp.com> 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 Mon, Apr 22, 2019 at 07:51:25PM +0300, laurentiu.tudor@nxp.com wrote: > From: Laurentiu Tudor > > If possible / available call into the DMA API to get a proper iommu > mapping and a dma address for the newly allocated coherent dma memory. I don't think this is so simple. The original use case of dma_declare_coherent_memory was memory that is local to a device, where we copy in data through a MMIO mapping and the device can then access it. This use case still seems to be alive in the ohci-sm501 and ohci-tmio drivers. Going through the iommu in those cases would be counter productive. The other use cases, including the OF ones seem to be (and Marek who added that support should correct me if I'm wrong) normal host DRAM that is just set aside for the device. So if we want to support these prealloc pools with an iommu we need to split the use cases. I have to say I really hate the way we do the DMA "coherent" allocations, so I'm all in favor of that, it just hasn't bubbled up towards the front of my todo list yet. My highlevel plan here would be: a) move the two OHCI drivers away from our current DMA declare coherent code, and just use a trivial genalloc allocator for their MMIO space, given that the USB layer already wraps the dma_alloc/free APIs anyway b) move the rest of the DMA coherent stuff into the actual dma map ops, similar to how we handle CMA allocations. In fact we should probably do this by a new page allocation helper that tries CMA, "coherent" or the page allocator as fallback b) also merge the OF-side handling of CMA vs "coherent" into a single implementation. Preferably dropping the misleading "coherent" name while we are at it.