Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753109AbcC2M5z (ORCPT ); Tue, 29 Mar 2016 08:57:55 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:52674 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751625AbcC2M5x (ORCPT ); Tue, 29 Mar 2016 08:57:53 -0400 Subject: Re: [PATCH 2/3] swiotlb: prefix dma_to_phys and phys_to_dma functions To: Stefano Stabellini , Konrad Rzeszutek Wilk References: <1458252137-24497-1-git-send-email-okaya@codeaurora.org> <1458252137-24497-2-git-send-email-okaya@codeaurora.org> <56EBF09A.1060503@arm.com> <56EC1805.5060207@codeaurora.org> Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, timur@codeaurora.org, cov@codeaurora.org, nwatters@codeaurora.org, linux-mips@linux-mips.org, linux-ia64@vger.kernel.org, linux-xtensa@linux-xtensa.org, Catalin Marinas , Will Deacon , Max Filippov , Chris Metcalf , Paul Mackerras , "H. Peter Anvin" , Huacai Chen , Guan Xuetao , Marek Szyprowski , Jisheng Zhang , Florian Fainelli , Russell King , Aaro Koskinen , Michael Ellerman , X86 , Ingo Molnar , Benjamin Herrenschmidt , Guenter Roeck , Fenghua Yu , Denys Vlasenko , Arnd Bergmann , Konrad Rzeszutek Wilk , Akinobu Mita , Bjorn Helgaas , Thomas Gleixner , Valentin Rothberg , Chris Zankel , Tony Luck , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Dean Nelson , LKML , Ralf Baechle , "Suthikulpanit, Suravee" , Joe Perches , Andrew Morton From: Sinan Kaya Message-ID: <56FA7BC9.2010903@codeaurora.org> Date: Tue, 29 Mar 2016 08:57:45 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2121 Lines: 50 On 3/29/2016 8:44 AM, Stefano Stabellini wrote: > Could you please explain what is the problem that you are trying to > solve? In other words, what is the issue with assuming that physical > address = dma address (and the current dma_to_phys and phys_to_dma > static inlines) if no arm64 platforms violate it? That's pretty much > what is done on x86 too (without X86_DMA_REMAP). > > If you want to make sure that the assumption is not violated, you can > introduce a boot time check or a BUG_ON somewhere. > > If there is an arm64 platform with phys_addr != dma_addr, we need proper > support for it. In fact even if there is an IOMMU on that platform, when > running Xen on it, the IOMMU would be used by the hypervisor and Linux > would still end up without it, using the swiotlb. The problem is that device drivers are trying to use dma_to_phys and phys_to_dma APIs to do address translation even though these two API do not exist in DMA mapping layer. (see patch #1 and I made the same mistake in my HIDMA code) Especially, when a device is behind an IOMMU; the DMA addresses are not equal to physical addresses. Usage of dma_to_phys causes a crash on the system. I'm trying to prefix the dma_to_phys and phys_to_dma API with swiotlb so that we know what it is intended for and usage of these API in drivers need to be discouraged in the future during code reviews. Since I renamed the API, Robin Murphy made a suggestion to convert this phys_to_virt(swiotlb_dma_to_phys(dev, dma_handle)) to this #define swiotlb_to_virt(addr) phys_to_virt((phys_addr_t)(addr)) swiotlb_to_virt(dma_handle) just to reduce code clutter since we know swiotlb_dma_to_phys returns phys already for ARM64 architecture. I think we can do this exercise later. I'll undo this change for the moment. Let's focus on the API rename. I don't want this general purpose dma_to_phys API returning phys=dma value. This is not correct. -- Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project