Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751998AbdFTNuk (ORCPT ); Tue, 20 Jun 2017 09:50:40 -0400 Received: from foss.arm.com ([217.140.101.70]:38950 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751098AbdFTNuj (ORCPT ); Tue, 20 Jun 2017 09:50:39 -0400 Subject: Re: [PATCH v5 3/7] drivers: dma-coherent: Account dma_pfn_offset when used with device tree To: Christoph Hellwig , Vladimir Murzin Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux@armlinux.org.uk, sza@esh.hu, arnd@arndb.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, alexandre.torgue@st.com, benjamin.gaignard@linaro.org, kbuild-all@01.org, Michal Nazarewicz , Marek Szyprowski , Roger Quadros References: <1495621472-9323-1-git-send-email-vladimir.murzin@arm.com> <1495621472-9323-4-git-send-email-vladimir.murzin@arm.com> <20170620134219.GA31496@infradead.org> From: Robin Murphy Message-ID: Date: Tue, 20 Jun 2017 14:50:34 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 In-Reply-To: <20170620134219.GA31496@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1114 Lines: 27 On 20/06/17 14:42, Christoph Hellwig wrote: > Wouldn't the smal patch below solve the same issue in a simple way? That assumes that all devices accessing a shared pool will have the same dma_pfn_offset as the first one, which cannot strictly be relied upon (even if it is highly likely in practice). Robin. > diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c > index 640a7e63c453..e8f8447d705b 100644 > --- a/drivers/base/dma-coherent.c > +++ b/drivers/base/dma-coherent.c > @@ -290,9 +290,11 @@ EXPORT_SYMBOL(dma_mmap_from_coherent); > static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) > { > struct dma_coherent_mem *mem = rmem->priv; > + dma_addr_t dev_addr = ((rmem->base >> PAGE_SHIFT) - > + dev->dma_pfn_offset) << PAGE_SHIFT; > > if (!mem && > - !dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, > + !dma_init_coherent_memory(rmem->base, dev_addr, rmem->size, > DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE, > &mem)) { > pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", >